75{
78
80 string usr;
81 string pwd;
82 string cookie;
83 string id;
85 string detectorFile;
87 int run;
88 string variant;
90 double precision;
92
93 try {
94
95 JParser<> zap(
"Auxiliary program to download or update detector from database.");
96
101 zap[
'D'] =
make_field(
id,
"detector identifier") =
"";
102 zap[
'r'] =
make_field(run,
"run number") = -1;
103 zap[
'@'] =
make_field(calset,
"calibration sets \"<key> = <value>[; <key> = <value>]\"" << endl
111 zap[
'W'] =
make_field(wizzard,
"-W add base modules; -WW set time offsets of acoustic sensors");
114
115 zap(argc, argv);
116 }
117 catch(const exception &error) {
118 FATAL(error.what() << endl);
119 }
120
121
123
124 for (vector<JEquation_t>::const_iterator i = calset.begin(); i != calset.end(); ++i) {
125
127 FATAL(
"Invalid calibration set \"" << i->getKey() <<
"\"" << endl);
128 else
130 }
131
135 FATAL(
"Inconsistent specificaton of calibration sets, either {}, {t,p,r}cal or {t,p,r,a,c,s}cal.");
136 }
137
138 const bool file = (detectorFile != "");
151 const bool daq = (run != -1);
152
153 if (file &&
id !=
"") {
FATAL(
"Inconsistent specificaton of detector file and detector identifier."); }
154 if (file && tpr) {
FATAL(
"Inconsistent specificaton of detector file and {t,p,r}cal calibration sets."); }
155 if (file && tpracs) {
FATAL(
"Inconsistent specificaton of detector file and {t,p,r,a,c,s}cal calibration sets."); }
156 if (file && daq) {
FATAL(
"Inconsistent specificaton of detector file and run number."); }
157
158 if (tpr &&
id ==
"") {
FATAL(
"Inconsistent specificaton of {t,p,r}cal calibration sets and no detector identifier."); }
159 if (tpr && variant !=
"") {
FATAL(
"Inconsistent specificaton of {t,p,r}cal calibration sets and variant."); }
160 if (tpr && daq) {
FATAL(
"Inconsistent specificaton of {t,p,r}cal calibration sets and run number."); }
161
162 if (tpracs &&
id ==
"") {
FATAL(
"Inconsistent specificaton of {t,p,r,a,c,s}cal calibration sets and no detector identifier."); }
163 if (tpracs && variant ==
"") {
FATAL(
"Inconsistent specificaton of {t,p,r,a,c,s}cal calibration sets and no variant."); }
164 if (tpracs && daq) {
FATAL(
"Inconsistent specificaton of {t,p,r,a,c,s}cal calibration sets and run number."); }
165
166 if (daq &&
id ==
"") {
FATAL(
"Inconsistent specificaton of run number and no detector identifier."); }
167
168 if (wizzard &&
169 variant != "" &&
171 FATAL(
"Inconsistent detector variant and option -W.");
172 }
173
174 try {
175 JDB::reset(usr, pwd, cookie);
176 }
177 catch(const exception& error) {
178 FATAL(error.what() << endl);
179 }
180
182
183 try {
184
185 if (file)
187 else if (tpr)
188 *(JDB::get()->DetX)(id.c_str(),
192 else if (tpracs)
193 *(JDB::get()->DetX)(id.c_str(),
201 else if (daq && variant == "")
202 *(JDB::get()->DetX)(
id.c_str(), run) >>
detector;
203 else if (daq && variant != "")
205 else
206 FATAL(
"Invalid options.");
207 }
208 catch(const exception& error) {
209 FATAL(error.what() << endl);
210 }
211
212
214
215 if (
detector.setToLatestVersion()) {
216 NOTICE(
"Set detector version to " <<
detector.getVersion() << endl);
217 }
218
219
220 if (wizzard) {
221
223
224 try {
225
227
229
231
232 rs >> clbmap;
233
234 rs.Close();
235 }
236 catch(const exception& error) {
237 FATAL(error.what() << endl);
238 }
239
241
242 for (JDetector::const_iterator module =
detector.begin(); module !=
detector.end(); ++module) {
243 zmap[module->getString()][module->getFloor()] = module->getPosition();
244 }
245
246 for (vector<JCLBMap>::const_iterator i = clbmap.begin(); i != clbmap.end(); ++i) {
247
248 if (i->FLOORID == 0) {
249
251
253
254 if (zmap[i->DUID].count(1) != 0) {
255
257
258 module.setPosition(JPosition3D(zmap[i->DUID][1].getX(),
259 zmap[i->DUID][1].getY(),
260 isARCADetector(detector) ? ARCA_TBARZ_M :
261 isORCADetector(detector) ? ORCA_TBARZ_M :
262 0.0));
263
264 NOTICE(
"Adding module " << module << endl);
265
267
268 } else {
269
270 ERROR(
"Missing floor in string " <<
FILL(4,
'0') << i->DUID <<
FILL() << endl);
271 }
272
273 } else if (zmap[i->DUID].count(1) != 0) {
274
275 if (fabs(p->getX() - zmap[i->DUID][1].getX()) > precision ||
276 fabs(p->getY() - zmap[i->DUID][1].getY()) > precision) {
277
278 NOTICE(
"Offset module " <<
getLabel(p->getLocation()) <<
" (x,y) position "
279 <<
SCIENTIFIC(12,3) << (p->getX() - zmap[i->DUID][1].getX()) <<
' '
280 <<
SCIENTIFIC(12,3) << (p->getY() - zmap[i->DUID][1].getY()) << endl);
281
282 p->setPosition(
JPosition3D(zmap[i->DUID][1].getX(),
283 zmap[i->DUID][1].getY(),
284 p->getZ()));
285 }
286
287 } else {
288
289 FATAL(
"Missing floor in string " << setw(4) << i->DUID << endl);
290 }
291 }
292 }
293 }
294
295 if (wizzard > 1) {
296
297 try {
298
300
302
303 if (! (rs >> detector_t)) {
305 }
306
308
310
312
314
316
317 const JLocation_t location = router.getLocation(i->first);
318
319 JDetector::iterator p = find_if(
detector.begin(),
324
326
327 try {
328
330
331 if (t0 != p->getT0()) {
332
333 NOTICE(
"Set module time calibration " <<
getLabel(p->getLocation()) <<
' ' << setw(10) << p->getID() <<
' ' << setw(28) << left << i->first << right <<
' ' <<
FIXED(12,3) << t0 << endl);
334
335 p->setCalibration(t0);
336 }
337 }
338 catch(const exception& error) {
339 if (i->first.getVariant() != NOPIEZO) {
340 ERROR(location <<
' ' << error.what() << endl);
341 }
342 }
343
344 } else {
345
346 ERROR(
"No module for UPI " << i->first <<
" at " << location << endl);
347 }
348 }
349 }
350 }
351 catch(const exception& error) {
352 FATAL(error.what() << endl);
353 }
354 }
355
358 else
360}
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Auxiliary class for specifying selection of database data.
JSelector & add(const JSelector &selection)
Add selection.
double getT0() const
Get time offset.
Logical location of module.
const JLocation & getLocation() const
Get location.
Data structure for a composite optical module.
Data structure for position in three dimensions.
int getID() const
Get identifier.
Utility class to parse command line options.
static const JPBS_t HYDROPHONE(4, 5)
PBS of hydrophone
static const JPBS_t ACOUSTIC_SENSOR(3, 4, 3, 6, 2)
PBS of piezo sensor
ResultSet & getResultSet(const std::string &query)
Get result set.
static JGetPBSSequences getPBSSequences
Function object to get PBS sequences as a function of PBS.
const char * getTable()
Get table name.
JDetectorsHelper & getDetector()
Auxiliary function for helper object initialisation.
std::vector< JServer > getServernames()
Get list of names of available database servers.
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications.
static const JGetDetectorVersion getDetectorVersion
Function object to map detector version to numerical value.
void load(const std::string &file_name, JDetector &detector)
Load detector from input file.
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
std::vector< T > getDetectorVersions()
Get detector versions.
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
std::iterator_traits< T >::value_type getAverage(T __begin, T __end)
Get average.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static const std::string TCAL
PMT time offsets.
static const std::string PCAL
(optical|base) module positions
static const std::string SCAL
(module|PMT) status
static const std::string RCAL
optical module orientations
static const std::string ACAL
acoustic time offsets (piezo sensor or hydrophone)
static const std::string CCAL
compass alignment (a.k.a. quaternion calibration)
Auxiliary data structure for sequence of same character.
Auxiliary data structure for floating point format specification.
map_type::const_iterator range_const_iterator
void configure(const std::string &detid, const bool option=false)
Configure detector integration for given detector identifier.
range_type find(const JUPI_t &upi) const
Find range of products with given UPI.
Auxiliary data structure for location of product in detector.
int string
position in detector
int floor
position in string
Product breakdown structure (PBS).
Auxiliary class to map UPI to location in detector.
Wrapper class for server name.
Template definition for getting table specific selector.
@ V4
Version with quaternion and time offset per module.
Auxiliary data structure for streaming of STL containers.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
std::string nick_name
nick name (e.g. "xcal")
Auxiliary data structure for correspondence between nick and full name of calibration types.
bool hasNickname(const std::string &type) const
Has calibration type.
Auxiliary data structure for floating point format specification.