6 |
*/ |
*/ |
7 |
// |
// |
8 |
#include <sstream> |
#include <sstream> |
9 |
|
#include <iostream> |
10 |
// |
// |
11 |
#include <TFile.h> |
#include <TFile.h> |
12 |
#include <TTree.h> |
#include <TTree.h> |
13 |
|
#include <TTimeStamp.h> |
14 |
#include <EventHeader.h> |
#include <EventHeader.h> |
15 |
#include <PscuHeader.h> |
#include <PscuHeader.h> |
16 |
// |
// |
17 |
#include <GLTables.h> |
#include <GLTables.h> |
18 |
|
#include <sgp4.h> |
19 |
// |
// |
20 |
ClassImp(GL_TRK_CALIB); |
ClassImp(GL_TRK_CALIB); |
21 |
ClassImp(GL_RUN); |
ClassImp(GL_RUN); |
24 |
ClassImp(GL_S4_CALIB); |
ClassImp(GL_S4_CALIB); |
25 |
ClassImp(GL_CALO_CALIB); |
ClassImp(GL_CALO_CALIB); |
26 |
ClassImp(GL_TIMESYNC); |
ClassImp(GL_TIMESYNC); |
27 |
|
ClassImp(GL_TLE); |
28 |
// |
// |
29 |
using namespace std; |
using namespace std; |
30 |
|
|
62 |
VALIDATION = 0; |
VALIDATION = 0; |
63 |
} |
} |
64 |
|
|
65 |
|
|
66 |
void GL_RUN::Clear() { |
void GL_RUN::Clear() { |
67 |
ID = 0; |
ID = 0; |
68 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
127 |
OBT2 = 0; |
OBT2 = 0; |
128 |
PKT1 = 0; |
PKT1 = 0; |
129 |
PKT2 = 0; |
PKT2 = 0; |
130 |
|
BOOT_NUMBER = 0; |
131 |
|
VALIDATION = 0; |
132 |
} |
} |
133 |
|
|
134 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
154 |
obtfirst = 0; |
obtfirst = 0; |
155 |
pktfirst = 0; |
pktfirst = 0; |
156 |
toffset = 0; |
toffset = 0; |
157 |
ID = 0; |
// ID = 0; |
158 |
ID_RAW = 0; |
// ID_RAW = 0; |
159 |
OBT0 = 0; |
OBT0 = 0; |
160 |
TIMESYNC = 0; |
TIMESYNC = 0; |
161 |
TYPE = 0; |
TYPE = 0; |
162 |
}// **************************************************** |
} |
163 |
|
|
164 |
|
// **************************************************** |
165 |
|
|
166 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
167 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
335 |
CAL_DSP_MASK = 0; |
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. |
* Function to fill the GL_RUN table of the DB. |
857 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
858 |
Row = pResult->Next(); |
Row = pResult->Next(); |
859 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
860 |
|
// Set_GL_RUN(Row); |
861 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
862 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
863 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
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)); |
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)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
866 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
867 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
868 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
869 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
870 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
871 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
872 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
873 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
874 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
875 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
876 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
877 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
878 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
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)); |
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)); |
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)); |
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)); |
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)); |
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)); |
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)); |
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)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
887 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
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)); |
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)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
890 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
891 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
892 |
}; |
}; |
893 |
}; |
}; |
894 |
// delete pResult; |
// delete pResult; |
1032 |
* Function to query the GL_TRK_CALIB table of the DB. |
* Function to query the GL_TRK_CALIB table of the DB. |
1033 |
* |
* |
1034 |
* \param run starting time |
* \param run starting time |
1035 |
|
* \param dbc DB server |
1036 |
* \return struct of type GL_TRK_CALIB_data, which stores the query result |
* \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){ |
Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(UInt_t time, TSQLServer *dbc){ |
1044 |
stringstream myquery; |
stringstream myquery; |
1045 |
// ---------------- |
// ---------------- |
1046 |
myquery.str(""); |
myquery.str(""); |
1047 |
myquery << "select ID,ID_ROOT_L0,EV_ROOT_CALIBTRK1,EV_ROOT_CALIBTRK2,FROM_TIME,TO_TIME,OBT1,OBT2,PKT1,PKT2 from GL_TRK_CALIB where FROM_TIME <= "<< time; |
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;"; |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1049 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1050 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1056 |
stringstream row; |
stringstream row; |
1057 |
row.str(""); |
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 |
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)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1060 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
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()); |
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()); |
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)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1064 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1065 |
// |
// |
1066 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
1067 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
1068 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
1069 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
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; |
delete pResult; |
1075 |
|
// |
1076 |
|
// if ( TO_TIME < time ) return(51); |
1077 |
// |
// |
|
if(TO_TIME < time)return(51); |
|
1078 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
1079 |
// |
// |
1080 |
return 0; |
return 0; |
1087 |
* \param run starting time |
* \param run starting time |
1088 |
* \return struct of type GL_CALO_CALIB_data, which stores the query result |
* \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 section, TSQLServer *dbc){ |
Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB(UInt_t time, UInt_t &uptime, UInt_t section, TSQLServer *dbc){ |
1091 |
// MySQL variables |
// MySQL variables |
1092 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1093 |
TSQLRow *Row; |
TSQLRow *Row; |
1094 |
int t; |
int t; |
1095 |
stringstream myquery; |
stringstream myquery; |
1096 |
|
uptime = 0; |
1097 |
// |
// |
1098 |
// select the correct calibration |
// select the correct calibration |
1099 |
// |
// |
1101 |
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT,VALIDATION from GL_CALO_CALIB where SECTION=" << section; |
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; |
myquery << " and FROM_TIME <= " << time; |
1103 |
myquery << " and TO_TIME > " << time; |
myquery << " and TO_TIME > " << time; |
1104 |
myquery << " and VALIDATION=1;"; |
myquery << " ;"; |
1105 |
|
//myquery << " and VALIDATION=1;"; |
1106 |
// |
// |
1107 |
pResult = dbc->Query(myquery.str().c_str()); |
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... |
// if it is corrupted validation is 0 and we have no results from the query... |
1117 |
// |
// |
1118 |
if( !pResult->GetRowCount() ){ |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
|
// pResult->Delete(); |
|
1119 |
// |
// |
1120 |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
// in this case take relax the conditions and take the valid calibration that preceed the correct one |
1121 |
// |
// |
1124 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1125 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1126 |
pResult = dbc->Query(myquery.str().c_str()); |
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 |
// if no results yet quit with error |
1130 |
// |
// |
1131 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
1132 |
|
// |
1133 |
|
Row = pResult->Next(); |
1134 |
|
// |
1135 |
}; |
}; |
1136 |
// |
// |
1137 |
// store infos and exit |
// store infos and exit |
1138 |
// |
// |
|
Row = pResult->Next(); |
|
1139 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
1140 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1141 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1163 |
// ---------------- |
// ---------------- |
1164 |
myquery.str(""); |
myquery.str(""); |
1165 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
1166 |
myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1167 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1168 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1169 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1263 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1264 |
TSQLRow *Row; |
TSQLRow *Row; |
1265 |
stringstream myquery; |
stringstream myquery; |
1266 |
|
stringstream rname; |
1267 |
|
rname.str(""); |
1268 |
// ---------------- |
// ---------------- |
1269 |
myquery.str(""); |
myquery.str(""); |
1270 |
myquery << "select "; |
myquery << "select "; |
1281 |
stringstream fname; |
stringstream fname; |
1282 |
fname.str(""); |
fname.str(""); |
1283 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
1284 |
|
rname << Row->GetField(1); |
1285 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1286 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1287 |
}; |
}; |
1301 |
// |
// |
1302 |
// look for Resurs offset |
// look for Resurs offset |
1303 |
// |
// |
1304 |
UInt_t t0 = 0; |
T0 = 0; |
1305 |
// |
// |
1306 |
myquery.str(""); |
// |
1307 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
1308 |
<< idraw << " AND TO_ID_RAW >= " |
oss.str(""); |
1309 |
<< idraw << ";"; |
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 |
pResult = dbc->Query(myquery.str().c_str()); |
<< rname.str().c_str() << "';"; |
1311 |
if ( pResult ){ |
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(); |
Row = pResult->Next(); |
1338 |
if ( Row ){ |
if ( !Row ){ |
1339 |
// |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1340 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
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 |
// look for the correct timesync entry |
1348 |
// |
// |
1349 |
myquery.str(""); |
myquery.str(""); |
1350 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1351 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1352 |
<< ";"; |
<< ";"; |
1353 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1354 |
if ( pResult ){ |
if ( pResult ){ |
1355 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1356 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1357 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0; |
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 |
// |
// |
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 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
/** |
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 ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
1397 |
|
return((Long64_t)pkt_num+16777215LL); |
1398 |
|
}; |
1399 |
// |
// |
1400 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1401 |
if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
return((Long64_t)pkt_num-16777215LL); |
|
return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
|
|
} else { |
|
|
return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
|
|
}; |
|
1402 |
}; |
}; |
1403 |
// |
// |
1404 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
1405 |
// |
// |
1406 |
}; |
}; |
1407 |
|
|
1408 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
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 ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
1414 |
// |
// |
1415 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1416 |
if ( (pkt_num-16777215) < 0 ){ |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
|
return((16777215-pkt_num)); |
|
|
} else { |
|
|
return((pkt_num-16777215)); |
|
|
}; |
|
1417 |
}; |
}; |
1418 |
// |
// |
1419 |
return(pkt_num); |
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 |
|
} |