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

Contents of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.30 - (show annotations) (download)
Fri Sep 7 21:10:57 2007 UTC (17 years, 2 months ago) by mocchiut
Branch: MAIN
Changes since 1.29: +23 -11 lines
Reconnection code updated

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

  ViewVC Help
Powered by ViewVC 1.1.23