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> |
14 |
#include <PscuHeader.h> |
#include <PscuHeader.h> |
15 |
// |
// |
16 |
#include <GLTables.h> |
#include <GLTables.h> |
17 |
|
#include <sgp4.h> |
18 |
// |
// |
19 |
ClassImp(GL_TRK_CALIB); |
ClassImp(GL_TRK_CALIB); |
20 |
ClassImp(GL_RUN); |
ClassImp(GL_RUN); |
23 |
ClassImp(GL_S4_CALIB); |
ClassImp(GL_S4_CALIB); |
24 |
ClassImp(GL_CALO_CALIB); |
ClassImp(GL_CALO_CALIB); |
25 |
ClassImp(GL_TIMESYNC); |
ClassImp(GL_TIMESYNC); |
26 |
|
ClassImp(GL_TLE); |
27 |
// |
// |
28 |
using namespace std; |
using namespace std; |
29 |
|
|
61 |
VALIDATION = 0; |
VALIDATION = 0; |
62 |
} |
} |
63 |
|
|
64 |
|
|
65 |
void GL_RUN::Clear() { |
void GL_RUN::Clear() { |
66 |
ID = 0; |
ID = 0; |
67 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
126 |
OBT2 = 0; |
OBT2 = 0; |
127 |
PKT1 = 0; |
PKT1 = 0; |
128 |
PKT2 = 0; |
PKT2 = 0; |
129 |
|
BOOT_NUMBER = 0; |
130 |
|
VALIDATION = 0; |
131 |
} |
} |
132 |
|
|
133 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
158 |
OBT0 = 0; |
OBT0 = 0; |
159 |
TIMESYNC = 0; |
TIMESYNC = 0; |
160 |
TYPE = 0; |
TYPE = 0; |
161 |
}// **************************************************** |
} |
162 |
|
|
163 |
|
GL_TLE::GL_TLE(){ |
164 |
|
} |
165 |
|
|
166 |
|
// **************************************************** |
167 |
|
|
168 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
169 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
337 |
CAL_DSP_MASK = 0; |
CAL_DSP_MASK = 0; |
338 |
}; |
}; |
339 |
|
|
340 |
|
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
341 |
|
for( Int_t t = 0; t < 30; t++){ |
342 |
|
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
343 |
|
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
344 |
|
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
345 |
|
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
346 |
|
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
347 |
|
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
348 |
|
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
349 |
|
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
350 |
|
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
351 |
|
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
352 |
|
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
353 |
|
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
354 |
|
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
355 |
|
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
356 |
|
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
357 |
|
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
358 |
|
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
359 |
|
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
360 |
|
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
361 |
|
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
362 |
|
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
363 |
|
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
364 |
|
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
365 |
|
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
366 |
|
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
367 |
|
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
368 |
|
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
369 |
|
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
370 |
|
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
371 |
|
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
372 |
|
}; |
373 |
|
|
374 |
|
} |
375 |
|
|
376 |
|
/** |
377 |
|
* |
378 |
|
* |
379 |
|
* |
380 |
|
**/ |
381 |
|
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
382 |
|
// MySQL variables |
383 |
|
TSQLResult *pResult; |
384 |
|
TSQLRow *Row; |
385 |
|
stringstream myquery; |
386 |
|
// |
387 |
|
if ( !IDRUN ) IDRUN = ID; |
388 |
|
if ( !IDRUN ) return 1; |
389 |
|
// ---------------- |
390 |
|
myquery.str(""); |
391 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
392 |
|
myquery << "ID"; |
393 |
|
myquery << ",ID_RUN_FRAG"; |
394 |
|
myquery << ",ID_ROOT_L0"; |
395 |
|
myquery << ",ID_ROOT_L2"; |
396 |
|
myquery << ",RUNHEADER_TIME"; |
397 |
|
myquery << ",RUNTRAILER_TIME"; |
398 |
|
myquery << ",RUNHEADER_OBT"; |
399 |
|
myquery << ",RUNTRAILER_OBT"; |
400 |
|
myquery << ",RUNHEADER_PKT"; |
401 |
|
myquery << ",RUNTRAILER_PKT"; |
402 |
|
myquery << ",BOOT_NUMBER"; |
403 |
|
myquery << ",EV_FROM"; |
404 |
|
myquery << ",EV_TO"; |
405 |
|
myquery << ",NEVENTS"; |
406 |
|
myquery << ",PKT_COUNTER"; |
407 |
|
myquery << ",PKT_READY_COUNTER"; |
408 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
409 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
410 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
411 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
412 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
413 |
|
myquery << ",ACQ_BUILD_INFO"; |
414 |
|
myquery << ",ACQ_VAR_INFO"; |
415 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
416 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
417 |
|
myquery << ",TRK_CALIB_USED"; |
418 |
|
myquery << ",CAL_DSP_MASK"; |
419 |
|
myquery << ",LAST_TIMESYNC"; |
420 |
|
myquery << ",OBT_TIMESYNC"; |
421 |
|
myquery << ",VALIDATION"; |
422 |
|
myquery << ",INSERT_TIME"; |
423 |
|
myquery << ") SELECT * FROM "; |
424 |
|
myquery << FromTable.Data(); |
425 |
|
myquery << " WHERE ID="; |
426 |
|
myquery << (UInt_t)IDRUN << ";"; |
427 |
|
// |
428 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
429 |
|
// |
430 |
|
dbc->Query(myquery.str().c_str()); |
431 |
|
// |
432 |
|
TString fileL0 = ""; |
433 |
|
TString fileL2 = ""; |
434 |
|
myquery.str(""); |
435 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
436 |
|
myquery << (UInt_t)ID_ROOT_L0 << ";"; |
437 |
|
// |
438 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
439 |
|
// |
440 |
|
pResult = dbc->Query(myquery.str().c_str()); |
441 |
|
// |
442 |
|
Row = pResult->Next(); |
443 |
|
if( Row != NULL ){ |
444 |
|
fileL0 = (TString)Row->GetField(0); |
445 |
|
}; |
446 |
|
// |
447 |
|
// |
448 |
|
// |
449 |
|
myquery.str(""); |
450 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
451 |
|
myquery << (UInt_t)ID_ROOT_L2 << ";"; |
452 |
|
// |
453 |
|
// printf("3myquery 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 |
|
fileL2 = (TString)Row->GetField(0); |
460 |
|
}; |
461 |
|
// |
462 |
|
// |
463 |
|
// |
464 |
|
myquery.str(""); |
465 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
466 |
|
myquery << fileL0.Data() << "' where ID="; |
467 |
|
myquery << IDRUN << ";"; |
468 |
|
// |
469 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
470 |
|
// |
471 |
|
dbc->Query(myquery.str().c_str()); |
472 |
|
// |
473 |
|
myquery.str(""); |
474 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
475 |
|
myquery << fileL2.Data() << "' where ID="; |
476 |
|
myquery << IDRUN << ";"; |
477 |
|
// |
478 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
479 |
|
// |
480 |
|
dbc->Query(myquery.str().c_str()); |
481 |
|
// |
482 |
|
myquery.str(""); |
483 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
484 |
|
myquery << FromTable.Data() << "' where ID="; |
485 |
|
myquery << IDRUN << ";"; |
486 |
|
// |
487 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
488 |
|
// |
489 |
|
// |
490 |
|
dbc->Query(myquery.str().c_str()); |
491 |
|
// |
492 |
|
myquery.str(""); |
493 |
|
myquery << " DELETE FROM "; |
494 |
|
myquery << FromTable.Data() << " where ID="; |
495 |
|
myquery << IDRUN << ";"; |
496 |
|
// |
497 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
498 |
|
// |
499 |
|
// |
500 |
|
dbc->Query(myquery.str().c_str()); |
501 |
|
// |
502 |
|
return 0; |
503 |
|
}; |
504 |
|
|
505 |
|
|
506 |
|
|
507 |
|
/** |
508 |
|
* |
509 |
|
* |
510 |
|
* |
511 |
|
**/ |
512 |
|
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t ID,TString FromTable){ |
513 |
|
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
514 |
|
//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; |
515 |
|
return 0; |
516 |
|
}; |
517 |
|
|
518 |
/** |
/** |
519 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
734 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
735 |
Row = pResult->Next(); |
Row = pResult->Next(); |
736 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
737 |
|
// Set_GL_RUN(Row); |
738 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
739 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
740 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
741 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
742 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
743 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
744 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
745 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
746 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
747 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
748 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
749 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
750 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
751 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
752 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
753 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
754 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
755 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
756 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
757 |
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)); |
758 |
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)); |
759 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
760 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
761 |
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)); |
762 |
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)); |
763 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
764 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
765 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
766 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
767 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
768 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
769 |
}; |
}; |
770 |
}; |
}; |
771 |
// delete pResult; |
// delete pResult; |
909 |
* Function to query the GL_TRK_CALIB table of the DB. |
* Function to query the GL_TRK_CALIB table of the DB. |
910 |
* |
* |
911 |
* \param run starting time |
* \param run starting time |
912 |
|
* \param dbc DB server |
913 |
* \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 |
914 |
*/ |
*/ |
915 |
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){ |
921 |
stringstream myquery; |
stringstream myquery; |
922 |
// ---------------- |
// ---------------- |
923 |
myquery.str(""); |
myquery.str(""); |
924 |
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; |
925 |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
926 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
927 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
933 |
stringstream row; |
stringstream row; |
934 |
row.str(""); |
row.str(""); |
935 |
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 |
936 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
937 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
938 |
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()); |
939 |
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()); |
940 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
941 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
942 |
// |
// |
943 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
944 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
945 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
946 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
947 |
}; |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
948 |
|
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
949 |
|
}; |
950 |
}; |
}; |
951 |
delete pResult; |
delete pResult; |
952 |
|
// |
953 |
|
// if ( TO_TIME < time ) return(51); |
954 |
// |
// |
|
if(TO_TIME < time)return(51); |
|
955 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
956 |
// |
// |
957 |
return 0; |
return 0; |
1140 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1141 |
TSQLRow *Row; |
TSQLRow *Row; |
1142 |
stringstream myquery; |
stringstream myquery; |
1143 |
|
stringstream rname; |
1144 |
|
rname.str(""); |
1145 |
// ---------------- |
// ---------------- |
1146 |
myquery.str(""); |
myquery.str(""); |
1147 |
myquery << "select "; |
myquery << "select "; |
1158 |
stringstream fname; |
stringstream fname; |
1159 |
fname.str(""); |
fname.str(""); |
1160 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
1161 |
|
rname << Row->GetField(1); |
1162 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1163 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1164 |
}; |
}; |
1180 |
// |
// |
1181 |
UInt_t t0 = 0; |
UInt_t t0 = 0; |
1182 |
// |
// |
1183 |
myquery.str(""); |
// |
1184 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
1185 |
<< idraw << " AND TO_ID_RAW >= " |
oss.str(""); |
1186 |
<< idraw << ";"; |
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1187 |
pResult = dbc->Query(myquery.str().c_str()); |
<< rname.str().c_str() << "';"; |
1188 |
if ( pResult ){ |
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1189 |
|
pResult = dbc->Query(oss.str().c_str()); |
1190 |
|
Row = pResult->Next(); |
1191 |
|
// |
1192 |
|
TString name=rname.str().c_str(); |
1193 |
|
UInt_t dworbit = 0; |
1194 |
|
Int_t nlength = name.Length(); |
1195 |
|
if ( nlength < 5 ) return; |
1196 |
|
TString dwo = 0; |
1197 |
|
for (Int_t i = 0; i<5; i++){ |
1198 |
|
dwo.Append(name[i],1); |
1199 |
|
}; |
1200 |
|
if ( dwo.IsDigit() ){ |
1201 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1202 |
|
} else { |
1203 |
|
dwo=""; |
1204 |
|
for (Int_t i = 8; i<13; i++){ |
1205 |
|
dwo.Append(name[i],1); |
1206 |
|
}; |
1207 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
1208 |
|
}; |
1209 |
|
// if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
1210 |
|
// |
1211 |
|
if ( !Row ){ |
1212 |
|
oss.str(""); |
1213 |
|
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1214 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1215 |
|
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1216 |
|
pResult = dbc->Query(oss.str().c_str()); |
1217 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1218 |
if ( Row ){ |
if ( !Row ){ |
1219 |
// |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1220 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
return; |
|
// |
|
1221 |
}; |
}; |
1222 |
}; |
}; |
1223 |
// |
// |
1224 |
|
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
1225 |
|
// |
1226 |
|
// myquery.str(""); |
1227 |
|
// myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
1228 |
|
// << idraw << " AND TO_ID_RAW >= " |
1229 |
|
// << idraw << ";"; |
1230 |
|
// pResult = dbc->Query(myquery.str().c_str()); |
1231 |
|
// if ( pResult ){ |
1232 |
|
// Row = pResult->Next(); |
1233 |
|
// if ( Row ){ |
1234 |
|
// // |
1235 |
|
// t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
1236 |
|
// // |
1237 |
|
// }; |
1238 |
|
// }; |
1239 |
|
// |
1240 |
// |
// |
1241 |
// look for the correct timesync entry |
// look for the correct timesync entry |
1242 |
// |
// |
1308 |
* @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 |
1309 |
* |
* |
1310 |
*/ |
*/ |
1311 |
TString GL_TIMESYNC::ConvertTime(TString tzone, UInt_t dbt){ |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
1312 |
// |
// |
1313 |
TDatime *time = new TDatime(); |
TDatime *time = new TDatime(); |
1314 |
TString rtime; |
TString rtime; |
1315 |
|
Bool_t found = false; |
1316 |
// |
// |
1317 |
time->Set(dbt,false); // MSK = Moscow Winter Time |
time->Set(dbt,false); // UTC (Coordinated Universal Time) |
1318 |
// |
// |
1319 |
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1320 |
// |
// |
1321 |
UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3 hs |
UInt_t timeMSK = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
1322 |
time->Set(timeUTC,false); |
time->Set(timeMSK,false); |
1323 |
|
found = true; |
1324 |
// |
// |
1325 |
}; |
}; |
1326 |
// |
// |
1327 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
1328 |
// |
// |
1329 |
UInt_t timeCET = time->Convert() - 60*60*2; // CET (Central European Time) = Moscow Winter Time - 2 hs |
UInt_t timeCET = time->Convert() + 60*60*1; // CET (Central European Time) = UTC + 1 hs |
1330 |
time->Set(timeCET,false); |
time->Set(timeCET,false); |
1331 |
|
found = true; |
1332 |
// |
// |
1333 |
}; |
}; |
1334 |
// |
// |
1335 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1336 |
// |
// |
1337 |
UInt_t timeCEST = time->Convert() - 60*60*1; // CEST (Central European Summer Time) = Moscow Winter Time - 1 h |
UInt_t timeCEST = time->Convert() + 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
1338 |
time->Set(timeCEST,false); |
time->Set(timeCEST,false); |
1339 |
|
found = true; |
1340 |
// |
// |
1341 |
}; |
}; |
1342 |
// |
// |
1343 |
if ( !strcmp(tzone.Data(),"MSD") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
1344 |
// |
// |
1345 |
UInt_t timeMSD = time->Convert() + 60*60*1; // MSD (Moscow Summer Time) = Moscow Winter Time + 1 h |
UInt_t timeMSD = time->Convert() + 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
1346 |
time->Set(timeMSD,false); |
time->Set(timeMSD,false); |
1347 |
|
found = true; |
1348 |
// |
// |
1349 |
}; |
}; |
1350 |
// |
// |
1351 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1352 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1353 |
|
tzone = "UTC"; |
1354 |
|
}; |
1355 |
|
// |
1356 |
rtime = time->AsSQLString(); |
rtime = time->AsSQLString(); |
1357 |
// |
// |
1358 |
return(rtime); |
return(rtime); |
1366 |
* @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 |
1367 |
* |
* |
1368 |
*/ |
*/ |
1369 |
TString GL_TIMESYNC::UnConvertTime(TString tzone, UInt_t dbt){ |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
1370 |
// |
// |
1371 |
TDatime *time = new TDatime(); |
TDatime *time = new TDatime(); |
1372 |
TString rtime; |
TString rtime; |
1373 |
// |
// |
1374 |
time->Set(dbt,false); // MSK = Moscow Winter Time |
Bool_t found = false; |
1375 |
// |
// |
1376 |
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
time->Set(dbt,false); // tzone |
1377 |
|
// |
1378 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1379 |
// |
// |
1380 |
UInt_t timeUTC = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) +3 hs = Moscow Winter Time |
UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
1381 |
time->Set(timeUTC,false); |
time->Set(timeUTC,false); |
1382 |
|
found = true; |
1383 |
// |
// |
1384 |
}; |
}; |
1385 |
// |
// |
1386 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
1387 |
// |
// |
1388 |
UInt_t timeCET = time->Convert() + 60*60*2; // CET (Central European Time) + 2 hs = Moscow Winter Time |
UInt_t timeCET = time->Convert() - 60*60*1; // CET (Central European Time) - 1 hs = UTC |
1389 |
time->Set(timeCET,false); |
time->Set(timeCET,false); |
1390 |
|
found = true; |
1391 |
// |
// |
1392 |
}; |
}; |
1393 |
// |
// |
1394 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
1395 |
// |
// |
1396 |
UInt_t timeCEST = time->Convert() + 60*60*1; // CEST (Central European Summer Time) + 1 h = Moscow Winter Time |
UInt_t timeCEST = time->Convert() - 60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
1397 |
time->Set(timeCEST,false); |
time->Set(timeCEST,false); |
1398 |
|
found = true; |
1399 |
// |
// |
1400 |
}; |
}; |
1401 |
// |
// |
1402 |
if ( !strcmp(tzone.Data(),"MSD") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
1403 |
// |
// |
1404 |
UInt_t timeMSD = time->Convert() - 60*60*1; // MSD (Moscow Summer Time) - 1 h = Moscow Winter Time |
UInt_t timeMSD = time->Convert() - 60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
1405 |
time->Set(timeMSD,false); |
time->Set(timeMSD,false); |
1406 |
|
found = true; |
1407 |
// |
// |
1408 |
}; |
}; |
1409 |
// |
// |
1410 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1411 |
|
// |
1412 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1413 |
|
tzone = "UTC"; |
1414 |
|
}; |
1415 |
|
// |
1416 |
rtime = time->AsSQLString(); |
rtime = time->AsSQLString(); |
1417 |
// |
// |
1418 |
return(rtime); |
return(rtime); |
1419 |
} |
} |
1420 |
|
|
1421 |
|
|
1422 |
|
// **************************************************** |
1423 |
|
/** |
1424 |
|
* Function to query the GL_TLE table of the DB. |
1425 |
|
* |
1426 |
|
* time is the unix time for which a good tle is requested. |
1427 |
|
* |
1428 |
|
* Return the pointer to a cTle object that has the closest and |
1429 |
|
* previous date compared with time. |
1430 |
|
* |
1431 |
|
* If errors occurs it returns NULL. |
1432 |
|
*/ |
1433 |
|
cTle* GL_TLE::Query_GL_TLE(UInt_t time, TSQLServer *dbc){ |
1434 |
|
stringstream myquery; |
1435 |
|
myquery.str(""); |
1436 |
|
|
1437 |
|
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
1438 |
|
<< "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;"; |
1439 |
|
|
1440 |
|
|
1441 |
|
return Query_GL_TLE_go(myquery.str(), dbc); |
1442 |
|
} |
1443 |
|
|
1444 |
|
|
1445 |
|
// **************************************************** |
1446 |
|
/** |
1447 |
|
* Function to query the GL_TLE table of the DB. |
1448 |
|
* |
1449 |
|
* date is a datetime format YYYY-MM-DD hh:mm:ss for which a good tle |
1450 |
|
* is requested. |
1451 |
|
* |
1452 |
|
* Return the pointer to a cTle object that has the closest and |
1453 |
|
* previous date compared with time. |
1454 |
|
* |
1455 |
|
* If errors occurs it returns NULL. |
1456 |
|
*/ |
1457 |
|
cTle* GL_TLE::Query_GL_TLE(TString date, TSQLServer *dbc){ |
1458 |
|
stringstream myquery; |
1459 |
|
myquery.str(""); |
1460 |
|
|
1461 |
|
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
1462 |
|
<< "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;"; |
1463 |
|
|
1464 |
|
|
1465 |
|
return Query_GL_TLE_go(myquery.str(), dbc); |
1466 |
|
} |
1467 |
|
|
1468 |
|
|
1469 |
|
// **************************************************** |
1470 |
|
/** |
1471 |
|
* Private function used by Query_GL_TLE methods. |
1472 |
|
* |
1473 |
|
* myquery is the query string. |
1474 |
|
* |
1475 |
|
* Return the pointer to a cTle object that has the closest and |
1476 |
|
* previous date compared with time. |
1477 |
|
* |
1478 |
|
* If errors occurs it returns NULL. |
1479 |
|
*/ |
1480 |
|
cTle* GL_TLE::Query_GL_TLE_go(TString myquery, TSQLServer *dbc){ |
1481 |
|
cTle *tle; |
1482 |
|
string tle1, tle2, tle3; |
1483 |
|
|
1484 |
|
// MySQL variables |
1485 |
|
TSQLResult *result; |
1486 |
|
TSQLRow *row; |
1487 |
|
|
1488 |
|
result = dbc->Query(myquery.Data()); |
1489 |
|
if(! result->GetRowCount() ) return NULL; |
1490 |
|
|
1491 |
|
row = result->Next(); |
1492 |
|
tle1 = row->GetField(0); |
1493 |
|
tle2 = row->GetField(1); |
1494 |
|
tle3 = row->GetField(2); |
1495 |
|
|
1496 |
|
tle = new cTle(tle1, tle2, tle3); |
1497 |
|
|
1498 |
|
delete result; |
1499 |
|
delete row; |
1500 |
|
|
1501 |
|
return tle; |
1502 |
|
} |