| 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); |
| 24 |
ClassImp(GL_PARAM); |
ClassImp(GL_PARAM); |
| 25 |
ClassImp(GL_S4_CALIB); |
ClassImp(GL_S4_CALIB); |
| 26 |
ClassImp(GL_CALO_CALIB); |
ClassImp(GL_CALO_CALIB); |
| 27 |
|
ClassImp(GL_CALOPULSE_CALIB); |
| 28 |
ClassImp(GL_TIMESYNC); |
ClassImp(GL_TIMESYNC); |
| 29 |
|
ClassImp(GL_TLE); |
| 30 |
// |
// |
| 31 |
using namespace std; |
using namespace std; |
| 32 |
|
|
| 33 |
|
GL_TABLES::GL_TABLES(){ |
| 34 |
|
}; |
| 35 |
|
|
| 36 |
|
GL_TABLES::GL_TABLES(TString host, TString user, TString psw){ |
| 37 |
|
fHost = new TString(host.Data()); |
| 38 |
|
fUser = new TString(user.Data()); |
| 39 |
|
fPsw = new TString(psw.Data()); |
| 40 |
|
fSet = true; |
| 41 |
|
fNquery = 0; |
| 42 |
|
mh = host.Data(); |
| 43 |
|
mu = user.Data(); |
| 44 |
|
mp = psw.Data(); |
| 45 |
|
}; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
void GL_TABLES::Set(TString host, TString user, TString psw){ |
| 49 |
|
fHost = new TString(host.Data()); |
| 50 |
|
fUser = new TString(user.Data()); |
| 51 |
|
fPsw = new TString(psw.Data()); |
| 52 |
|
fSet = true; |
| 53 |
|
fNquery = 0; |
| 54 |
|
mh = host.Data(); |
| 55 |
|
mu = user.Data(); |
| 56 |
|
mp = psw.Data(); |
| 57 |
|
}; |
| 58 |
|
|
| 59 |
|
Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ |
| 60 |
|
// |
| 61 |
|
// |
| 62 |
|
// |
| 63 |
|
if ( !fSet ){ |
| 64 |
|
return true; |
| 65 |
|
}; |
| 66 |
|
// |
| 67 |
|
// printf(" host is %s \n",fHost->Data()); |
| 68 |
|
// |
| 69 |
|
stringstream myquery; |
| 70 |
|
myquery.str(""); |
| 71 |
|
myquery << "show databases;"; |
| 72 |
|
if ( dbc ){ |
| 73 |
|
if ( dbc->IsConnected() ){ |
| 74 |
|
dbc->Query(myquery.str().c_str()); |
| 75 |
|
fNquery++; |
| 76 |
|
if ( !(dbc->GetErrorCode()) ){ |
| 77 |
|
// printf("ok\n"); |
| 78 |
|
// |
| 79 |
|
// if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){ |
| 80 |
|
// if ( !(dbc->GetErrorCode()) ){ |
| 81 |
|
// is connected |
| 82 |
|
return true; |
| 83 |
|
// }; |
| 84 |
|
}; |
| 85 |
|
}; |
| 86 |
|
}; |
| 87 |
|
// |
| 88 |
|
if ( true ) { |
| 89 |
|
// |
| 90 |
|
printf(" WARNING: Lost connection to DB! try to recover... \n"); |
| 91 |
|
// |
| 92 |
|
TString host = fHost->Data(); |
| 93 |
|
TString user = fUser->Data(); |
| 94 |
|
TString psw = fPsw->Data(); |
| 95 |
|
delete dbc; |
| 96 |
|
dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); |
| 97 |
|
// |
| 98 |
|
myquery.str(""); |
| 99 |
|
myquery << "show databases;"; |
| 100 |
|
dbc->Query(myquery.str().c_str()); |
| 101 |
|
fNquery++; |
| 102 |
|
// if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){ |
| 103 |
|
if ( !(dbc->GetErrorCode()) ){ |
| 104 |
|
// |
| 105 |
|
printf(" ...connection recovered, I can continue! \n"); |
| 106 |
|
// |
| 107 |
|
myquery.str(""); |
| 108 |
|
myquery << "SET time_zone='+0:00'"; |
| 109 |
|
dbc->Query(myquery.str().c_str()); |
| 110 |
|
fNquery++; |
| 111 |
|
myquery.str(""); |
| 112 |
|
myquery << "SET wait_timeout=173000;"; |
| 113 |
|
dbc->Query(myquery.str().c_str()); |
| 114 |
|
fNquery++; |
| 115 |
|
return true; |
| 116 |
|
}; |
| 117 |
|
}; |
| 118 |
|
// |
| 119 |
|
printf(" GLTABLES: connection is gone away, query will fail\n"); |
| 120 |
|
// |
| 121 |
|
return false; |
| 122 |
|
// |
| 123 |
|
}; |
| 124 |
|
|
| 125 |
|
void GL_TABLES::ResetCounters(){ |
| 126 |
|
fNquery = 0; |
| 127 |
|
}; |
| 128 |
|
|
| 129 |
|
void GL_TABLES::AddQ(){ |
| 130 |
|
if ( fSet ) fNquery++; |
| 131 |
|
}; |
| 132 |
|
|
| 133 |
|
UInt_t GL_TABLES::GetNqueries(){ |
| 134 |
|
UInt_t rn = 0; |
| 135 |
|
rn += (UInt_t&)fNquery; |
| 136 |
|
return(rn); |
| 137 |
|
}; |
| 138 |
|
|
| 139 |
GL_RUN::GL_RUN() { |
GL_RUN::GL_RUN() { |
| 140 |
ID = 0; |
ID = 0; |
| 141 |
ID_RUN_FRAG = 0; |
ID_RUN_FRAG = 0; |
| 246 |
FROM_TIME = 0; |
FROM_TIME = 0; |
| 247 |
TO_TIME = 0; |
TO_TIME = 0; |
| 248 |
SECTION = 0; |
SECTION = 0; |
| 249 |
|
OBT = 0; |
| 250 |
|
PKT = 0; |
| 251 |
|
BOOT_NUMBER = 0; |
| 252 |
|
VALIDATION = 0; |
| 253 |
|
} |
| 254 |
|
|
| 255 |
|
GL_CALOPULSE_CALIB::GL_CALOPULSE_CALIB(){ |
| 256 |
|
ID = 0; |
| 257 |
|
ID_ROOT_L0 = 0; |
| 258 |
|
EV_ROOT = 0; |
| 259 |
|
FROM_TIME = 0; |
| 260 |
|
TO_TIME = 0; |
| 261 |
|
SECTION = 0; |
| 262 |
|
PULSED_STRIP = 0; |
| 263 |
|
PULSE_AMPLITUDE = 0; |
| 264 |
|
OBT = 0; |
| 265 |
|
PKT = 0; |
| 266 |
|
BOOT_NUMBER = 0; |
| 267 |
|
VALIDATION = 0; |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
GL_S4_CALIB::GL_S4_CALIB(){ |
GL_S4_CALIB::GL_S4_CALIB(){ |
| 273 |
EV_ROOT = 0; |
EV_ROOT = 0; |
| 274 |
FROM_TIME = 0; |
FROM_TIME = 0; |
| 275 |
TO_TIME = 0; |
TO_TIME = 0; |
| 276 |
PARAM_FIT0 = 0.; |
OBT = 0; |
| 277 |
PARAM_FIT1 = 0.; |
PKT = 0; |
| 278 |
|
BOOT_NUMBER = 0; |
| 279 |
} |
} |
| 280 |
|
|
| 281 |
GL_TIMESYNC::GL_TIMESYNC(){ |
GL_TIMESYNC::GL_TIMESYNC(){ |
| 282 |
obtfirst = 0; |
obtfirst = 0; |
| 283 |
pktfirst = 0; |
pktfirst = 0; |
| 284 |
toffset = 0; |
ID_RESURS_OFFSET = 0; |
| 285 |
ID = 0; |
ID = 0; |
| 286 |
ID_RAW = 0; |
ID_RAW = 0; |
| 287 |
OBT0 = 0; |
OBT0 = 0; |
| 288 |
TIMESYNC = 0; |
TIMESYNC = 0; |
| 289 |
TYPE = 0; |
TYPE = 0; |
| 290 |
}// **************************************************** |
} |
| 291 |
|
|
| 292 |
|
// **************************************************** |
| 293 |
|
|
| 294 |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
void GL_RUN::SetEV_FROM(UInt_t evfrom){ |
| 295 |
EV_FROM = evfrom; |
EV_FROM = evfrom; |
| 499 |
|
|
| 500 |
} |
} |
| 501 |
|
|
| 502 |
|
/** |
| 503 |
|
* This method delete the run from the "FromTable" table and store it in the GL_RUN_TRASH table |
| 504 |
|
* If IDRUN is 0 "this->ID" run is used. |
| 505 |
|
* |
| 506 |
|
**/ |
| 507 |
|
Int_t GL_RUN::DeleteRun(TSQLServer *dbc,UInt_t IDRUN,TString FromTable){ |
| 508 |
|
// MySQL variables |
| 509 |
|
TSQLResult *pResult; |
| 510 |
|
TSQLRow *Row; |
| 511 |
|
stringstream myquery; |
| 512 |
|
// |
| 513 |
|
if ( !IDRUN ) IDRUN = ID; |
| 514 |
|
if ( !IDRUN ) return 1; |
| 515 |
|
// ---------------- |
| 516 |
|
myquery.str(""); |
| 517 |
|
myquery << " INSERT INTO GL_RUN_TRASH ("; |
| 518 |
|
myquery << "ID"; |
| 519 |
|
myquery << ",ID_RUN_FRAG"; |
| 520 |
|
myquery << ",ID_ROOT_L0"; |
| 521 |
|
myquery << ",ID_ROOT_L2"; |
| 522 |
|
myquery << ",RUNHEADER_TIME"; |
| 523 |
|
myquery << ",RUNTRAILER_TIME"; |
| 524 |
|
myquery << ",RUNHEADER_OBT"; |
| 525 |
|
myquery << ",RUNTRAILER_OBT"; |
| 526 |
|
myquery << ",RUNHEADER_PKT"; |
| 527 |
|
myquery << ",RUNTRAILER_PKT"; |
| 528 |
|
myquery << ",BOOT_NUMBER"; |
| 529 |
|
myquery << ",EV_FROM"; |
| 530 |
|
myquery << ",EV_TO"; |
| 531 |
|
myquery << ",NEVENTS"; |
| 532 |
|
myquery << ",PKT_COUNTER"; |
| 533 |
|
myquery << ",PKT_READY_COUNTER"; |
| 534 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 535 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 536 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 537 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 538 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 539 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 540 |
|
myquery << ",ACQ_VAR_INFO"; |
| 541 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 542 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 543 |
|
myquery << ",TRK_CALIB_USED"; |
| 544 |
|
myquery << ",CAL_DSP_MASK"; |
| 545 |
|
myquery << ",LAST_TIMESYNC"; |
| 546 |
|
myquery << ",OBT_TIMESYNC"; |
| 547 |
|
myquery << ",VALIDATION"; |
| 548 |
|
myquery << ",INSERT_TIME"; |
| 549 |
|
myquery << ") SELECT * FROM "; |
| 550 |
|
myquery << FromTable.Data(); |
| 551 |
|
myquery << " WHERE ID="; |
| 552 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 553 |
|
// |
| 554 |
|
// printf("1myquery is %s \n",myquery.str().c_str()); |
| 555 |
|
// |
| 556 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 557 |
|
this->GetGLTABLES()->AddQ(); |
| 558 |
|
dbc->Query(myquery.str().c_str()); |
| 559 |
|
// |
| 560 |
|
// retrieve this ID_TRASH |
| 561 |
|
// |
| 562 |
|
myquery.str(""); |
| 563 |
|
myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1"; |
| 564 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 565 |
|
this->GetGLTABLES()->AddQ(); |
| 566 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 567 |
|
// |
| 568 |
|
UInt_t idtrash = 0; |
| 569 |
|
UInt_t idl0 = 0; |
| 570 |
|
UInt_t idl2 = 0; |
| 571 |
|
// |
| 572 |
|
Row = pResult->Next(); |
| 573 |
|
if( Row != NULL ){ |
| 574 |
|
idtrash = (UInt_t)atoll(Row->GetField(0)); |
| 575 |
|
idl0 = (UInt_t)atoll(Row->GetField(1)); |
| 576 |
|
idl2 = (UInt_t)atoll(Row->GetField(2)); |
| 577 |
|
}; |
| 578 |
|
// |
| 579 |
|
TString fileL0 = ""; |
| 580 |
|
TString fileL2 = ""; |
| 581 |
|
myquery.str(""); |
| 582 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
| 583 |
|
myquery << idl0 << ";"; |
| 584 |
|
// |
| 585 |
|
// printf("2myquery is %s \n",myquery.str().c_str()); |
| 586 |
|
// |
| 587 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 588 |
|
this->GetGLTABLES()->AddQ(); |
| 589 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 590 |
|
// |
| 591 |
|
Row = pResult->Next(); |
| 592 |
|
if( Row != NULL ){ |
| 593 |
|
fileL0 = (TString)Row->GetField(0); |
| 594 |
|
}; |
| 595 |
|
// |
| 596 |
|
// |
| 597 |
|
// |
| 598 |
|
myquery.str(""); |
| 599 |
|
myquery << " SELECT NAME FROM GL_ROOT WHERE ID="; |
| 600 |
|
myquery << idl2 << ";"; |
| 601 |
|
// |
| 602 |
|
// printf("3myquery is %s \n",myquery.str().c_str()); |
| 603 |
|
// |
| 604 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 605 |
|
this->GetGLTABLES()->AddQ(); |
| 606 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 607 |
|
// |
| 608 |
|
Row = pResult->Next(); |
| 609 |
|
if( Row != NULL ){ |
| 610 |
|
fileL2 = (TString)Row->GetField(0); |
| 611 |
|
}; |
| 612 |
|
// |
| 613 |
|
// |
| 614 |
|
// |
| 615 |
|
myquery.str(""); |
| 616 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL0='"; |
| 617 |
|
myquery << fileL0.Data() << "' where ID_TRASH="; |
| 618 |
|
myquery << idtrash << ";"; |
| 619 |
|
// |
| 620 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 621 |
|
// |
| 622 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 623 |
|
this->GetGLTABLES()->AddQ(); |
| 624 |
|
dbc->Query(myquery.str().c_str()); |
| 625 |
|
// |
| 626 |
|
myquery.str(""); |
| 627 |
|
myquery << " UPDATE GL_RUN_TRASH SET FILENAMEL2='"; |
| 628 |
|
myquery << fileL2.Data() << "' where ID_TRASH="; |
| 629 |
|
myquery << idtrash << ";"; |
| 630 |
|
// |
| 631 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 632 |
|
// |
| 633 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 634 |
|
this->GetGLTABLES()->AddQ(); |
| 635 |
|
dbc->Query(myquery.str().c_str()); |
| 636 |
|
// |
| 637 |
|
myquery.str(""); |
| 638 |
|
myquery << " UPDATE GL_RUN_TRASH SET BELONGED_TO='"; |
| 639 |
|
myquery << FromTable.Data() << "' where ID_TRASH="; |
| 640 |
|
myquery << idtrash << ";"; |
| 641 |
|
// |
| 642 |
|
// printf("4myquery is %s \n",myquery.str().c_str()); |
| 643 |
|
// |
| 644 |
|
// |
| 645 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 646 |
|
this->GetGLTABLES()->AddQ(); |
| 647 |
|
dbc->Query(myquery.str().c_str()); |
| 648 |
|
// |
| 649 |
|
myquery.str(""); |
| 650 |
|
myquery << " DELETE FROM "; |
| 651 |
|
myquery << FromTable.Data() << " where ID="; |
| 652 |
|
myquery << IDRUN << ";"; |
| 653 |
|
// |
| 654 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
| 655 |
|
// |
| 656 |
|
// |
| 657 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 658 |
|
this->GetGLTABLES()->AddQ(); |
| 659 |
|
dbc->Query(myquery.str().c_str()); |
| 660 |
|
// |
| 661 |
|
return 0; |
| 662 |
|
}; |
| 663 |
|
|
| 664 |
|
|
| 665 |
|
|
| 666 |
|
/** |
| 667 |
|
* This method restore a run from the GL_RUN_TRASH table. |
| 668 |
|
* If ID is 0 "this->ID" is used; if "ToTable" is empty BELONG_TO field of GL_RUN_TRASH is used. |
| 669 |
|
* |
| 670 |
|
**/ |
| 671 |
|
Int_t GL_RUN::RestoreRun(TSQLServer *dbc,UInt_t IDRUN,TString ToTable){ |
| 672 |
|
// insert into GL_RUN_FRAGMENTS select * FROM GL_RUN where ID=11; |
| 673 |
|
//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; |
| 674 |
|
// MySQL variables |
| 675 |
|
TSQLResult *pResult; |
| 676 |
|
TSQLRow *Row; |
| 677 |
|
stringstream myquery; |
| 678 |
|
// |
| 679 |
|
if ( !IDRUN ) IDRUN = ID; |
| 680 |
|
if ( !IDRUN ) return 1; |
| 681 |
|
// |
| 682 |
|
if ( !strcmp(ToTable.Data(),"") ){ |
| 683 |
|
// |
| 684 |
|
myquery.str(""); |
| 685 |
|
myquery << " SELECT BELONGED_TO FROM GL_RUN_TRASH WHERE ID="; |
| 686 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 687 |
|
// |
| 688 |
|
printf(" qui? myquery is %s \n",myquery.str().c_str()); |
| 689 |
|
// |
| 690 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 691 |
|
this->GetGLTABLES()->AddQ(); |
| 692 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 693 |
|
// |
| 694 |
|
Row = pResult->Next(); |
| 695 |
|
if( Row != NULL ){ |
| 696 |
|
ToTable = (TString)Row->GetField(0); |
| 697 |
|
} else { |
| 698 |
|
return 1; |
| 699 |
|
}; |
| 700 |
|
}; |
| 701 |
|
// ---------------- |
| 702 |
|
myquery.str(""); |
| 703 |
|
myquery << " INSERT INTO "; |
| 704 |
|
myquery << ToTable.Data(); |
| 705 |
|
myquery << " ("; |
| 706 |
|
myquery << "ID"; |
| 707 |
|
myquery << ",ID_RUN_FRAG"; |
| 708 |
|
myquery << ",ID_ROOT_L0"; |
| 709 |
|
myquery << ",ID_ROOT_L2"; |
| 710 |
|
myquery << ",RUNHEADER_TIME"; |
| 711 |
|
myquery << ",RUNTRAILER_TIME"; |
| 712 |
|
myquery << ",RUNHEADER_OBT"; |
| 713 |
|
myquery << ",RUNTRAILER_OBT"; |
| 714 |
|
myquery << ",RUNHEADER_PKT"; |
| 715 |
|
myquery << ",RUNTRAILER_PKT"; |
| 716 |
|
myquery << ",BOOT_NUMBER"; |
| 717 |
|
myquery << ",EV_FROM"; |
| 718 |
|
myquery << ",EV_TO"; |
| 719 |
|
myquery << ",NEVENTS"; |
| 720 |
|
myquery << ",PKT_COUNTER"; |
| 721 |
|
myquery << ",PKT_READY_COUNTER"; |
| 722 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 723 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 724 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 725 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 726 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 727 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 728 |
|
myquery << ",ACQ_VAR_INFO"; |
| 729 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 730 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 731 |
|
myquery << ",TRK_CALIB_USED"; |
| 732 |
|
myquery << ",CAL_DSP_MASK"; |
| 733 |
|
myquery << ",LAST_TIMESYNC"; |
| 734 |
|
myquery << ",OBT_TIMESYNC"; |
| 735 |
|
myquery << ",VALIDATION"; |
| 736 |
|
myquery << ",INSERT_TIME"; |
| 737 |
|
myquery << ") SELECT "; |
| 738 |
|
myquery << "ID"; |
| 739 |
|
myquery << ",ID_RUN_FRAG"; |
| 740 |
|
myquery << ",ID_ROOT_L0"; |
| 741 |
|
myquery << ",ID_ROOT_L2"; |
| 742 |
|
myquery << ",RUNHEADER_TIME"; |
| 743 |
|
myquery << ",RUNTRAILER_TIME"; |
| 744 |
|
myquery << ",RUNHEADER_OBT"; |
| 745 |
|
myquery << ",RUNTRAILER_OBT"; |
| 746 |
|
myquery << ",RUNHEADER_PKT"; |
| 747 |
|
myquery << ",RUNTRAILER_PKT"; |
| 748 |
|
myquery << ",BOOT_NUMBER"; |
| 749 |
|
myquery << ",EV_FROM"; |
| 750 |
|
myquery << ",EV_TO"; |
| 751 |
|
myquery << ",NEVENTS"; |
| 752 |
|
myquery << ",PKT_COUNTER"; |
| 753 |
|
myquery << ",PKT_READY_COUNTER"; |
| 754 |
|
myquery << ",COMPILATIONTIMESTAMP"; |
| 755 |
|
myquery << ",FAV_WRK_SCHEDULE"; |
| 756 |
|
myquery << ",EFF_WRK_SCHEDULE"; |
| 757 |
|
myquery << ",PRH_VAR_TRG_MODE_A"; |
| 758 |
|
myquery << ",PRH_VAR_TRG_MODE_B"; |
| 759 |
|
myquery << ",ACQ_BUILD_INFO"; |
| 760 |
|
myquery << ",ACQ_VAR_INFO"; |
| 761 |
|
myquery << ",RM_ACQ_AFTER_CALIB"; |
| 762 |
|
myquery << ",RM_ACQ_SETTING_MODE"; |
| 763 |
|
myquery << ",TRK_CALIB_USED"; |
| 764 |
|
myquery << ",CAL_DSP_MASK"; |
| 765 |
|
myquery << ",LAST_TIMESYNC"; |
| 766 |
|
myquery << ",OBT_TIMESYNC"; |
| 767 |
|
myquery << ",VALIDATION"; |
| 768 |
|
myquery << ",INSERT_TIME"; |
| 769 |
|
myquery << " FROM GL_RUN_TRASH "; |
| 770 |
|
myquery << " WHERE BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
| 771 |
|
myquery << (UInt_t)IDRUN << ";"; |
| 772 |
|
// |
| 773 |
|
// printf("5myquery is %s \n",myquery.str().c_str()); |
| 774 |
|
// |
| 775 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 776 |
|
this->GetGLTABLES()->AddQ(); |
| 777 |
|
dbc->Query(myquery.str().c_str()); |
| 778 |
|
// |
| 779 |
|
// |
| 780 |
|
myquery.str(""); |
| 781 |
|
myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID="; |
| 782 |
|
myquery << IDRUN << ";"; |
| 783 |
|
// |
| 784 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 785 |
|
this->GetGLTABLES()->AddQ(); |
| 786 |
|
dbc->Query(myquery.str().c_str()); |
| 787 |
|
// |
| 788 |
|
return 0; |
| 789 |
|
}; |
| 790 |
|
|
| 791 |
/** |
/** |
| 792 |
* Function to fill the GL_RUN table of the DB. |
* Function to fill the GL_RUN table of the DB. |
| 865 |
// |
// |
| 866 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
| 867 |
// |
// |
| 868 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 869 |
|
this->GetGLTABLES()->AddQ(); |
| 870 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
| 871 |
// |
// |
| 872 |
return 0; |
return 0; |
| 943 |
// |
// |
| 944 |
// printf("myquery is %s \n",myquery.str().c_str()); |
// printf("myquery is %s \n",myquery.str().c_str()); |
| 945 |
// |
// |
| 946 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 947 |
|
this->GetGLTABLES()->AddQ(); |
| 948 |
dbc->Query(myquery.str().c_str()); |
dbc->Query(myquery.str().c_str()); |
| 949 |
// |
// |
| 950 |
return 0; |
return 0; |
| 1002 |
myquery << " from GL_RUN where ID=" << run << ";"; |
myquery << " from GL_RUN where ID=" << run << ";"; |
| 1003 |
// |
// |
| 1004 |
// printf(" myquery is %s \n",myquery.str().c_str()); |
// printf(" myquery is %s \n",myquery.str().c_str()); |
| 1005 |
|
if ( !this->IsConnected(dbc) ) return -57; |
| 1006 |
|
this->AddQ(); |
| 1007 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1008 |
// |
// |
| 1009 |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
// printf(" getrowcount %i \n",pResult->GetRowCount()); |
| 1015 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1016 |
// Set_GL_RUN(Row); |
// Set_GL_RUN(Row); |
| 1017 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1018 |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 1019 |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); |
| 1020 |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 1021 |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
if (t== 3) ID_ROOT_L2 = (UInt_t)atoll(Row->GetField(t)); |
| 1022 |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 4) RUNHEADER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1023 |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t== 5) RUNTRAILER_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1024 |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 6) RUNHEADER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 1025 |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 7) RUNTRAILER_OBT = (UInt_t)atoll(Row->GetField(t)); |
| 1026 |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 8) RUNHEADER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 1027 |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
if (t== 9) RUNTRAILER_PKT = (UInt_t)atoll(Row->GetField(t)); |
| 1028 |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
if (t==10) EV_FROM = (UInt_t)atoll(Row->GetField(t)); |
| 1029 |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
if (t==11) EV_TO = (UInt_t)atoll(Row->GetField(t)); |
| 1030 |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
if (t==12) NEVENTS = (UInt_t)atoll(Row->GetField(t)); |
| 1031 |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==13) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 1032 |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if (t==14) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 1033 |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
if (t==15) COMPILATIONTIMESTAMP = (UInt_t)atoll(Row->GetField(t)); |
| 1034 |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==16) FAV_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 1035 |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
if (t==17) EFF_WRK_SCHEDULE = (UInt_t)atoll(Row->GetField(t)); |
| 1036 |
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)); |
| 1037 |
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)); |
| 1038 |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==20) ACQ_BUILD_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 1039 |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
if (t==21) ACQ_VAR_INFO = (UInt_t)atoll(Row->GetField(t)); |
| 1040 |
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)); |
| 1041 |
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)); |
| 1042 |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==24) PKT_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 1043 |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
if (t==25) PKT_READY_COUNTER = (UInt_t)atoll(Row->GetField(t)); |
| 1044 |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); |
| 1045 |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); |
| 1046 |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); |
| 1047 |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); |
| 1048 |
}; |
}; |
| 1049 |
}; |
}; |
| 1050 |
// delete pResult; |
// delete pResult; |
| 1102 |
// |
// |
| 1103 |
// printf(" query is %s \n",myquery.str().c_str()); |
// printf(" query is %s \n",myquery.str().c_str()); |
| 1104 |
// |
// |
| 1105 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1106 |
|
this->GetGLTABLES()->AddQ(); |
| 1107 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1108 |
if(!pResult->GetRowCount())return(-50); |
if(!pResult->GetRowCount())return(-50); |
| 1109 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1169 |
myquery << ",NAME"; |
myquery << ",NAME"; |
| 1170 |
myquery << " from GL_ROOT where ID=" << id << ";"; |
myquery << " from GL_ROOT where ID=" << id << ";"; |
| 1171 |
// |
// |
| 1172 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1173 |
|
this->GetGLTABLES()->AddQ(); |
| 1174 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1175 |
if(!pResult->GetRowCount())return (-51); |
if(!pResult->GetRowCount())return (-51); |
| 1176 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1180 |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if(t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 1181 |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t)); |
| 1182 |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); |
| 1183 |
if(t==3) PATH = Row->GetField(t); |
if(t==3) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/'; |
| 1184 |
if(t==4) NAME = Row->GetField(t); |
if(t==4) NAME = Row->GetField(t); |
| 1185 |
}; |
}; |
| 1186 |
}; |
}; |
| 1205 |
// ---------------- |
// ---------------- |
| 1206 |
myquery.str(""); |
myquery.str(""); |
| 1207 |
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; |
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; |
| 1208 |
myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " AND VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; // RIVEDERE LA VALIDAZIONE!!! |
| 1209 |
|
myquery << " and EV_ROOT_CALIBTRK1>=0 and EV_ROOT_CALIBTRK2>=0 "; // EM! SE MANCA UN PACCHETTO DEI DUE IL PROCESSAMENTO CRASHA... DA RIVEDERE LA VALIDAZIONE |
| 1210 |
|
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1211 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1212 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1213 |
|
this->GetGLTABLES()->AddQ(); |
| 1214 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1215 |
if(!pResult->GetRowCount())return (-53); |
if(!pResult->GetRowCount())return (-53); |
| 1216 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1268 |
myquery << " ;"; |
myquery << " ;"; |
| 1269 |
//myquery << " and VALIDATION=1;"; |
//myquery << " and VALIDATION=1;"; |
| 1270 |
// |
// |
| 1271 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1272 |
|
this->GetGLTABLES()->AddQ(); |
| 1273 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1274 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
| 1275 |
// |
// |
| 1289 |
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; |
| 1290 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
| 1291 |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1292 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1293 |
|
this->GetGLTABLES()->AddQ(); |
| 1294 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1295 |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
// printf(" mysquery is %s\n",myquery.str().c_str()); |
| 1296 |
// |
// |
| 1314 |
pResult->Delete(); |
pResult->Delete(); |
| 1315 |
return 0; |
return 0; |
| 1316 |
}; |
}; |
| 1317 |
|
|
| 1318 |
|
|
| 1319 |
|
// **************************************************** |
| 1320 |
|
/** |
| 1321 |
|
* Function to query the GL_CALOPULSE_CALIB table of the DB. |
| 1322 |
|
* |
| 1323 |
|
* \param run starting time |
| 1324 |
|
* \return struct of type GL_CALOPULSE_CALIB_data, which stores the query result |
| 1325 |
|
*/ |
| 1326 |
|
Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){ |
| 1327 |
|
// MySQL variables |
| 1328 |
|
TSQLResult *pResult; |
| 1329 |
|
TSQLRow *Row; |
| 1330 |
|
int t; |
| 1331 |
|
stringstream myquery; |
| 1332 |
|
// |
| 1333 |
|
// select the correct calibration i.e. the closest to our time |
| 1334 |
|
// |
| 1335 |
|
myquery.str(""); |
| 1336 |
|
myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALOPULSE_CALIB where SECTION=" << section; |
| 1337 |
|
myquery << " and PULSE_AMPLITUDE=" << pampli; |
| 1338 |
|
myquery << " and VALIDATION=1 and (PULSED_STRIP IS NULL OR PULSED_STRIP<100) ORDER BY ABS(" << time << "-FROM_TIME) asc limit 1;"; |
| 1339 |
|
// printf(" myq is %s \n",myquery.str().c_str()); |
| 1340 |
|
// |
| 1341 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1342 |
|
this->GetGLTABLES()->AddQ(); |
| 1343 |
|
pResult = dbc->Query(myquery.str().c_str()); |
| 1344 |
|
// |
| 1345 |
|
if( !pResult ) return(-54); |
| 1346 |
|
// |
| 1347 |
|
Row = pResult->Next(); |
| 1348 |
|
// |
| 1349 |
|
if( !Row ) return (-54); |
| 1350 |
|
// |
| 1351 |
|
// store infos and exit |
| 1352 |
|
// |
| 1353 |
|
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1354 |
|
// printf(" field %i is %s \n",t,Row->GetField(t)); |
| 1355 |
|
if (t==0) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 1356 |
|
if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1357 |
|
if (t==2) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1358 |
|
if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
| 1359 |
|
}; |
| 1360 |
|
pResult->Delete(); |
| 1361 |
|
return 0; |
| 1362 |
|
}; |
| 1363 |
|
|
| 1364 |
|
|
| 1365 |
// **************************************************** |
// **************************************************** |
| 1366 |
/** |
/** |
| 1367 |
* Function to query the GL_S4_CALIB table of the DB. |
* Function to query the GL_S4_CALIB table of the DB. |
| 1378 |
stringstream myquery; |
stringstream myquery; |
| 1379 |
// ---------------- |
// ---------------- |
| 1380 |
myquery.str(""); |
myquery.str(""); |
| 1381 |
myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time; |
myquery << "select ID,ID_ROOT_L0,EV_ROOT,FROM_TIME,TO_TIME from GL_S4_CALIB where FROM_TIME <= "<< time; |
| 1382 |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1383 |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
// myquery << " ORDER BY FROM_TIME DESC LIMIT 1;"; |
| 1384 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1385 |
|
this->GetGLTABLES()->AddQ(); |
| 1386 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1387 |
if(!pResult->GetRowCount())return (-55);//throw -55; |
if(!pResult->GetRowCount())return (-55);//throw -55; |
| 1388 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1390 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1391 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1392 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 1393 |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
if (t==1) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); |
| 1394 |
if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
if (t==2) EV_ROOT = (UInt_t)atoll(Row->GetField(t)); |
| 1395 |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1396 |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) TO_TIME = (UInt_t)atoll(Row->GetField(t)); |
|
if (t==5) PARAM_FIT0 = atof(Row->GetField(t)); |
|
|
if (t==6) PARAM_FIT1 = atof(Row->GetField(t)); |
|
| 1397 |
}; |
}; |
| 1398 |
}; |
}; |
| 1399 |
delete pResult; |
delete pResult; |
| 1421 |
// ---------------- |
// ---------------- |
| 1422 |
myquery.str(""); |
myquery.str(""); |
| 1423 |
myquery << " select "; |
myquery << " select "; |
| 1424 |
myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME "; |
myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE "; |
| 1425 |
myquery << " from GL_PARAM "; |
myquery << " from GL_PARAM "; |
| 1426 |
myquery << " where TYPE = '"<<type<<"' "; |
myquery << " where TYPE = '"<<type<<"' "; |
| 1427 |
myquery << " and FROM_TIME <= " << time; |
myquery << " and FROM_TIME <= " << time; |
| 1428 |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
myquery << " ORDER BY TO_TIME DESC LIMIT 1;"; |
| 1429 |
// |
// |
| 1430 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1431 |
|
this->GetGLTABLES()->AddQ(); |
| 1432 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1433 |
if(!pResult->GetRowCount())return (-52); |
if(!pResult->GetRowCount())return (-52); |
| 1434 |
for( r=0; r < 1000; r++){ |
for( r=0; r < 1000; r++){ |
| 1436 |
if( Row == NULL ) break; |
if( Row == NULL ) break; |
| 1437 |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
for( t = 0; t < pResult->GetFieldCount(); t++){ |
| 1438 |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
if (t==0) ID = (UInt_t)atoll(Row->GetField(t)); |
| 1439 |
if (t==1) PATH = Row->GetField(t);// put in fpath the path to that file |
if (t==1) PATH = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';// put in fpath the path to that file |
| 1440 |
if (t==2) NAME = Row->GetField(t); |
if (t==2) NAME = Row->GetField(t); |
| 1441 |
if (t==3) DESCR = Row->GetField(t); |
if (t==3) DESCR = Row->GetField(t); |
| 1442 |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t)); |
| 1481 |
TSQLResult *pResult; |
TSQLResult *pResult; |
| 1482 |
TSQLRow *Row; |
TSQLRow *Row; |
| 1483 |
stringstream myquery; |
stringstream myquery; |
| 1484 |
|
stringstream rname; |
| 1485 |
|
// pcksList packetsNames; |
| 1486 |
|
// pcksList::iterator Iter; |
| 1487 |
|
// getPacketsNames(packetsNames); |
| 1488 |
|
rname.str(""); |
| 1489 |
// ---------------- |
// ---------------- |
| 1490 |
myquery.str(""); |
myquery.str(""); |
| 1491 |
myquery << "select "; |
myquery << "select "; |
| 1495 |
myquery << type.Data(); |
myquery << type.Data(); |
| 1496 |
myquery << "=" << id << ";"; |
myquery << "=" << id << ";"; |
| 1497 |
// |
// |
| 1498 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1499 |
|
this->GetGLTABLES()->AddQ(); |
| 1500 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1501 |
if( pResult->GetRowCount() ){ |
if( pResult->GetRowCount() ){ |
| 1502 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1503 |
if( Row ){ |
if( Row ){ |
| 1504 |
stringstream fname; |
stringstream fname; |
| 1505 |
fname.str(""); |
fname.str(""); |
| 1506 |
fname << Row->GetField(0) << "/" << Row->GetField(1); |
fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); |
| 1507 |
|
rname << Row->GetField(1); |
| 1508 |
file = new TFile(fname.str().c_str(),"READ"); |
file = new TFile(fname.str().c_str(),"READ"); |
| 1509 |
idraw = (UInt_t)atoll(Row->GetField(2)); |
idraw = (UInt_t)atoll(Row->GetField(2)); |
| 1510 |
}; |
}; |
| 1520 |
ph = eh->GetPscuHeader(); |
ph = eh->GetPscuHeader(); |
| 1521 |
pktfirst = ph->GetCounter(); |
pktfirst = ph->GetCounter(); |
| 1522 |
obtfirst = ph->GetOrbitalTime(); |
obtfirst = ph->GetOrbitalTime(); |
| 1523 |
|
// |
| 1524 |
|
// code = eh->GetCounter(); |
| 1525 |
|
// UInt_t en = 0; |
| 1526 |
|
// for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){ |
| 1527 |
|
// en = code->Get(GetPacketType(*Iter)); |
| 1528 |
|
// if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){ |
| 1529 |
|
// // |
| 1530 |
|
// TTree *TC = 0; |
| 1531 |
|
// TC = (TTree*)file->Get("CalibCalPed"); |
| 1532 |
|
// if ( !TC || TC->IsZombie() ) return; |
| 1533 |
|
// EventHeader *ehc = 0; |
| 1534 |
|
// PscuHeader *phc = 0; |
| 1535 |
|
// TC->SetBranchAddress("Header", &ehc); |
| 1536 |
|
// TC->GetEntry(0); |
| 1537 |
|
// phc = ehc->GetPscuHeader(); |
| 1538 |
|
// pktfirst = phc->GetCounter(); |
| 1539 |
|
// obtfirst = phc->GetOrbitalTime(); |
| 1540 |
|
// // |
| 1541 |
|
// }; |
| 1542 |
|
// }; |
| 1543 |
|
// |
| 1544 |
}; |
}; |
| 1545 |
// |
// |
| 1546 |
// look for Resurs offset |
// look for Resurs offset |
| 1547 |
// |
// |
| 1548 |
UInt_t t0 = 0; |
T0 = 0; |
| 1549 |
// |
// |
| 1550 |
myquery.str(""); |
// |
| 1551 |
myquery << "SELECT OFFSET_DATE FROM GL_RESURS_OFFSET WHERE FROM_ID_RAW<= " |
stringstream oss; |
| 1552 |
<< idraw << " AND TO_ID_RAW >= " |
TString frn = rname.str().c_str(); |
| 1553 |
<< idraw << ";"; |
frn = frn.ReplaceAll(".root",5,".pam",4); |
| 1554 |
pResult = dbc->Query(myquery.str().c_str()); |
oss.str(""); |
| 1555 |
if ( pResult ){ |
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='" |
| 1556 |
Row = pResult->Next(); |
<< frn.Data() << "';"; |
| 1557 |
if ( Row ){ |
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1558 |
|
this->GetGLTABLES()->AddQ(); |
| 1559 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1560 |
|
Row = pResult->Next(); |
| 1561 |
|
// |
| 1562 |
|
TString name=rname.str().c_str(); |
| 1563 |
|
UInt_t dworbit = 0; |
| 1564 |
|
Int_t nlength = name.Length(); |
| 1565 |
|
// |
| 1566 |
|
// Is not a special file |
| 1567 |
|
// |
| 1568 |
|
if ( !Row ){ |
| 1569 |
|
delete pResult; |
| 1570 |
|
// |
| 1571 |
|
// New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset |
| 1572 |
|
// |
| 1573 |
|
oss.str(""); |
| 1574 |
|
oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; |
| 1575 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1576 |
|
this->GetGLTABLES()->AddQ(); |
| 1577 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1578 |
|
Bool_t fndit = false; |
| 1579 |
|
if ( pResult ){ |
| 1580 |
|
Row = pResult->Next(); |
| 1581 |
|
if ( Row ){ |
| 1582 |
|
oss.str(""); |
| 1583 |
|
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 ID=" |
| 1584 |
|
<< Row->GetField(0) << ";"; |
| 1585 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1586 |
|
this->GetGLTABLES()->AddQ(); |
| 1587 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1588 |
|
if ( pResult ){ |
| 1589 |
|
Row = pResult->Next(); |
| 1590 |
|
if ( Row ){ |
| 1591 |
|
// printf(" GREAT! the DB structure is the new one! \n"); |
| 1592 |
|
fndit = true; |
| 1593 |
|
dworbit = 1; |
| 1594 |
|
}; |
| 1595 |
|
}; |
| 1596 |
|
}; |
| 1597 |
|
}; |
| 1598 |
|
if ( !fndit ){ |
| 1599 |
|
delete pResult; |
| 1600 |
|
// |
| 1601 |
|
printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n"); |
| 1602 |
// |
// |
| 1603 |
t0 = (UInt_t)TDatime(Row->GetField(0)).Convert(); |
// Old code, we must trust the filename |
| 1604 |
|
// |
| 1605 |
|
if ( nlength < 5 ) return; |
| 1606 |
|
TString dwo = 0; |
| 1607 |
|
for (Int_t i = 0; i<5; i++){ |
| 1608 |
|
dwo.Append(name[i],1); |
| 1609 |
|
}; |
| 1610 |
|
if ( dwo.IsDigit() ){ |
| 1611 |
|
dworbit = (UInt_t)dwo.Atoi(); |
| 1612 |
|
} else { |
| 1613 |
|
dwo=""; |
| 1614 |
|
for (Int_t i = 8; i<13; i++){ |
| 1615 |
|
dwo.Append(name[i],1); |
| 1616 |
|
}; |
| 1617 |
|
if ( dwo.IsDigit() ){ |
| 1618 |
|
dworbit = (UInt_t)dwo.Atoi(); |
| 1619 |
|
} else { |
| 1620 |
|
dworbit = 1; |
| 1621 |
|
}; |
| 1622 |
|
}; |
| 1623 |
// |
// |
| 1624 |
|
oss.str(""); |
| 1625 |
|
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< " |
| 1626 |
|
<< dworbit << " order by FROM_ORBIT desc limit 1;"; |
| 1627 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1628 |
|
this->GetGLTABLES()->AddQ(); |
| 1629 |
|
pResult = dbc->Query(oss.str().c_str()); |
| 1630 |
|
Row = pResult->Next(); |
| 1631 |
|
if ( !Row ){ |
| 1632 |
|
printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); |
| 1633 |
|
return; |
| 1634 |
|
}; |
| 1635 |
}; |
}; |
| 1636 |
}; |
}; |
| 1637 |
// |
// |
| 1638 |
|
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); |
| 1639 |
|
T0 = (UInt_t)tu.GetSec(); |
| 1640 |
// |
// |
| 1641 |
// look for the correct timesync entry |
// look for the correct timesync entry |
| 1642 |
// |
// |
| 1643 |
myquery.str(""); |
myquery.str(""); |
| 1644 |
myquery << " SELECT OBT0,TIMESYNC FROM GL_TIMESYNC " |
myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " |
| 1645 |
<< " WHERE ID_RAW = " << idraw |
<< " WHERE ID_RAW = " << idraw |
| 1646 |
<< ";"; |
<< ";"; |
| 1647 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; |
| 1648 |
|
this->GetGLTABLES()->AddQ(); |
| 1649 |
pResult = dbc->Query(myquery.str().c_str()); |
pResult = dbc->Query(myquery.str().c_str()); |
| 1650 |
if ( pResult ){ |
if ( pResult ){ |
| 1651 |
Row = pResult->Next(); |
Row = pResult->Next(); |
| 1652 |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ |
| 1653 |
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)); |
| 1654 |
|
TIMESYNC = (UInt_t)atoll(Row->GetField(1)); |
| 1655 |
|
TYPE = (UInt_t)atoll(Row->GetField(2)); |
| 1656 |
|
toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0; |
| 1657 |
}; |
}; |
| 1658 |
}; |
}; |
| 1659 |
// |
// |
| 1672 |
// |
// |
| 1673 |
}; |
}; |
| 1674 |
|
|
| 1675 |
|
/** |
| 1676 |
|
* |
| 1677 |
|
* Returns the Resurs time given the OBT needed to process inclination and orbital infos |
| 1678 |
|
* |
| 1679 |
|
*/ |
| 1680 |
|
UInt_t GL_TIMESYNC::ResursTime(UInt_t OBT){ |
| 1681 |
|
// |
| 1682 |
|
return(((UInt_t)((Int_t)(this->DBobt(OBT)-this->DBobt(OBT0))/1000)+TIMESYNC)); |
| 1683 |
|
// |
| 1684 |
|
}; |
| 1685 |
|
|
| 1686 |
ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
|
| 1687 |
|
/** |
| 1688 |
|
* Return the correct packet number if we went back to zero |
| 1689 |
|
*/ |
| 1690 |
|
Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
| 1691 |
// |
// |
| 1692 |
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) ){ |
| 1693 |
|
return((Long64_t)pkt_num+16777215LL); |
| 1694 |
|
}; |
| 1695 |
// |
// |
| 1696 |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
| 1697 |
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())); |
|
|
}; |
|
| 1698 |
}; |
}; |
| 1699 |
// |
// |
| 1700 |
return((ULong64_t)obt); |
return((Long64_t)pkt_num); |
| 1701 |
// |
// |
| 1702 |
}; |
}; |
| 1703 |
|
|
| 1704 |
UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
/** |
| 1705 |
|
* Return the correct On Board Time if we went back to zero |
| 1706 |
|
*/ |
| 1707 |
|
Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
| 1708 |
// |
// |
| 1709 |
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())); |
| 1710 |
// |
// |
| 1711 |
if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
| 1712 |
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)); |
|
|
}; |
|
| 1713 |
}; |
}; |
| 1714 |
// |
// |
| 1715 |
return(pkt_num); |
return((Long64_t)obt); |
|
// |
|
| 1716 |
}; |
}; |
| 1717 |
|
|
| 1718 |
|
|
| 1719 |
|
|
| 1720 |
|
// ULong64_t GL_TIMESYNC::DBobt(UInt_t obt){ |
| 1721 |
|
// // |
| 1722 |
|
// if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ) return((ULong64_t)(obt+numeric_limits<UInt_t>::max())); |
| 1723 |
|
// // |
| 1724 |
|
// if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){ |
| 1725 |
|
// if ( (obt-numeric_limits<UInt_t>::max()) < 0 ){ |
| 1726 |
|
// return((ULong64_t)(numeric_limits<UInt_t>::max()-obt)); |
| 1727 |
|
// } else { |
| 1728 |
|
// return((ULong64_t)(obt-numeric_limits<UInt_t>::max())); |
| 1729 |
|
// }; |
| 1730 |
|
// }; |
| 1731 |
|
// // |
| 1732 |
|
// return((ULong64_t)obt); |
| 1733 |
|
// // |
| 1734 |
|
// }; |
| 1735 |
|
|
| 1736 |
|
// UInt_t GL_TIMESYNC::DBpkt(UInt_t pkt_num){ |
| 1737 |
|
// // |
| 1738 |
|
// if ( pkt_num < (pktfirst/2) && pktfirst > (16777214/2) ) return((pkt_num+16777215)); |
| 1739 |
|
// // |
| 1740 |
|
// if ( pkt_num > pktfirst*2 && pkt_num > (16777214/2) ){ |
| 1741 |
|
// if ( (pkt_num-16777215) < 0 ){ |
| 1742 |
|
// return((16777215-pkt_num)); |
| 1743 |
|
// } else { |
| 1744 |
|
// return((pkt_num-16777215)); |
| 1745 |
|
// }; |
| 1746 |
|
// }; |
| 1747 |
|
// // |
| 1748 |
|
// return(pkt_num); |
| 1749 |
|
// // |
| 1750 |
|
// }; |
| 1751 |
|
|
| 1752 |
/* |
/* |
| 1753 |
* |
* |
| 1754 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time in the DB from UInt_t to a string |
| 1759 |
*/ |
*/ |
| 1760 |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
TString GL_TIMESYNC::ConvertTime(TString &tzone, UInt_t dbt){ |
| 1761 |
// |
// |
| 1762 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
| 1763 |
TString rtime; |
TString rtime; |
| 1764 |
Bool_t found = false; |
Bool_t found = false; |
| 1765 |
// |
// |
| 1766 |
time->Set(dbt,false); // MSK = Moscow Winter Time |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
|
// |
|
|
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
|
| 1767 |
// |
// |
| 1768 |
UInt_t timeUTC = time->Convert() - 60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3 hs |
offset = 60*60*3; // UTC (Coordinated Universal Time) + 3hs = Moscow Winter Time |
|
time->Set(timeUTC,false); |
|
| 1769 |
found = true; |
found = true; |
| 1770 |
// |
// |
| 1771 |
}; |
}; |
| 1772 |
// |
// |
| 1773 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
| 1774 |
// |
// |
| 1775 |
UInt_t timeCET = time->Convert() - 60*60*2; // CET (Central European Time) = Moscow Winter Time - 2 hs |
offset = 60*60*1; // CET (Central European Time) = UTC + 1 hs |
|
time->Set(timeCET,false); |
|
| 1776 |
found = true; |
found = true; |
| 1777 |
// |
// |
| 1778 |
}; |
}; |
| 1779 |
// |
// |
| 1780 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
| 1781 |
// |
// |
| 1782 |
UInt_t timeCEST = time->Convert() - 60*60*1; // CEST (Central European Summer Time) = Moscow Winter Time - 1 h |
offset = 60*60*2; // CEST (Central European Summer Time) = UTC + 2 h |
|
time->Set(timeCEST,false); |
|
| 1783 |
found = true; |
found = true; |
| 1784 |
// |
// |
| 1785 |
}; |
}; |
| 1786 |
// |
// |
| 1787 |
if ( !strcmp(tzone.Data(),"MSD") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST")){ |
| 1788 |
// |
// |
| 1789 |
UInt_t timeMSD = time->Convert() + 60*60*1; // MSD (Moscow Summer Time) = Moscow Winter Time + 1 h |
offset = 60*60*4; // MSD (Moscow Summer Time) = UTC + 4 h |
|
time->Set(timeMSD,false); |
|
| 1790 |
found = true; |
found = true; |
| 1791 |
// |
// |
| 1792 |
}; |
}; |
| 1793 |
// |
// |
| 1794 |
if ( !found && strcmp(tzone.Data(),"MSK") && strcmp(tzone.Data(),"") ){ |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
| 1795 |
printf("\n Unknown time zone %s using MSK \n",tzone.Data()); |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
| 1796 |
tzone = "MSK"; |
tzone = "UTC"; |
| 1797 |
}; |
}; |
| 1798 |
// |
// |
| 1799 |
rtime = time->AsSQLString(); |
dbt += offset; |
| 1800 |
|
// |
| 1801 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
| 1802 |
|
// |
| 1803 |
|
rtime = time->AsString("s"); |
| 1804 |
|
// |
| 1805 |
|
delete time; |
| 1806 |
// |
// |
| 1807 |
return(rtime); |
return(rtime); |
| 1808 |
} |
} |
| 1809 |
|
|
| 1810 |
/* |
/* |
| 1811 |
* |
* |
| 1812 |
* Convert the time in the DB from UInt_t to a string |
* Convert the time from TZONE to UTC |
| 1813 |
* |
* |
| 1814 |
* @param dbt time in the DB |
* @param dbt time in the DB |
| 1815 |
* @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 |
| 1817 |
*/ |
*/ |
| 1818 |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
TString GL_TIMESYNC::UnConvertTime(TString &tzone, UInt_t dbt){ |
| 1819 |
// |
// |
| 1820 |
TDatime *time = new TDatime(); |
Int_t offset = 0; |
| 1821 |
TString rtime; |
TString rtime; |
| 1822 |
// |
// |
| 1823 |
Bool_t found = false; |
Bool_t found = false; |
| 1824 |
// |
// |
| 1825 |
time->Set(dbt,false); // MSK = Moscow Winter Time |
if ( !strcmp(tzone.Data(),"MSK") || !strcmp(tzone.Data(),"MWT") ){ |
|
// |
|
|
if ( !strcmp(tzone.Data(),"UTC") || !strcmp(tzone.Data(),"GMT") ){ |
|
| 1826 |
// |
// |
| 1827 |
UInt_t timeUTC = time->Convert() + 60*60*3; // UTC (Coordinated Universal Time) +3 hs = Moscow Winter Time |
offset = -60*60*3; // UTC (Coordinated Universal Time) = Moscow Winter Time - 3hs |
|
time->Set(timeUTC,false); |
|
| 1828 |
found = true; |
found = true; |
| 1829 |
// |
// |
| 1830 |
}; |
}; |
| 1831 |
// |
// |
| 1832 |
if ( !strcmp(tzone.Data(),"CET") ){ |
if ( !strcmp(tzone.Data(),"CET") ){ |
| 1833 |
// |
// |
| 1834 |
UInt_t timeCET = time->Convert() + 60*60*2; // CET (Central European Time) + 2 hs = Moscow Winter Time |
offset = -60*60*1; // CET (Central European Time) - 1 hs = UTC |
|
time->Set(timeCET,false); |
|
| 1835 |
found = true; |
found = true; |
| 1836 |
// |
// |
| 1837 |
}; |
}; |
| 1838 |
// |
// |
| 1839 |
if ( !strcmp(tzone.Data(),"CEST") ){ |
if ( !strcmp(tzone.Data(),"CEST") ){ |
| 1840 |
// |
// |
| 1841 |
UInt_t timeCEST = time->Convert() + 60*60*1; // CEST (Central European Summer Time) + 1 h = Moscow Winter Time |
offset = -60*60*2; // CEST (Central European Summer Time) - 2 h = UTC |
|
time->Set(timeCEST,false); |
|
| 1842 |
found = true; |
found = true; |
| 1843 |
// |
// |
| 1844 |
}; |
}; |
| 1845 |
// |
// |
| 1846 |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
if ( !strcmp(tzone.Data(),"MSD") || !strcmp(tzone.Data(),"MST") ){ |
| 1847 |
// |
// |
| 1848 |
UInt_t timeMSD = time->Convert() - 60*60*1; // MSD (Moscow Summer Time) - 1 h = Moscow Winter Time |
offset = -60*60*4; // MSD (Moscow Summer Time) - 4 h = UTC |
|
time->Set(timeMSD,false); |
|
| 1849 |
found = true; |
found = true; |
| 1850 |
// |
// |
| 1851 |
}; |
}; |
| 1852 |
// |
// |
| 1853 |
if ( !found && strcmp(tzone.Data(),"MSK") && strcmp(tzone.Data(),"") ){ |
if ( !found && strcmp(tzone.Data(),"UTC") && strcmp(tzone.Data(),"GMT") && strcmp(tzone.Data(),"") ){ |
| 1854 |
// |
// |
| 1855 |
printf("\n Unknown time zone %s using MSK \n",tzone.Data()); |
offset = 0; |
| 1856 |
tzone = "MSK"; |
printf("\n Unknown time zone %s using UTC \n",tzone.Data()); |
| 1857 |
|
tzone = "UTC"; |
| 1858 |
}; |
}; |
| 1859 |
// |
// |
| 1860 |
rtime = time->AsSQLString(); |
dbt += offset; |
| 1861 |
|
TTimeStamp *time = new TTimeStamp((time_t)dbt,0); |
| 1862 |
|
// |
| 1863 |
|
rtime = time->AsString("s"); |
| 1864 |
// |
// |
| 1865 |
return(rtime); |
return(rtime); |
| 1866 |
} |
} |
| 1867 |
|
|
| 1868 |
|
|
| 1869 |
|
// |
| 1870 |
|
// Build a query and call DoQuery. |
| 1871 |
|
// |
| 1872 |
|
// date it's an SQL datetime date and dbc is the connection to be |
| 1873 |
|
// used. It will query for the tle with the nearest but previous date |
| 1874 |
|
// and the immediatly next one. |
| 1875 |
|
// |
| 1876 |
|
Int_t GL_TLE::Query(TString date, TSQLServer *dbc){ |
| 1877 |
|
stringstream myquery; |
| 1878 |
|
myquery.str(""); |
| 1879 |
|
|
| 1880 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1881 |
|
<< "WHERE FROM_TIME <= '" << date.Data() |
| 1882 |
|
<< "' ORDER BY FROM_TIME DESC LIMIT 1) " |
| 1883 |
|
<< "UNION " |
| 1884 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1885 |
|
<< "WHERE FROM_TIME > '" << date.Data() |
| 1886 |
|
<< "' ORDER BY FROM_TIME ASC LIMIT 1)"; |
| 1887 |
|
|
| 1888 |
|
return DoQuery(myquery.str().c_str(), dbc); |
| 1889 |
|
} |
| 1890 |
|
|
| 1891 |
|
|
| 1892 |
|
// |
| 1893 |
|
// Build a query and call DoQuery. |
| 1894 |
|
// |
| 1895 |
|
// time is the UTC date in unix time (UTC) and dbc is the connection |
| 1896 |
|
// to be used. It will query for the tle with the nearest but |
| 1897 |
|
// previous date and the immediatly next one. |
| 1898 |
|
// |
| 1899 |
|
// Returns the value returned by DoQuery(). |
| 1900 |
|
// |
| 1901 |
|
Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){ |
| 1902 |
|
stringstream myquery; |
| 1903 |
|
myquery.str(""); |
| 1904 |
|
|
| 1905 |
|
myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1906 |
|
<< "WHERE FROM_TIME <= FROM_UNIXTIME('" << time |
| 1907 |
|
<< "') ORDER BY FROM_TIME DESC LIMIT 1) " |
| 1908 |
|
<< "UNION " |
| 1909 |
|
<< "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE " |
| 1910 |
|
<< "WHERE FROM_TIME > FROM_UNIXTIME('" << time |
| 1911 |
|
<< "') ORDER BY FROM_TIME ASC LIMIT 1)"; |
| 1912 |
|
|
| 1913 |
|
return DoQuery(myquery.str().c_str(), dbc); |
| 1914 |
|
} |
| 1915 |
|
|
| 1916 |
|
|
| 1917 |
|
// |
| 1918 |
|
// Do the query myquery on the connectio dbc. Initialize tle, |
| 1919 |
|
// tleFromTime and tleToTime. |
| 1920 |
|
// |
| 1921 |
|
// We should have two rows (unless the table is old). From the last |
| 1922 |
|
// one we only take tleToTime. |
| 1923 |
|
// |
| 1924 |
|
// Returns 0 for success, 1 for failure. |
| 1925 |
|
// |
| 1926 |
|
Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){ |
| 1927 |
|
TSQLResult *result; |
| 1928 |
|
TSQLRow *row; |
| 1929 |
|
|
| 1930 |
|
// Set the right time_zone (otherwise horrible things will occur! :) |
| 1931 |
|
if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; |
| 1932 |
|
dbc->Query("SET time_zone = '+0:00'"); |
| 1933 |
|
|
| 1934 |
|
// Do the query |
| 1935 |
|
this->GetGLTABLES()->AddQ(); |
| 1936 |
|
result = dbc->Query(myquery.Data()); |
| 1937 |
|
if(! result->GetRowCount() ) { |
| 1938 |
|
cerr << "GL_TLE: query failed: " << myquery.Data() << endl; |
| 1939 |
|
return 1; |
| 1940 |
|
} |
| 1941 |
|
|
| 1942 |
|
// Get results |
| 1943 |
|
row = result->Next(); // first tle row |
| 1944 |
|
tle = GiveTle(row); |
| 1945 |
|
|
| 1946 |
|
tleFromTime = strtol(row->GetField(4), NULL, 10); |
| 1947 |
|
|
| 1948 |
|
row = result->Next(); // second tle row |
| 1949 |
|
if(row) |
| 1950 |
|
tleToTime = strtol(row->GetField(4), NULL, 10); |
| 1951 |
|
else { |
| 1952 |
|
cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n"; |
| 1953 |
|
tleToTime = UINT_MAX; |
| 1954 |
|
} |
| 1955 |
|
|
| 1956 |
|
delete row; |
| 1957 |
|
delete result; |
| 1958 |
|
|
| 1959 |
|
return 0; |
| 1960 |
|
} |
| 1961 |
|
|
| 1962 |
|
|
| 1963 |
|
// |
| 1964 |
|
// Build a cTle object from the GL_TLE row. |
| 1965 |
|
// |
| 1966 |
|
cTle* GL_TLE::GiveTle(TSQLRow *row) { |
| 1967 |
|
cTle *thistle = NULL; |
| 1968 |
|
string tle1, tle2, tle3; |
| 1969 |
|
|
| 1970 |
|
// Build cTle object |
| 1971 |
|
tle1 = row->GetField(1); |
| 1972 |
|
tle2 = row->GetField(2); |
| 1973 |
|
tle3 = row->GetField(3); |
| 1974 |
|
|
| 1975 |
|
thistle = new cTle(tle1, tle2, tle3); |
| 1976 |
|
|
| 1977 |
|
return thistle; |
| 1978 |
|
} |