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 |
|
GL_TLE::GL_TLE(){ |
165 |
|
} |
166 |
|
|
167 |
|
// **************************************************** |
168 |
|
|
169 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
170 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
338 |
CAL_DSP_MASK = 0; |
CAL_DSP_MASK = 0; |
339 |
}; |
}; |
340 |
|
|
341 |
|
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
342 |
|
for( Int_t t = 0; t < 30; t++){ |
343 |
|
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
344 |
|
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
345 |
|
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
346 |
|
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
347 |
|
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
348 |
|
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
349 |
|
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
350 |
|
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
351 |
|
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
352 |
|
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
353 |
|
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
354 |
|
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
355 |
|
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
356 |
|
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
357 |
|
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
358 |
|
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
359 |
|
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
360 |
|
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
361 |
|
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
362 |
|
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
363 |
|
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
364 |
|
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
365 |
|
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
366 |
|
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
367 |
|
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
368 |
|
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
369 |
|
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
370 |
|
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
371 |
|
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
372 |
|
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
373 |
|
}; |
374 |
|
|
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){ |
383 |
|
// MySQL variables |
384 |
|
TSQLResult *pResult; |
385 |
|
TSQLRow *Row; |
386 |
|
stringstream myquery; |
387 |
|
// |
388 |
|
if ( !IDRUN ) IDRUN = ID; |
389 |
|
if ( !IDRUN ) return 1; |
390 |
|
// ---------------- |
391 |
|
myquery.str(""); |
392 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
393 |
|
myquery << "ID"; |
394 |
|
myquery << ",ID_RUN_FRAG"; |
395 |
|
myquery << ",ID_ROOT_L0"; |
396 |
|
myquery << ",ID_ROOT_L2"; |
397 |
|
myquery << ",RUNHEADER_TIME"; |
398 |
|
myquery << ",RUNTRAILER_TIME"; |
399 |
|
myquery << ",RUNHEADER_OBT"; |
400 |
|
myquery << ",RUNTRAILER_OBT"; |
401 |
|
myquery << ",RUNHEADER_PKT"; |
402 |
|
myquery << ",RUNTRAILER_PKT"; |
403 |
|
myquery << ",BOOT_NUMBER"; |
404 |
|
myquery << ",EV_FROM"; |
405 |
|
myquery << ",EV_TO"; |
406 |
|
myquery << ",NEVENTS"; |
407 |
|
myquery << ",PKT_COUNTER"; |
408 |
|
myquery << ",PKT_READY_COUNTER"; |
409 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
410 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
411 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
412 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
413 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
414 |
|
myquery << ",ACQ_BUILD_INFO"; |
415 |
|
myquery << ",ACQ_VAR_INFO"; |
416 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
417 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
418 |
|
myquery << ",TRK_CALIB_USED"; |
419 |
|
myquery << ",CAL_DSP_MASK"; |
420 |
|
myquery << ",LAST_TIMESYNC"; |
421 |
|
myquery << ",OBT_TIMESYNC"; |
422 |
|
myquery << ",VALIDATION"; |
423 |
|
myquery << ",INSERT_TIME"; |
424 |
|
myquery << ") SELECT * FROM "; |
425 |
|
myquery << FromTable.Data(); |
426 |
|
myquery << " WHERE ID="; |
427 |
|
myquery << (UInt_t)IDRUN << ";"; |
428 |
|
// |
429 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
430 |
|
// |
431 |
|
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 = ""; |
451 |
|
TString fileL2 = ""; |
452 |
|
myquery.str(""); |
453 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
454 |
|
myquery << idl0 << ";"; |
455 |
|
// |
456 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
457 |
|
// |
458 |
|
pResult = dbc->Query(myquery.str().c_str()); |
459 |
|
// |
460 |
|
Row = pResult->Next(); |
461 |
|
if( Row != NULL ){ |
462 |
|
fileL0 = (TString)Row->GetField(0); |
463 |
|
}; |
464 |
|
// |
465 |
|
// |
466 |
|
// |
467 |
|
myquery.str(""); |
468 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
469 |
|
myquery << idl2 << ";"; |
470 |
|
// |
471 |
|
// printf("3myquery is %s \n",myquery.str().c_str()); |
472 |
|
// |
473 |
|
pResult = dbc->Query(myquery.str().c_str()); |
474 |
|
// |
475 |
|
Row = pResult->Next(); |
476 |
|
if( Row != NULL ){ |
477 |
|
fileL2 = (TString)Row->GetField(0); |
478 |
|
}; |
479 |
|
// |
480 |
|
// |
481 |
|
// |
482 |
|
myquery.str(""); |
483 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
484 |
|
myquery << fileL0.Data() << "' where ID_TRASH="; |
485 |
|
myquery << idtrash << ";"; |
486 |
|
// |
487 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
488 |
|
// |
489 |
|
dbc->Query(myquery.str().c_str()); |
490 |
|
// |
491 |
|
myquery.str(""); |
492 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
493 |
|
myquery << fileL2.Data() << "' where ID_TRASH="; |
494 |
|
myquery << idtrash << ";"; |
495 |
|
// |
496 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
497 |
|
// |
498 |
|
dbc->Query(myquery.str().c_str()); |
499 |
|
// |
500 |
|
myquery.str(""); |
501 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
502 |
|
myquery << FromTable.Data() << "' where ID_TRASH="; |
503 |
|
myquery << idtrash << ";"; |
504 |
|
// |
505 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
506 |
|
// |
507 |
|
// |
508 |
|
dbc->Query(myquery.str().c_str()); |
509 |
|
// |
510 |
|
myquery.str(""); |
511 |
|
myquery << " DELETE FROM "; |
512 |
|
myquery << FromTable.Data() << " where ID="; |
513 |
|
myquery << IDRUN << ";"; |
514 |
|
// |
515 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
516 |
|
// |
517 |
|
// |
518 |
|
dbc->Query(myquery.str().c_str()); |
519 |
|
// |
520 |
|
return 0; |
521 |
|
}; |
522 |
|
|
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 IDRUN,TString ToTable){ |
531 |
|
// 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; |
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; |
642 |
|
}; |
643 |
|
|
644 |
/** |
/** |
645 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
716 |
myquery << (UInt_t)BOOT_NUMBER << "','"; |
myquery << (UInt_t)BOOT_NUMBER << "','"; |
717 |
myquery << (UInt_t)VALIDATION << "');"; |
myquery << (UInt_t)VALIDATION << "');"; |
718 |
// |
// |
719 |
//printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
720 |
// |
// |
721 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
722 |
// |
// |
850 |
myquery << ",VALIDATION"; |
myquery << ",VALIDATION"; |
851 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
852 |
// |
// |
853 |
|
// printf(" myquery is %s \n",myquery.str().c_str()); |
854 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
855 |
if(!pResult->GetRowCount())return(-50); |
// |
856 |
|
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
857 |
|
// |
858 |
|
if( !pResult->GetRowCount() ) return(-50); |
859 |
|
// |
860 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
861 |
Row = pResult->Next(); |
Row = pResult->Next(); |
862 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
863 |
|
// 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; |
898 |
|
return(0); |
|
return 0; |
|
|
|
|
899 |
}; |
}; |
900 |
|
|
901 |
/** |
/** |
906 |
* |
* |
907 |
*/ |
*/ |
908 |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TString where, TSQLServer *dbc){ |
|
// Bool_t debug = 1; |
|
909 |
// MySQL variables |
// MySQL variables |
910 |
TSQLResult *pResult; |
TSQLResult *pResult; |
911 |
TSQLRow *Row; |
TSQLRow *Row; |
913 |
int r; |
int r; |
914 |
stringstream myquery; |
stringstream myquery; |
915 |
// ---------------- |
// ---------------- |
|
// NB! unsigned long long integers: when set to a number use ULL to store the correct number |
|
916 |
myquery.str(""); |
myquery.str(""); |
917 |
myquery << " select "; |
myquery << " select "; |
|
// myquery << " * "; |
|
918 |
myquery << "ID"; |
myquery << "ID"; |
919 |
|
myquery << ",ID_RUN_FRAG"; |
920 |
myquery << ",ID_ROOT_L0"; |
myquery << ",ID_ROOT_L0"; |
921 |
|
myquery << ",ID_ROOT_L2"; |
922 |
myquery << ",RUNHEADER_TIME"; |
myquery << ",RUNHEADER_TIME"; |
923 |
myquery << ",RUNTRAILER_TIME"; |
myquery << ",RUNTRAILER_TIME"; |
924 |
myquery << ",RUNHEADER_OBT"; |
myquery << ",RUNHEADER_OBT"; |
944 |
myquery << ",TRK_CALIB_USED"; |
myquery << ",TRK_CALIB_USED"; |
945 |
myquery << ",CAL_DSP_MASK"; |
myquery << ",CAL_DSP_MASK"; |
946 |
myquery << ",BOOT_NUMBER"; |
myquery << ",BOOT_NUMBER"; |
947 |
|
myquery << ",VALIDATION"; |
948 |
myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";"; |
myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";"; |
949 |
// |
// |
950 |
|
// printf(" query is %s \n",myquery.str().c_str()); |
951 |
|
// |
952 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
953 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
954 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
955 |
Row = pResult->Next(); |
Row = pResult->Next(); |
956 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
957 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
958 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
959 |
if (t== 1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
960 |
if (t== 2) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
961 |
if (t== 3) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
962 |
if (t== 4) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
963 |
if (t== 5) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
964 |
if (t== 6) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
965 |
if (t== 7) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
966 |
if (t== 8) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
967 |
if (t== 9) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
968 |
if (t==10) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
969 |
if (t==11) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
970 |
if (t==12) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
971 |
if (t==13) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
972 |
if (t==14) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
973 |
if (t==15) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
974 |
if (t==16) PRH_VAR_TRG_MODE_A = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
975 |
if (t==17) PRH_VAR_TRG_MODE_B = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
976 |
if (t==18) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
977 |
if (t==19) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
978 |
if (t==20) RM_ACQ_AFTER_CALIB = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
979 |
if (t==21) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
980 |
if (t==22) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
981 |
if (t==23) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
982 |
if (t==24) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
983 |
if (t==25) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
984 |
if (t==26) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
985 |
}; |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
986 |
|
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
987 |
|
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
988 |
|
}; |
989 |
}; |
}; |
990 |
delete pResult; |
// delete pResult; |
991 |
|
return(0); |
|
return 0; |
|
|
|
|
992 |
};// **************************************************** |
};// **************************************************** |
993 |
|
|
994 |
/** |
/** |
995 |
* Function to query the GL_ROOT table of the DB. |
* Function to query the GL_ROOT table of the DB. |
996 |
* |
* |
1035 |
* Function to query the GL_TRK_CALIB table of the DB. |
* Function to query the GL_TRK_CALIB table of the DB. |
1036 |
* |
* |
1037 |
* \param run starting time |
* \param run starting time |
1038 |
|
* \param dbc DB server |
1039 |
* \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 |
1040 |
*/ |
*/ |
1041 |
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){ |
1047 |
stringstream myquery; |
stringstream myquery; |
1048 |
// ---------------- |
// ---------------- |
1049 |
myquery.str(""); |
myquery.str(""); |
1050 |
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; |
1051 |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1052 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1053 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1056 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1057 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
1058 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1059 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
stringstream row; |
1060 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
row.str(""); |
1061 |
if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(Row->GetField(t)); |
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 |
1062 |
if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
1063 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1064 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==2) EV_ROOT_CALIBTRK1 = (UInt_t)atoll(row.str().c_str()); |
1065 |
|
if (t==3) EV_ROOT_CALIBTRK2 = (UInt_t)atoll(row.str().c_str()); |
1066 |
|
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
1067 |
|
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
1068 |
// |
// |
1069 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
1070 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
1071 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
1072 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
1073 |
}; |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
1074 |
|
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
1075 |
|
}; |
1076 |
}; |
}; |
1077 |
delete pResult; |
delete pResult; |
1078 |
|
// |
1079 |
|
// if ( TO_TIME < time ) return(51); |
1080 |
// |
// |
|
if(TO_TIME < time)return(51); |
|
1081 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
1082 |
// |
// |
1083 |
return 0; |
return 0; |
1090 |
* \param run starting time |
* \param run starting time |
1091 |
* \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 |
1092 |
*/ |
*/ |
1093 |
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){ |
1094 |
// MySQL variables |
// MySQL variables |
1095 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1096 |
TSQLRow *Row; |
TSQLRow *Row; |
1097 |
int t; |
int t; |
1098 |
stringstream myquery; |
stringstream myquery; |
1099 |
|
uptime = 0; |
1100 |
// |
// |
1101 |
// select the correct calibration |
// select the correct calibration |
1102 |
// |
// |
1104 |
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; |
1105 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1106 |
myquery << " and TO_TIME > " << time; |
myquery << " and TO_TIME > " << time; |
1107 |
myquery << " and VALIDATION=1;"; |
myquery << " ;"; |
1108 |
|
//myquery << " and VALIDATION=1;"; |
1109 |
// |
// |
1110 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1111 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1112 |
|
// |
1113 |
|
if( !pResult->GetRowCount() ) return(-54); |
1114 |
|
Row = pResult->Next(); |
1115 |
|
if( Row == NULL ) return (-54); |
1116 |
|
// |
1117 |
|
uptime = (UInt_t)atoll(Row->GetField(2)); |
1118 |
// |
// |
1119 |
// 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... |
1120 |
// |
// |
1121 |
if( !pResult->GetRowCount() ){ |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
|
// pResult->Delete(); |
|
1122 |
// |
// |
1123 |
// 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 |
1124 |
// |
// |
1127 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
1128 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
1129 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1130 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
1131 |
// |
// |
1132 |
// if no results yet quit with error |
// if no results yet quit with error |
1133 |
// |
// |
1134 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
1135 |
|
// |
1136 |
|
Row = pResult->Next(); |
1137 |
|
// |
1138 |
}; |
}; |
1139 |
// |
// |
1140 |
// store infos and exit |
// store infos and exit |
1141 |
// |
// |
|
Row = pResult->Next(); |
|
1142 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
1143 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
1144 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
1166 |
// ---------------- |
// ---------------- |
1167 |
myquery.str(""); |
myquery.str(""); |
1168 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
1169 |
myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1170 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
1171 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1172 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
1266 |
TSQLResult *pResult; |
TSQLResult *pResult; |
1267 |
TSQLRow *Row; |
TSQLRow *Row; |
1268 |
stringstream myquery; |
stringstream myquery; |
1269 |
|
stringstream rname; |
1270 |
|
rname.str(""); |
1271 |
// ---------------- |
// ---------------- |
1272 |
myquery.str(""); |
myquery.str(""); |
1273 |
myquery << "select "; |
myquery << "select "; |
1284 |
stringstream fname; |
stringstream fname; |
1285 |
fname.str(""); |
fname.str(""); |
1286 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
1287 |
|
rname << Row->GetField(1); |
1288 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
1289 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
1290 |
}; |
}; |
1304 |
// |
// |
1305 |
// look for Resurs offset |
// look for Resurs offset |
1306 |
// |
// |
1307 |
UInt_t t0 = 0; |
T0 = 0; |
1308 |
// |
// |
1309 |
myquery.str(""); |
// |
1310 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
1311 |
<< idraw << " AND TO_ID_RAW >= " |
oss.str(""); |
1312 |
<< idraw << ";"; |
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
1313 |
pResult = dbc->Query(myquery.str().c_str()); |
<< rname.str().c_str() << "';"; |
1314 |
if ( pResult ){ |
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1315 |
|
pResult = dbc->Query(oss.str().c_str()); |
1316 |
|
Row = pResult->Next(); |
1317 |
|
// |
1318 |
|
TString name=rname.str().c_str(); |
1319 |
|
UInt_t dworbit = 0; |
1320 |
|
Int_t nlength = name.Length(); |
1321 |
|
if ( nlength < 5 ) return; |
1322 |
|
TString dwo = 0; |
1323 |
|
for (Int_t i = 0; i<5; i++){ |
1324 |
|
dwo.Append(name[i],1); |
1325 |
|
}; |
1326 |
|
if ( dwo.IsDigit() ){ |
1327 |
|
dworbit = (UInt_t)dwo.Atoi(); |
1328 |
|
} else { |
1329 |
|
dwo=""; |
1330 |
|
for (Int_t i = 8; i<13; i++){ |
1331 |
|
dwo.Append(name[i],1); |
1332 |
|
}; |
1333 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
1334 |
|
}; |
1335 |
|
// if ( IsDebug() ) printf(" Downlink orbit is %i (dwo = %s) \n",dworbit,dwo.Data()); |
1336 |
|
// |
1337 |
|
if ( !Row ){ |
1338 |
|
oss.str(""); |
1339 |
|
oss << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
1340 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
1341 |
|
// if ( IsDebug() ) printf(" %s \n",oss.str().c_str()); |
1342 |
|
pResult = dbc->Query(oss.str().c_str()); |
1343 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1344 |
if ( Row ){ |
if ( !Row ){ |
1345 |
// |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
1346 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
return; |
|
// |
|
1347 |
}; |
}; |
1348 |
}; |
}; |
1349 |
// |
// |
1350 |
|
// |
1351 |
|
TDatime ti = TDatime(Row->GetField(0)); |
1352 |
|
TTimeStamp tu = TTimeStamp((UInt_t)ti.GetYear(),(UInt_t)ti.GetMonth(),(UInt_t)ti.GetDay(),(UInt_t)ti.GetHour(),(UInt_t)ti.GetMinute(),(UInt_t)ti.GetSecond(),0,true,0); |
1353 |
|
T0 = (UInt_t)tu.GetSec(); |
1354 |
// |
// |
1355 |
// look for the correct timesync entry |
// look for the correct timesync entry |
1356 |
// |
// |
1357 |
myquery.str(""); |
myquery.str(""); |
1358 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
1359 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
1360 |
<< ";"; |
<< ";"; |
1361 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
1362 |
if ( pResult ){ |
if ( pResult ){ |
1363 |
Row = pResult->Next(); |
Row = pResult->Next(); |
1364 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
1365 |
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)); |
1366 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
1367 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
1368 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
1369 |
}; |
}; |
1370 |
}; |
}; |
1371 |
|
// |
1372 |
|
file->Close(); |
1373 |
delete pResult; |
delete pResult; |
1374 |
}; |
}; |
1375 |
|
|
1384 |
// |
// |
1385 |
}; |
}; |
1386 |
|
|
1387 |
|
/** |
1388 |
|
* |
1389 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
1390 |
|
* |
1391 |
|
*/ |
1392 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
1393 |
|
// |
1394 |
|
return(((UInt_t)((this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
1395 |
|
// |
1396 |
|
}; |
1397 |
|
|
1398 |
|
|
1399 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
1400 |
// |
// |
1427 |
return(pkt_num); |
return(pkt_num); |
1428 |
// |
// |
1429 |
}; |
}; |
1430 |
|
|
1431 |
|
/* |
1432 |
|
* |
1433 |
|
* Convert the time in the DB from UInt_t to a string |
1434 |
|
* |
1435 |
|
* @param dbt time in the DB |
1436 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1437 |
|
* |
1438 |
|
*/ |
1439 |
|
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
1440 |
|
// |
1441 |
|
Int_t offset = 0; |
1442 |
|
TString rtime; |
1443 |
|
Bool_t found = false; |
1444 |
|
// |
1445 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1446 |
|
// |
1447 |
|
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
1448 |
|
found = true; |
1449 |
|
// |
1450 |
|
}; |
1451 |
|
// |
1452 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1453 |
|
// |
1454 |
|
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
1455 |
|
found = true; |
1456 |
|
// |
1457 |
|
}; |
1458 |
|
// |
1459 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1460 |
|
// |
1461 |
|
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
1462 |
|
found = true; |
1463 |
|
// |
1464 |
|
}; |
1465 |
|
// |
1466 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
1467 |
|
// |
1468 |
|
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
1469 |
|
found = true; |
1470 |
|
// |
1471 |
|
}; |
1472 |
|
// |
1473 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1474 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1475 |
|
tzone = "UTC"; |
1476 |
|
}; |
1477 |
|
// |
1478 |
|
dbt += offset; |
1479 |
|
// |
1480 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1481 |
|
// |
1482 |
|
rtime = time->AsString("s"); |
1483 |
|
// |
1484 |
|
delete time; |
1485 |
|
// |
1486 |
|
return(rtime); |
1487 |
|
} |
1488 |
|
|
1489 |
|
/* |
1490 |
|
* |
1491 |
|
* Convert the time from TZONE to UTC |
1492 |
|
* |
1493 |
|
* @param dbt time in the DB |
1494 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
1495 |
|
* |
1496 |
|
*/ |
1497 |
|
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
1498 |
|
// |
1499 |
|
Int_t offset = 0; |
1500 |
|
TString rtime; |
1501 |
|
// |
1502 |
|
Bool_t found = false; |
1503 |
|
// |
1504 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
1505 |
|
// |
1506 |
|
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
1507 |
|
found = true; |
1508 |
|
// |
1509 |
|
}; |
1510 |
|
// |
1511 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
1512 |
|
// |
1513 |
|
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
1514 |
|
found = true; |
1515 |
|
// |
1516 |
|
}; |
1517 |
|
// |
1518 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
1519 |
|
// |
1520 |
|
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
1521 |
|
found = true; |
1522 |
|
// |
1523 |
|
}; |
1524 |
|
// |
1525 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
1526 |
|
// |
1527 |
|
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
1528 |
|
found = true; |
1529 |
|
// |
1530 |
|
}; |
1531 |
|
// |
1532 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
1533 |
|
// |
1534 |
|
offset = 0; |
1535 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
1536 |
|
tzone = "UTC"; |
1537 |
|
}; |
1538 |
|
// |
1539 |
|
dbt += offset; |
1540 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
1541 |
|
// |
1542 |
|
rtime = time->AsString("s"); |
1543 |
|
// |
1544 |
|
return(rtime); |
1545 |
|
} |
1546 |
|
|
1547 |
|
|
1548 |
|
// **************************************************** |
1549 |
|
/** |
1550 |
|
* Function to query the GL_TLE table of the DB. |
1551 |
|
* |
1552 |
|
* time is the unix time for which a good tle is requested. |
1553 |
|
* |
1554 |
|
* Return the pointer to a cTle object that has the closest and |
1555 |
|
* previous date compared with time. |
1556 |
|
* |
1557 |
|
* If errors occurs it returns NULL. |
1558 |
|
*/ |
1559 |
|
cTle* GL_TLE::Query_GL_TLE(UInt_t time, TSQLServer *dbc){ |
1560 |
|
stringstream myquery; |
1561 |
|
myquery.str(""); |
1562 |
|
|
1563 |
|
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
1564 |
|
<< "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;"; |
1565 |
|
|
1566 |
|
|
1567 |
|
return Query_GL_TLE_go(myquery.str(), dbc); |
1568 |
|
} |
1569 |
|
|
1570 |
|
|
1571 |
|
// **************************************************** |
1572 |
|
/** |
1573 |
|
* Function to query the GL_TLE table of the DB. |
1574 |
|
* |
1575 |
|
* date is a datetime format YYYY-MM-DD hh:mm:ss for which a good tle |
1576 |
|
* is requested. |
1577 |
|
* |
1578 |
|
* Return the pointer to a cTle object that has the closest and |
1579 |
|
* previous date compared with time. |
1580 |
|
* |
1581 |
|
* If errors occurs it returns NULL. |
1582 |
|
*/ |
1583 |
|
cTle* GL_TLE::Query_GL_TLE(TString date, TSQLServer *dbc){ |
1584 |
|
stringstream myquery; |
1585 |
|
myquery.str(""); |
1586 |
|
|
1587 |
|
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
1588 |
|
<< "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;"; |
1589 |
|
|
1590 |
|
|
1591 |
|
return Query_GL_TLE_go(myquery.str(), dbc); |
1592 |
|
} |
1593 |
|
|
1594 |
|
|
1595 |
|
// **************************************************** |
1596 |
|
/** |
1597 |
|
* Private function used by Query_GL_TLE methods. |
1598 |
|
* |
1599 |
|
* myquery is the query string. |
1600 |
|
* |
1601 |
|
* Return the pointer to a cTle object that has the closest and |
1602 |
|
* previous date compared with time. |
1603 |
|
* |
1604 |
|
* If errors occurs it returns NULL. |
1605 |
|
*/ |
1606 |
|
cTle* GL_TLE::Query_GL_TLE_go(TString myquery, TSQLServer *dbc){ |
1607 |
|
cTle *tle; |
1608 |
|
string tle1, tle2, tle3; |
1609 |
|
|
1610 |
|
// MySQL variables |
1611 |
|
TSQLResult *result; |
1612 |
|
TSQLRow *row; |
1613 |
|
|
1614 |
|
result = dbc->Query(myquery.Data()); |
1615 |
|
if(! result->GetRowCount() ) return NULL; |
1616 |
|
|
1617 |
|
row = result->Next(); |
1618 |
|
tle1 = row->GetField(0); |
1619 |
|
tle2 = row->GetField(1); |
1620 |
|
tle3 = row->GetField(2); |
1621 |
|
|
1622 |
|
tle = new cTle(tle1, tle2, tle3); |
1623 |
|
|
1624 |
|
delete result; |
1625 |
|
delete row; |
1626 |
|
|
1627 |
|
return tle; |
1628 |
|
} |