/[PAMELA software]/YodaProfiler/src/GLTables.cpp
ViewVC logotype

Diff of /YodaProfiler/src/GLTables.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.20 by mocchiut, Mon Nov 27 14:25:34 2006 UTC revision 1.27 by mocchiut, Wed Apr 18 13:55:00 2007 UTC
# Line 17  Line 17 
17  #include <GLTables.h>  #include <GLTables.h>
18  #include <sgp4.h>  #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);
# Line 28  ClassImp(GL_TLE); Line 29  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;
# Line 161  GL_TIMESYNC::GL_TIMESYNC(){ Line 254  GL_TIMESYNC::GL_TIMESYNC(){
254    TYPE     = 0;    TYPE     = 0;
255  }  }
256    
 GL_TLE::GL_TLE(){  
 }  
   
257  // ****************************************************  // ****************************************************
258    
259  void GL_RUN::SetEV_FROM(UInt_t evfrom){  void GL_RUN::SetEV_FROM(UInt_t evfrom){
# Line 428  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 518  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
518    //    //
519    //  printf("1myquery is %s \n",myquery.str().c_str());    //  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());    dbc->Query(myquery.str().c_str());
524    //    //
525    // retrieve this ID_TRASH    // retrieve this ID_TRASH
526    //    //
527    myquery.str("");    myquery.str("");
528    myquery << " SELECT ID_TRASH,ID_ROOT_L0,ID_ROOT_L2 FROM GL_RUN_TRASH ORDER BY ID_TRASH DESC LIMIT 1";      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());    pResult = dbc->Query(myquery.str().c_str());
532    //    //
533    UInt_t idtrash = 0;    UInt_t idtrash = 0;
# Line 455  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 549  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
549    //    //
550    //  printf("2myquery is %s \n",myquery.str().c_str());    //  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());    pResult = dbc->Query(myquery.str().c_str());
555    //    //
556    Row = pResult->Next();          Row = pResult->Next();      
# Line 470  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 566  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
566    //    //
567    //  printf("3myquery is %s \n",myquery.str().c_str());    //  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());    pResult = dbc->Query(myquery.str().c_str());
572    //    //
573    Row = pResult->Next();          Row = pResult->Next();      
# Line 486  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 584  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
584    //    //
585    //  printf("4myquery is %s \n",myquery.str().c_str());    //  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());    dbc->Query(myquery.str().c_str());
590    //    //
591    myquery.str("");    myquery.str("");
# Line 495  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 595  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
595    //    //
596    //  printf("4myquery is %s \n",myquery.str().c_str());    //  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());    dbc->Query(myquery.str().c_str());
601    //    //
602    myquery.str("");    myquery.str("");
# Line 505  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 607  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
607    //  printf("4myquery is %s \n",myquery.str().c_str());    //  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());    dbc->Query(myquery.str().c_str());
613    //    //
614    myquery.str("");    myquery.str("");
# Line 515  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 619  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
619    //  printf("5myquery is %s \n",myquery.str().c_str());    //  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());    dbc->Query(myquery.str().c_str());
625    //    //
626    return 0;    return 0;
# Line 546  Int_t GL_RUN::RestoreRun(TSQLServer *dbc Line 652  Int_t GL_RUN::RestoreRun(TSQLServer *dbc
652      //      //
653      printf(" qui? myquery is %s \n",myquery.str().c_str());      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());      pResult = dbc->Query(myquery.str().c_str());
658      //      //
659      Row = pResult->Next();            Row = pResult->Next();      
# Line 629  Int_t GL_RUN::RestoreRun(TSQLServer *dbc Line 737  Int_t GL_RUN::RestoreRun(TSQLServer *dbc
737    //    //
738    //  printf("5myquery is %s \n",myquery.str().c_str());    //  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());    dbc->Query(myquery.str().c_str());
743    //    //
744    //    //
# Line 636  Int_t GL_RUN::RestoreRun(TSQLServer *dbc Line 746  Int_t GL_RUN::RestoreRun(TSQLServer *dbc
746    myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID=";    myquery << " DELETE FROM GL_RUN_TRASH where BELONGED_TO='GL_RUN_FRAGMENTS' AND ID=";
747    myquery << IDRUN << ";";    myquery << IDRUN << ";";
748    //    //
749      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
750      this->GetGLTABLES()->AddQ();
751    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
752    //    //
753    return 0;    return 0;
# Line 718  Int_t GL_RUN::Fill_GL_RUN(TSQLServer *db Line 830  Int_t GL_RUN::Fill_GL_RUN(TSQLServer *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;
# Line 794  Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQL Line 908  Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQL
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;
# Line 851  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T Line 967  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T
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());    //  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    //    //
974    //  printf(" getrowcount %i \n",pResult->GetRowCount());    //  printf(" getrowcount %i \n",pResult->GetRowCount());
# Line 949  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt Line 1067  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt
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++){
# Line 1014  Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, Line 1134  Int_t GL_ROOT::Query_GL_ROOT(UInt_t id,
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++){
# Line 1023  Int_t GL_ROOT::Query_GL_ROOT(UInt_t id, Line 1145  Int_t GL_ROOT::Query_GL_ROOT(UInt_t id,
1145            if(t==0) ID     = (UInt_t)atoll(Row->GetField(t));            if(t==0) ID     = (UInt_t)atoll(Row->GetField(t));
1146            if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));            if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));
1147            if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));            if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
1148            if(t==3) PATH   = Row->GetField(t);            if(t==3) PATH   = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';
1149            if(t==4) NAME   = Row->GetField(t);            if(t==4) NAME   = Row->GetField(t);
1150        };        };
1151    };    };
# Line 1048  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U Line 1170  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U
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,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;
1173    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!!!
1174      myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1175    //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1176      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1177      this->GetGLTABLES()->AddQ();
1178    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1179    if(!pResult->GetRowCount())return (-53);    if(!pResult->GetRowCount())return (-53);
1180    for( r=0; r < 1000; r++){    for( r=0; r < 1000; r++){
# Line 1107  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1232  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1232    myquery << " ;";    myquery << " ;";
1233    //myquery << " and VALIDATION=1;";    //myquery << " and VALIDATION=1;";
1234    //    //
1235      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1236      this->GetGLTABLES()->AddQ();
1237    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1238    //  printf(" mysquery is %s\n",myquery.str().c_str());    //  printf(" mysquery is %s\n",myquery.str().c_str());
1239    //    //
# Line 1126  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1253  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1253      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;
1254      myquery << " and FROM_TIME <= " << time;      myquery << " and FROM_TIME <= " << time;
1255      myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";      myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
1256        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1257        this->GetGLTABLES()->AddQ();
1258      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
1259      //    printf(" mysquery is %s\n",myquery.str().c_str());      //    printf(" mysquery is %s\n",myquery.str().c_str());
1260      //      //
# Line 1168  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn Line 1297  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn
1297    myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;    myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;
1298    myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1299    //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1300      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1301      this->GetGLTABLES()->AddQ();
1302    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1303    if(!pResult->GetRowCount())return (-55);//throw -55;    if(!pResult->GetRowCount())return (-55);//throw -55;
1304    for( r=0; r < 1000; r++){    for( r=0; r < 1000; r++){
# Line 1208  Int_t GL_PARAM::Query_GL_PARAM(UInt_t ti Line 1339  Int_t GL_PARAM::Query_GL_PARAM(UInt_t ti
1339    // ----------------        // ----------------    
1340    myquery.str("");    myquery.str("");
1341    myquery << " select ";    myquery << " select ";
1342    myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME ";    myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE ";
1343    myquery << " from GL_PARAM ";    myquery << " from GL_PARAM ";
1344    myquery << " where TYPE = '"<<type<<"' ";    myquery << " where TYPE = '"<<type<<"' ";
1345    myquery << " and FROM_TIME <= " << time;    myquery << " and FROM_TIME <= " << time;
1346    myquery << " ORDER BY TO_TIME DESC LIMIT 1;";      myquery << " ORDER BY TO_TIME DESC LIMIT 1;";  
1347    //    //
1348      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1349      this->GetGLTABLES()->AddQ();
1350    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1351    if(!pResult->GetRowCount())return (-52);    if(!pResult->GetRowCount())return (-52);
1352    for( r=0; r < 1000; r++){    for( r=0; r < 1000; r++){
# Line 1221  Int_t GL_PARAM::Query_GL_PARAM(UInt_t ti Line 1354  Int_t GL_PARAM::Query_GL_PARAM(UInt_t ti
1354        if( Row == NULL ) break;        if( Row == NULL ) break;
1355        for( t = 0; t < pResult->GetFieldCount(); t++){        for( t = 0; t < pResult->GetFieldCount(); t++){
1356          if (t==0) ID        = (UInt_t)atoll(Row->GetField(t));          if (t==0) ID        = (UInt_t)atoll(Row->GetField(t));
1357            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
1358            if (t==2) NAME      = Row->GetField(t);            if (t==2) NAME      = Row->GetField(t);
1359            if (t==3) DESCR     = Row->GetField(t);            if (t==3) DESCR     = Row->GetField(t);
1360            if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));            if (t==4) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
# Line 1267  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1400  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1400    TSQLRow *Row;    TSQLRow *Row;
1401    stringstream myquery;    stringstream myquery;
1402    stringstream rname;    stringstream rname;
1403      //  pcksList packetsNames;
1404      //  pcksList::iterator Iter;
1405      //  getPacketsNames(packetsNames);
1406    rname.str("");    rname.str("");
1407    // ----------------    // ----------------
1408    myquery.str("");    myquery.str("");
# Line 1277  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1413  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1413    myquery << type.Data();    myquery << type.Data();
1414    myquery << "=" << id << ";";        myquery << "=" << id << ";";    
1415    //    //
1416      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1417      this->GetGLTABLES()->AddQ();
1418    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1419    if( pResult->GetRowCount() ){    if( pResult->GetRowCount() ){
1420      Row = pResult->Next();            Row = pResult->Next();      
1421      if( Row ){      if( Row ){
1422        stringstream fname;        stringstream fname;
1423        fname.str("");        fname.str("");
1424        fname << Row->GetField(0) << "/" << Row->GetField(1);        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1425        rname << Row->GetField(1);        rname << Row->GetField(1);
1426        file = new TFile(fname.str().c_str(),"READ");        file = new TFile(fname.str().c_str(),"READ");
1427        idraw = (UInt_t)atoll(Row->GetField(2));        idraw = (UInt_t)atoll(Row->GetField(2));
# Line 1300  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1438  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1438      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
1439      pktfirst = ph->GetCounter();      pktfirst = ph->GetCounter();
1440      obtfirst = ph->GetOrbitalTime();        obtfirst = ph->GetOrbitalTime();  
1441        //
1442    //     code = eh->GetCounter();
1443    //     UInt_t en = 0;
1444    //     for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
1445    //       en = code->Get(GetPacketType(*Iter));
1446    //       if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){
1447    //      //
1448    //      TTree *TC = 0;
1449    //      TC = (TTree*)file->Get("CalibCalPed");
1450    //      if ( !TC || TC->IsZombie() ) return;
1451    //      EventHeader *ehc = 0;
1452    //      PscuHeader *phc = 0;
1453    //      TC->SetBranchAddress("Header", &ehc);
1454    //      TC->GetEntry(0);
1455    //      phc = ehc->GetPscuHeader();
1456    //      pktfirst = phc->GetCounter();
1457    //      obtfirst = phc->GetOrbitalTime();  
1458    //       //
1459    //       };
1460    //     };  
1461        //
1462    };    };
1463    //    //
1464    // look for Resurs offset    // look for Resurs offset
# Line 1308  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1467  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1467    //    //
1468    //    //
1469    stringstream oss;    stringstream oss;
1470      TString frn = rname.str().c_str();
1471      frn = frn.ReplaceAll(".root",5,".pam",4);
1472    oss.str("");    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 SPECIAL_FILE='"    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='"
1474        << rname.str().c_str() << "';";        << frn.Data() << "';";
1475      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1476      this->GetGLTABLES()->AddQ();
1477    pResult = dbc->Query(oss.str().c_str());    pResult = dbc->Query(oss.str().c_str());
1478    Row = pResult->Next();    Row = pResult->Next();
1479    //    //
# Line 1329  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1492  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1492      for (Int_t i = 8; i<13; i++){      for (Int_t i = 8; i<13; i++){
1493        dwo.Append(name[i],1);        dwo.Append(name[i],1);
1494      };          };    
1495      if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();      if ( dwo.IsDigit() ){
1496          dworbit = (UInt_t)dwo.Atoi();
1497        } else {
1498          dworbit = 1;
1499        };
1500    };    };
1501    //    //
1502      //
1503    if ( !Row ){    if ( !Row ){
1504      oss.str("");      oss.str("");
1505      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< "      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< "
1506          << dworbit << " order by FROM_ORBIT desc limit 1;";          << dworbit << " order by FROM_ORBIT desc limit 1;";
1507        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1508        this->GetGLTABLES()->AddQ();
1509      pResult = dbc->Query(oss.str().c_str());      pResult = dbc->Query(oss.str().c_str());
1510      Row = pResult->Next();      Row = pResult->Next();
1511      if ( !Row ){      if ( !Row ){
# Line 1353  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1523  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1523    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "
1524        << " WHERE ID_RAW = " << idraw        << " WHERE ID_RAW = " << idraw
1525        << ";";        << ";";
1526      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1527      this->GetGLTABLES()->AddQ();
1528    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1529    if ( pResult ){    if ( pResult ){
1530      Row = pResult->Next();      Row = pResult->Next();
# Line 1573  TString GL_TIMESYNC::UnConvertTime(TStri Line 1745  TString GL_TIMESYNC::UnConvertTime(TStri
1745  }  }
1746    
1747    
1748  // ****************************************************  //
1749  /**  // Build a query and call DoQuery.
1750   * Function to query the GL_TLE table of the DB.  //
1751   *  // date it's an SQL datetime date and dbc is the connection to be
1752   * time is the unix time for which a good tle is requested.  // used.  It will query for the tle with the nearest but previous date
1753   *  // and the immediatly next one.
1754   * Return the pointer to a cTle object that has the closest and  //
1755   * previous date compared with time.  Int_t GL_TLE::Query(TString date, TSQLServer *dbc){
  *  
  * If errors occurs it returns NULL.  
  */  
 cTle* GL_TLE::Query_GL_TLE(UInt_t time, TSQLServer *dbc){  
1756    stringstream myquery;    stringstream myquery;
1757    myquery.str("");    myquery.str("");
1758    
1759    myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "    myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1760            << "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;";              << "WHERE FROM_TIME <= '" << date.Data()
1761              << "' ORDER BY FROM_TIME DESC LIMIT 1) "
1762              << "UNION "
1763              << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1764              << "WHERE FROM_TIME > '" << date.Data()
1765              << "' ORDER BY FROM_TIME ASC LIMIT 1)";
1766    
1767    return Query_GL_TLE_go(myquery.str(), dbc);    return DoQuery(myquery.str().c_str(), dbc);
1768  }  }
1769    
1770    
1771  // ****************************************************  //
1772  /**  // Build a query and call DoQuery.
1773   * Function to query the GL_TLE table of the DB.  //
1774   *  // time is the UTC date in unix time (UTC) and dbc is the connection
1775   * date is a datetime format YYYY-MM-DD hh:mm:ss for which a good tle  // to be used.  It will query for the tle with the nearest but
1776   * is requested.  // previous date and the immediatly next one.
1777   *  //
1778   * Return the pointer to a cTle object that has the closest and  // Returns the value returned by DoQuery().
1779   * previous date compared with time.  //
1780   *  Int_t GL_TLE::Query(UInt_t time, TSQLServer *dbc){
  * If errors occurs it returns NULL.  
  */  
 cTle* GL_TLE::Query_GL_TLE(TString date, TSQLServer *dbc){  
1781    stringstream myquery;    stringstream myquery;
1782    myquery.str("");    myquery.str("");
1783    
1784    myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "    myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1785            << "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;";              << "WHERE FROM_TIME <= FROM_UNIXTIME('" << time
1786              << "') ORDER BY FROM_TIME DESC LIMIT 1) "
1787              << "UNION "
1788              << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1789              << "WHERE FROM_TIME > FROM_UNIXTIME('" << time
1790              << "') ORDER BY FROM_TIME ASC LIMIT 1)";
1791    
1792      return DoQuery(myquery.str().c_str(), dbc);
   return Query_GL_TLE_go(myquery.str(), dbc);  
1793  }  }
1794    
1795    
1796  // ****************************************************  //
1797  /**  // Do the query myquery on the connectio dbc.  Initialize tle,
1798   * Private function used by Query_GL_TLE methods.  // tleFromTime and tleToTime.
1799   *  //
1800   * myquery is the query string.  // We should have two rows (unless the table is old).  From the last
1801   *  // one we only take tleToTime.
1802   * Return the pointer to a cTle object that has the closest and  //
1803   * previous date compared with time.  // Returns 0 for success, 1 for failure.
1804   *  //
1805   * If errors occurs it returns NULL.  Int_t GL_TLE::DoQuery(TString myquery, TSQLServer *dbc){
  */  
 cTle* GL_TLE::Query_GL_TLE_go(TString myquery, TSQLServer *dbc){  
   cTle *tle;  
   string tle1, tle2, tle3;  
   
   // MySQL variables  
1806    TSQLResult *result;    TSQLResult *result;
1807    TSQLRow *row;    TSQLRow *row;
1808    
1809      // Set the right time_zone (otherwise horrible things will occur! :)
1810      dbc->Query("SET time_zone = '+0:00'");
1811    
1812      // Do the query
1813      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1814      this->GetGLTABLES()->AddQ();
1815    result = dbc->Query(myquery.Data());    result = dbc->Query(myquery.Data());
1816    if(! result->GetRowCount() ) return NULL;    if(! result->GetRowCount() ) {
1817        cerr << "GL_TLE: query failed: " << myquery.Data() << endl;
1818        return 1;
1819      }
1820    
1821      // Get results
1822      row = result->Next(); // first tle row
1823      tle = GiveTle(row);
1824    
1825      tleFromTime = strtol(row->GetField(4), NULL, 10);
1826    
1827      row = result->Next(); // second tle row
1828      if(row)
1829        tleToTime = strtol(row->GetField(4), NULL, 10);
1830      else {
1831        cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n";
1832        tleToTime = UINT_MAX;
1833      }
1834    
1835      delete row;
1836      delete result;
1837    
1838    row = result->Next();    return 0;
1839    tle1 = row->GetField(0);  }
   tle2 = row->GetField(1);  
   tle3 = row->GetField(2);  
1840    
   tle = new cTle(tle1, tle2, tle3);  
1841    
1842    delete result;  //
1843    delete row;  // Build a cTle object from the GL_TLE row.
1844    //
1845    cTle* GL_TLE::GiveTle(TSQLRow *row) {
1846      cTle *thistle = NULL;
1847      string tle1, tle2, tle3;
1848    
1849      // Build cTle object
1850      tle1 = row->GetField(1);
1851      tle2 = row->GetField(2);
1852      tle3 = row->GetField(3);
1853    
1854      thistle = new cTle(tle1, tle2, tle3);
1855    
1856    return tle;    return thistle;
1857  }  }

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.27

  ViewVC Help
Powered by ViewVC 1.1.23