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 |
// |
// |
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; |
375 |
} |
} |
376 |
|
|
377 |
/** |
/** |
378 |
* |
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
379 |
* |
* If IDRUN is 0 "this->ID" run is used. |
380 |
* |
* |
381 |
**/ |
**/ |
382 |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
430 |
// |
// |
431 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
432 |
// |
// |
433 |
|
// retrieve this ID_TRASH |
434 |
|
// |
435 |
|
myquery.str(""); |
436 |
|
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
437 |
|
pResult = dbc->Query(myquery.str().c_str()); |
438 |
|
// |
439 |
|
UInt_t idtrash = 0; |
440 |
|
UInt_t idl0 = 0; |
441 |
|
UInt_t idl2 = 0; |
442 |
|
// |
443 |
|
Row = pResult->Next(); |
444 |
|
if( Row != NULL ){ |
445 |
|
idtrash = (UInt_t)atoll(Row->GetField(0)); |
446 |
|
idl0 = (UInt_t)atoll(Row->GetField(1)); |
447 |
|
idl2 = (UInt_t)atoll(Row->GetField(2)); |
448 |
|
}; |
449 |
|
// |
450 |
TString fileL0 = ""; |
TString fileL0 = ""; |
451 |
TString fileL2 = ""; |
TString fileL2 = ""; |
452 |
myquery.str(""); |
myquery.str(""); |
453 |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
454 |
myquery << (UInt_t)ID_ROOT_L0 << ";"; |
myquery << idl0 << ";"; |
455 |
// |
// |
456 |
// printf("2myquery is %s \n",myquery.str().c_str()); |
// printf("2myquery is %s \n",myquery.str().c_str()); |
457 |
// |
// |
466 |
// |
// |
467 |
myquery.str(""); |
myquery.str(""); |
468 |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
469 |
myquery << (UInt_t)ID_ROOT_L2 << ";"; |
myquery << idl2 << ";"; |
470 |
// |
// |
471 |
// printf("3myquery is %s \n",myquery.str().c_str()); |
// printf("3myquery is %s \n",myquery.str().c_str()); |
472 |
// |
// |
481 |
// |
// |
482 |
myquery.str(""); |
myquery.str(""); |
483 |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
484 |
myquery << fileL0.Data() << "' where ID="; |
myquery << fileL0.Data() << "' where ID_TRASH="; |
485 |
myquery << IDRUN << ";"; |
myquery << idtrash << ";"; |
486 |
// |
// |
487 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// printf("4myquery is %s \n",myquery.str().c_str()); |
488 |
// |
// |
490 |
// |
// |
491 |
myquery.str(""); |
myquery.str(""); |
492 |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
493 |
myquery << fileL2.Data() << "' where ID="; |
myquery << fileL2.Data() << "' where ID_TRASH="; |
494 |
myquery << IDRUN << ";"; |
myquery << idtrash << ";"; |
495 |
// |
// |
496 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// printf("4myquery is %s \n",myquery.str().c_str()); |
497 |
// |
// |
499 |
// |
// |
500 |
myquery.str(""); |
myquery.str(""); |
501 |
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
502 |
myquery << FromTable.Data() << "' where ID="; |
myquery << FromTable.Data() << "' where ID_TRASH="; |
503 |
myquery << IDRUN << ";"; |
myquery << idtrash << ";"; |
504 |
// |
// |
505 |
// printf("4myquery is %s \n",myquery.str().c_str()); |
// printf("4myquery is %s \n",myquery.str().c_str()); |
506 |
// |
// |
523 |
|
|
524 |
|
|
525 |
/** |
/** |
526 |
* |
* This method restore a run from the GL_RUN_TRASH table. |
527 |
* |
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
528 |
* |
* |
529 |
**/ |
**/ |
530 |
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t ID,TString FromTable){ |
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
531 |
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
532 |
//insert into GL_RUN_TRASH VALUES (ID , ID_RUN_FRAG , ID_ROOT_L0 , ID_ROOT_L2 , RUNHEADER_TIME , RUNTRAILER_TIME , RUNHEADER_OBT , RUNTRAILER_OBT , RUNHEADER_PKT , RUNTRAILER_PKT , BOOT_NUMBER , EV_FROM , EV_TO , NEVENTS , PKT_COUNTER , PKT_READY_COUNTER , COMPILATIONTIMESTAMP , FAV_WRK_SCHEDULE , EFF_WRK_SCHEDULE , PRH_VAR_TRG_MODE_A , PRH_VAR_TRG_MODE_B , ACQ_BUILD_INFO , ACQ_VAR_INFO , RM_ACQ_AFTER_CALIB , RM_ACQ_SETTING_MODE, TRK_CALIB_USED,CAL_DSP_MASK, LAST_TIMESYNC, OBT_TIMESYNC, VALIDATION, INSERT_TIME) select * FROM GL_RUN where ID=11; |
//insert into GL_RUN_TRASH VALUES (ID , ID_RUN_FRAG , ID_ROOT_L0 , ID_ROOT_L2 , RUNHEADER_TIME , RUNTRAILER_TIME , RUNHEADER_OBT , RUNTRAILER_OBT , RUNHEADER_PKT , RUNTRAILER_PKT , BOOT_NUMBER , EV_FROM , EV_TO , NEVENTS , PKT_COUNTER , PKT_READY_COUNTER , COMPILATIONTIMESTAMP , FAV_WRK_SCHEDULE , EFF_WRK_SCHEDULE , PRH_VAR_TRG_MODE_A , PRH_VAR_TRG_MODE_B , ACQ_BUILD_INFO , ACQ_VAR_INFO , RM_ACQ_AFTER_CALIB , RM_ACQ_SETTING_MODE, TRK_CALIB_USED,CAL_DSP_MASK, LAST_TIMESYNC, OBT_TIMESYNC, VALIDATION, INSERT_TIME) select * FROM GL_RUN where ID=11; |
533 |
|
// MySQL variables |
534 |
|
TSQLResult *pResult; |
535 |
|
TSQLRow *Row; |
536 |
|
stringstream myquery; |
537 |
|
// |
538 |
|
if ( !IDRUN ) IDRUN = ID; |
539 |
|
if ( !IDRUN ) return 1; |
540 |
|
// |
541 |
|
if ( !strcmp(ToTable.Data(),"") ){ |
542 |
|
// |
543 |
|
myquery.str(""); |
544 |
|
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
545 |
|
myquery << (UInt_t)IDRUN << ";"; |
546 |
|
// |
547 |
|
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
548 |
|
// |
549 |
|
pResult = dbc->Query(myquery.str().c_str()); |
550 |
|
// |
551 |
|
Row = pResult->Next(); |
552 |
|
if( Row != NULL ){ |
553 |
|
ToTable = (TString)Row->GetField(0); |
554 |
|
} else { |
555 |
|
return 1; |
556 |
|
}; |
557 |
|
}; |
558 |
|
// ---------------- |
559 |
|
myquery.str(""); |
560 |
|
myquery << " INSERT INTO "; |
561 |
|
myquery << ToTable.Data(); |
562 |
|
myquery << " ("; |
563 |
|
myquery << "ID"; |
564 |
|
myquery << ",ID_RUN_FRAG"; |
565 |
|
myquery << ",ID_ROOT_L0"; |
566 |
|
myquery << ",ID_ROOT_L2"; |
567 |
|
myquery << ",RUNHEADER_TIME"; |
568 |
|
myquery << ",RUNTRAILER_TIME"; |
569 |
|
myquery << ",RUNHEADER_OBT"; |
570 |
|
myquery << ",RUNTRAILER_OBT"; |
571 |
|
myquery << ",RUNHEADER_PKT"; |
572 |
|
myquery << ",RUNTRAILER_PKT"; |
573 |
|
myquery << ",BOOT_NUMBER"; |
574 |
|
myquery << ",EV_FROM"; |
575 |
|
myquery << ",EV_TO"; |
576 |
|
myquery << ",NEVENTS"; |
577 |
|
myquery << ",PKT_COUNTER"; |
578 |
|
myquery << ",PKT_READY_COUNTER"; |
579 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
580 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
581 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
582 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
583 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
584 |
|
myquery << ",ACQ_BUILD_INFO"; |
585 |
|
myquery << ",ACQ_VAR_INFO"; |
586 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
587 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
588 |
|
myquery << ",TRK_CALIB_USED"; |
589 |
|
myquery << ",CAL_DSP_MASK"; |
590 |
|
myquery << ",LAST_TIMESYNC"; |
591 |
|
myquery << ",OBT_TIMESYNC"; |
592 |
|
myquery << ",VALIDATION"; |
593 |
|
myquery << ",INSERT_TIME"; |
594 |
|
myquery << ") SELECT "; |
595 |
|
myquery << "ID"; |
596 |
|
myquery << ",ID_RUN_FRAG"; |
597 |
|
myquery << ",ID_ROOT_L0"; |
598 |
|
myquery << ",ID_ROOT_L2"; |
599 |
|
myquery << ",RUNHEADER_TIME"; |
600 |
|
myquery << ",RUNTRAILER_TIME"; |
601 |
|
myquery << ",RUNHEADER_OBT"; |
602 |
|
myquery << ",RUNTRAILER_OBT"; |
603 |
|
myquery << ",RUNHEADER_PKT"; |
604 |
|
myquery << ",RUNTRAILER_PKT"; |
605 |
|
myquery << ",BOOT_NUMBER"; |
606 |
|
myquery << ",EV_FROM"; |
607 |
|
myquery << ",EV_TO"; |
608 |
|
myquery << ",NEVENTS"; |
609 |
|
myquery << ",PKT_COUNTER"; |
610 |
|
myquery << ",PKT_READY_COUNTER"; |
611 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
612 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
613 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
614 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
615 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
616 |
|
myquery << ",ACQ_BUILD_INFO"; |
617 |
|
myquery << ",ACQ_VAR_INFO"; |
618 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
619 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
620 |
|
myquery << ",TRK_CALIB_USED"; |
621 |
|
myquery << ",CAL_DSP_MASK"; |
622 |
|
myquery << ",LAST_TIMESYNC"; |
623 |
|
myquery << ",OBT_TIMESYNC"; |
624 |
|
myquery << ",VALIDATION"; |
625 |
|
myquery << ",INSERT_TIME"; |
626 |
|
myquery << " FROM GL_RUN_TRASH "; |
627 |
|
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
628 |
|
myquery << (UInt_t)IDRUN << ";"; |
629 |
|
// |
630 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
631 |
|
// |
632 |
|
dbc->Query(myquery.str().c_str()); |
633 |
|
// |
634 |
|
// |
635 |
|
myquery.str(""); |
636 |
|
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
637 |
|
myquery << IDRUN << ";"; |
638 |
|
// |
639 |
|
dbc->Query(myquery.str().c_str()); |
640 |
|
// |
641 |
return 0; |
return 0; |
642 |
}; |
}; |
643 |
|
|
862 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
863 |
// Set_GL_RUN(Row); |
// Set_GL_RUN(Row); |
864 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
865 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
866 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
867 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
868 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
869 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
870 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
871 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
872 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
873 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
874 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
875 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
876 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
877 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
878 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
879 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
880 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
881 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
882 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
883 |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
884 |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
885 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
886 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
887 |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
888 |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
889 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
890 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
891 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
892 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
893 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
894 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
895 |
}; |
}; |
896 |
}; |
}; |
897 |
// delete pResult; |
// delete pResult; |
1304 |
// |
// |
1305 |
// look for Resurs offset |
// look for Resurs offset |
1306 |
// |
// |
1307 |
UInt_t t0 = 0; |
T0 = 0; |
1308 |
// |
// |
1309 |
// |
// |
1310 |
stringstream oss; |
stringstream oss; |
1311 |
oss.str(""); |
oss.str(""); |
1312 |
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
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='" |
1313 |
<< rname.str().c_str() << "';"; |
<< rname.str().c_str() << "';"; |
|
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
|
1314 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1315 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1316 |
// |
// |
1331 |
}; |
}; |
1332 |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
1333 |
}; |
}; |
|
// if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
|
1334 |
// |
// |
1335 |
if ( !Row ){ |
if ( !Row ){ |
1336 |
oss.str(""); |
oss.str(""); |
1337 |
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
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< " |
1338 |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
|
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
|
1339 |
pResult = dbc->Query(oss.str().c_str()); |
pResult = dbc->Query(oss.str().c_str()); |
1340 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1341 |
if ( !Row ){ |
if ( !Row ){ |
1344 |
}; |
}; |
1345 |
}; |
}; |
1346 |
// |
// |
1347 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
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); |
1348 |
// |
T0 = (UInt_t)tu.GetSec(); |
|
// myquery.str(""); |
|
|
// myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
|
|
// << idraw << " AND TO_ID_RAW >= " |
|
|
// << idraw << ";"; |
|
|
// pResult = dbc->Query(myquery.str().c_str()); |
|
|
// if ( pResult ){ |
|
|
// Row = pResult->Next(); |
|
|
// if ( Row ){ |
|
|
// // |
|
|
// t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
|
|
// // |
|
|
// }; |
|
|
// }; |
|
|
// |
|
1349 |
// |
// |
1350 |
// look for the correct timesync entry |
// look for the correct timesync entry |
1351 |
// |
// |
1352 |
myquery.str(""); |
myquery.str(""); |
1353 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1354 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1355 |
<< ";"; |
<< ";"; |
1356 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1357 |
if ( pResult ){ |
if ( pResult ){ |
1358 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1359 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1360 |
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)); |
1361 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1362 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1363 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
1364 |
}; |
}; |
1365 |
}; |
}; |
1366 |
// |
// |
1379 |
// |
// |
1380 |
}; |
}; |
1381 |
|
|
1382 |
|
/** |
1383 |
|
* |
1384 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
1385 |
|
* |
1386 |
|
*/ |
1387 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1388 |
|
// |
1389 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1390 |
|
// |
1391 |
|
}; |
1392 |
|
|
1393 |
|
|
1394 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
/** |
1395 |
|
* Return the correct packet number if we went back to zero |
1396 |
|
*/ |
1397 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1398 |
// |
// |
1399 |
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) ){ |
1400 |
|
return((Long64_t)pkt_num+16777215LL); |
1401 |
|
}; |
1402 |
// |
// |
1403 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1404 |
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())); |
|
|
}; |
|
1405 |
}; |
}; |
1406 |
// |
// |
1407 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
1408 |
// |
// |
1409 |
}; |
}; |
1410 |
|
|
1411 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
1412 |
|
* Return the correct On Board Time if we went back to zero |
1413 |
|
*/ |
1414 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1415 |
// |
// |
1416 |
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())); |
1417 |
// |
// |
1418 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1419 |
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)); |
|
|
}; |
|
1420 |
}; |
}; |
1421 |
// |
// |
1422 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
1423 |
}; |
}; |
1424 |
|
|
1425 |
|
|
1426 |
|
|
1427 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1428 |
|
// // |
1429 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
1430 |
|
// // |
1431 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
1432 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
1433 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
1434 |
|
// } else { |
1435 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
1436 |
|
// }; |
1437 |
|
// }; |
1438 |
|
// // |
1439 |
|
// return((ULong64_t)obt); |
1440 |
|
// // |
1441 |
|
// }; |
1442 |
|
|
1443 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
1444 |
|
// // |
1445 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
1446 |
|
// // |
1447 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
1448 |
|
// if ( (pkt_num-16777215) < 0 ){ |
1449 |
|
// return((16777215-pkt_num)); |
1450 |
|
// } else { |
1451 |
|
// return((pkt_num-16777215)); |
1452 |
|
// }; |
1453 |
|
// }; |
1454 |
|
// // |
1455 |
|
// return(pkt_num); |
1456 |
|
// // |
1457 |
|
// }; |
1458 |
|
|
1459 |
/* |
/* |
1460 |
* |
* |
1461 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time in the DB from UInt_t to a string |
1466 |
*/ |
*/ |
1467 |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
1468 |
// |
// |
1469 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
1470 |
TString rtime; |
TString rtime; |
1471 |
Bool_t found = false; |
Bool_t found = false; |
1472 |
// |
// |
|
time->Set(dbt,false); // UTC (Coordinated Universal Time) |
|
|
// |
|
1473 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1474 |
// |
// |
1475 |
UInt_t timeMSK = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
|
time->Set(timeMSK,false); |
|
1476 |
found = true; |
found = true; |
1477 |
// |
// |
1478 |
}; |
}; |
1479 |
// |
// |
1480 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
1481 |
// |
// |
1482 |
UInt_t timeCET = time->Convert() + 60*60*1; // CET (Central European Time) = UTC + 1 hs |
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
|
time->Set(timeCET,false); |
|
1483 |
found = true; |
found = true; |
1484 |
// |
// |
1485 |
}; |
}; |
1486 |
// |
// |
1487 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1488 |
// |
// |
1489 |
UInt_t timeCEST = time->Convert() + 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
|
time->Set(timeCEST,false); |
|
1490 |
found = true; |
found = true; |
1491 |
// |
// |
1492 |
}; |
}; |
1493 |
// |
// |
1494 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
1495 |
// |
// |
1496 |
UInt_t timeMSD = time->Convert() + 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
|
time->Set(timeMSD,false); |
|
1497 |
found = true; |
found = true; |
1498 |
// |
// |
1499 |
}; |
}; |
1503 |
tzone = "UTC"; |
tzone = "UTC"; |
1504 |
}; |
}; |
1505 |
// |
// |
1506 |
rtime = time->AsSQLString(); |
dbt += offset; |
1507 |
|
// |
1508 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1509 |
|
// |
1510 |
|
rtime = time->AsString("s"); |
1511 |
|
// |
1512 |
|
delete time; |
1513 |
// |
// |
1514 |
return(rtime); |
return(rtime); |
1515 |
} |
} |
1516 |
|
|
1517 |
/* |
/* |
1518 |
* |
* |
1519 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time from TZONE to UTC |
1520 |
* |
* |
1521 |
* @param dbt time in the DB |
* @param dbt time in the DB |
1522 |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1524 |
*/ |
*/ |
1525 |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
1526 |
// |
// |
1527 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
1528 |
TString rtime; |
TString rtime; |
1529 |
// |
// |
1530 |
Bool_t found = false; |
Bool_t found = false; |
1531 |
// |
// |
|
time->Set(dbt,false); // tzone |
|
|
// |
|
1532 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1533 |
// |
// |
1534 |
UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
|
time->Set(timeUTC,false); |
|
1535 |
found = true; |
found = true; |
1536 |
// |
// |
1537 |
}; |
}; |
1538 |
// |
// |
1539 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
1540 |
// |
// |
1541 |
UInt_t timeCET = time->Convert() - 60*60*1; // CET (Central European Time) - 1 hs = UTC |
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
|
time->Set(timeCET,false); |
|
1542 |
found = true; |
found = true; |
1543 |
// |
// |
1544 |
}; |
}; |
1545 |
// |
// |
1546 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1547 |
// |
// |
1548 |
UInt_t timeCEST = time->Convert() - 60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
|
time->Set(timeCEST,false); |
|
1549 |
found = true; |
found = true; |
1550 |
// |
// |
1551 |
}; |
}; |
1552 |
// |
// |
1553 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
1554 |
// |
// |
1555 |
UInt_t timeMSD = time->Convert() - 60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
|
time->Set(timeMSD,false); |
|
1556 |
found = true; |
found = true; |
1557 |
// |
// |
1558 |
}; |
}; |
1559 |
// |
// |
1560 |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1561 |
// |
// |
1562 |
|
offset = 0; |
1563 |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1564 |
tzone = "UTC"; |
tzone = "UTC"; |
1565 |
}; |
}; |
1566 |
// |
// |
1567 |
rtime = time->AsSQLString(); |
dbt += offset; |
1568 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1569 |
|
// |
1570 |
|
rtime = time->AsString("s"); |
1571 |
// |
// |
1572 |
return(rtime); |
return(rtime); |
1573 |
} |
} |