Jpp 21.0.0
the software that should make you happy
Loading...
Searching...
No Matches
JSonDetector.cc File Reference

Auxiliary program to decompose detector to separate calibrations. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include "JDB/JDB.hh"
#include "JDB/JSelector.hh"
#include "JDB/JSelectorSupportkit.hh"
#include "JDB/JDBToolkit.hh"
#include "JDB/JDetectors.hh"
#include "JDB/JPersons.hh"
#include "JDB/JRuns.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorCalibration.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JDetectorSupportkit.hh"
#include "JTools/JRange.hh"
#include "JSon/JSon.hh"
#include "JSon/JSupport.hh"
#include "JLang/JVectorize.hh"
#include "JSystem/JDateAndTime.hh"
#include "Jeep/JeepToolkit.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 decompose detector to separate calibrations.

Note that the validity range is defined in the following order.

  1. option -V "<UTC min> <UTC max>";
  2. option -r "<first run> <last run>";
Author
mdejong

Definition in file JSonDetector.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 75 of file JSonDetector.cc.

76{
77 using namespace std;
78 using namespace JPP;
79
80 typedef JRange<time_t> JRange_t;
81
82 JServer server;
83 string usr;
84 string pwd;
85 string cookie;
86 string detectorFile;
87 string outputFile;
88 JRange_t validity;
89 JRange_t range;
90 double precision;
91 int debug;
92
93 try {
94
95 JParser<> zap("Auxiliary program to decompose detector to separate calibrations.");
96
97 zap['s'] = make_field(server) = getServernames();
98 zap['u'] = make_field(usr) = "";
99 zap['!'] = make_field(pwd) = "";
100 zap['C'] = make_field(cookie) = "";
101 zap['a'] = make_field(detectorFile, "detector file");
102 zap['o'] = make_field(outputFile, "detector calibrations file in JSON format."\
103 "\nFile name should contain wild card \'" << FILENAME_WILDCARD << "\' or"\
104 "\none of the key words: " << JEEPZ() << make_array(getCalibrationType.begin(),
105 getCalibrationType.end(),
106 &JCalibrationType::nick_name));
107 zap['V'] = make_field(validity, "validity range UTC [s], e.g. \"<UTC min> <UTC max>\"") = JRange_t(UTC_INVALID_S, UTC_INVALID_S);
108 zap['r'] = make_field(range, "run range e.g. \"<first run> <last run>\"") = JRange_t(RUN_INVALID, RUN_INVALID);
109 zap['p'] = make_field(precision, "precision for match with reference module") = 1.0e-5;
110 zap['d'] = make_field(debug) = 1;
111
112 zap(argc, argv);
113 }
114 catch(const exception &error) {
115 FATAL(error.what() << endl);
116 }
117
118
119
121
122 try {
123 load(detectorFile, detector);
124 }
125 catch(const JException& error) {
126 FATAL(error);
127 }
128
129 if (!hasDetectorAddressMap(detector.getID())) {
130 FATAL("No detector address map for detector identier " << detector.getID() << endl);
131 }
132
133 const JDetectorBuilder& demo = getDetectorBuilder(detector.getID());
134
135 string userid = "";
136 string detoid = "";
137 string locid = "";
138
139 try {
140
141 JDB::reset(usr, pwd, cookie);
142
143 {
144 ResultSet& rs = getResultSet(JPersons::getName(), getSelector<JPersons>(JDB::get()->User()));
145
146 for (JPersons object; rs >> object; ) {
147 userid = object.OID;
148 }
149
150 rs.Close();
151 }
152 {
153 ResultSet& rs = getResultSet(JDetectors::getName(), getSelector<JDetectors>(detector.getID()));
154
155 for (JDetectors object; rs >> object; ) {
156 locid = object.LOCATIONID;
157 detoid = object.OID;
158 }
159
160 rs.Close();
161 }
162
163 if (range.getLowerLimit() != RUN_INVALID && validity.getLowerLimit() == UTC_INVALID_S) {
164
165 ResultSet& rs = getResultSet(JRuns::getName(), getSelector<JRuns>(detector.getID(), range.getLowerLimit()));
166
167 for (JRuns object; rs >> object; ) {
168 validity.setLowerLimit(object.UNIXJOBSTART / 1000);
169 }
170
171 rs.Close();
172 }
173
174 if (range.getUpperLimit() != RUN_INVALID && validity.getUpperLimit() == UTC_INVALID_S) {
175
176 ResultSet& rs = getResultSet(JRuns::getName(), getSelector<JRuns>(detector.getID(), range.getUpperLimit()));
177
178 for (JRuns object; rs >> object; ) {
179 validity.setUpperLimit(object.UNIXJOBEND / 1000);
180 }
181
182 rs.Close();
183 }
184 }
185 catch(const exception& error) {
186 FATAL(error.what() << endl);
187 }
188
189
190 // Test compatibility of modules with reference(s).
191
192 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
193
194 if (module->getFloor() != 0) {
195
196 JModule buffer = demo.getModule(module->getID(), module->getLocation());
197
198 const JRotation3D R = getRotation(buffer, *module);
199
200 buffer.rotate(R);
201
202 if (!JModule::compare(buffer, *module, precision)) {
203
204 for (size_t i = 0; i != module->size(); ++i) {
205 DEBUG("PMT " << setw(2) << i << ' '
206 << (*module)[i].getDirection() << ' '
207 << buffer[i].getDirection() << ' '
208 << FIXED(7,3) << acos(getDot((*module)[i].getDirection(), buffer[i].getDirection())) * 180.0 / PI << " [deg]" << endl);
209 }
210
211 FATAL("Module " << setw(10) << module->getID() << ' ' << module->getLocation() << " incompatible with reference." << endl);
212 }
213 }
214 }
215
216 const json header = { { UserId_t, userid },
217 { TypeId_t, json() },
218 { LocationId_t, locid },
219 { DetOID_t, detoid },
220 { StartTime_t, JDateAndTime(true).toString() },
221 { EndTime_t, JDateAndTime(true).toString() },
222 getJSon(ValidFrom_t, validity.getLowerLimit()),
223 getJSon(ValidThrough_t, validity.getUpperLimit()) };
224
225 const json error = { {Message_t, "" },
226 {Code_t, OK_t },
227 {Arguments_t, json::array() } };
228
229
230 json js;
231
232 js[Comment_t] = json(detector.comment);
233 js[Error_t] = json(error);
234
235 if (hasWildCard(outputFile.c_str()) || outputFile.find(TCAL) != string::npos) {
236
238
239 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
240 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
241 data.push_back(JPMTCalibration_t(pmt->getID(), getCalibration(JCalibration(), *pmt)));
242 }
243 }
244
245 js[Data_t][0] = json(header);
246 js[Data_t][0][PMTT0s_t] = json(data);
247
249 }
250
251 if (hasWildCard(outputFile) || outputFile.find(PCAL) != string::npos) {
252
254
255 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
256
257 const JModule& buffer = demo.getModule(module->getID(), module->getLocation());
258
259 if (buffer.getFloor() == 0)
260 data[0].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
261 else
262 data[1].push_back(JModulePosition_t(module->getID(), getPosition(buffer, *module)));
263 }
264
265 js[Data_t][0] = json(header);
266 js[Data_t][0][BasePositions_t] = json(data[0]);
267 js[Data_t][0][DOMPositions_t] = json(data[1]);
268
270 }
271
272 if (hasWildCard(outputFile) || outputFile.find(RCAL) != string::npos) {
273
275
276 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
277
278 const JModule& buffer = demo.getModule(module->getID(), module->getLocation());
279
280 if (module->getFloor() != 0) {
281 data.push_back(JModuleRotation_t(module->getID(), getRotation(buffer, *module)));
282 }
283 }
284
285 js[Data_t][0] = json(header);
286 js[Data_t][0][DOMRotations_t] = json(data);
287
289 }
290
291 if (hasWildCard(outputFile) || outputFile.find(ACAL) != string::npos) {
292
294
295 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
296
297 if (module->getFloor() == 0)
298 data[0].push_back(JModuleCalibration_t(module->getID(), module->getT0()));
299 else
300 data[1].push_back(JModuleCalibration_t(module->getID(), module->getT0()));
301 }
302
303 js[Data_t][0] = json(header);
304 js[Data_t][0][BaseAcousticT0_t] = json(data[0]);
305 js[Data_t][0][DOMAcousticT0_t] = json(data[1]);
306
308 }
309
310 if (hasWildCard(outputFile) || outputFile.find(CCAL) != string::npos) {
311
313
314 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
315 if (module->getFloor() == 0)
316 data[0].push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
317 else
318 data[1].push_back(JCompassRotation_t(module->getID(), module->getQuaternion()));
319 }
320
321 js[Data_t][0] = json(header);
322 js[Data_t][0][BaseCompassRotations_t] = json(data[0]);
323 js[Data_t][0][DOMCompassRotations_t] = json(data[1]);
324
326 }
327
328 if (hasWildCard(outputFile) || outputFile.find(SCAL) != string::npos) {
329
330 js[Data_t][0] = json(header);
331
332 {
334
335 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
336 for (JModule::const_iterator pmt = module->begin(); pmt != module->end(); ++pmt) {
337 data.push_back(JPMTStatus_t(pmt->getID(), pmt->getStatus()));
338 }
339 }
340
341 js[Data_t][0][PMTStatusInfo_t ] = json(data);
342 }
343 {
345
346 for (JDetector::const_iterator module = detector.begin(); module != detector.end(); ++module) {
347 if (module->getFloor() == 0)
348 data[0].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
349 else
350 data[1].push_back(JModuleStatus_t(module->getID(), module->getStatus()));
351 }
352
353 js[Data_t][0][BaseStatusInfo_t] = json(data[0]);
354 js[Data_t][0][DOMStatusInfo_t] = json(data[1]);
355 }
356
358 }
359
360 return 0;
361}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2107
nlohmann::json json
Data structure for time calibration.
Detector data structure.
Definition JDetector.hh:96
int getFloor() const
Get floor number.
Definition JLocation.hh:146
Data structure for a composite optical module.
Definition JModule.hh:76
void rotate(const JRotation3D &R)
Rotate module.
Definition JModule.hh:315
General exception.
Definition JException.hh:25
Utility class to parse command line options.
Definition JParser.hh:1664
Range of values.
Definition JRange.hh:42
JDirection3D getDirection(const Vec &dir)
Get direction.
JPosition3D getPosition(const Vec &pos)
Get position.
ResultSet & getResultSet(const std::string &query)
Get result set.
Definition JDB.hh:442
std::vector< JServer > getServernames()
Get list of names of available database servers.
Definition JDB.hh:108
JDetectorBuilder & getDetectorBuilder()
Get detector builder.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
JCalibration getCalibration(const JCalibration &first, const JCalibration &second)
Get calibration to go from first to second calibration.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
bool hasDetectorAddressMap(const int id)
Check if detector address map is available.
std::string setWildCard(const std::string &file_name, const std::string &value)
Get file name by setting wild card to given value.
bool hasWildCard(const std::string &file_name)
Check presence of wild card.
double getDot(const JFirst_t &first, const JSecond_t &second)
Get dot product of objects.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:448
Detector file.
Definition JHead.hh:227
Wrapper class for server name.
Definition JDB.hh:54
Template definition for getting table specific selector.
Auxiliary data structure for compass rotation.
Auxiliary interface for building detector.
const JModule & getModule(const int id=-1, const JLocation &location=JLocation()) const
Get module.
Auxiliary data structure for module time calibration.
Auxiliary data structure for module position.
Auxiliary data structure for module rotation.
Auxiliary data structure for module status.
Auxiliary data structure for PMT time calibration.
Auxiliary data structure for PMT status.
Auxiliary data structure for streaming of STL containers.
Auxiliary data structure for correspondence between nick and full name of calibration types.
Auxiliary class for date and time.
std::string toString() const
Get ASCII formatted date and time.