Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JBaseModuleWriter.cc File Reference

Auxiliary program to write base module data. More...

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <map>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JCLBMap.hh"
#include "JDB/JDBToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JBase.hh"
#include "JAcoustics/JAcousticsToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to write base module data.

Author
mdejong

Definition in file JBaseModuleWriter.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JBaseModuleWriter.cc.

31 {
32  using namespace std;
33  using namespace JPP;
34 
35  string usr;
36  string pwd;
37  string cookie;
38  string detectorFile;
39  string outputFile;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to write base module data.");
45 
46  zap['u'] = make_field(usr) = "";
47  zap['!'] = make_field(pwd) = "";
48  zap['C'] = make_field(cookie) = "";
49  zap['o'] = make_field(outputFile, "output file");
50  zap['a'] = make_field(detectorFile, "detector file");
51  zap['d'] = make_field(debug) = 1;
52 
53  zap(argc, argv);
54  }
55  catch(const exception &error) {
56  FATAL(error.what() << endl);
57  }
58 
59 
61 
62  try {
63  load(detectorFile, detector);
64  }
65  catch(const JException& error) {
66  FATAL(error);
67  }
68 
69 
70  vector<JCLBMap> clbmap;
71 
72  try {
73 
74  JDB::reset(usr, pwd, cookie);
75 
76  ResultSet& rs = getResultSet(getTable<JCLBMap>(), getSelector<JCLBMap>(getDetector(detector.getID())));
77 
78  if (! (rs >> clbmap)) {
79  THROW(JDatabaseException, "Error reading " << getTable<JCLBMap>());
80  }
81 
82  rs.Close();
83  }
84  catch(const exception& error) {
85  FATAL(error.what() << endl);
86  }
87 
88 
90 
91  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
92  if (module->getFloor() <= 2) {
93  zmap[module->getString()][module->getFloor()] = *module;
94  }
95  }
96 
97 
98  ofstream out(outputFile);
99 
100  for (vector<JCLBMap>::const_iterator i = clbmap.begin(); i != clbmap.end(); ++i) {
101 
102  if (i->FLOORID == 0) {
103 
104  const double z0 = 0.0;
105  const double z1 = zmap[i->DUID][1].getZ();
106  const double z2 = zmap[i->DUID][2].getZ();
107  const double t1 = getT0(zmap[i->DUID][1]);
108  const double t2 = getT0(zmap[i->DUID][2]);
109 
110  // linear extrapolation of time offsets
111 
112  const double t0 = t1 + (z0 - z1) * (t2 - t1) / (z2 - z1);
113 
114  out << setw(9) << i->DOMID << ' '
115  << setw(3) << i->DUID << ' '
116  << setw(2) << i->FLOORID << ' '
117  << FIXED(9,3) << zmap[i->DUID][1].getX() << ' '
118  << FIXED(9,3) << zmap[i->DUID][1].getY() << ' '
119  << FIXED(9,3) << z0 << ' '
120  << FIXED(12,3) << t0 << endl;
121  }
122  }
123 
124  out.close();
125 }
Utility class to parse command line options.
Definition: JParser.hh:1493
General exception.
Definition: JException.hh:23
Database exception.
Definition: JException.hh:648
Detector data structure.
Definition: JDetector.hh:80
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
Auxiliary data structure for floating point format specification.
Definition: JPrint.hh:481
string outputFile
Detector file.
Definition: JHead.hh:130
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
void load(const JString &file_name, JDetector &detector)
Load detector from input file.
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
double getT0(const JModule &module)
Get time offset of optical module.
static const JDetectorsHelper & getDetector
Function object for mapping serial number and object identifier of detectors.
Definition: JDBToolkit.hh:131
void reset(T &value)
Reset value.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
Template definition for getting table specific selector.