Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDetCalibrations.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <map>
5 
6 #include "JDB/JDB.hh"
7 #include "JDB/JSelector.hh"
10 #include "JDB/JDBToolkit.hh"
11 
12 #include "JDetector/JDetector.hh"
14 
15 #include "JSon/JSupport.hh"
16 
17 #include "JSupport/JMeta.hh"
18 
19 #include "Jeep/JPrint.hh"
20 #include "Jeep/JParser.hh"
21 #include "Jeep/JMessage.hh"
22 
23 
24 /**
25  * \file
26  *
27  * Auxiliary program to download default detector from database.
28  * \author mdejong
29  */
30 int main(int argc, char **argv)
31 {
32  using namespace std;
33  using namespace JPP;
34 
35  JServer server;
36  string usr;
37  string pwd;
38  string cookie;
39  string id;
40  string outputFile;
41  string variant;
42  int debug;
43 
44  try {
45 
46  JParser<> zap("Auxiliary program to download default detector from database.");
47 
48  zap['s'] = make_field(server) = getServernames();
49  zap['u'] = make_field(usr) = "";
50  zap['!'] = make_field(pwd) = "";
51  zap['C'] = make_field(cookie) = "";
52  zap['D'] = make_field(id, "detector identifier");
53  zap['o'] = make_field(outputFile);
54  zap['V'] = make_field(variant, "detector version") = getDetectorVersions<string>();
55  zap['d'] = make_field(debug) = 2;
56 
57  zap(argc, argv);
58  }
59  catch(const exception &error) {
60  FATAL(error.what() << endl);
61  }
62 
63 
64  try {
65 
66  JDB::reset(usr, pwd, cookie);
67 
68  id = getDetector<string>(id);
69 
70  ResultSet& rs = getResultSet(getTable<JDetCalibrations>(), getSelector<JDetCalibrations>(id));
71 
73 
74  for (JDetCalibrations buffer; rs >> buffer; ) {
75 
76  const string type = getCalibrationType.getNickname(buffer.OPTYPE);
77 
78  if (calibration.count(type) == 0 || calibration[type].STARTTIME < buffer.STARTTIME) {
79  calibration[type] = buffer;
80  }
81  }
82 
83  rs.Close();
84 
85  JDetector detector;
86 
87  detector.comment.add(JMeta(argc,argv));
88 
89  for (const auto& key : { TCAL, PCAL, RCAL, ACAL, CCAL, SCAL }) {
90 
91  if (calibration.count(key) == 0) {
92  FATAL("Missing " << key << " calibration." << endl);
93  }
94 
95  detector.comment.add(MAKE_STRING(key << " = " << calibration[key].OPERATIONID));
96  }
97 
98  *(JDB::get()->DetX)(id.c_str(),
99  calibration[TCAL].OPERATIONID.c_str(),
100  calibration[PCAL].OPERATIONID.c_str(),
101  calibration[RCAL].OPERATIONID.c_str(),
102  calibration[ACAL].OPERATIONID.c_str(),
103  calibration[CCAL].OPERATIONID.c_str(),
104  calibration[SCAL].OPERATIONID.c_str(),
105  getDetectorVersion(variant)) >> detector;
106 
107  store(outputFile.c_str(), detector);
108  }
109  catch(const exception& error) {
110  FATAL(error.what() << endl);
111  }
112 }
Utility class to parse command line options.
Definition: JParser.hh:1711
int main(int argc, char *argv[])
Definition: Main.cc:15
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
string outputFile
Data structure for detector geometry and calibration.
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
then set_variable PMT_FILE set_variable DAQ_FILE set_variable OUTPUT_FILE set_variable DETECTOR else fatal Wrong number of arguments fi JPrintTree f $DAQ_FILE type
static const std::string TCAL
PMT time offsets.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
ROOT I/O of application specific meta data.
JSon definitions and auxiliaries.
static const std::string RCAL
optical module orientations
General purpose messaging.
static const JGetDetectorVersion getDetectorVersion
Function object to map detector version to numerical value.
#define FATAL(A)
Definition: JMessage.hh:67
void reset(T &value)
Reset value.
const std::string & getNickname(const std::string &type) const
Get calibration type.
Utility class to parse command line options.
static const std::string SCAL
(module|PMT) status
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition: JDB.hh:436
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:106
do set_variable DETECTOR_TXT $WORKDIR detector
static const std::string PCAL
(optical|base) module positions
JSON::getCalibrationType getCalibrationType
int debug
debug level