| 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; |
| 162 |
} |
} |
| 163 |
|
|
|
GL_TLE::GL_TLE(){ |
|
|
} |
|
|
|
|
| 164 |
// **************************************************** |
// **************************************************** |
| 165 |
|
|
| 166 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
| 371 |
|
|
| 372 |
} |
} |
| 373 |
|
|
| 374 |
|
/** |
| 375 |
|
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
| 376 |
|
* If IDRUN is 0 "this->ID" run is used. |
| 377 |
|
* |
| 378 |
|
**/ |
| 379 |
|
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
| 380 |
|
// MySQL variables |
| 381 |
|
TSQLResult *pResult; |
| 382 |
|
TSQLRow *Row; |
| 383 |
|
stringstream myquery; |
| 384 |
|
// |
| 385 |
|
if ( !IDRUN ) IDRUN = ID; |
| 386 |
|
if ( !IDRUN ) return 1; |
| 387 |
|
// ---------------- |
| 388 |
|
myquery.str(""); |
| 389 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
| 390 |
|
myquery << "ID"; |
| 391 |
|
myquery << ",ID_RUN_FRAG"; |
| 392 |
|
myquery << ",ID_ROOT_L0"; |
| 393 |
|
myquery << ",ID_ROOT_L2"; |
| 394 |
|
myquery << ",RUNHEADER_TIME"; |
| 395 |
|
myquery << ",RUNTRAILER_TIME"; |
| 396 |
|
myquery << ",RUNHEADER_OBT"; |
| 397 |
|
myquery << ",RUNTRAILER_OBT"; |
| 398 |
|
myquery << ",RUNHEADER_PKT"; |
| 399 |
|
myquery << ",RUNTRAILER_PKT"; |
| 400 |
|
myquery << ",BOOT_NUMBER"; |
| 401 |
|
myquery << ",EV_FROM"; |
| 402 |
|
myquery << ",EV_TO"; |
| 403 |
|
myquery << ",NEVENTS"; |
| 404 |
|
myquery << ",PKT_COUNTER"; |
| 405 |
|
myquery << ",PKT_READY_COUNTER"; |
| 406 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 407 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 408 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 409 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 410 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 411 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 412 |
|
myquery << ",ACQ_VAR_INFO"; |
| 413 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 414 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 415 |
|
myquery << ",TRK_CALIB_USED"; |
| 416 |
|
myquery << ",CAL_DSP_MASK"; |
| 417 |
|
myquery << ",LAST_TIMESYNC"; |
| 418 |
|
myquery << ",OBT_TIMESYNC"; |
| 419 |
|
myquery << ",VALIDATION"; |
| 420 |
|
myquery << ",INSERT_TIME"; |
| 421 |
|
myquery << ") SELECT * FROM "; |
| 422 |
|
myquery << FromTable.Data(); |
| 423 |
|
myquery << " WHERE ID="; |
| 424 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 425 |
|
// |
| 426 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
| 427 |
|
// |
| 428 |
|
dbc->Query(myquery.str().c_str()); |
| 429 |
|
// |
| 430 |
|
// retrieve this ID_TRASH |
| 431 |
|
// |
| 432 |
|
myquery.str(""); |
| 433 |
|
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
| 434 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 435 |
|
// |
| 436 |
|
UInt_t idtrash = 0; |
| 437 |
|
UInt_t idl0 = 0; |
| 438 |
|
UInt_t idl2 = 0; |
| 439 |
|
// |
| 440 |
|
Row = pResult->Next(); |
| 441 |
|
if( Row != NULL ){ |
| 442 |
|
idtrash = (UInt_t)atoll(Row->GetField(0)); |
| 443 |
|
idl0 = (UInt_t)atoll(Row->GetField(1)); |
| 444 |
|
idl2 = (UInt_t)atoll(Row->GetField(2)); |
| 445 |
|
}; |
| 446 |
|
// |
| 447 |
|
TString fileL0 = ""; |
| 448 |
|
TString fileL2 = ""; |
| 449 |
|
myquery.str(""); |
| 450 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
| 451 |
|
myquery << idl0 << ";"; |
| 452 |
|
// |
| 453 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
| 454 |
|
// |
| 455 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 456 |
|
// |
| 457 |
|
Row = pResult->Next(); |
| 458 |
|
if( Row != NULL ){ |
| 459 |
|
fileL0 = (TString)Row->GetField(0); |
| 460 |
|
}; |
| 461 |
|
// |
| 462 |
|
// |
| 463 |
|
// |
| 464 |
|
myquery.str(""); |
| 465 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
| 466 |
|
myquery << idl2 << ";"; |
| 467 |
|
// |
| 468 |
|
// printf("3myquery is %s \n",myquery.str().c_str()); |
| 469 |
|
// |
| 470 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 471 |
|
// |
| 472 |
|
Row = pResult->Next(); |
| 473 |
|
if( Row != NULL ){ |
| 474 |
|
fileL2 = (TString)Row->GetField(0); |
| 475 |
|
}; |
| 476 |
|
// |
| 477 |
|
// |
| 478 |
|
// |
| 479 |
|
myquery.str(""); |
| 480 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
| 481 |
|
myquery << fileL0.Data() << "' where ID_TRASH="; |
| 482 |
|
myquery << idtrash << ";"; |
| 483 |
|
// |
| 484 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 485 |
|
// |
| 486 |
|
dbc->Query(myquery.str().c_str()); |
| 487 |
|
// |
| 488 |
|
myquery.str(""); |
| 489 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
| 490 |
|
myquery << fileL2.Data() << "' where ID_TRASH="; |
| 491 |
|
myquery << idtrash << ";"; |
| 492 |
|
// |
| 493 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 494 |
|
// |
| 495 |
|
dbc->Query(myquery.str().c_str()); |
| 496 |
|
// |
| 497 |
|
myquery.str(""); |
| 498 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
| 499 |
|
myquery << FromTable.Data() << "' where ID_TRASH="; |
| 500 |
|
myquery << idtrash << ";"; |
| 501 |
|
// |
| 502 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 503 |
|
// |
| 504 |
|
// |
| 505 |
|
dbc->Query(myquery.str().c_str()); |
| 506 |
|
// |
| 507 |
|
myquery.str(""); |
| 508 |
|
myquery << " DELETE FROM "; |
| 509 |
|
myquery << FromTable.Data() << " where ID="; |
| 510 |
|
myquery << IDRUN << ";"; |
| 511 |
|
// |
| 512 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
| 513 |
|
// |
| 514 |
|
// |
| 515 |
|
dbc->Query(myquery.str().c_str()); |
| 516 |
|
// |
| 517 |
|
return 0; |
| 518 |
|
}; |
| 519 |
|
|
| 520 |
|
|
| 521 |
|
|
| 522 |
|
/** |
| 523 |
|
* This method restore a run from the GL_RUN_TRASH table. |
| 524 |
|
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
| 525 |
|
* |
| 526 |
|
**/ |
| 527 |
|
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
| 528 |
|
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
| 529 |
|
//insert into GL_RUN_TRASH VALUES (ID , ID_RUN_FRAG , ID_ROOT_L0 , ID_ROOT_L2 , RUNHEADER_TIME , RUNTRAILER_TIME , RUNHEADER_OBT , RUNTRAILER_OBT , RUNHEADER_PKT , RUNTRAILER_PKT , BOOT_NUMBER , EV_FROM , EV_TO , NEVENTS , PKT_COUNTER , PKT_READY_COUNTER , COMPILATIONTIMESTAMP , FAV_WRK_SCHEDULE , EFF_WRK_SCHEDULE , PRH_VAR_TRG_MODE_A , PRH_VAR_TRG_MODE_B , ACQ_BUILD_INFO , ACQ_VAR_INFO , RM_ACQ_AFTER_CALIB , RM_ACQ_SETTING_MODE, TRK_CALIB_USED,CAL_DSP_MASK, LAST_TIMESYNC, OBT_TIMESYNC, VALIDATION, INSERT_TIME) select * FROM GL_RUN where ID=11; |
| 530 |
|
// MySQL variables |
| 531 |
|
TSQLResult *pResult; |
| 532 |
|
TSQLRow *Row; |
| 533 |
|
stringstream myquery; |
| 534 |
|
// |
| 535 |
|
if ( !IDRUN ) IDRUN = ID; |
| 536 |
|
if ( !IDRUN ) return 1; |
| 537 |
|
// |
| 538 |
|
if ( !strcmp(ToTable.Data(),"") ){ |
| 539 |
|
// |
| 540 |
|
myquery.str(""); |
| 541 |
|
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
| 542 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 543 |
|
// |
| 544 |
|
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
| 545 |
|
// |
| 546 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 547 |
|
// |
| 548 |
|
Row = pResult->Next(); |
| 549 |
|
if( Row != NULL ){ |
| 550 |
|
ToTable = (TString)Row->GetField(0); |
| 551 |
|
} else { |
| 552 |
|
return 1; |
| 553 |
|
}; |
| 554 |
|
}; |
| 555 |
|
// ---------------- |
| 556 |
|
myquery.str(""); |
| 557 |
|
myquery << " INSERT INTO "; |
| 558 |
|
myquery << ToTable.Data(); |
| 559 |
|
myquery << " ("; |
| 560 |
|
myquery << "ID"; |
| 561 |
|
myquery << ",ID_RUN_FRAG"; |
| 562 |
|
myquery << ",ID_ROOT_L0"; |
| 563 |
|
myquery << ",ID_ROOT_L2"; |
| 564 |
|
myquery << ",RUNHEADER_TIME"; |
| 565 |
|
myquery << ",RUNTRAILER_TIME"; |
| 566 |
|
myquery << ",RUNHEADER_OBT"; |
| 567 |
|
myquery << ",RUNTRAILER_OBT"; |
| 568 |
|
myquery << ",RUNHEADER_PKT"; |
| 569 |
|
myquery << ",RUNTRAILER_PKT"; |
| 570 |
|
myquery << ",BOOT_NUMBER"; |
| 571 |
|
myquery << ",EV_FROM"; |
| 572 |
|
myquery << ",EV_TO"; |
| 573 |
|
myquery << ",NEVENTS"; |
| 574 |
|
myquery << ",PKT_COUNTER"; |
| 575 |
|
myquery << ",PKT_READY_COUNTER"; |
| 576 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 577 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 578 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 579 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 580 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 581 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 582 |
|
myquery << ",ACQ_VAR_INFO"; |
| 583 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 584 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 585 |
|
myquery << ",TRK_CALIB_USED"; |
| 586 |
|
myquery << ",CAL_DSP_MASK"; |
| 587 |
|
myquery << ",LAST_TIMESYNC"; |
| 588 |
|
myquery << ",OBT_TIMESYNC"; |
| 589 |
|
myquery << ",VALIDATION"; |
| 590 |
|
myquery << ",INSERT_TIME"; |
| 591 |
|
myquery << ") SELECT "; |
| 592 |
|
myquery << "ID"; |
| 593 |
|
myquery << ",ID_RUN_FRAG"; |
| 594 |
|
myquery << ",ID_ROOT_L0"; |
| 595 |
|
myquery << ",ID_ROOT_L2"; |
| 596 |
|
myquery << ",RUNHEADER_TIME"; |
| 597 |
|
myquery << ",RUNTRAILER_TIME"; |
| 598 |
|
myquery << ",RUNHEADER_OBT"; |
| 599 |
|
myquery << ",RUNTRAILER_OBT"; |
| 600 |
|
myquery << ",RUNHEADER_PKT"; |
| 601 |
|
myquery << ",RUNTRAILER_PKT"; |
| 602 |
|
myquery << ",BOOT_NUMBER"; |
| 603 |
|
myquery << ",EV_FROM"; |
| 604 |
|
myquery << ",EV_TO"; |
| 605 |
|
myquery << ",NEVENTS"; |
| 606 |
|
myquery << ",PKT_COUNTER"; |
| 607 |
|
myquery << ",PKT_READY_COUNTER"; |
| 608 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 609 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 610 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 611 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 612 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 613 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 614 |
|
myquery << ",ACQ_VAR_INFO"; |
| 615 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 616 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 617 |
|
myquery << ",TRK_CALIB_USED"; |
| 618 |
|
myquery << ",CAL_DSP_MASK"; |
| 619 |
|
myquery << ",LAST_TIMESYNC"; |
| 620 |
|
myquery << ",OBT_TIMESYNC"; |
| 621 |
|
myquery << ",VALIDATION"; |
| 622 |
|
myquery << ",INSERT_TIME"; |
| 623 |
|
myquery << " FROM GL_RUN_TRASH "; |
| 624 |
|
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
| 625 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 626 |
|
// |
| 627 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
| 628 |
|
// |
| 629 |
|
dbc->Query(myquery.str().c_str()); |
| 630 |
|
// |
| 631 |
|
// |
| 632 |
|
myquery.str(""); |
| 633 |
|
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
| 634 |
|
myquery << IDRUN << ";"; |
| 635 |
|
// |
| 636 |
|
dbc->Query(myquery.str().c_str()); |
| 637 |
|
// |
| 638 |
|
return 0; |
| 639 |
|
}; |
| 640 |
|
|
| 641 |
/** |
/** |
| 642 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
| 859 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 860 |
// Set_GL_RUN(Row); |
// Set_GL_RUN(Row); |
| 861 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 862 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 863 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
| 864 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 865 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
| 866 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 867 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 868 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 869 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 870 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 871 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 872 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
| 873 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
| 874 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
| 875 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 876 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 877 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
| 878 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 879 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 880 |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
if (t==18) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
| 881 |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
if (t==19) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
| 882 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 883 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 884 |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
if (t==22) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
| 885 |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
if (t==23) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
| 886 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 887 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 888 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
| 889 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
| 890 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
| 891 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 892 |
}; |
}; |
| 893 |
}; |
}; |
| 894 |
// delete pResult; |
// delete pResult; |
| 1263 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1264 |
TSQLRow *Row; |
TSQLRow *Row; |
| 1265 |
stringstream myquery; |
stringstream myquery; |
| 1266 |
|
stringstream rname; |
| 1267 |
|
rname.str(""); |
| 1268 |
// ---------------- |
// ---------------- |
| 1269 |
myquery.str(""); |
myquery.str(""); |
| 1270 |
myquery << "select "; |
myquery << "select "; |
| 1281 |
stringstream fname; |
stringstream fname; |
| 1282 |
fname.str(""); |
fname.str(""); |
| 1283 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
| 1284 |
|
rname << Row->GetField(1); |
| 1285 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
| 1286 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
| 1287 |
}; |
}; |
| 1301 |
// |
// |
| 1302 |
// look for Resurs offset |
// look for Resurs offset |
| 1303 |
// |
// |
| 1304 |
UInt_t t0 = 0; |
T0 = 0; |
| 1305 |
// |
// |
| 1306 |
myquery.str(""); |
// |
| 1307 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
| 1308 |
<< idraw << " AND TO_ID_RAW >= " |
oss.str(""); |
| 1309 |
<< idraw << ";"; |
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE SPECIAL_FILE='" |
| 1310 |
pResult = dbc->Query(myquery.str().c_str()); |
<< rname.str().c_str() << "';"; |
| 1311 |
if ( pResult ){ |
pResult = dbc->Query(oss.str().c_str()); |
| 1312 |
|
Row = pResult->Next(); |
| 1313 |
|
// |
| 1314 |
|
TString name=rname.str().c_str(); |
| 1315 |
|
UInt_t dworbit = 0; |
| 1316 |
|
Int_t nlength = name.Length(); |
| 1317 |
|
if ( nlength < 5 ) return; |
| 1318 |
|
TString dwo = 0; |
| 1319 |
|
for (Int_t i = 0; i<5; i++){ |
| 1320 |
|
dwo.Append(name[i],1); |
| 1321 |
|
}; |
| 1322 |
|
if ( dwo.IsDigit() ){ |
| 1323 |
|
dworbit = (UInt_t)dwo.Atoi(); |
| 1324 |
|
} else { |
| 1325 |
|
dwo=""; |
| 1326 |
|
for (Int_t i = 8; i<13; i++){ |
| 1327 |
|
dwo.Append(name[i],1); |
| 1328 |
|
}; |
| 1329 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
| 1330 |
|
}; |
| 1331 |
|
// |
| 1332 |
|
if ( !Row ){ |
| 1333 |
|
oss.str(""); |
| 1334 |
|
oss << "SELECT YEAR(OFFSET_DATE),MONTH(OFFSET_DATE),DAY(OFFSET_DATE),HOUR(OFFSET_DATE),MINUTE(OFFSET_DATE),SECOND(OFFSET_DATE) FROM GL_RESURS_OFFSET WHERE FROM_ORBIT< " |
| 1335 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
| 1336 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1337 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1338 |
if ( Row ){ |
if ( !Row ){ |
| 1339 |
// |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
| 1340 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
return; |
|
// |
|
| 1341 |
}; |
}; |
| 1342 |
}; |
}; |
| 1343 |
// |
// |
| 1344 |
|
TTimeStamp tu = TTimeStamp((UInt_t)atoi(Row->GetField(0)),(UInt_t)atoi(Row->GetField(1)),(UInt_t)atoi(Row->GetField(2)),(UInt_t)atoi(Row->GetField(3)),(UInt_t)atoi(Row->GetField(4)),(UInt_t)atoi(Row->GetField(5)),0,true,0); |
| 1345 |
|
T0 = (UInt_t)tu.GetSec(); |
| 1346 |
// |
// |
| 1347 |
// look for the correct timesync entry |
// look for the correct timesync entry |
| 1348 |
// |
// |
| 1349 |
myquery.str(""); |
myquery.str(""); |
| 1350 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
| 1351 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
| 1352 |
<< ";"; |
<< ";"; |
| 1353 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1354 |
if ( pResult ){ |
if ( pResult ){ |
| 1355 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1356 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
| 1357 |
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + t0; |
OBT0 = (UInt_t)atoll(Row->GetField(0)); |
| 1358 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1359 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1360 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
| 1361 |
}; |
}; |
| 1362 |
}; |
}; |
| 1363 |
// |
// |
| 1376 |
// |
// |
| 1377 |
}; |
}; |
| 1378 |
|
|
| 1379 |
|
/** |
| 1380 |
|
* |
| 1381 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
| 1382 |
|
* |
| 1383 |
|
*/ |
| 1384 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
| 1385 |
|
// |
| 1386 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
| 1387 |
|
// |
| 1388 |
|
}; |
| 1389 |
|
|
| 1390 |
|
|
| 1391 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
/** |
| 1392 |
|
* Return the correct packet number if we went back to zero |
| 1393 |
|
*/ |
| 1394 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
| 1395 |
// |
// |
| 1396 |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ){ |
| 1397 |
|
return((Long64_t)pkt_num+16777215LL); |
| 1398 |
|
}; |
| 1399 |
// |
// |
| 1400 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
| 1401 |
if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
return((Long64_t)pkt_num-16777215LL); |
|
return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
|
|
} else { |
|
|
return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
|
|
}; |
|
| 1402 |
}; |
}; |
| 1403 |
// |
// |
| 1404 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
| 1405 |
// |
// |
| 1406 |
}; |
}; |
| 1407 |
|
|
| 1408 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
| 1409 |
|
* Return the correct On Board Time if we went back to zero |
| 1410 |
|
*/ |
| 1411 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
| 1412 |
// |
// |
| 1413 |
if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((Long64_t)(obt+numeric_limits<UInt_t>::max())); |
| 1414 |
// |
// |
| 1415 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
| 1416 |
if ( (pkt_num-16777215) < 0 ){ |
return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max()); |
|
return((16777215-pkt_num)); |
|
|
} else { |
|
|
return((pkt_num-16777215)); |
|
|
}; |
|
| 1417 |
}; |
}; |
| 1418 |
// |
// |
| 1419 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
| 1420 |
}; |
}; |
| 1421 |
|
|
| 1422 |
|
|
| 1423 |
|
|
| 1424 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
| 1425 |
|
// // |
| 1426 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
| 1427 |
|
// // |
| 1428 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
| 1429 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
| 1430 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
| 1431 |
|
// } else { |
| 1432 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
| 1433 |
|
// }; |
| 1434 |
|
// }; |
| 1435 |
|
// // |
| 1436 |
|
// return((ULong64_t)obt); |
| 1437 |
|
// // |
| 1438 |
|
// }; |
| 1439 |
|
|
| 1440 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
| 1441 |
|
// // |
| 1442 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
| 1443 |
|
// // |
| 1444 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
| 1445 |
|
// if ( (pkt_num-16777215) < 0 ){ |
| 1446 |
|
// return((16777215-pkt_num)); |
| 1447 |
|
// } else { |
| 1448 |
|
// return((pkt_num-16777215)); |
| 1449 |
|
// }; |
| 1450 |
|
// }; |
| 1451 |
|
// // |
| 1452 |
|
// return(pkt_num); |
| 1453 |
|
// // |
| 1454 |
|
// }; |
| 1455 |
|
|
| 1456 |
/* |
/* |
| 1457 |
* |
* |
| 1458 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time in the DB from UInt_t to a string |
| 1463 |
*/ |
*/ |
| 1464 |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
| 1465 |
// |
// |
| 1466 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
| 1467 |
TString rtime; |
TString rtime; |
| 1468 |
Bool_t found = false; |
Bool_t found = false; |
| 1469 |
// |
// |
|
time->Set(dbt,false); // UTC (Coordinated Universal Time) |
|
|
// |
|
| 1470 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
| 1471 |
// |
// |
| 1472 |
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); |
|
| 1473 |
found = true; |
found = true; |
| 1474 |
// |
// |
| 1475 |
}; |
}; |
| 1476 |
// |
// |
| 1477 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
| 1478 |
// |
// |
| 1479 |
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); |
|
| 1480 |
found = true; |
found = true; |
| 1481 |
// |
// |
| 1482 |
}; |
}; |
| 1483 |
// |
// |
| 1484 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
| 1485 |
// |
// |
| 1486 |
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); |
|
| 1487 |
found = true; |
found = true; |
| 1488 |
// |
// |
| 1489 |
}; |
}; |
| 1490 |
// |
// |
| 1491 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
| 1492 |
// |
// |
| 1493 |
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); |
|
| 1494 |
found = true; |
found = true; |
| 1495 |
// |
// |
| 1496 |
}; |
}; |
| 1500 |
tzone = "UTC"; |
tzone = "UTC"; |
| 1501 |
}; |
}; |
| 1502 |
// |
// |
| 1503 |
rtime = time->AsSQLString(); |
dbt += offset; |
| 1504 |
|
// |
| 1505 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
| 1506 |
|
// |
| 1507 |
|
rtime = time->AsString("s"); |
| 1508 |
|
// |
| 1509 |
|
delete time; |
| 1510 |
// |
// |
| 1511 |
return(rtime); |
return(rtime); |
| 1512 |
} |
} |
| 1513 |
|
|
| 1514 |
/* |
/* |
| 1515 |
* |
* |
| 1516 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time from TZONE to UTC |
| 1517 |
* |
* |
| 1518 |
* @param dbt time in the DB |
* @param dbt time in the DB |
| 1519 |
* @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 |
| 1521 |
*/ |
*/ |
| 1522 |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
| 1523 |
// |
// |
| 1524 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
| 1525 |
TString rtime; |
TString rtime; |
| 1526 |
// |
// |
| 1527 |
Bool_t found = false; |
Bool_t found = false; |
| 1528 |
// |
// |
|
time->Set(dbt,false); // tzone |
|
|
// |
|
| 1529 |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
| 1530 |
// |
// |
| 1531 |
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); |
|
| 1532 |
found = true; |
found = true; |
| 1533 |
// |
// |
| 1534 |
}; |
}; |
| 1535 |
// |
// |
| 1536 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
| 1537 |
// |
// |
| 1538 |
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); |
|
| 1539 |
found = true; |
found = true; |
| 1540 |
// |
// |
| 1541 |
}; |
}; |
| 1542 |
// |
// |
| 1543 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
| 1544 |
// |
// |
| 1545 |
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); |
|
| 1546 |
found = true; |
found = true; |
| 1547 |
// |
// |
| 1548 |
}; |
}; |
| 1549 |
// |
// |
| 1550 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
| 1551 |
// |
// |
| 1552 |
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); |
|
| 1553 |
found = true; |
found = true; |
| 1554 |
// |
// |
| 1555 |
}; |
}; |
| 1556 |
// |
// |
| 1557 |
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(),"") ){ |
| 1558 |
// |
// |
| 1559 |
|
offset = 0; |
| 1560 |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
| 1561 |
tzone = "UTC"; |
tzone = "UTC"; |
| 1562 |
}; |
}; |
| 1563 |
// |
// |
| 1564 |
rtime = time->AsSQLString(); |
dbt += offset; |
| 1565 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
| 1566 |
|
// |
| 1567 |
|
rtime = time->AsString("s"); |
| 1568 |
// |
// |
| 1569 |
return(rtime); |
return(rtime); |
| 1570 |
} |
} |
| 1571 |
|
|
| 1572 |
|
|
| 1573 |
// **************************************************** |
// |
| 1574 |
/** |
// Build a query and call DoQuery. |
| 1575 |
* Function to query the GL_TLE table of the DB. |
// |
| 1576 |
* |
// date it's an SQL datetime date and dbc is the connection to be |
| 1577 |
* time is the unix time for which a good tle is requested. |
// used. It will query for the tle with the nearest but previous date |
| 1578 |
* |
// and the immediatly next one. |
| 1579 |
* Return the pointer to a cTle object that has the closest and |
// |
| 1580 |
* previous date compared with time. |
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
|
* |
|
|
* If errors occurs it returns NULL. |
|
|
*/ |
|
|
cTle* GL_TLE::Query_GL_TLE(UInt_t time, TSQLServer *dbc){ |
|
| 1581 |
stringstream myquery; |
stringstream myquery; |
| 1582 |
myquery.str(""); |
myquery.str(""); |
| 1583 |
|
|
| 1584 |
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1585 |
<< "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;"; |
<< "WHERE FROM_TIME <= '" << date.Data() |
| 1586 |
|
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
| 1587 |
|
<< "UNION " |
| 1588 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1589 |
|
<< "WHERE FROM_TIME > '" << date.Data() |
| 1590 |
|
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
| 1591 |
|
|
| 1592 |
return Query_GL_TLE_go(myquery.str(), dbc); |
return DoQuery(myquery.str().c_str(), dbc); |
| 1593 |
} |
} |
| 1594 |
|
|
| 1595 |
|
|
| 1596 |
// **************************************************** |
// |
| 1597 |
/** |
// Build a query and call DoQuery. |
| 1598 |
* Function to query the GL_TLE table of the DB. |
// |
| 1599 |
* |
// time is the UTC date in unix time (UTC) and dbc is the connection |
| 1600 |
* date is a datetime format YYYY-MM-DD hh:mm:ss for which a good tle |
// to be used. It will query for the tle with the nearest but |
| 1601 |
* is requested. |
// previous date and the immediatly next one. |
| 1602 |
* |
// |
| 1603 |
* Return the pointer to a cTle object that has the closest and |
// Returns the value returned by DoQuery(). |
| 1604 |
* previous date compared with time. |
// |
| 1605 |
* |
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
|
* If errors occurs it returns NULL. |
|
|
*/ |
|
|
cTle* GL_TLE::Query_GL_TLE(TString date, TSQLServer *dbc){ |
|
| 1606 |
stringstream myquery; |
stringstream myquery; |
| 1607 |
myquery.str(""); |
myquery.str(""); |
| 1608 |
|
|
| 1609 |
myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE " |
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1610 |
<< "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;"; |
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
| 1611 |
|
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
| 1612 |
|
<< "UNION " |
| 1613 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1614 |
|
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
| 1615 |
|
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
| 1616 |
|
|
| 1617 |
return Query_GL_TLE_go(myquery.str(), dbc); |
return DoQuery(myquery.str().c_str(), dbc); |
| 1618 |
} |
} |
| 1619 |
|
|
| 1620 |
|
|
| 1621 |
// **************************************************** |
// |
| 1622 |
/** |
// Do the query myquery on the connectio dbc. Initialize tle, |
| 1623 |
* Private function used by Query_GL_TLE methods. |
// tleFromTime and tleToTime. |
| 1624 |
* |
// |
| 1625 |
* myquery is the query string. |
// We should have two rows (unless the table is old). From the last |
| 1626 |
* |
// one we only take tleToTime. |
| 1627 |
* Return the pointer to a cTle object that has the closest and |
// |
| 1628 |
* previous date compared with time. |
// Returns 0 for success, 1 for failure. |
| 1629 |
* |
// |
| 1630 |
* If errors occurs it returns NULL. |
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
|
*/ |
|
|
cTle* GL_TLE::Query_GL_TLE_go(TString myquery, TSQLServer *dbc){ |
|
|
cTle *tle; |
|
|
string tle1, tle2, tle3; |
|
|
|
|
|
// MySQL variables |
|
| 1631 |
TSQLResult *result; |
TSQLResult *result; |
| 1632 |
TSQLRow *row; |
TSQLRow *row; |
| 1633 |
|
|
| 1634 |
|
// Set the right time_zone (otherwise horrible things will occur! :) |
| 1635 |
|
dbc->Query("SET time_zone = '+0:00'"); |
| 1636 |
|
|
| 1637 |
|
// Do the query |
| 1638 |
result = dbc->Query(myquery.Data()); |
result = dbc->Query(myquery.Data()); |
| 1639 |
if(! result->GetRowCount() ) return NULL; |
if(! result->GetRowCount() ) { |
| 1640 |
|
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
| 1641 |
|
return 1; |
| 1642 |
|
} |
| 1643 |
|
|
| 1644 |
|
// Get results |
| 1645 |
|
row = result->Next(); // first tle row |
| 1646 |
|
tle = GiveTle(row); |
| 1647 |
|
|
| 1648 |
|
tleFromTime = strtol(row->GetField(4), NULL, 10); |
| 1649 |
|
|
| 1650 |
|
row = result->Next(); // second tle row |
| 1651 |
|
if(row) |
| 1652 |
|
tleToTime = strtol(row->GetField(4), NULL, 10); |
| 1653 |
|
else { |
| 1654 |
|
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
| 1655 |
|
tleToTime = UINT_MAX; |
| 1656 |
|
} |
| 1657 |
|
|
| 1658 |
|
delete row; |
| 1659 |
|
delete result; |
| 1660 |
|
|
| 1661 |
|
return 0; |
| 1662 |
|
} |
| 1663 |
|
|
|
row = result->Next(); |
|
|
tle1 = row->GetField(0); |
|
|
tle2 = row->GetField(1); |
|
|
tle3 = row->GetField(2); |
|
| 1664 |
|
|
| 1665 |
tle = new cTle(tle1, tle2, tle3); |
// |
| 1666 |
|
// Build a cTle object from the GL_TLE row. |
| 1667 |
|
// |
| 1668 |
|
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
| 1669 |
|
cTle *thistle = NULL; |
| 1670 |
|
string tle1, tle2, tle3; |
| 1671 |
|
|
| 1672 |
|
// Build cTle object |
| 1673 |
|
tle1 = row->GetField(1); |
| 1674 |
|
tle2 = row->GetField(2); |
| 1675 |
|
tle3 = row->GetField(3); |
| 1676 |
|
|
| 1677 |
delete result; |
thistle = new cTle(tle1, tle2, tle3); |
|
delete row; |
|
| 1678 |
|
|
| 1679 |
return tle; |
return thistle; |
| 1680 |
} |
} |