Jpp  18.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JRunCalibration.cc File Reference

Auxiliary program to download official detector. More...

#include <iostream>
#include <iomanip>
#include <algorithm>
#include "dbclient/KM3NeTDBClient.h"
#include "JDB/JDB.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JCalibration.hh"
#include "JDB/JRunCalibration.hh"
#include "JDB/JSonSupportkit.hh"
#include "JSon/JSon.hh"
#include "JSon/JSupport.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JLang/JException.hh"
#include "JLang/JPredicate.hh"
#include "JLang/JManip.hh"
#include "JSupport/JMeta.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 official detector.

Author
mdejong

Definition in file JRunCalibration.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 70 of file JRunCalibration.cc.

71 {
72  using namespace std;
73  using namespace JPP;
74 
75  JServer server;
76  string usr;
77  string pwd;
78  string cookie;
79  string detid;
80  int run;
81  int ranking;
82  string variant;
83  string outputFile;
84  vector<string> format;
85  int debug;
86 
87  try {
88 
89  JParser<> zap("Auxiliary program to download official detector.");
90 
91  zap['s'] = make_field(server) = getServernames();
92  zap['u'] = make_field(usr) = "";
93  zap['!'] = make_field(pwd) = "";
94  zap['C'] = make_field(cookie) = "";
95  zap['D'] = make_field(detid);
96  zap['r'] = make_field(run);
97  zap['R'] = make_field(ranking, "ranking (1 is best)") = 1;
98  zap['V'] = make_field(variant, "detector version") = getDetectorVersions<string>();
99  zap['o'] = make_field(outputFile, "detector file or JSon files (must then contain wildcard \'" << FILENAME_WILDCARD << "\')") = "";
100  zap['F'] = make_field(format, "column names: "
101  << RUN_t << ' '
102  << PMT_T0_CALIBRATION_t << ' '
105  << ACOUSTIC_T0_CALIBRATION_t << ' '
106  << COMPASS_CALIBRATION_t << ' '
108  zap['d'] = make_field(debug) = 1;
109 
110  zap(argc, argv);
111  }
112  catch(const exception &error) {
113  FATAL(error.what() << endl);
114  }
115 
116  try {
117 
118  JDB::reset(usr, pwd, cookie);
119 
120  detid = getDetector<string>(detid);
121 
122  json js;
123 
125 
126  DEBUG(setw(2) << js << endl);
127 
128  if (!is_valid(js)) {
129  FATAL("JSon error code not okay." << endl);
130  }
131 
132  if (!js.contains(Data_t) || js[Data_t].empty()) {
133  FATAL("JSon output does not contain data." << endl);
134  }
135 
136  const calibration_type calibration = js[Data_t].get<calibration_type>();
137 
138  if (debug >= debug_t) {
139  for (const auto& element : calibration) {
140  cout << setw(24) << left << element.CalibrationType << ' ' << right << element.CalibrationId << endl;
141  }
142  }
143 
144  if (outputFile != "") {
145 
146  if (!hasWildCard(outputFile)) {
147 
149 
150  *(JDB::get()->DetX)(detid.c_str(),
151  calibration[PMT_T0_CALIBRATION_t] .c_str(),
152  calibration[DOM_POSITION_CALIBRATION_t].c_str(),
153  calibration[DOM_ROTATION_CALIBRATION_t].c_str(),
154  calibration[ACOUSTIC_T0_CALIBRATION_t] .c_str(),
155  calibration[COMPASS_CALIBRATION_t] .c_str(),
156  calibration[STATUS_CALIBRATION_t] .c_str(),
157  getDetectorVersion(variant)) >> detector;
158 
159  detector.comment.add(JMeta(argc,argv));
160 
162  detector.comment.add(MAKE_STRING(i << "=" << calibration[i]));
163  }
164 
165  if (detector.setToLatestVersion()) {
166  NOTICE("Set detector version to " << detector.getVersion() << endl);
167  }
168 
169  store(outputFile, detector);
170 
171  } else {
172 
173  for (const auto& element : calibration) {
174 
175  json buffer;
176 
177  to_json(buffer, APIV2::JCalibration_t::getName(), getSelector<APIV2::JCalibration_t>(detid, element.CalibrationId));
178 
179  if (is_valid(buffer))
180  store(setWildCard(outputFile.c_str(), getCalibrationType.getNickname(element.CalibrationType)), buffer);
181  else
182  ERROR("Invalid JSon data " << setw(2) << buffer);
183  }
184  }
185  }
186 
187  if (!format.empty()) {
188 
189  for (vector<string>::const_iterator i = format.begin(); i != format.end(); ++i) {
190 
191  if (*i == RUN_t)
192  cout << ' ' << run;
193  else
194  cout << ' ' << calibration[*i];
195  }
196 
197  cout << endl;
198  }
199  }
200  catch(const exception& error) {
201  FATAL(error.what() << endl);
202  }
203 
204  return 0;
205 }
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:1514
debug
Definition: JMessage.hh:29
static const std::string STATUS_CALIBRATION_t
(module|PMT) status
bool is_valid(const json &js)
Check validity of JSon data.
Detector data structure.
Definition: JDetector.hh:89
static const std::string DOM_ROTATION_CALIBRATION_t
optical module orientations
bool setToLatestVersion()
Set to latest version.
Definition: JDetector.hh:170
T get(const JHead &header)
Get object from header.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
Auxiliary data structure for correspondence between nick and full name of calibration types...
const std::string & getVersion() const
Get version.
string outputFile
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:127
Calibration.
Definition: JHead.hh:328
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
static const std::string PMT_T0_CALIBRATION_t
PMT time offsets.
static const std::string COMPASS_CALIBRATION_t
compass alignment (a.k.a. quaternion calibration)
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
static const JGetDetectorVersion getDetectorVersion
Function object to map detector version to numerical value.
static const std::string DOM_POSITION_CALIBRATION_t
(optical|base) module positions
#define FATAL(A)
Definition: JMessage.hh:67
std::string setWildCard(const std::string &file_name, const std::string &value)
Get file name by setting wild card to given value.
Definition: JeepToolkit.hh:66
void reset(T &value)
Reset value.
const std::string & getNickname(const std::string &type) const
Get calibration type.
static const std::string Data_t
nlohmann::json json
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:106
Wrapper class for server name.
Definition: JDB.hh:50
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:60
JComment & add(const std::string &comment)
Add comment.
Definition: JComment.hh:100
do set_variable DETECTOR_TXT $WORKDIR detector
void to_json(json &js, const std::string &query)
Get result set.
Definition: JDB.hh:461
static const char FILENAME_WILDCARD
wild card character for file name substitution
Definition: JeepToolkit.hh:44
static const std::string ACOUSTIC_T0_CALIBRATION_t
acoustic time offsets (piezo sensor or hydrophone)
Template definition for getting table specific selector.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53