Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDetectorDB.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 #include <map>
6 #include <algorithm>
7 
8 #include "JDB/JDB.hh"
9 #include "JDB/JSelector.hh"
11 #include "JDB/JCLBMap.hh"
12 #include "JDB/JDBToolkit.hh"
13 
14 #include "JDetector/JDetector.hh"
17 
18 #include "JLang/JComparator.hh"
19 #include "JLang/JPredicate.hh"
20 
21 #include "JSupport/JMeta.hh"
22 
23 #include "Jeep/JPrint.hh"
24 #include "Jeep/JParser.hh"
25 #include "Jeep/JMessage.hh"
26 
27 
28 /**
29  * \file
30  *
31  * Auxiliary program to print detector from database.
32  * \author mdejong
33  */
34 int main(int argc, char **argv)
35 {
36  using namespace std;
37  using namespace JPP;
38 
39  string usr;
40  string pwd;
41  string cookie;
42  string id;
43  string tcalset;
44  string pcalset;
45  string rcalset;
46  string detectorFile;
47  string outputFile;
48  int run;
49  bool wizzard;
50  int debug;
51 
52  try {
53 
54  JParser<> zap("Auxiliary program to print detector from database.");
55 
56  zap['u'] = make_field(usr) = "";
57  zap['!'] = make_field(pwd) = "";
58  zap['C'] = make_field(cookie) = "";
59  zap['D'] = make_field(id, "detector identifier") = "";
60  zap['r'] = make_field(run, "run number") = -1;
61  zap['t'] = make_field(tcalset, "tcal: t0 (time offsets) calibration set from DB") = "";
62  zap['p'] = make_field(pcalset, "pcal: position (x,y,z) calibration set from DB") = "";
63  zap['q'] = make_field(rcalset, "rcal: orientation (quarterions) calibration set from DB") = "";
64  zap['a'] = make_field(detectorFile) = "";
65  zap['o'] = make_field(outputFile) = "";
66  zap['W'] = make_field(wizzard);
67  zap['d'] = make_field(debug) = 2;
68 
69  zap(argc, argv);
70  }
71  catch(const exception &error) {
72  FATAL(error.what() << endl);
73  }
74 
75 
76  const int file = ((detectorFile != "" ? 1 : 0));
77  const int calset = ((tcalset.empty() ? 0 : 1) +
78  (pcalset.empty() ? 0 : 1) +
79  (rcalset.empty() ? 0 : 1));
80  const int daq = ((run != -1 ? 1 : 0));
81 
82  if (file != 0 && (file != 1)) { FATAL("Inconsistent specificaton of detector file."); }
83  if (calset != 0 && (calset != 3 || id == "")) { FATAL("Inconsistent specificaton of detector identifier, tcal, pcal and rcal calibration sets."); }
84  if (daq != 0 && (daq != 1 || id == "")) { FATAL("Inconsistent specificaton of detector identifier and run number."); }
85 
86  int np = 0;
87 
88  if (file == 1) { ++np; }
89  if (calset == 3) { ++np; }
90  if (daq == 1) { ++np; }
91 
92  if (np != 1) { FATAL("Specify detector file; OR detector identifier, tcal, pcal and rcal calibration set; OR detector identifier and run number."); }
93 
94 
95  try {
96  JDB::reset(usr, pwd, cookie);
97  }
98  catch(const exception& error) {
99  FATAL(error.what() << endl);
100  }
101 
103 
104  try {
105 
106  if (file == 1)
107  load(detectorFile, detector);
108  else if (calset == 3)
109  *(JDB::get()->DetX)(id.c_str(), tcalset.c_str(), pcalset.c_str(), rcalset.c_str()) >> detector;
110  else if (daq == 1)
111  *(JDB::get()->DetX)(id.c_str(), run) >> detector;
112  }
113  catch(const exception& error) {
114  FATAL(error.what() << endl);
115  }
116 
117  detector.comment.add(JMeta(argc,argv));
118 
119  if (detector.setToLatestVersion()) {
120  NOTICE("Set detector version to " << detector.getVersion() << endl);
121  }
122 
123  if (wizzard) {
124 
125  vector<JCLBMap> clbmap;
126 
127  try {
128 
129  JSelector selector = getSelector<JCLBMap>(getDetector(detector.getID()));
130 
131  selector.add(&JCLBMap::FLOORID, 0);
132 
133  ResultSet& rs = getResultSet(getTable<JCLBMap>(), selector);
134 
135  rs >> clbmap;
136 
137  rs.Close();
138  }
139  catch(const exception& error) {
140  FATAL(error.what() << endl);
141  }
142 
144 
145  for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
146  zmap[module->getString()][module->getFloor()] = module->getPosition();
147  }
148 
149  for (vector<JCLBMap>::const_iterator i = clbmap.begin(); i != clbmap.end(); ++i) {
150 
151  JDetector::iterator p = find_if(detector.begin(), detector.end(), make_predicate(&JModule::getID, i->DOMID, JComparison::eq()));
152 
153  if (i->FLOORID == 0 && p == detector.end()) {
154 
155  JModule module(i->DOMID, JLocation(i->DUID, i->FLOORID));
156 
157  module.setPosition(JPosition3D(zmap[i->DUID].begin()->second.getX(),
158  zmap[i->DUID].begin()->second.getY(),
159  TBARZ_M));
160 
161  const double t0 = 0.0;
162 
163  module.setCalibration(t0 - HYDROPHONE_DELAYTIME_US * 1.0e+3);
164 
165  NOTICE("Adding module " << module << endl);
166 
167  detector.push_back(module);
168  }
169  }
170  }
171 
172  if (outputFile != "")
174  else
175  cout << detector;
176 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1500
JPredicate< JResult_t T::*, JComparison::eq > make_predicate(JResult_t T::*member, const JResult_t value)
Helper method to create predicate for data member.
Definition: JPredicate.hh:128
Data structure for a composite optical module.
Definition: JModule.hh:57
static const double HYDROPHONE_DELAYTIME_US
Hydrophone delay time [us].
static const double TBARZ_M
T-bar position relative to seabed [m].
Detector data structure.
Definition: JDetector.hh:80
T get(const JHead &header)
Get object from header.
Auxiliary class for specifying selection of database data.
string outputFile
Data structure for detector geometry and calibration.
JDetectorsHelper getDetector
Function object for mapping serial number to object identifier of detector and vice versa...
Definition: JDBToolkit.cc:5
I/O formatting auxiliaries.
Detector file.
Definition: JHead.hh:196
Detector toolkit.
Logical location of module.
Definition: JLocation.hh:37
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
JSelector & add(const JSelector &selection)
Add selection.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
ROOT I/O of application specific meta data.
#define NOTICE(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
Utility class to parse command line options.
void setCalibration(const JCalibration &cal)
Set calibration.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:269
Data structure for position in three dimensions.
Definition: JPosition3D.hh:36
do set_variable DETECTOR_TXT $WORKDIR detector
Template definition for getting table specific selector.
void setPosition(const JVector3D &pos)
Set position.
Definition: JPosition3D.hh:152
int main(int argc, char *argv[])
Definition: Main.cpp:15