Jpp  18.0.0-rc.4
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 "JDetector/JDetectorSupportkit.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 71 of file JRunCalibration.cc.

72 {
73  using namespace std;
74  using namespace JPP;
75 
76  JServer server;
77  string usr;
78  string pwd;
79  string cookie;
80  string detid;
81  int run;
82  int ranking;
83  string variant;
84  string outputFile;
85  vector<string> format;
86  int debug;
87 
88  try {
89 
90  JParser<> zap("Auxiliary program to download official detector.");
91 
92  zap['s'] = make_field(server) = getServernames();
93  zap['u'] = make_field(usr) = "";
94  zap['!'] = make_field(pwd) = "";
95  zap['C'] = make_field(cookie) = "";
96  zap['D'] = make_field(detid);
97  zap['r'] = make_field(run);
98  zap['R'] = make_field(ranking, "ranking (1 is best)") = 1;
99  zap['V'] = make_field(variant, "detector version") = getDetectorVersions<string>();
100  zap['o'] = make_field(outputFile, "detector file or JSon files (must then contain wildcard \'" << FILENAME_WILD_CARD << "\')") = "";
101  zap['F'] = make_field(format, "column names: "
102  << RUN_t << ' '
103  << PMT_T0_CALIBRATION_t << ' '
106  << ACOUSTIC_T0_CALIBRATION_t << ' '
107  << COMPASS_CALIBRATION_t << ' '
109  zap['d'] = make_field(debug) = 1;
110 
111  zap(argc, argv);
112  }
113  catch(const exception &error) {
114  FATAL(error.what() << endl);
115  }
116 
117  try {
118 
119  JDB::reset(usr, pwd, cookie);
120 
121  detid = getDetector<string>(detid);
122 
123  json js;
124 
126 
127  DEBUG(setw(2) << js << endl);
128 
129  if (!is_valid(js)) {
130  FATAL("JSon error code not okay." << endl);
131  }
132 
133  if (!js.contains(Data_t) || js[Data_t].empty()) {
134  FATAL("JSon output does not contain data." << endl);
135  }
136 
137  const calibration_type calibration = js[Data_t].get<calibration_type>();
138 
139  if (debug >= debug_t) {
140  for (const auto& element : calibration) {
141  cout << setw(24) << left << element.CalibrationType << ' ' << right << element.CalibrationId << endl;
142  }
143  }
144 
145  if (outputFile != "") {
146 
147  if (!hasWildCard(outputFile)) {
148 
150 
151  *(JDB::get()->DetX)(detid.c_str(),
152  calibration[PMT_T0_CALIBRATION_t] .c_str(),
153  calibration[DOM_POSITION_CALIBRATION_t].c_str(),
154  calibration[DOM_ROTATION_CALIBRATION_t].c_str(),
155  calibration[ACOUSTIC_T0_CALIBRATION_t] .c_str(),
156  calibration[COMPASS_CALIBRATION_t] .c_str(),
157  calibration[STATUS_CALIBRATION_t] .c_str(),
158  getDetectorVersion(variant)) >> detector;
159 
160  detector.comment.add(JMeta(argc,argv));
161 
163  detector.comment.add(MAKE_STRING(i << "=" << calibration[i]));
164  }
165 
166  if (detector.setToLatestVersion()) {
167  NOTICE("Set detector version to " << detector.getVersion() << endl);
168  }
169 
170  store(outputFile, detector);
171 
172  } else {
173 
174  for (const auto& element : calibration) {
175 
176  json buffer;
177 
178  to_json(buffer, APIV2::JCalibration_t::getName(), getSelector<APIV2::JCalibration_t>(detid, element.CalibrationId));
179 
180  if (is_valid(buffer))
181  store(setWildCard(outputFile.c_str(), getCalibrationType.getNickname(element.CalibrationType)), buffer);
182  else
183  ERROR("Invalid JSon data " << setw(2) << buffer);
184  }
185  }
186  }
187 
188  if (!format.empty()) {
189 
190  for (vector<string>::const_iterator i = format.begin(); i != format.end(); ++i) {
191 
192  if (*i == RUN_t)
193  cout << ' ' << run;
194  else
195  cout << ' ' << calibration[*i];
196  }
197 
198  cout << endl;
199  }
200  }
201  catch(const exception& error) {
202  FATAL(error.what() << endl);
203  }
204 
205  return 0;
206 }
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
#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
static const char FILENAME_WILD_CARD
wild card character for file name substitution
Definition: JeepToolkit.hh:44
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:57
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 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