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

Contents of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Tue Jan 23 17:04:11 2007 UTC (17 years, 10 months ago) by mocchiut
Branch: MAIN
Changes since 1.20: +85 -61 lines
Updated GL_TLE class

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

  ViewVC Help
Powered by ViewVC 1.1.23