| 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_TABLES); |
| 21 |
ClassImp(GL_TRK_CALIB); |
ClassImp(GL_TRK_CALIB); |
| 22 |
ClassImp(GL_RUN); |
ClassImp(GL_RUN); |
| 23 |
ClassImp(GL_ROOT); |
ClassImp(GL_ROOT); |
| 25 |
ClassImp(GL_S4_CALIB); |
ClassImp(GL_S4_CALIB); |
| 26 |
ClassImp(GL_CALO_CALIB); |
ClassImp(GL_CALO_CALIB); |
| 27 |
ClassImp(GL_TIMESYNC); |
ClassImp(GL_TIMESYNC); |
| 28 |
|
ClassImp(GL_TLE); |
| 29 |
// |
// |
| 30 |
using namespace std; |
using namespace std; |
| 31 |
|
|
| 32 |
|
GL_TABLES::GL_TABLES(){ |
| 33 |
|
}; |
| 34 |
|
|
| 35 |
|
GL_TABLES::GL_TABLES(TString host, TString user, TString psw){ |
| 36 |
|
fHost = new TString(host.Data()); |
| 37 |
|
fUser = new TString(user.Data()); |
| 38 |
|
fPsw = new TString(psw.Data()); |
| 39 |
|
fSet = true; |
| 40 |
|
fNquery = 0; |
| 41 |
|
}; |
| 42 |
|
|
| 43 |
|
|
| 44 |
|
void GL_TABLES::Set(TString host, TString user, TString psw){ |
| 45 |
|
fHost = new TString(host.Data()); |
| 46 |
|
fUser = new TString(user.Data()); |
| 47 |
|
fPsw = new TString(psw.Data()); |
| 48 |
|
fSet = true; |
| 49 |
|
fNquery = 0; |
| 50 |
|
}; |
| 51 |
|
|
| 52 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ |
| 53 |
|
// |
| 54 |
|
// |
| 55 |
|
// |
| 56 |
|
if ( !fSet ){ |
| 57 |
|
return true; |
| 58 |
|
}; |
| 59 |
|
// |
| 60 |
|
// |
| 61 |
|
// |
| 62 |
|
// printf(" host is %s \n",fHost->Data()); |
| 63 |
|
// |
| 64 |
|
stringstream myquery; |
| 65 |
|
myquery.str(""); |
| 66 |
|
myquery << "show databases;"; |
| 67 |
|
dbc->Query(myquery.str().c_str()); |
| 68 |
|
fNquery++; |
| 69 |
|
// |
| 70 |
|
if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
| 71 |
|
// is connected |
| 72 |
|
return true; |
| 73 |
|
} else { |
| 74 |
|
// |
| 75 |
|
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
| 76 |
|
// |
| 77 |
|
TString host = fHost->Data(); |
| 78 |
|
TString user = fUser->Data(); |
| 79 |
|
TString psw = fPsw->Data(); |
| 80 |
|
delete dbc; |
| 81 |
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 82 |
|
// |
| 83 |
|
myquery.str(""); |
| 84 |
|
myquery << "show databases;"; |
| 85 |
|
dbc->Query(myquery.str().c_str()); |
| 86 |
|
fNquery++; |
| 87 |
|
// |
| 88 |
|
if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
| 89 |
|
// |
| 90 |
|
printf(" ...connection recovered, I can continue! \n"); |
| 91 |
|
// |
| 92 |
|
myquery.str(""); |
| 93 |
|
myquery << "SET time_zone='+0:00'"; |
| 94 |
|
dbc->Query(myquery.str().c_str()); |
| 95 |
|
fNquery++; |
| 96 |
|
myquery.str(""); |
| 97 |
|
myquery << "SET wait_timeout=173000;"; |
| 98 |
|
dbc->Query(myquery.str().c_str()); |
| 99 |
|
fNquery++; |
| 100 |
|
return true; |
| 101 |
|
}; |
| 102 |
|
}; |
| 103 |
|
// |
| 104 |
|
printf(" GLTABLES: connection is gone away, query will fail\n"); |
| 105 |
|
// |
| 106 |
|
return false; |
| 107 |
|
// |
| 108 |
|
}; |
| 109 |
|
|
| 110 |
|
void GL_TABLES::ResetCounters(){ |
| 111 |
|
fNquery = 0; |
| 112 |
|
}; |
| 113 |
|
|
| 114 |
|
void GL_TABLES::AddQ(){ |
| 115 |
|
if ( fSet ) fNquery++; |
| 116 |
|
}; |
| 117 |
|
|
| 118 |
|
UInt_t GL_TABLES::GetNqueries(){ |
| 119 |
|
UInt_t rn = 0; |
| 120 |
|
rn += (UInt_t&)fNquery; |
| 121 |
|
return(rn); |
| 122 |
|
}; |
| 123 |
|
|
| 124 |
GL_RUN::GL_RUN() { |
GL_RUN::GL_RUN() { |
| 125 |
ID = 0; |
ID = 0; |
| 126 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
| 155 |
VALIDATION = 0; |
VALIDATION = 0; |
| 156 |
} |
} |
| 157 |
|
|
| 158 |
|
|
| 159 |
void GL_RUN::Clear() { |
void GL_RUN::Clear() { |
| 160 |
ID = 0; |
ID = 0; |
| 161 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
| 220 |
OBT2 = 0; |
OBT2 = 0; |
| 221 |
PKT1 = 0; |
PKT1 = 0; |
| 222 |
PKT2 = 0; |
PKT2 = 0; |
| 223 |
|
BOOT_NUMBER = 0; |
| 224 |
|
VALIDATION = 0; |
| 225 |
} |
} |
| 226 |
|
|
| 227 |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
GL_CALO_CALIB::GL_CALO_CALIB(){ |
| 247 |
obtfirst = 0; |
obtfirst = 0; |
| 248 |
pktfirst = 0; |
pktfirst = 0; |
| 249 |
toffset = 0; |
toffset = 0; |
| 250 |
ID = 0; |
// ID = 0; |
| 251 |
ID_RAW = 0; |
// ID_RAW = 0; |
| 252 |
OBT0 = 0; |
OBT0 = 0; |
| 253 |
TIMESYNC = 0; |
TIMESYNC = 0; |
| 254 |
TYPE = 0; |
TYPE = 0; |
| 255 |
}// **************************************************** |
} |
| 256 |
|
|
| 257 |
|
// **************************************************** |
| 258 |
|
|
| 259 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
| 260 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
| 428 |
CAL_DSP_MASK = 0; |
CAL_DSP_MASK = 0; |
| 429 |
}; |
}; |
| 430 |
|
|
| 431 |
|
void GL_RUN::Set_GL_RUN(TSQLRow *Row){ |
| 432 |
|
for( Int_t t = 0; t < 30; t++){ |
| 433 |
|
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 434 |
|
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
| 435 |
|
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 436 |
|
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
| 437 |
|
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 438 |
|
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 439 |
|
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 440 |
|
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 441 |
|
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 442 |
|
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 443 |
|
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
| 444 |
|
if (t==11) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
| 445 |
|
if (t==12) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
| 446 |
|
if (t==13) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
| 447 |
|
if (t==14) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 448 |
|
if (t==15) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 449 |
|
if (t==16) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
| 450 |
|
if (t==17) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 451 |
|
if (t==18) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 452 |
|
if (t==19) PRH_VAR_TRG_MODE_A= (UInt_t)atoll(Row->GetField(t)); |
| 453 |
|
if (t==20) PRH_VAR_TRG_MODE_B= (UInt_t)atoll(Row->GetField(t)); |
| 454 |
|
if (t==21) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 455 |
|
if (t==22) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 456 |
|
if (t==23) RM_ACQ_AFTER_CALIB= (UInt_t)atoll(Row->GetField(t)); |
| 457 |
|
if (t==24) RM_ACQ_SETTING_MODE = (UInt_t)atoll(Row->GetField(t)); |
| 458 |
|
if (t==25) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
| 459 |
|
if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
| 460 |
|
if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 461 |
|
if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 462 |
|
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 463 |
|
}; |
| 464 |
|
|
| 465 |
|
} |
| 466 |
|
|
| 467 |
|
/** |
| 468 |
|
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
| 469 |
|
* If IDRUN is 0 "this->ID" run is used. |
| 470 |
|
* |
| 471 |
|
**/ |
| 472 |
|
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
| 473 |
|
// MySQL variables |
| 474 |
|
TSQLResult *pResult; |
| 475 |
|
TSQLRow *Row; |
| 476 |
|
stringstream myquery; |
| 477 |
|
// |
| 478 |
|
if ( !IDRUN ) IDRUN = ID; |
| 479 |
|
if ( !IDRUN ) return 1; |
| 480 |
|
// ---------------- |
| 481 |
|
myquery.str(""); |
| 482 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
| 483 |
|
myquery << "ID"; |
| 484 |
|
myquery << ",ID_RUN_FRAG"; |
| 485 |
|
myquery << ",ID_ROOT_L0"; |
| 486 |
|
myquery << ",ID_ROOT_L2"; |
| 487 |
|
myquery << ",RUNHEADER_TIME"; |
| 488 |
|
myquery << ",RUNTRAILER_TIME"; |
| 489 |
|
myquery << ",RUNHEADER_OBT"; |
| 490 |
|
myquery << ",RUNTRAILER_OBT"; |
| 491 |
|
myquery << ",RUNHEADER_PKT"; |
| 492 |
|
myquery << ",RUNTRAILER_PKT"; |
| 493 |
|
myquery << ",BOOT_NUMBER"; |
| 494 |
|
myquery << ",EV_FROM"; |
| 495 |
|
myquery << ",EV_TO"; |
| 496 |
|
myquery << ",NEVENTS"; |
| 497 |
|
myquery << ",PKT_COUNTER"; |
| 498 |
|
myquery << ",PKT_READY_COUNTER"; |
| 499 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 500 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 501 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 502 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 503 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 504 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 505 |
|
myquery << ",ACQ_VAR_INFO"; |
| 506 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 507 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 508 |
|
myquery << ",TRK_CALIB_USED"; |
| 509 |
|
myquery << ",CAL_DSP_MASK"; |
| 510 |
|
myquery << ",LAST_TIMESYNC"; |
| 511 |
|
myquery << ",OBT_TIMESYNC"; |
| 512 |
|
myquery << ",VALIDATION"; |
| 513 |
|
myquery << ",INSERT_TIME"; |
| 514 |
|
myquery << ") SELECT * FROM "; |
| 515 |
|
myquery << FromTable.Data(); |
| 516 |
|
myquery << " WHERE ID="; |
| 517 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 518 |
|
// |
| 519 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
| 520 |
|
// |
| 521 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 522 |
|
this->GetGLTABLES()->AddQ(); |
| 523 |
|
dbc->Query(myquery.str().c_str()); |
| 524 |
|
// |
| 525 |
|
// retrieve this ID_TRASH |
| 526 |
|
// |
| 527 |
|
myquery.str(""); |
| 528 |
|
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
| 529 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 530 |
|
this->GetGLTABLES()->AddQ(); |
| 531 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 532 |
|
// |
| 533 |
|
UInt_t idtrash = 0; |
| 534 |
|
UInt_t idl0 = 0; |
| 535 |
|
UInt_t idl2 = 0; |
| 536 |
|
// |
| 537 |
|
Row = pResult->Next(); |
| 538 |
|
if( Row != NULL ){ |
| 539 |
|
idtrash = (UInt_t)atoll(Row->GetField(0)); |
| 540 |
|
idl0 = (UInt_t)atoll(Row->GetField(1)); |
| 541 |
|
idl2 = (UInt_t)atoll(Row->GetField(2)); |
| 542 |
|
}; |
| 543 |
|
// |
| 544 |
|
TString fileL0 = ""; |
| 545 |
|
TString fileL2 = ""; |
| 546 |
|
myquery.str(""); |
| 547 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
| 548 |
|
myquery << idl0 << ";"; |
| 549 |
|
// |
| 550 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
| 551 |
|
// |
| 552 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 553 |
|
this->GetGLTABLES()->AddQ(); |
| 554 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 555 |
|
// |
| 556 |
|
Row = pResult->Next(); |
| 557 |
|
if( Row != NULL ){ |
| 558 |
|
fileL0 = (TString)Row->GetField(0); |
| 559 |
|
}; |
| 560 |
|
// |
| 561 |
|
// |
| 562 |
|
// |
| 563 |
|
myquery.str(""); |
| 564 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
| 565 |
|
myquery << idl2 << ";"; |
| 566 |
|
// |
| 567 |
|
// printf("3myquery is %s \n",myquery.str().c_str()); |
| 568 |
|
// |
| 569 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 570 |
|
this->GetGLTABLES()->AddQ(); |
| 571 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 572 |
|
// |
| 573 |
|
Row = pResult->Next(); |
| 574 |
|
if( Row != NULL ){ |
| 575 |
|
fileL2 = (TString)Row->GetField(0); |
| 576 |
|
}; |
| 577 |
|
// |
| 578 |
|
// |
| 579 |
|
// |
| 580 |
|
myquery.str(""); |
| 581 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
| 582 |
|
myquery << fileL0.Data() << "' where ID_TRASH="; |
| 583 |
|
myquery << idtrash << ";"; |
| 584 |
|
// |
| 585 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 586 |
|
// |
| 587 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 588 |
|
this->GetGLTABLES()->AddQ(); |
| 589 |
|
dbc->Query(myquery.str().c_str()); |
| 590 |
|
// |
| 591 |
|
myquery.str(""); |
| 592 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
| 593 |
|
myquery << fileL2.Data() << "' where ID_TRASH="; |
| 594 |
|
myquery << idtrash << ";"; |
| 595 |
|
// |
| 596 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 597 |
|
// |
| 598 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 599 |
|
this->GetGLTABLES()->AddQ(); |
| 600 |
|
dbc->Query(myquery.str().c_str()); |
| 601 |
|
// |
| 602 |
|
myquery.str(""); |
| 603 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
| 604 |
|
myquery << FromTable.Data() << "' where ID_TRASH="; |
| 605 |
|
myquery << idtrash << ";"; |
| 606 |
|
// |
| 607 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 608 |
|
// |
| 609 |
|
// |
| 610 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 611 |
|
this->GetGLTABLES()->AddQ(); |
| 612 |
|
dbc->Query(myquery.str().c_str()); |
| 613 |
|
// |
| 614 |
|
myquery.str(""); |
| 615 |
|
myquery << " DELETE FROM "; |
| 616 |
|
myquery << FromTable.Data() << " where ID="; |
| 617 |
|
myquery << IDRUN << ";"; |
| 618 |
|
// |
| 619 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
| 620 |
|
// |
| 621 |
|
// |
| 622 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 623 |
|
this->GetGLTABLES()->AddQ(); |
| 624 |
|
dbc->Query(myquery.str().c_str()); |
| 625 |
|
// |
| 626 |
|
return 0; |
| 627 |
|
}; |
| 628 |
|
|
| 629 |
|
|
| 630 |
|
|
| 631 |
|
/** |
| 632 |
|
* This method restore a run from the GL_RUN_TRASH table. |
| 633 |
|
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
| 634 |
|
* |
| 635 |
|
**/ |
| 636 |
|
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
| 637 |
|
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
| 638 |
|
//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; |
| 639 |
|
// MySQL variables |
| 640 |
|
TSQLResult *pResult; |
| 641 |
|
TSQLRow *Row; |
| 642 |
|
stringstream myquery; |
| 643 |
|
// |
| 644 |
|
if ( !IDRUN ) IDRUN = ID; |
| 645 |
|
if ( !IDRUN ) return 1; |
| 646 |
|
// |
| 647 |
|
if ( !strcmp(ToTable.Data(),"") ){ |
| 648 |
|
// |
| 649 |
|
myquery.str(""); |
| 650 |
|
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
| 651 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 652 |
|
// |
| 653 |
|
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
| 654 |
|
// |
| 655 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 656 |
|
this->GetGLTABLES()->AddQ(); |
| 657 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 658 |
|
// |
| 659 |
|
Row = pResult->Next(); |
| 660 |
|
if( Row != NULL ){ |
| 661 |
|
ToTable = (TString)Row->GetField(0); |
| 662 |
|
} else { |
| 663 |
|
return 1; |
| 664 |
|
}; |
| 665 |
|
}; |
| 666 |
|
// ---------------- |
| 667 |
|
myquery.str(""); |
| 668 |
|
myquery << " INSERT INTO "; |
| 669 |
|
myquery << ToTable.Data(); |
| 670 |
|
myquery << " ("; |
| 671 |
|
myquery << "ID"; |
| 672 |
|
myquery << ",ID_RUN_FRAG"; |
| 673 |
|
myquery << ",ID_ROOT_L0"; |
| 674 |
|
myquery << ",ID_ROOT_L2"; |
| 675 |
|
myquery << ",RUNHEADER_TIME"; |
| 676 |
|
myquery << ",RUNTRAILER_TIME"; |
| 677 |
|
myquery << ",RUNHEADER_OBT"; |
| 678 |
|
myquery << ",RUNTRAILER_OBT"; |
| 679 |
|
myquery << ",RUNHEADER_PKT"; |
| 680 |
|
myquery << ",RUNTRAILER_PKT"; |
| 681 |
|
myquery << ",BOOT_NUMBER"; |
| 682 |
|
myquery << ",EV_FROM"; |
| 683 |
|
myquery << ",EV_TO"; |
| 684 |
|
myquery << ",NEVENTS"; |
| 685 |
|
myquery << ",PKT_COUNTER"; |
| 686 |
|
myquery << ",PKT_READY_COUNTER"; |
| 687 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 688 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 689 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 690 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 691 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 692 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 693 |
|
myquery << ",ACQ_VAR_INFO"; |
| 694 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 695 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 696 |
|
myquery << ",TRK_CALIB_USED"; |
| 697 |
|
myquery << ",CAL_DSP_MASK"; |
| 698 |
|
myquery << ",LAST_TIMESYNC"; |
| 699 |
|
myquery << ",OBT_TIMESYNC"; |
| 700 |
|
myquery << ",VALIDATION"; |
| 701 |
|
myquery << ",INSERT_TIME"; |
| 702 |
|
myquery << ") SELECT "; |
| 703 |
|
myquery << "ID"; |
| 704 |
|
myquery << ",ID_RUN_FRAG"; |
| 705 |
|
myquery << ",ID_ROOT_L0"; |
| 706 |
|
myquery << ",ID_ROOT_L2"; |
| 707 |
|
myquery << ",RUNHEADER_TIME"; |
| 708 |
|
myquery << ",RUNTRAILER_TIME"; |
| 709 |
|
myquery << ",RUNHEADER_OBT"; |
| 710 |
|
myquery << ",RUNTRAILER_OBT"; |
| 711 |
|
myquery << ",RUNHEADER_PKT"; |
| 712 |
|
myquery << ",RUNTRAILER_PKT"; |
| 713 |
|
myquery << ",BOOT_NUMBER"; |
| 714 |
|
myquery << ",EV_FROM"; |
| 715 |
|
myquery << ",EV_TO"; |
| 716 |
|
myquery << ",NEVENTS"; |
| 717 |
|
myquery << ",PKT_COUNTER"; |
| 718 |
|
myquery << ",PKT_READY_COUNTER"; |
| 719 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 720 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 721 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 722 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 723 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 724 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 725 |
|
myquery << ",ACQ_VAR_INFO"; |
| 726 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 727 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 728 |
|
myquery << ",TRK_CALIB_USED"; |
| 729 |
|
myquery << ",CAL_DSP_MASK"; |
| 730 |
|
myquery << ",LAST_TIMESYNC"; |
| 731 |
|
myquery << ",OBT_TIMESYNC"; |
| 732 |
|
myquery << ",VALIDATION"; |
| 733 |
|
myquery << ",INSERT_TIME"; |
| 734 |
|
myquery << " FROM GL_RUN_TRASH "; |
| 735 |
|
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
| 736 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 737 |
|
// |
| 738 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
| 739 |
|
// |
| 740 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 741 |
|
this->GetGLTABLES()->AddQ(); |
| 742 |
|
dbc->Query(myquery.str().c_str()); |
| 743 |
|
// |
| 744 |
|
// |
| 745 |
|
myquery.str(""); |
| 746 |
|
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
| 747 |
|
myquery << IDRUN << ";"; |
| 748 |
|
// |
| 749 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 750 |
|
this->GetGLTABLES()->AddQ(); |
| 751 |
|
dbc->Query(myquery.str().c_str()); |
| 752 |
|
// |
| 753 |
|
return 0; |
| 754 |
|
}; |
| 755 |
|
|
| 756 |
/** |
/** |
| 757 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
| 830 |
// |
// |
| 831 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
| 832 |
// |
// |
| 833 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 834 |
|
this->GetGLTABLES()->AddQ(); |
| 835 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
| 836 |
// |
// |
| 837 |
return 0; |
return 0; |
| 908 |
// |
// |
| 909 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
| 910 |
// |
// |
| 911 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 912 |
|
this->GetGLTABLES()->AddQ(); |
| 913 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
| 914 |
// |
// |
| 915 |
return 0; |
return 0; |
| 966 |
myquery << ",VALIDATION"; |
myquery << ",VALIDATION"; |
| 967 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
| 968 |
// |
// |
| 969 |
|
// printf(" myquery is %s \n",myquery.str().c_str()); |
| 970 |
|
if ( !this->IsConnected(dbc) ) return -57; |
| 971 |
|
this->AddQ(); |
| 972 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 973 |
if(!pResult->GetRowCount())return(-50); |
// |
| 974 |
|
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
| 975 |
|
// |
| 976 |
|
if( !pResult->GetRowCount() ) return(-50); |
| 977 |
|
// |
| 978 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 979 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 980 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 981 |
|
// Set_GL_RUN(Row); |
| 982 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 983 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 984 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
| 985 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 986 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
| 987 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 988 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 989 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 990 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 991 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 992 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 993 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
| 994 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
| 995 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
| 996 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 997 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 998 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
| 999 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 1000 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 1001 |
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)); |
| 1002 |
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)); |
| 1003 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 1004 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 1005 |
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)); |
| 1006 |
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)); |
| 1007 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 1008 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 1009 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
| 1010 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
| 1011 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
| 1012 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
|
|
|
|
|
|
| 1013 |
}; |
}; |
| 1014 |
}; |
}; |
| 1015 |
delete pResult; |
// delete pResult; |
| 1016 |
|
return(0); |
|
return 0; |
|
|
|
|
| 1017 |
}; |
}; |
| 1018 |
|
|
| 1019 |
/** |
/** |
| 1067 |
// |
// |
| 1068 |
// printf(" query is %s \n",myquery.str().c_str()); |
// printf(" query is %s \n",myquery.str().c_str()); |
| 1069 |
// |
// |
| 1070 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1071 |
|
this->GetGLTABLES()->AddQ(); |
| 1072 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1073 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
| 1074 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1134 |
myquery << ",NAME"; |
myquery << ",NAME"; |
| 1135 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
myquery << " from GL_ROOT where ID=" << id << ";"; |
| 1136 |
// |
// |
| 1137 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1138 |
|
this->GetGLTABLES()->AddQ(); |
| 1139 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1140 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
| 1141 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1157 |
* Function to query the GL_TRK_CALIB table of the DB. |
* Function to query the GL_TRK_CALIB table of the DB. |
| 1158 |
* |
* |
| 1159 |
* \param run starting time |
* \param run starting time |
| 1160 |
|
* \param dbc DB server |
| 1161 |
* \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 |
| 1162 |
*/ |
*/ |
| 1163 |
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){ |
| 1169 |
stringstream myquery; |
stringstream myquery; |
| 1170 |
// ---------------- |
// ---------------- |
| 1171 |
myquery.str(""); |
myquery.str(""); |
| 1172 |
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; |
| 1173 |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1174 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1175 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1176 |
|
this->GetGLTABLES()->AddQ(); |
| 1177 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1178 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
| 1179 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1183 |
stringstream row; |
stringstream row; |
| 1184 |
row.str(""); |
row.str(""); |
| 1185 |
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 |
| 1186 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 1187 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 1188 |
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()); |
| 1189 |
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()); |
| 1190 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1191 |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==5) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1192 |
// |
// |
| 1193 |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==6) OBT1 = (UInt_t)atoll(Row->GetField(t)); |
| 1194 |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==7) OBT2 = (UInt_t)atoll(Row->GetField(t)); |
| 1195 |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
if (t==8) PKT1 = (UInt_t)atoll(Row->GetField(t)); |
| 1196 |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
if (t==9) PKT2 = (UInt_t)atoll(Row->GetField(t)); |
| 1197 |
}; |
if (t==10) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
| 1198 |
|
if (t==11) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1199 |
|
}; |
| 1200 |
}; |
}; |
| 1201 |
delete pResult; |
delete pResult; |
| 1202 |
|
// |
| 1203 |
|
// if ( TO_TIME < time ) return(51); |
| 1204 |
// |
// |
|
if(TO_TIME < time)return(51); |
|
| 1205 |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
if ( (!OBT1 && !PKT1 ) || (!OBT2 && !PKT2) ) return(52); // ONE CALIBRATION PACKET IS MISSING! |
| 1206 |
// |
// |
| 1207 |
return 0; |
return 0; |
| 1214 |
* \param run starting time |
* \param run starting time |
| 1215 |
* \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 |
| 1216 |
*/ |
*/ |
| 1217 |
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){ |
| 1218 |
// MySQL variables |
// MySQL variables |
| 1219 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1220 |
TSQLRow *Row; |
TSQLRow *Row; |
| 1221 |
int t; |
int t; |
| 1222 |
stringstream myquery; |
stringstream myquery; |
| 1223 |
|
uptime = 0; |
| 1224 |
// |
// |
| 1225 |
// select the correct calibration |
// select the correct calibration |
| 1226 |
// |
// |
| 1228 |
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; |
| 1229 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
| 1230 |
myquery << " and TO_TIME > " << time; |
myquery << " and TO_TIME > " << time; |
| 1231 |
myquery << " and VALIDATION=1;"; |
myquery << " ;"; |
| 1232 |
|
//myquery << " and VALIDATION=1;"; |
| 1233 |
// |
// |
| 1234 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1235 |
|
this->GetGLTABLES()->AddQ(); |
| 1236 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1237 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
| 1238 |
|
// |
| 1239 |
|
if( !pResult->GetRowCount() ) return(-54); |
| 1240 |
|
Row = pResult->Next(); |
| 1241 |
|
if( Row == NULL ) return (-54); |
| 1242 |
|
// |
| 1243 |
|
uptime = (UInt_t)atoll(Row->GetField(2)); |
| 1244 |
// |
// |
| 1245 |
// 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... |
| 1246 |
// |
// |
| 1247 |
if( !pResult->GetRowCount() ){ |
if( atoi(Row->GetField(4)) == 0 ){ // if validation = 0 |
|
// pResult->Delete(); |
|
| 1248 |
// |
// |
| 1249 |
// 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 |
| 1250 |
// |
// |
| 1252 |
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; |
| 1253 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
| 1254 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1255 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1256 |
|
this->GetGLTABLES()->AddQ(); |
| 1257 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1258 |
|
// printf(" mysquery is %s\n",myquery.str().c_str()); |
| 1259 |
// |
// |
| 1260 |
// if no results yet quit with error |
// if no results yet quit with error |
| 1261 |
// |
// |
| 1262 |
if( !pResult->GetRowCount() ) return (-54); |
if( !pResult->GetRowCount() ) return (-54); |
| 1263 |
|
// |
| 1264 |
|
Row = pResult->Next(); |
| 1265 |
|
// |
| 1266 |
}; |
}; |
| 1267 |
// |
// |
| 1268 |
// store infos and exit |
// store infos and exit |
| 1269 |
// |
// |
|
Row = pResult->Next(); |
|
| 1270 |
if( Row == NULL ) return (-54); |
if( Row == NULL ) return (-54); |
| 1271 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1272 |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 1294 |
// ---------------- |
// ---------------- |
| 1295 |
myquery.str(""); |
myquery.str(""); |
| 1296 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
| 1297 |
myquery << " AND VALIDATION = 1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1298 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1299 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1300 |
|
this->GetGLTABLES()->AddQ(); |
| 1301 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1302 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
| 1303 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1344 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
| 1345 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
| 1346 |
// |
// |
| 1347 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1348 |
|
this->GetGLTABLES()->AddQ(); |
| 1349 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1350 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
| 1351 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1398 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1399 |
TSQLRow *Row; |
TSQLRow *Row; |
| 1400 |
stringstream myquery; |
stringstream myquery; |
| 1401 |
|
stringstream rname; |
| 1402 |
|
rname.str(""); |
| 1403 |
// ---------------- |
// ---------------- |
| 1404 |
myquery.str(""); |
myquery.str(""); |
| 1405 |
myquery << "select "; |
myquery << "select "; |
| 1409 |
myquery << type.Data(); |
myquery << type.Data(); |
| 1410 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
| 1411 |
// |
// |
| 1412 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1413 |
|
this->GetGLTABLES()->AddQ(); |
| 1414 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1415 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
| 1416 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1418 |
stringstream fname; |
stringstream fname; |
| 1419 |
fname.str(""); |
fname.str(""); |
| 1420 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
| 1421 |
|
rname << Row->GetField(1); |
| 1422 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
| 1423 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
| 1424 |
}; |
}; |
| 1438 |
// |
// |
| 1439 |
// look for Resurs offset |
// look for Resurs offset |
| 1440 |
// |
// |
| 1441 |
UInt_t t0 = 0; |
T0 = 0; |
| 1442 |
// |
// |
| 1443 |
myquery.str(""); |
// |
| 1444 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
| 1445 |
<< idraw << " AND TO_ID_RAW >= " |
oss.str(""); |
| 1446 |
<< 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='" |
| 1447 |
pResult = dbc->Query(myquery.str().c_str()); |
<< rname.str().c_str() << "';"; |
| 1448 |
if ( pResult ){ |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1449 |
|
this->GetGLTABLES()->AddQ(); |
| 1450 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1451 |
|
Row = pResult->Next(); |
| 1452 |
|
// |
| 1453 |
|
TString name=rname.str().c_str(); |
| 1454 |
|
UInt_t dworbit = 0; |
| 1455 |
|
Int_t nlength = name.Length(); |
| 1456 |
|
if ( nlength < 5 ) return; |
| 1457 |
|
TString dwo = 0; |
| 1458 |
|
for (Int_t i = 0; i<5; i++){ |
| 1459 |
|
dwo.Append(name[i],1); |
| 1460 |
|
}; |
| 1461 |
|
if ( dwo.IsDigit() ){ |
| 1462 |
|
dworbit = (UInt_t)dwo.Atoi(); |
| 1463 |
|
} else { |
| 1464 |
|
dwo=""; |
| 1465 |
|
for (Int_t i = 8; i<13; i++){ |
| 1466 |
|
dwo.Append(name[i],1); |
| 1467 |
|
}; |
| 1468 |
|
if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi(); |
| 1469 |
|
}; |
| 1470 |
|
// |
| 1471 |
|
if ( !Row ){ |
| 1472 |
|
oss.str(""); |
| 1473 |
|
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< " |
| 1474 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
| 1475 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1476 |
|
this->GetGLTABLES()->AddQ(); |
| 1477 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1478 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1479 |
if ( Row ){ |
if ( !Row ){ |
| 1480 |
// |
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
| 1481 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
return; |
|
// |
|
| 1482 |
}; |
}; |
| 1483 |
}; |
}; |
| 1484 |
// |
// |
| 1485 |
|
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); |
| 1486 |
|
T0 = (UInt_t)tu.GetSec(); |
| 1487 |
// |
// |
| 1488 |
// look for the correct timesync entry |
// look for the correct timesync entry |
| 1489 |
// |
// |
| 1490 |
myquery.str(""); |
myquery.str(""); |
| 1491 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
| 1492 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
| 1493 |
<< ";"; |
<< ";"; |
| 1494 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1495 |
|
this->GetGLTABLES()->AddQ(); |
| 1496 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1497 |
if ( pResult ){ |
if ( pResult ){ |
| 1498 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1499 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
| 1500 |
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)); |
| 1501 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1502 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1503 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
| 1504 |
}; |
}; |
| 1505 |
}; |
}; |
| 1506 |
|
// |
| 1507 |
|
file->Close(); |
| 1508 |
delete pResult; |
delete pResult; |
| 1509 |
}; |
}; |
| 1510 |
|
|
| 1519 |
// |
// |
| 1520 |
}; |
}; |
| 1521 |
|
|
| 1522 |
|
/** |
| 1523 |
|
* |
| 1524 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
| 1525 |
|
* |
| 1526 |
|
*/ |
| 1527 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
| 1528 |
|
// |
| 1529 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
| 1530 |
|
// |
| 1531 |
|
}; |
| 1532 |
|
|
| 1533 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
|
| 1534 |
|
/** |
| 1535 |
|
* Return the correct packet number if we went back to zero |
| 1536 |
|
*/ |
| 1537 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
| 1538 |
// |
// |
| 1539 |
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) ){ |
| 1540 |
|
return((Long64_t)pkt_num+16777215LL); |
| 1541 |
|
}; |
| 1542 |
// |
// |
| 1543 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
| 1544 |
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())); |
|
|
}; |
|
| 1545 |
}; |
}; |
| 1546 |
// |
// |
| 1547 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
| 1548 |
// |
// |
| 1549 |
}; |
}; |
| 1550 |
|
|
| 1551 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
| 1552 |
|
* Return the correct On Board Time if we went back to zero |
| 1553 |
|
*/ |
| 1554 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
| 1555 |
// |
// |
| 1556 |
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())); |
| 1557 |
// |
// |
| 1558 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
| 1559 |
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)); |
|
|
}; |
|
| 1560 |
}; |
}; |
| 1561 |
// |
// |
| 1562 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
| 1563 |
}; |
}; |
| 1564 |
|
|
| 1565 |
|
|
| 1566 |
|
|
| 1567 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
| 1568 |
|
// // |
| 1569 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
| 1570 |
|
// // |
| 1571 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
| 1572 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
| 1573 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
| 1574 |
|
// } else { |
| 1575 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
| 1576 |
|
// }; |
| 1577 |
|
// }; |
| 1578 |
|
// // |
| 1579 |
|
// return((ULong64_t)obt); |
| 1580 |
|
// // |
| 1581 |
|
// }; |
| 1582 |
|
|
| 1583 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
| 1584 |
|
// // |
| 1585 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
| 1586 |
|
// // |
| 1587 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
| 1588 |
|
// if ( (pkt_num-16777215) < 0 ){ |
| 1589 |
|
// return((16777215-pkt_num)); |
| 1590 |
|
// } else { |
| 1591 |
|
// return((pkt_num-16777215)); |
| 1592 |
|
// }; |
| 1593 |
|
// }; |
| 1594 |
|
// // |
| 1595 |
|
// return(pkt_num); |
| 1596 |
|
// // |
| 1597 |
|
// }; |
| 1598 |
|
|
| 1599 |
|
/* |
| 1600 |
|
* |
| 1601 |
|
* Convert the time in the DB from UInt_t to a string |
| 1602 |
|
* |
| 1603 |
|
* @param dbt time in the DB |
| 1604 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
| 1605 |
|
* |
| 1606 |
|
*/ |
| 1607 |
|
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
| 1608 |
|
// |
| 1609 |
|
Int_t offset = 0; |
| 1610 |
|
TString rtime; |
| 1611 |
|
Bool_t found = false; |
| 1612 |
|
// |
| 1613 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
| 1614 |
|
// |
| 1615 |
|
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
| 1616 |
|
found = true; |
| 1617 |
|
// |
| 1618 |
|
}; |
| 1619 |
|
// |
| 1620 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
| 1621 |
|
// |
| 1622 |
|
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
| 1623 |
|
found = true; |
| 1624 |
|
// |
| 1625 |
|
}; |
| 1626 |
|
// |
| 1627 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
| 1628 |
|
// |
| 1629 |
|
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
| 1630 |
|
found = true; |
| 1631 |
|
// |
| 1632 |
|
}; |
| 1633 |
|
// |
| 1634 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
| 1635 |
|
// |
| 1636 |
|
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
| 1637 |
|
found = true; |
| 1638 |
|
// |
| 1639 |
|
}; |
| 1640 |
|
// |
| 1641 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
| 1642 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
| 1643 |
|
tzone = "UTC"; |
| 1644 |
|
}; |
| 1645 |
|
// |
| 1646 |
|
dbt += offset; |
| 1647 |
|
// |
| 1648 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
| 1649 |
|
// |
| 1650 |
|
rtime = time->AsString("s"); |
| 1651 |
|
// |
| 1652 |
|
delete time; |
| 1653 |
|
// |
| 1654 |
|
return(rtime); |
| 1655 |
|
} |
| 1656 |
|
|
| 1657 |
|
/* |
| 1658 |
|
* |
| 1659 |
|
* Convert the time from TZONE to UTC |
| 1660 |
|
* |
| 1661 |
|
* @param dbt time in the DB |
| 1662 |
|
* @param tzone Time Zone, can be UTC,GMT,CET,CEST,MSD default is MSK |
| 1663 |
|
* |
| 1664 |
|
*/ |
| 1665 |
|
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
| 1666 |
|
// |
| 1667 |
|
Int_t offset = 0; |
| 1668 |
|
TString rtime; |
| 1669 |
|
// |
| 1670 |
|
Bool_t found = false; |
| 1671 |
|
// |
| 1672 |
|
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
| 1673 |
|
// |
| 1674 |
|
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
| 1675 |
|
found = true; |
| 1676 |
|
// |
| 1677 |
|
}; |
| 1678 |
|
// |
| 1679 |
|
if ( !strcmp(tzone.Data(),"CET") ){ |
| 1680 |
|
// |
| 1681 |
|
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
| 1682 |
|
found = true; |
| 1683 |
|
// |
| 1684 |
|
}; |
| 1685 |
|
// |
| 1686 |
|
if ( !strcmp(tzone.Data(),"CEST") ){ |
| 1687 |
|
// |
| 1688 |
|
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
| 1689 |
|
found = true; |
| 1690 |
|
// |
| 1691 |
|
}; |
| 1692 |
|
// |
| 1693 |
|
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
| 1694 |
|
// |
| 1695 |
|
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
| 1696 |
|
found = true; |
| 1697 |
|
// |
| 1698 |
|
}; |
| 1699 |
|
// |
| 1700 |
|
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
| 1701 |
|
// |
| 1702 |
|
offset = 0; |
| 1703 |
|
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
| 1704 |
|
tzone = "UTC"; |
| 1705 |
|
}; |
| 1706 |
|
// |
| 1707 |
|
dbt += offset; |
| 1708 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
| 1709 |
|
// |
| 1710 |
|
rtime = time->AsString("s"); |
| 1711 |
|
// |
| 1712 |
|
return(rtime); |
| 1713 |
|
} |
| 1714 |
|
|
| 1715 |
|
|
| 1716 |
|
// |
| 1717 |
|
// Build a query and call DoQuery. |
| 1718 |
|
// |
| 1719 |
|
// date it's an SQL datetime date and dbc is the connection to be |
| 1720 |
|
// used. It will query for the tle with the nearest but previous date |
| 1721 |
|
// and the immediatly next one. |
| 1722 |
|
// |
| 1723 |
|
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
| 1724 |
|
stringstream myquery; |
| 1725 |
|
myquery.str(""); |
| 1726 |
|
|
| 1727 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1728 |
|
<< "WHERE FROM_TIME <= '" << date.Data() |
| 1729 |
|
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
| 1730 |
|
<< "UNION " |
| 1731 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1732 |
|
<< "WHERE FROM_TIME > '" << date.Data() |
| 1733 |
|
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
| 1734 |
|
|
| 1735 |
|
return DoQuery(myquery.str().c_str(), dbc); |
| 1736 |
|
} |
| 1737 |
|
|
| 1738 |
|
|
| 1739 |
|
// |
| 1740 |
|
// Build a query and call DoQuery. |
| 1741 |
|
// |
| 1742 |
|
// time is the UTC date in unix time (UTC) and dbc is the connection |
| 1743 |
|
// to be used. It will query for the tle with the nearest but |
| 1744 |
|
// previous date and the immediatly next one. |
| 1745 |
|
// |
| 1746 |
|
// Returns the value returned by DoQuery(). |
| 1747 |
|
// |
| 1748 |
|
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
| 1749 |
|
stringstream myquery; |
| 1750 |
|
myquery.str(""); |
| 1751 |
|
|
| 1752 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1753 |
|
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
| 1754 |
|
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
| 1755 |
|
<< "UNION " |
| 1756 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1757 |
|
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
| 1758 |
|
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
| 1759 |
|
|
| 1760 |
|
return DoQuery(myquery.str().c_str(), dbc); |
| 1761 |
|
} |
| 1762 |
|
|
| 1763 |
|
|
| 1764 |
|
// |
| 1765 |
|
// Do the query myquery on the connectio dbc. Initialize tle, |
| 1766 |
|
// tleFromTime and tleToTime. |
| 1767 |
|
// |
| 1768 |
|
// We should have two rows (unless the table is old). From the last |
| 1769 |
|
// one we only take tleToTime. |
| 1770 |
|
// |
| 1771 |
|
// Returns 0 for success, 1 for failure. |
| 1772 |
|
// |
| 1773 |
|
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
| 1774 |
|
TSQLResult *result; |
| 1775 |
|
TSQLRow *row; |
| 1776 |
|
|
| 1777 |
|
// Set the right time_zone (otherwise horrible things will occur! :) |
| 1778 |
|
dbc->Query("SET time_zone = '+0:00'"); |
| 1779 |
|
|
| 1780 |
|
// Do the query |
| 1781 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1782 |
|
this->GetGLTABLES()->AddQ(); |
| 1783 |
|
result = dbc->Query(myquery.Data()); |
| 1784 |
|
if(! result->GetRowCount() ) { |
| 1785 |
|
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
| 1786 |
|
return 1; |
| 1787 |
|
} |
| 1788 |
|
|
| 1789 |
|
// Get results |
| 1790 |
|
row = result->Next(); // first tle row |
| 1791 |
|
tle = GiveTle(row); |
| 1792 |
|
|
| 1793 |
|
tleFromTime = strtol(row->GetField(4), NULL, 10); |
| 1794 |
|
|
| 1795 |
|
row = result->Next(); // second tle row |
| 1796 |
|
if(row) |
| 1797 |
|
tleToTime = strtol(row->GetField(4), NULL, 10); |
| 1798 |
|
else { |
| 1799 |
|
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
| 1800 |
|
tleToTime = UINT_MAX; |
| 1801 |
|
} |
| 1802 |
|
|
| 1803 |
|
delete row; |
| 1804 |
|
delete result; |
| 1805 |
|
|
| 1806 |
|
return 0; |
| 1807 |
|
} |
| 1808 |
|
|
| 1809 |
|
|
| 1810 |
|
// |
| 1811 |
|
// Build a cTle object from the GL_TLE row. |
| 1812 |
|
// |
| 1813 |
|
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
| 1814 |
|
cTle *thistle = NULL; |
| 1815 |
|
string tle1, tle2, tle3; |
| 1816 |
|
|
| 1817 |
|
// Build cTle object |
| 1818 |
|
tle1 = row->GetField(1); |
| 1819 |
|
tle2 = row->GetField(2); |
| 1820 |
|
tle3 = row->GetField(3); |
| 1821 |
|
|
| 1822 |
|
thistle = new cTle(tle1, tle2, tle3); |
| 1823 |
|
|
| 1824 |
|
return thistle; |
| 1825 |
|
} |