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
Functions
JDetCalibrations.cc File Reference

Auxiliary program to download default detector from database. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDetCalibrations.hh"
#include "JDB/JDBToolkit.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JSon/JSupport.hh"
#include "JSupport/JMeta.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 download default detector from database.

Author
mdejong

Definition in file JDetCalibrations.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file JDetCalibrations.cc.

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
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
#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.
#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.
static const std::string RCAL
optical module orientations
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.
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