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

Contents of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations) (download)
Tue Nov 7 12:17:44 2006 UTC (18 years ago) by mocchiut
Branch: MAIN
CVS Tags: v2r02
Changes since 1.15: +58 -71 lines
Time screw bug fixed, now everything in UTC

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

  ViewVC Help
Powered by ViewVC 1.1.23