Jpp  master_rocky
the software that should make you happy
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

◆ main()

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(),
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 
170 
171  } else {
172 
173  for (const auto& element : calibration) {
174 
175  json buffer;
176 
177  get_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 }
string outputFile
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
#define ERROR(A)
Definition: JMessage.hh:66
#define NOTICE(A)
Definition: JMessage.hh:64
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:63
nlohmann::json json
Detector data structure.
Definition: JDetector.hh:96
Utility class to parse command line options.
Definition: JParser.hh:1698
void get_json(json &js, const std::string &query)
Get json.
Definition: JDB.hh:462
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition: JDB.hh:107
static const JGetDetectorVersion getDetectorVersion
Function object to map detector version to numerical value.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
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
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
Definition: JeepToolkit.hh:53
@ debug_t
debug
Definition: JMessage.hh:29
static const char FILENAME_WILDCARD
wild card character for file name substitution
Definition: JeepToolkit.hh:44
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
const char * getName()
Get ROOT name of given data type.
Definition: JRootToolkit.hh:62
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)
bool is_valid(const json &js)
Check validity of JSon data.
static const std::string DOM_POSITION_CALIBRATION_t
(optical|base) module positions
static const std::string STATUS_CALIBRATION_t
(module|PMT) status
static const std::string Data_t
static const std::string DOM_ROTATION_CALIBRATION_t
optical module orientations
static const std::string ACOUSTIC_T0_CALIBRATION_t
acoustic time offsets (piezo sensor or hydrophone)
void reset(T &value)
Reset value.
Definition: JSTDTypes.hh:14
Calibration.
Definition: JHead.hh:330
Detector file.
Definition: JHead.hh:227
Wrapper class for server name.
Definition: JDB.hh:53
Template definition for getting table specific selector.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:68
Auxiliary data structure for correspondence between nick and full name of calibration types.
const std::string & getNickname(const std::string &type) const
Get calibration type.
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:72