/[PAMELA software]/YodaProfiler/src/GLTables.cpp
ViewVC logotype

Contents of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download)
Tue Oct 24 14:24:22 2006 UTC (18 years, 1 month ago) by mocchiut
Branch: MAIN
Changes since 1.13: +197 -10 lines
Bug fixed in GL_TIMESYNC

1 /**
2 * \file GLTables.cpp
3 * \author Elena Vannuccini
4 *
5 * The file contains implementation of the methods to query the DB.
6 */
7 //
8 #include <sstream>
9 #include <iostream>
10 //
11 #include <TFile.h>
12 #include <TTree.h>
13 #include <EventHeader.h>
14 #include <PscuHeader.h>
15 //
16 #include <GLTables.h>
17 #include <sgp4.h>
18 //
19 ClassImp(GL_TRK_CALIB);
20 ClassImp(GL_RUN);
21 ClassImp(GL_ROOT);
22 ClassImp(GL_PARAM);
23 ClassImp(GL_S4_CALIB);
24 ClassImp(GL_CALO_CALIB);
25 ClassImp(GL_TIMESYNC);
26 ClassImp(GL_TLE);
27 //
28 using namespace std;
29
30 GL_RUN::GL_RUN() {
31 ID = 0;
32 ID_RUN_FRAG = 0;
33 ID_ROOT_L0 = 0;
34 ID_ROOT_L2 = 0;
35 RUNHEADER_TIME = 0;
36 RUNTRAILER_TIME = 0;
37 EV_FROM = 0;
38 EV_TO = 0;
39 TRK_CALIB_USED = 0;
40 EFF_WRK_SCHEDULE = 0;
41 PRH_VAR_TRG_MODE_A = 0;
42 PRH_VAR_TRG_MODE_B = 0;
43 ACQ_BUILD_INFO = 0;
44 ACQ_VAR_INFO = 0;
45 RUNHEADER_OBT = 0;
46 RUNTRAILER_OBT = 0;
47 RUNHEADER_PKT = 0;
48 RUNTRAILER_PKT = 0;
49 NEVENTS = 0;
50 LAST_TIMESYNC = 0;
51 OBT_TIMESYNC = 0;
52 COMPILATIONTIMESTAMP = 0;
53 FAV_WRK_SCHEDULE = 0;
54 RM_ACQ_AFTER_CALIB = 0;
55 RM_ACQ_SETTING_MODE = 0;
56 PKT_COUNTER = 0;
57 PKT_READY_COUNTER = 0;
58 TRK_CALIB_USED = 0;
59 CAL_DSP_MASK = 0;
60 BOOT_NUMBER = 0;
61 VALIDATION = 0;
62 }
63
64
65 void GL_RUN::Clear() {
66 ID = 0;
67 ID_RUN_FRAG = 0;
68 ID_ROOT_L0 = 0;
69 ID_ROOT_L2 = 0;
70 RUNHEADER_TIME = 0;
71 RUNTRAILER_TIME = 0;
72 EV_FROM = 0;
73 EV_TO = 0;
74 TRK_CALIB_USED = 0;
75 EFF_WRK_SCHEDULE = 0;
76 PRH_VAR_TRG_MODE_A = 0;
77 PRH_VAR_TRG_MODE_B = 0;
78 ACQ_BUILD_INFO = 0;
79 ACQ_VAR_INFO = 0;
80 RUNHEADER_OBT = 0;
81 RUNTRAILER_OBT = 0;
82 RUNHEADER_PKT = 0;
83 RUNTRAILER_PKT = 0;
84 NEVENTS = 0;
85 LAST_TIMESYNC = 0;
86 OBT_TIMESYNC = 0;
87 COMPILATIONTIMESTAMP = 0;
88 FAV_WRK_SCHEDULE = 0;
89 RM_ACQ_AFTER_CALIB = 0;
90 RM_ACQ_SETTING_MODE = 0;
91 PKT_COUNTER = 0;
92 PKT_READY_COUNTER = 0;
93 TRK_CALIB_USED = 0;
94 CAL_DSP_MASK = 0;
95 BOOT_NUMBER = 0;
96 VALIDATION = 0;
97 }
98
99 GL_ROOT::GL_ROOT(){
100 ID = 0;
101 ID_RAW = 0;
102 ID_TIMESYNC = 0;
103 PATH = "";
104 NAME = "";
105 }
106
107 GL_PARAM::GL_PARAM(){
108 ID = 0;
109 PATH = "";
110 NAME = "";
111 DESCR = "";
112 FROM_TIME = 0;
113 TO_TIME = 0;
114 TYPE = 0;
115 }
116
117
118 GL_TRK_CALIB::GL_TRK_CALIB(){
119 ID = 0;
120 ID_ROOT_L0 = 0;
121 EV_ROOT_CALIBTRK1 = 0;
122 EV_ROOT_CALIBTRK2 = 0;
123 FROM_TIME = 0;
124 TO_TIME = 0;
125 OBT1 = 0;
126 OBT2 = 0;
127 PKT1 = 0;
128 PKT2 = 0;
129 BOOT_NUMBER = 0;
130 VALIDATION = 0;
131 }
132
133 GL_CALO_CALIB::GL_CALO_CALIB(){
134 ID = 0;
135 ID_ROOT_L0 = 0;
136 EV_ROOT = 0;
137 FROM_TIME = 0;
138 TO_TIME = 0;
139 SECTION = 0;
140 }
141
142 GL_S4_CALIB::GL_S4_CALIB(){
143 ID = 0;
144 ID_ROOT_L0 = 0;
145 EV_ROOT = 0;
146 FROM_TIME = 0;
147 TO_TIME = 0;
148 PARAM_FIT0 = 0.;
149 PARAM_FIT1 = 0.;
150 }
151
152 GL_TIMESYNC::GL_TIMESYNC(){
153 obtfirst = 0;
154 pktfirst = 0;
155 toffset = 0;
156 ID = 0;
157 ID_RAW = 0;
158 OBT0 = 0;
159 TIMESYNC = 0;
160 TYPE = 0;
161 }
162
163 GL_TLE::GL_TLE(){
164 }
165
166 // ****************************************************
167
168 void GL_RUN::SetEV_FROM(UInt_t evfrom){
169 EV_FROM = evfrom;
170 };
171
172 void GL_RUN::SetEV_TO(UInt_t evto){
173 EV_TO = evto;
174 };
175
176 void GL_RUN::SetNEVENTS(UInt_t nev){
177 NEVENTS = nev;
178 };
179
180 void GL_RUN::SetBOOTNUMBER(UInt_t boot){
181 BOOT_NUMBER = boot;
182 };
183
184 void GL_RUN::SetRUNHEADER_TIME(UInt_t absth){
185 RUNHEADER_TIME = absth;
186 };
187
188 void GL_RUN::SetRUNTRAILER_TIME(UInt_t abstt){
189 RUNTRAILER_TIME = abstt;
190 };
191
192 void GL_RUN::SetRUNHEADER_PKT(UInt_t absth){
193 RUNHEADER_PKT = absth;
194 };
195
196 void GL_RUN::SetRUNTRAILER_PKT(UInt_t abstt){
197 RUNTRAILER_PKT = abstt;
198 };
199
200 void GL_RUN::SetRUNHEADER_OBT(UInt_t absth){
201 RUNHEADER_OBT = absth;
202 };
203
204 void GL_RUN::SetRUNTRAILER_OBT(UInt_t abstt){
205 RUNTRAILER_OBT = abstt;
206 };
207
208 void GL_RUN::SetID_ROOT_L2(UInt_t idl2){
209 ID_ROOT_L2 = idl2;
210 };
211
212 void GL_RUN::SetID_ROOT_L0(UInt_t idroot){
213 ID_ROOT_L0 = idroot;
214 };
215
216 void GL_RUN::SetID_RUN_FRAG(UInt_t idfrag){
217 ID_RUN_FRAG = idfrag;
218 };
219
220 void GL_RUN::SetVALIDATION(UInt_t valid){
221 VALIDATION = valid;
222 };
223
224 void GL_RUN::SetLAST_TIMESYNC(UInt_t ts){
225 LAST_TIMESYNC = ts;
226 };
227
228 void GL_RUN::SetOBT_TIMESYNC(UInt_t ts){
229 OBT_TIMESYNC = ts;
230 };
231
232 void GL_RUN:: SetPKT_COUNTER(UInt_t value){
233 PKT_COUNTER = value;
234 };
235
236 void GL_RUN:: SetPKT_READY_COUNTER(UInt_t value){
237 PKT_READY_COUNTER = value;
238 };
239
240 void GL_RUN:: SetCOMPILATIONTIMESTAMP(UInt_t value){
241 COMPILATIONTIMESTAMP = value;
242 };
243
244 void GL_RUN:: SetFAV_WRK_SCHEDULE(UInt_t value){
245 FAV_WRK_SCHEDULE = value;
246 };
247
248 void GL_RUN:: SetEFF_WRK_SCHEDULE(UInt_t value){
249 EFF_WRK_SCHEDULE = value;
250 };
251
252 void GL_RUN:: SetPRH_VAR_TRG_MODE_A(UInt_t value){
253 PRH_VAR_TRG_MODE_A = value;
254 };
255
256 void GL_RUN:: SetPRH_VAR_TRG_MODE_B(UInt_t value){
257 PRH_VAR_TRG_MODE_B = value;
258 };
259
260 void GL_RUN:: SetACQ_BUILD_INFO(UInt_t value){
261 ACQ_BUILD_INFO = value;
262 };
263
264 void GL_RUN:: SetACQ_VAR_INFO(UInt_t value){
265 ACQ_VAR_INFO = value;
266 };
267
268 void GL_RUN:: SetRM_ACQ_AFTER_CALIB(UInt_t value){
269 RM_ACQ_AFTER_CALIB = value;
270 };
271
272 void GL_RUN:: SetRM_ACQ_SETTING_MODE(UInt_t value){
273 RM_ACQ_SETTING_MODE = value;
274 };
275
276 void GL_RUN:: SetTRK_CALIB_USED(UInt_t value){
277 TRK_CALIB_USED = value;
278 };
279
280 void GL_RUN:: SetCAL_DSP_MASK(UInt_t value){
281 CAL_DSP_MASK = value;
282 };
283
284 void GL_RUN:: SetID(UInt_t value){
285 ID = value;
286 };
287
288 void GL_RUN::Set_GL_RUNT(RunTrailerEvent *runt, PscuHeader *pht){
289 PKT_COUNTER = runt->PKT_COUNTER;
290 PKT_READY_COUNTER = runt->PKT_ReadyCounter;
291 RUNTRAILER_OBT = pht->GetOrbitalTime();
292 RUNTRAILER_PKT = pht->GetCounter();
293 };
294
295 void GL_RUN::Set_GL_RUNH(RunHeaderEvent *runh, PscuHeader *phh){
296 TRK_CALIB_USED = runh->TRK_CALIB_USED;
297 PRH_VAR_TRG_MODE_A = runh->PRH_VAR_TRIGGER_MODE_A;
298 PRH_VAR_TRG_MODE_B = runh->PRH_VAR_TRIGGER_MODE_B;
299 ACQ_BUILD_INFO = runh->ACQ_BUILD_INFO;
300 ACQ_VAR_INFO = runh->ACQ_VAR_INFO;
301 RUNHEADER_OBT = phh->GetOrbitalTime();
302 RUNHEADER_PKT = phh->GetCounter();
303 LAST_TIMESYNC = runh->LAST_TIME_SYNC_INFO;
304 OBT_TIMESYNC = runh->OBT_TIME_SYNC;
305 COMPILATIONTIMESTAMP = runh->COMPILATIONTIMESTAMP;
306 FAV_WRK_SCHEDULE = runh->FAVOURITE_WORKING_SCHEDULE;
307 EFF_WRK_SCHEDULE = runh->EFFECTIVE_WORKING_SCHEDULE;
308 RM_ACQ_AFTER_CALIB = runh->RM_ACQ_AFTER_CALIB;
309 RM_ACQ_SETTING_MODE = runh->RM_ACQ_SETTING_MODE;
310 TRK_CALIB_USED = runh->TRK_CALIB_USED;
311 CAL_DSP_MASK = runh->CAL_DSP_MASK;
312 };
313
314 void GL_RUN::Set_GL_RUNT0(){
315 PKT_COUNTER = 0;
316 PKT_READY_COUNTER = 0;
317 RUNTRAILER_OBT = 0;
318 RUNTRAILER_PKT = 0;
319 };
320
321 void GL_RUN::Set_GL_RUNH0(){
322 TRK_CALIB_USED = 0;
323 PRH_VAR_TRG_MODE_A = 0;
324 PRH_VAR_TRG_MODE_B = 0;
325 ACQ_BUILD_INFO = 0;
326 ACQ_VAR_INFO = 0;
327 RUNHEADER_OBT = 0;
328 RUNHEADER_PKT = 0;
329 LAST_TIMESYNC = 0;
330 OBT_TIMESYNC = 0;
331 COMPILATIONTIMESTAMP = 0;
332 FAV_WRK_SCHEDULE = 0;
333 EFF_WRK_SCHEDULE = 0;
334 RM_ACQ_AFTER_CALIB = 0;
335 RM_ACQ_SETTING_MODE = 0;
336 TRK_CALIB_USED = 0;
337 CAL_DSP_MASK = 0;
338 };
339
340 void GL_RUN::Set_GL_RUN(TSQLRow *Row){
341 for( Int_t t = 0; t < 30; t++){
342 if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
343 if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
344 if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
345 if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
346 if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
347 if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
348 if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
349 if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
350 if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
351 if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
352 if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
353 if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t));
354 if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t));
355 if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t));
356 if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
357 if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
358 if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
359 if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
360 if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
361 if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
362 if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
363 if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
364 if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
365 if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
366 if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
367 if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
368 if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
369 if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
370 if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
371 if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
372 };
373
374 }
375
376 /**
377 *
378 *
379 *
380 **/
381 Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){
382 // MySQL variables
383 TSQLResult *pResult;
384 TSQLRow *Row;
385 stringstream myquery;
386 //
387 if ( !IDRUN ) IDRUN = ID;
388 if ( !IDRUN ) return 1;
389 // ----------------
390 myquery.str("");
391 myquery << " INSERT INTO GL_RUN_TRASH (";
392 myquery << "ID";
393 myquery << ",ID_RUN_FRAG";
394 myquery << ",ID_ROOT_L0";
395 myquery << ",ID_ROOT_L2";
396 myquery << ",RUNHEADER_TIME";
397 myquery << ",RUNTRAILER_TIME";
398 myquery << ",RUNHEADER_OBT";
399 myquery << ",RUNTRAILER_OBT";
400 myquery << ",RUNHEADER_PKT";
401 myquery << ",RUNTRAILER_PKT";
402 myquery << ",BOOT_NUMBER";
403 myquery << ",EV_FROM";
404 myquery << ",EV_TO";
405 myquery << ",NEVENTS";
406 myquery << ",PKT_COUNTER";
407 myquery << ",PKT_READY_COUNTER";
408 myquery << ",COMPILATIONTIMESTAMP";
409 myquery << ",FAV_WRK_SCHEDULE";
410 myquery << ",EFF_WRK_SCHEDULE";
411 myquery << ",PRH_VAR_TRG_MODE_A";
412 myquery << ",PRH_VAR_TRG_MODE_B";
413 myquery << ",ACQ_BUILD_INFO";
414 myquery << ",ACQ_VAR_INFO";
415 myquery << ",RM_ACQ_AFTER_CALIB";
416 myquery << ",RM_ACQ_SETTING_MODE";
417 myquery << ",TRK_CALIB_USED";
418 myquery << ",CAL_DSP_MASK";
419 myquery << ",LAST_TIMESYNC";
420 myquery << ",OBT_TIMESYNC";
421 myquery << ",VALIDATION";
422 myquery << ",INSERT_TIME";
423 myquery << ") SELECT * FROM ";
424 myquery << FromTable.Data();
425 myquery << " WHERE ID=";
426 myquery << (UInt_t)IDRUN << ";";
427 //
428 // printf("1myquery is %s \n",myquery.str().c_str());
429 //
430 dbc->Query(myquery.str().c_str());
431 //
432 TString fileL0 = "";
433 TString fileL2 = "";
434 myquery.str("");
435 myquery << " SELECT NAME FROM GL_ROOT WHERE ID=";
436 myquery << (UInt_t)ID_ROOT_L0 << ";";
437 //
438 // printf("2myquery is %s \n",myquery.str().c_str());
439 //
440 pResult = dbc->Query(myquery.str().c_str());
441 //
442 Row = pResult->Next();
443 if( Row != NULL ){
444 fileL0 = (TString)Row->GetField(0);
445 };
446 //
447 //
448 //
449 myquery.str("");
450 myquery << " SELECT NAME FROM GL_ROOT WHERE ID=";
451 myquery << (UInt_t)ID_ROOT_L2 << ";";
452 //
453 // printf("3myquery is %s \n",myquery.str().c_str());
454 //
455 pResult = dbc->Query(myquery.str().c_str());
456 //
457 Row = pResult->Next();
458 if( Row != NULL ){
459 fileL2 = (TString)Row->GetField(0);
460 };
461 //
462 //
463 //
464 myquery.str("");
465 myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='";
466 myquery << fileL0.Data() << "' where ID=";
467 myquery << IDRUN << ";";
468 //
469 // printf("4myquery is %s \n",myquery.str().c_str());
470 //
471 dbc->Query(myquery.str().c_str());
472 //
473 myquery.str("");
474 myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='";
475 myquery << fileL2.Data() << "' where ID=";
476 myquery << IDRUN << ";";
477 //
478 // printf("4myquery is %s \n",myquery.str().c_str());
479 //
480 dbc->Query(myquery.str().c_str());
481 //
482 myquery.str("");
483 myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='";
484 myquery << FromTable.Data() << "' where ID=";
485 myquery << IDRUN << ";";
486 //
487 // printf("4myquery is %s \n",myquery.str().c_str());
488 //
489 //
490 dbc->Query(myquery.str().c_str());
491 //
492 myquery.str("");
493 myquery << " DELETE FROM ";
494 myquery << FromTable.Data() << " where ID=";
495 myquery << IDRUN << ";";
496 //
497 // printf("5myquery is %s \n",myquery.str().c_str());
498 //
499 //
500 dbc->Query(myquery.str().c_str());
501 //
502 return 0;
503 };
504
505
506
507 /**
508 *
509 *
510 *
511 **/
512 Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t ID,TString FromTable){
513 // insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11;
514 //insert into GL_RUN_TRASH VALUES (ID , ID_RUN_FRAG , ID_ROOT_L0 , ID_ROOT_L2 , RUNHEADER_TIME , RUNTRAILER_TIME , RUNHEADER_OBT , RUNTRAILER_OBT , RUNHEADER_PKT , RUNTRAILER_PKT , BOOT_NUMBER , EV_FROM , EV_TO , NEVENTS , PKT_COUNTER , PKT_READY_COUNTER , COMPILATIONTIMESTAMP , FAV_WRK_SCHEDULE , EFF_WRK_SCHEDULE , PRH_VAR_TRG_MODE_A , PRH_VAR_TRG_MODE_B , ACQ_BUILD_INFO , ACQ_VAR_INFO , RM_ACQ_AFTER_CALIB , RM_ACQ_SETTING_MODE, TRK_CALIB_USED,CAL_DSP_MASK, LAST_TIMESYNC, OBT_TIMESYNC, VALIDATION, INSERT_TIME) select * FROM GL_RUN where ID=11;
515 return 0;
516 };
517
518 /**
519 * Function to fill the GL_RUN table of the DB.
520 *
521 * \param
522 *
523 */
524 Int_t GL_RUN::Fill_GL_RUN(TSQLServer *dbc){
525 // MySQL variables
526 stringstream myquery;
527 // ----------------
528 myquery.str("");
529 myquery << " INSERT INTO GL_RUN (";
530 myquery << "ID";
531 myquery << ",ID_RUN_FRAG";
532 myquery << ",ID_ROOT_L0";
533 myquery << ",ID_ROOT_L2";
534 myquery << ",RUNHEADER_TIME";
535 myquery << ",RUNTRAILER_TIME";
536 myquery << ",RUNHEADER_OBT";
537 myquery << ",RUNTRAILER_OBT";
538 myquery << ",RUNHEADER_PKT";
539 myquery << ",RUNTRAILER_PKT";
540 myquery << ",EV_FROM";
541 myquery << ",EV_TO";
542 myquery << ",NEVENTS";
543 myquery << ",LAST_TIMESYNC";
544 myquery << ",OBT_TIMESYNC";
545 myquery << ",COMPILATIONTIMESTAMP";
546 myquery << ",FAV_WRK_SCHEDULE";
547 myquery << ",EFF_WRK_SCHEDULE";
548 myquery << ",PRH_VAR_TRG_MODE_A";
549 myquery << ",PRH_VAR_TRG_MODE_B";
550 myquery << ",ACQ_BUILD_INFO";
551 myquery << ",ACQ_VAR_INFO";
552 myquery << ",RM_ACQ_AFTER_CALIB";
553 myquery << ",RM_ACQ_SETTING_MODE";
554 myquery << ",PKT_COUNTER";
555 myquery << ",PKT_READY_COUNTER";
556 myquery << ",TRK_CALIB_USED";
557 myquery << ",CAL_DSP_MASK";
558 myquery << ",BOOT_NUMBER";
559 myquery << ",VALIDATION";
560 myquery << ") VALUES ('";
561
562 myquery << (UInt_t)ID << "','";
563 myquery << (UInt_t)ID_RUN_FRAG << "','";
564 myquery << (UInt_t)ID_ROOT_L0 << "','";
565 myquery << (UInt_t)ID_ROOT_L2 << "','";
566 myquery << (UInt_t)RUNHEADER_TIME << "','";
567 myquery << (UInt_t)RUNTRAILER_TIME << "','";
568 myquery << (UInt_t)RUNHEADER_OBT << "','";
569 myquery << (UInt_t)RUNTRAILER_OBT << "','";
570 myquery << (UInt_t)RUNHEADER_PKT << "','";
571 myquery << (UInt_t)RUNTRAILER_PKT << "','";
572 myquery << (UInt_t)EV_FROM << "','";
573 myquery << (UInt_t)EV_TO << "','";
574 myquery << (UInt_t)NEVENTS << "','";
575 myquery << (UInt_t)LAST_TIMESYNC << "','";
576 myquery << (UInt_t)OBT_TIMESYNC << "','";
577 myquery << (UInt_t)COMPILATIONTIMESTAMP << "','";
578 myquery << (UInt_t)FAV_WRK_SCHEDULE << "','";
579 myquery << (UInt_t)EFF_WRK_SCHEDULE << "','";
580 myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','";
581 myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','";
582 myquery << (UInt_t)ACQ_BUILD_INFO << "','";
583 myquery << (UInt_t)ACQ_VAR_INFO << "','";
584 myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','";
585 myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','";
586 myquery << (UInt_t)PKT_COUNTER << "','";
587 myquery << (UInt_t)PKT_READY_COUNTER << "','";
588 myquery << (UInt_t)TRK_CALIB_USED << "','";
589 myquery << (UInt_t)CAL_DSP_MASK << "','";
590 myquery << (UInt_t)BOOT_NUMBER << "','";
591 myquery << (UInt_t)VALIDATION << "');";
592 //
593 // printf("myquery is %s \n",myquery.str().c_str());
594 //
595 dbc->Query(myquery.str().c_str());
596 //
597 return 0;
598
599 };// ****************************************************
600
601 /**
602 * Function to fill the GL_RUN table of the DB.
603 *
604 * \param
605 *
606 */
607 Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQLServer *dbc){
608 // MySQL variables
609 stringstream myquery;
610 // ----------------
611 myquery.str("");
612 myquery << " INSERT INTO GL_RUN_FRAGMENTS (";
613 myquery << "ID";
614 myquery << ",ID_ROOT_L0";
615 myquery << ",RUNHEADER_TIME";
616 myquery << ",RUNTRAILER_TIME";
617 myquery << ",RUNHEADER_OBT";
618 myquery << ",RUNTRAILER_OBT";
619 myquery << ",RUNHEADER_PKT";
620 myquery << ",RUNTRAILER_PKT";
621 myquery << ",EV_FROM";
622 myquery << ",EV_TO";
623 myquery << ",NEVENTS";
624 myquery << ",LAST_TIMESYNC";
625 myquery << ",OBT_TIMESYNC";
626 myquery << ",COMPILATIONTIMESTAMP";
627 myquery << ",FAV_WRK_SCHEDULE";
628 myquery << ",EFF_WRK_SCHEDULE";
629 myquery << ",PRH_VAR_TRG_MODE_A";
630 myquery << ",PRH_VAR_TRG_MODE_B";
631 myquery << ",ACQ_BUILD_INFO";
632 myquery << ",ACQ_VAR_INFO";
633 myquery << ",RM_ACQ_AFTER_CALIB";
634 myquery << ",RM_ACQ_SETTING_MODE";
635 myquery << ",PKT_COUNTER";
636 myquery << ",PKT_READY_COUNTER";
637 myquery << ",TRK_CALIB_USED";
638 myquery << ",CAL_DSP_MASK";
639 myquery << ",BOOT_NUMBER";
640 myquery << ") VALUES ('";
641 myquery << (UInt_t)ID << "','";
642 myquery << (UInt_t)ID_ROOT_L0 << "','";
643 myquery << (UInt_t)RUNHEADER_TIME << "','";
644 myquery << (UInt_t)RUNTRAILER_TIME << "','";
645 myquery << (UInt_t)RUNHEADER_OBT << "','";
646 myquery << (UInt_t)RUNTRAILER_OBT << "','";
647 myquery << (UInt_t)RUNHEADER_PKT << "','";
648 myquery << (UInt_t)RUNTRAILER_PKT << "','";
649 myquery << (UInt_t)EV_FROM << "','";
650 myquery << (UInt_t)EV_TO << "','";
651 myquery << (UInt_t)NEVENTS << "','";
652 myquery << (UInt_t)LAST_TIMESYNC << "','";
653 myquery << (UInt_t)OBT_TIMESYNC << "','";
654 myquery << (UInt_t)COMPILATIONTIMESTAMP << "','";
655 myquery << (UInt_t)FAV_WRK_SCHEDULE << "','";
656 myquery << (UInt_t)EFF_WRK_SCHEDULE << "','";
657 myquery << (UInt_t)PRH_VAR_TRG_MODE_A << "','";
658 myquery << (UInt_t)PRH_VAR_TRG_MODE_B << "','";
659 myquery << (UInt_t)ACQ_BUILD_INFO << "','";
660 myquery << (UInt_t)ACQ_VAR_INFO << "','";
661 myquery << (UInt_t)RM_ACQ_AFTER_CALIB << "','";
662 myquery << (UInt_t)RM_ACQ_SETTING_MODE << "','";
663 myquery << (UInt_t)PKT_COUNTER << "','";
664 myquery << (UInt_t)PKT_READY_COUNTER << "','";
665 myquery << (UInt_t)TRK_CALIB_USED << "','";
666 myquery << (UInt_t)CAL_DSP_MASK << "','";
667 myquery << (UInt_t)BOOT_NUMBER << "');";
668 //
669 // printf("myquery is %s \n",myquery.str().c_str());
670 //
671 dbc->Query(myquery.str().c_str());
672 //
673 return 0;
674
675 };// ****************************************************
676
677
678 /**
679 * Function to query the GL_RUN table of the DB.
680 *
681 * \param RUN id
682 * \return struct of type GL_RUN _data, which stores the query result
683 *
684 */
685 Int_t GL_RUN::Query_GL_RUN(UInt_t run, TSQLServer *dbc){
686 // MySQL variables
687 TSQLResult *pResult;
688 TSQLRow *Row;
689 int t;
690 int r;
691 stringstream myquery;
692 // ----------------
693 myquery.str("");
694 myquery << " select ";
695 myquery << "ID";
696 myquery << ",ID_RUN_FRAG";
697 myquery << ",ID_ROOT_L0";
698 myquery << ",ID_ROOT_L2";
699 myquery << ",RUNHEADER_TIME";
700 myquery << ",RUNTRAILER_TIME";
701 myquery << ",RUNHEADER_OBT";
702 myquery << ",RUNTRAILER_OBT";
703 myquery << ",RUNHEADER_PKT";
704 myquery << ",RUNTRAILER_PKT";
705 myquery << ",EV_FROM";
706 myquery << ",EV_TO";
707 myquery << ",NEVENTS";
708 myquery << ",LAST_TIMESYNC";
709 myquery << ",OBT_TIMESYNC";
710 myquery << ",COMPILATIONTIMESTAMP";
711 myquery << ",FAV_WRK_SCHEDULE";
712 myquery << ",EFF_WRK_SCHEDULE";
713 myquery << ",PRH_VAR_TRG_MODE_A";
714 myquery << ",PRH_VAR_TRG_MODE_B";
715 myquery << ",ACQ_BUILD_INFO";
716 myquery << ",ACQ_VAR_INFO";
717 myquery << ",RM_ACQ_AFTER_CALIB";
718 myquery << ",RM_ACQ_SETTING_MODE";
719 myquery << ",PKT_COUNTER";
720 myquery << ",PKT_READY_COUNTER";
721 myquery << ",TRK_CALIB_USED";
722 myquery << ",CAL_DSP_MASK";
723 myquery << ",BOOT_NUMBER";
724 myquery << ",VALIDATION";
725 myquery << " from GL_RUN where ID=" << run << ";";
726 //
727 // printf(" myquery is %s \n",myquery.str().c_str());
728 pResult = dbc->Query(myquery.str().c_str());
729 //
730 // printf(" getrowcount %i \n",pResult->GetRowCount());
731 //
732 if( !pResult->GetRowCount() ) return(-50);
733 //
734 for( r=0; r < 1000; r++){
735 Row = pResult->Next();
736 if( Row == NULL ) break;
737 // Set_GL_RUN(Row);
738 for( t = 0; t < pResult->GetFieldCount(); t++){
739 if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
740 if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
741 if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
742 if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
743 if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
744 if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
745 if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
746 if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
747 if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
748 if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
749 if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t));
750 if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t));
751 if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t));
752 if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
753 if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
754 if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
755 if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
756 if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
757 if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
758 if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
759 if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
760 if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
761 if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
762 if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
763 if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
764 if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
765 if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
766 if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
767 if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
768 if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
769 };
770 };
771 // delete pResult;
772 return(0);
773 };
774
775 /**
776 * Function to query the GL_RUN table of the DB.
777 *
778 * \param where = condition string
779 * \return struct of type GL_RUN _data, which stores the query result
780 *
781 */
782 Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){
783 // MySQL variables
784 TSQLResult *pResult;
785 TSQLRow *Row;
786 int t;
787 int r;
788 stringstream myquery;
789 // ----------------
790 myquery.str("");
791 myquery << " select ";
792 myquery << "ID";
793 myquery << ",ID_RUN_FRAG";
794 myquery << ",ID_ROOT_L0";
795 myquery << ",ID_ROOT_L2";
796 myquery << ",RUNHEADER_TIME";
797 myquery << ",RUNTRAILER_TIME";
798 myquery << ",RUNHEADER_OBT";
799 myquery << ",RUNTRAILER_OBT";
800 myquery << ",RUNHEADER_PKT";
801 myquery << ",RUNTRAILER_PKT";
802 myquery << ",EV_FROM";
803 myquery << ",EV_TO";
804 myquery << ",NEVENTS";
805 myquery << ",LAST_TIMESYNC";
806 myquery << ",OBT_TIMESYNC";
807 myquery << ",COMPILATIONTIMESTAMP";
808 myquery << ",FAV_WRK_SCHEDULE";
809 myquery << ",EFF_WRK_SCHEDULE";
810 myquery << ",PRH_VAR_TRG_MODE_A";
811 myquery << ",PRH_VAR_TRG_MODE_B";
812 myquery << ",ACQ_BUILD_INFO";
813 myquery << ",ACQ_VAR_INFO";
814 myquery << ",RM_ACQ_AFTER_CALIB";
815 myquery << ",RM_ACQ_SETTING_MODE";
816 myquery << ",PKT_COUNTER";
817 myquery << ",PKT_READY_COUNTER";
818 myquery << ",TRK_CALIB_USED";
819 myquery << ",CAL_DSP_MASK";
820 myquery << ",BOOT_NUMBER";
821 myquery << ",VALIDATION";
822 myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";";
823 //
824 // printf(" query is %s \n",myquery.str().c_str());
825 //
826 pResult = dbc->Query(myquery.str().c_str());
827 if(!pResult->GetRowCount())return(-50);
828 for( r=0; r < 1000; r++){
829 Row = pResult->Next();
830 if( Row == NULL ) break;
831 for( t = 0; t < pResult->GetFieldCount(); t++){
832 if (t== 0) ID = (UInt_t)atoll(Row->GetField(t));
833 if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t));
834 if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
835 if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t));
836 if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t));
837 if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t));
838 if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t));
839 if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t));
840 if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t));
841 if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t));
842 if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t));
843 if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t));
844 if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t));
845 if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
846 if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
847 if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t));
848 if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
849 if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t));
850 if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t));
851 if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t));
852 if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t));
853 if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t));
854 if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t));
855 if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t));
856 if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t));
857 if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t));
858 if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t));
859 if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t));
860 if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
861 if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t));
862 };
863 };
864 // delete pResult;
865 return(0);
866 };// ****************************************************
867
868 /**
869 * Function to query the GL_ROOT table of the DB.
870 *
871 * \param entry ID
872 * \return struct of type GL_ROOT_data, which stores the query result
873 */
874 Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, TSQLServer *dbc){
875 // MySQL variables
876 TSQLResult *pResult;
877 TSQLRow *Row;
878 int t;
879 int r;
880 stringstream myquery;
881 // ----------------
882 myquery.str("");
883 myquery << "select ";
884 myquery << " ID";
885 myquery << ",ID_RAW";
886 myquery << ",ID_TIMESYNC";
887 myquery << ",PATH";
888 myquery << ",NAME";
889 myquery << " from GL_ROOT where ID=" << id << ";";
890 //
891 pResult = dbc->Query(myquery.str().c_str());
892 if(!pResult->GetRowCount())return (-51);
893 for( r=0; r < 1000; r++){
894 Row = pResult->Next();
895 if( Row == NULL ) break;
896 for( t = 0; t < pResult->GetFieldCount(); t++){
897 if(t==0) ID = (UInt_t)atoll(Row->GetField(t));
898 if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));
899 if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
900 if(t==3) PATH = Row->GetField(t);
901 if(t==4) NAME = Row->GetField(t);
902 };
903 };
904 delete pResult;
905 return 0;
906 };
907 // ****************************************************
908 /**
909 * Function to query the GL_TRK_CALIB table of the DB.
910 *
911 * \param run starting time
912 * \param dbc DB server
913 * \return struct of type GL_TRK_CALIB_data, which stores the query result
914 */
915 Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){
916 // MySQL variables
917 TSQLResult *pResult;
918 TSQLRow *Row;
919 int t;
920 int r;
921 stringstream myquery;
922 // ----------------
923 myquery.str("");
924 myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2,BOOT_NUMBER,VALIDATION from GL_TRK_CALIB where FROM_TIME <= "<< time;
925 myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
926 // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
927 pResult = dbc->Query(myquery.str().c_str());
928 if(!pResult->GetRowCount())return (-53);
929 for( r=0; r < 1000; r++){
930 Row = pResult->Next();
931 if( Row == NULL ) break;
932 for( t = 0; t < pResult->GetFieldCount(); t++){
933 stringstream row;
934 row.str("");
935 row << "0" << Row->GetField(t); // add leading 0 since we have two fields that could be "null" and we want to avoid crashes due to atoll
936 if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
937 if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
938 if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str());
939 if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str());
940 if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
941 if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
942 //
943 if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t));
944 if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t));
945 if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t));
946 if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t));
947 if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t));
948 if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t));
949 };
950 };
951 delete pResult;
952 //
953 // if ( TO_TIME < time ) return(51);
954 //
955 if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING!
956 //
957 return 0;
958 };
959
960 // ****************************************************
961 /**
962 * Function to query the GL_CALO_CALIB table of the DB.
963 *
964 * \param run starting time
965 * \return struct of type GL_CALO_CALIB_data, which stores the query result
966 */
967 Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){
968 // MySQL variables
969 TSQLResult *pResult;
970 TSQLRow *Row;
971 int t;
972 stringstream myquery;
973 uptime = 0;
974 //
975 // select the correct calibration
976 //
977 myquery.str("");
978 myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
979 myquery << " and FROM_TIME <= " << time;
980 myquery << " and TO_TIME > " << time;
981 myquery << " ;";
982 //myquery << " and VALIDATION=1;";
983 //
984 pResult = dbc->Query(myquery.str().c_str());
985 // printf(" mysquery is %s\n",myquery.str().c_str());
986 //
987 if( !pResult->GetRowCount() ) return(-54);
988 Row = pResult->Next();
989 if( Row == NULL ) return (-54);
990 //
991 uptime = (UInt_t)atoll(Row->GetField(2));
992 //
993 // if it is corrupted validation is 0 and we have no results from the query...
994 //
995 if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0
996 //
997 // in this case take relax the conditions and take the valid calibration that preceed the correct one
998 //
999 myquery.str("");
1000 myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section;
1001 myquery << " and FROM_TIME <= " << time;
1002 myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
1003 pResult = dbc->Query(myquery.str().c_str());
1004 // printf(" mysquery is %s\n",myquery.str().c_str());
1005 //
1006 // if no results yet quit with error
1007 //
1008 if( !pResult->GetRowCount() ) return (-54);
1009 //
1010 Row = pResult->Next();
1011 //
1012 };
1013 //
1014 // store infos and exit
1015 //
1016 if( Row == NULL ) return (-54);
1017 for( t = 0; t < pResult->GetFieldCount(); t++){
1018 if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
1019 if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1020 if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t));
1021 if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
1022 };
1023 pResult->Delete();
1024 return 0;
1025 };
1026 // ****************************************************
1027 /**
1028 * Function to query the GL_S4_CALIB table of the DB.
1029 *
1030 * \param run starting time
1031 * \return struct of type GL_S4_CALIB_data, which stores the query result
1032 */
1033 Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UInt_t time, TSQLServer *dbc){
1034 // MySQL variables
1035 TSQLResult *pResult;
1036 TSQLRow *Row;
1037 int t;
1038 int r;
1039 stringstream myquery;
1040 // ----------------
1041 myquery.str("");
1042 myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;
1043 myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
1044 // myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";
1045 pResult = dbc->Query(myquery.str().c_str());
1046 if(!pResult->GetRowCount())return (-55);//throw -55;
1047 for( r=0; r < 1000; r++){
1048 Row = pResult->Next();
1049 if( Row == NULL ) break;
1050 for( t = 0; t < pResult->GetFieldCount(); t++){
1051 if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
1052 if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t));
1053 if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
1054 if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1055 if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t));
1056 if (t==5) PARAM_FIT0 = atof(Row->GetField(t));
1057 if (t==6) PARAM_FIT1 = atof(Row->GetField(t));
1058 };
1059 };
1060 delete pResult;
1061 //
1062 if(TO_TIME < time)return(51);
1063 //
1064 return 0;
1065 };
1066 // ****************************************************
1067 /**
1068 * Function to query the GL_PARAM table of the DB.
1069 *
1070 * \param run starting time
1071 * \param parameter description (DESCR)
1072 * \return struct of type GL_ROOT_data, which stores the query result
1073 */
1074 Int_t GL_PARAM::Query_GL_PARAM(UInt_t time, UInt_t type, TSQLServer *dbc){
1075 // Bool_t debug = 1;
1076 // MySQL variables
1077 TSQLResult *pResult;
1078 TSQLRow *Row;
1079 int t;
1080 int r;
1081 stringstream myquery;
1082 // ----------------
1083 myquery.str("");
1084 myquery << " select ";
1085 myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME ";
1086 myquery << " from GL_PARAM ";
1087 myquery << " where TYPE = '"<<type<<"' ";
1088 myquery << " and FROM_TIME <= " << time;
1089 myquery << " ORDER BY TO_TIME DESC LIMIT 1;";
1090 //
1091 pResult = dbc->Query(myquery.str().c_str());
1092 if(!pResult->GetRowCount())return (-52);
1093 for( r=0; r < 1000; r++){
1094 Row = pResult->Next();
1095 if( Row == NULL ) break;
1096 for( t = 0; t < pResult->GetFieldCount(); t++){
1097 if (t==0) ID = (UInt_t)atoll(Row->GetField(t));
1098 if (t==1) PATH = Row->GetField(t);// put in fpath the path to that file
1099 if (t==2) NAME = Row->GetField(t);
1100 if (t==3) DESCR = Row->GetField(t);
1101 if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1102 if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t));
1103 if (t==6) TYPE = (UInt_t)atoll(Row->GetField(t));
1104 };
1105 };
1106 delete pResult;
1107 //
1108 if(TO_TIME==0) TO_TIME = numeric_limits<UInt_t>::max();
1109 //
1110 if(TO_TIME < time) return(51);
1111 //
1112 return 0;
1113 };
1114
1115
1116 /**
1117 * Fills a struct cGLRun with values from a GLRun object (to put data into a F77 common).
1118 */
1119
1120 void GL_RUN::GetLevel2Struct(cGLRun *l2) const{
1121 l2->id = ID;
1122 l2->id_reg_run = ID_ROOT_L0;
1123 l2->id_reg_run_l2 = ID_ROOT_L2;
1124 l2->runheader_time = RUNHEADER_TIME;
1125 l2->runtrailer_time = RUNTRAILER_TIME;
1126 l2->ev_from = EV_FROM;
1127 l2->trk_calib_used = TRK_CALIB_USED;
1128 l2->eff_wrk_schedule = EFF_WRK_SCHEDULE;
1129 l2->prh_var_trg_mode_a = PRH_VAR_TRG_MODE_A;
1130 l2->prh_var_trg_mode_b = PRH_VAR_TRG_MODE_B;
1131 l2->acq_build_info = ACQ_BUILD_INFO;
1132 l2->acq_var_info = ACQ_VAR_INFO;
1133 };
1134
1135 GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
1136 // MySQL variables
1137 TFile *file = 0;
1138 UInt_t idraw = 0;
1139 //
1140 TSQLResult *pResult;
1141 TSQLRow *Row;
1142 stringstream myquery;
1143 stringstream rname;
1144 rname.str("");
1145 // ----------------
1146 myquery.str("");
1147 myquery << "select ";
1148 myquery << "PATH";
1149 myquery << ",NAME,ID_RAW";
1150 myquery << " from GL_ROOT where ";
1151 myquery << type.Data();
1152 myquery << "=" << id << ";";
1153 //
1154 pResult = dbc->Query(myquery.str().c_str());
1155 if( pResult->GetRowCount() ){
1156 Row = pResult->Next();
1157 if( Row ){
1158 stringstream fname;
1159 fname.str("");
1160 fname << Row->GetField(0) << "/" << Row->GetField(1);
1161 rname << Row->GetField(1);
1162 file = new TFile(fname.str().c_str(),"READ");
1163 idraw = (UInt_t)atoll(Row->GetField(2));
1164 };
1165 };
1166 //
1167 if ( file && file->IsOpen() ){
1168 TTree *T=(TTree*)file->Get("Physics");
1169 pamela::EventHeader *eh = 0;
1170 pamela::PscuHeader *ph = 0;
1171 T->SetBranchAddress("Header", &eh);
1172 //
1173 T->GetEntry(0);
1174 ph = eh->GetPscuHeader();
1175 pktfirst = ph->GetCounter();
1176 obtfirst = ph->GetOrbitalTime();
1177 };
1178 //
1179 // look for Resurs offset
1180 //
1181 UInt_t t0 = 0;
1182 //
1183 //
1184 stringstream oss;
1185 oss.str("");
1186 oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='"
1187 << rname.str().c_str() << "';";
1188 // if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
1189 pResult = dbc->Query(oss.str().c_str());
1190 Row = pResult->Next();
1191 //
1192 TString name=rname.str().c_str();
1193 UInt_t dworbit = 0;
1194 Int_t nlength = name.Length();
1195 if ( nlength < 5 ) return;
1196 TString dwo = 0;
1197 for (Int_t i = 0; i<5; i++){
1198 dwo.Append(name[i],1);
1199 };
1200 if ( dwo.IsDigit() ){
1201 dworbit = (UInt_t)dwo.Atoi();
1202 } else {
1203 dwo="";
1204 for (Int_t i = 8; i<13; i++){
1205 dwo.Append(name[i],1);
1206 };
1207 if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();
1208 };
1209 // if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data());
1210 //
1211 if ( !Row ){
1212 oss.str("");
1213 oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< "
1214 << dworbit << " order by FROM_ORBIT desc limit 1;";
1215 // if ( IsDebug() ) printf(" %s \n",oss.str().c_str());
1216 pResult = dbc->Query(oss.str().c_str());
1217 Row = pResult->Next();
1218 if ( !Row ){
1219 printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1220 return;
1221 };
1222 };
1223 //
1224 t0 = (UInt_t)TDatime(Row->GetField(0)).Convert();
1225 //
1226 // myquery.str("");
1227 // myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= "
1228 // << idraw << " AND TO_ID_RAW >= "
1229 // << idraw << ";";
1230 // pResult = dbc->Query(myquery.str().c_str());
1231 // if ( pResult ){
1232 // Row = pResult->Next();
1233 // if ( Row ){
1234 // //
1235 // t0 = (UInt_t)TDatime(Row->GetField(0)).Convert();
1236 // //
1237 // };
1238 // };
1239 //
1240 //
1241 // look for the correct timesync entry
1242 //
1243 myquery.str("");
1244 myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC "
1245 << " WHERE ID_RAW = " << idraw
1246 << ";";
1247 pResult = dbc->Query(myquery.str().c_str());
1248 if ( pResult ){
1249 Row = pResult->Next();
1250 if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){
1251 toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0;
1252 };
1253 };
1254 //
1255 file->Close();
1256 delete pResult;
1257 };
1258
1259 /**
1260 *
1261 * Returns the DB absolute time needed to associate calibrations to data
1262 *
1263 */
1264 UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){
1265 //
1266 return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1267 //
1268 };
1269
1270
1271 ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){
1272 //
1273 if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max()));
1274 //
1275 if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1276 if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){
1277 return((ULong64_t)(numeric_limits<UInt_t>::max()-obt));
1278 } else {
1279 return((ULong64_t)(obt-numeric_limits<UInt_t>::max()));
1280 };
1281 };
1282 //
1283 return((ULong64_t)obt);
1284 //
1285 };
1286
1287 UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){
1288 //
1289 if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215));
1290 //
1291 if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){
1292 if ( (pkt_num-16777215) < 0 ){
1293 return((16777215-pkt_num));
1294 } else {
1295 return((pkt_num-16777215));
1296 };
1297 };
1298 //
1299 return(pkt_num);
1300 //
1301 };
1302
1303 /*
1304 *
1305 * Convert the time in the DB from UInt_t to a string
1306 *
1307 * @param dbt time in the DB
1308 * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK
1309 *
1310 */
1311 TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){
1312 //
1313 TDatime *time = new TDatime();
1314 TString rtime;
1315 Bool_t found = false;
1316 //
1317 time->Set(dbt,false); // UTC (Coordinated Universal Time)
1318 //
1319 if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){
1320 //
1321 UInt_t timeMSK = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time
1322 time->Set(timeMSK,false);
1323 found = true;
1324 //
1325 };
1326 //
1327 if ( !strcmp(tzone.Data(),"CET") ){
1328 //
1329 UInt_t timeCET = time->Convert() + 60*60*1; // CET (Central European Time) = UTC + 1 hs
1330 time->Set(timeCET,false);
1331 found = true;
1332 //
1333 };
1334 //
1335 if ( !strcmp(tzone.Data(),"CEST") ){
1336 //
1337 UInt_t timeCEST = time->Convert() + 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h
1338 time->Set(timeCEST,false);
1339 found = true;
1340 //
1341 };
1342 //
1343 if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){
1344 //
1345 UInt_t timeMSD = time->Convert() + 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h
1346 time->Set(timeMSD,false);
1347 found = true;
1348 //
1349 };
1350 //
1351 if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){
1352 printf("\n Unknown time zone %s using UTC \n",tzone.Data());
1353 tzone = "UTC";
1354 };
1355 //
1356 rtime = time->AsSQLString();
1357 //
1358 return(rtime);
1359 }
1360
1361 /*
1362 *
1363 * Convert the time in the DB from UInt_t to a string
1364 *
1365 * @param dbt time in the DB
1366 * @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK
1367 *
1368 */
1369 TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){
1370 //
1371 TDatime *time = new TDatime();
1372 TString rtime;
1373 //
1374 Bool_t found = false;
1375 //
1376 time->Set(dbt,false); // tzone
1377 //
1378 if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){
1379 //
1380 UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs
1381 time->Set(timeUTC,false);
1382 found = true;
1383 //
1384 };
1385 //
1386 if ( !strcmp(tzone.Data(),"CET") ){
1387 //
1388 UInt_t timeCET = time->Convert() - 60*60*1; // CET (Central European Time) - 1 hs = UTC
1389 time->Set(timeCET,false);
1390 found = true;
1391 //
1392 };
1393 //
1394 if ( !strcmp(tzone.Data(),"CEST") ){
1395 //
1396 UInt_t timeCEST = time->Convert() - 60*60*2; // CEST (Central European Summer Time) - 2 h = UTC
1397 time->Set(timeCEST,false);
1398 found = true;
1399 //
1400 };
1401 //
1402 if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){
1403 //
1404 UInt_t timeMSD = time->Convert() - 60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC
1405 time->Set(timeMSD,false);
1406 found = true;
1407 //
1408 };
1409 //
1410 if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){
1411 //
1412 printf("\n Unknown time zone %s using UTC \n",tzone.Data());
1413 tzone = "UTC";
1414 };
1415 //
1416 rtime = time->AsSQLString();
1417 //
1418 return(rtime);
1419 }
1420
1421
1422 // ****************************************************
1423 /**
1424 * Function to query the GL_TLE table of the DB.
1425 *
1426 * time is the unix time for which a good tle is requested.
1427 *
1428 * Return the pointer to a cTle object that has the closest and
1429 * previous date compared with time.
1430 *
1431 * If errors occurs it returns NULL.
1432 */
1433 cTle* GL_TLE::Query_GL_TLE(UInt_t time, TSQLServer *dbc){
1434 stringstream myquery;
1435 myquery.str("");
1436
1437 myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "
1438 << "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;";
1439
1440
1441 return Query_GL_TLE_go(myquery.str(), dbc);
1442 }
1443
1444
1445 // ****************************************************
1446 /**
1447 * Function to query the GL_TLE table of the DB.
1448 *
1449 * date is a datetime format YYYY-MM-DD hh:mm:ss for which a good tle
1450 * is requested.
1451 *
1452 * Return the pointer to a cTle object that has the closest and
1453 * previous date compared with time.
1454 *
1455 * If errors occurs it returns NULL.
1456 */
1457 cTle* GL_TLE::Query_GL_TLE(TString date, TSQLServer *dbc){
1458 stringstream myquery;
1459 myquery.str("");
1460
1461 myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "
1462 << "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;";
1463
1464
1465 return Query_GL_TLE_go(myquery.str(), dbc);
1466 }
1467
1468
1469 // ****************************************************
1470 /**
1471 * Private function used by Query_GL_TLE methods.
1472 *
1473 * myquery is the query string.
1474 *
1475 * Return the pointer to a cTle object that has the closest and
1476 * previous date compared with time.
1477 *
1478 * If errors occurs it returns NULL.
1479 */
1480 cTle* GL_TLE::Query_GL_TLE_go(TString myquery, TSQLServer *dbc){
1481 cTle *tle;
1482 string tle1, tle2, tle3;
1483
1484 // MySQL variables
1485 TSQLResult *result;
1486 TSQLRow *row;
1487
1488 result = dbc->Query(myquery.Data());
1489 if(! result->GetRowCount() ) return NULL;
1490
1491 row = result->Next();
1492 tle1 = row->GetField(0);
1493 tle2 = row->GetField(1);
1494 tle3 = row->GetField(2);
1495
1496 tle = new cTle(tle1, tle2, tle3);
1497
1498 delete result;
1499 delete row;
1500
1501 return tle;
1502 }

  ViewVC Help
Powered by ViewVC 1.1.23