/[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.31 by mocchiut, Sun Sep 9 18:59:41 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      mh = host.Data();
42      mu = user.Data();
43      mp = psw.Data();
44    };
45    
46    
47    void GL_TABLES::Set(TString host, TString user, TString psw){
48      fHost = new TString(host.Data());
49      fUser = new TString(user.Data());
50      fPsw = new TString(psw.Data());
51      fSet = true;
52      fNquery = 0;
53      mh = host.Data();
54      mu = user.Data();
55      mp = psw.Data();
56    };
57    
58    Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){
59      //
60      //
61      //
62      if ( !fSet ){
63        return true;
64      };
65      //
66      //
67      //
68      //    printf(" host is %s \n",fHost->Data());
69      //
70      stringstream myquery;  
71      myquery.str("");
72      myquery << "show databases;";
73      if ( dbc ){
74        if ( dbc->IsConnected() ){
75          dbc->Query(myquery.str().c_str());
76          fNquery++;
77          if ( !(dbc->GetErrorCode()) ){
78            //      printf("ok\n");
79            //
80            //  if ( (dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006) ){
81            //    if ( !(dbc->GetErrorCode()) ){
82            // is connected
83            return true;
84            //    };
85          };
86        };
87      };
88      //  printf("porca di quella \n");
89      if ( true ) {
90        //
91        printf(" WARNING: Lost connection to DB! try to recover... \n");
92        //
93        TString host = fHost->Data();
94        TString user = fUser->Data();
95        TString psw = fPsw->Data();
96        delete dbc;
97        dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
98        //
99        myquery.str("");
100        myquery << "show databases;";
101        dbc->Query(myquery.str().c_str());
102        fNquery++;
103        //    printf(" e riporca di quella \n");
104        //
105        //    if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){
106        if ( !(dbc->GetErrorCode()) ){
107          //
108          printf(" ...connection recovered, I can continue! \n");
109          //
110          myquery.str("");
111          myquery << "SET time_zone='+0:00'";
112          dbc->Query(myquery.str().c_str());
113          fNquery++;
114          myquery.str("");
115          myquery << "SET wait_timeout=173000;";
116          dbc->Query(myquery.str().c_str());      
117          fNquery++;
118          return true;
119        };
120      };
121      //
122      printf(" GLTABLES: connection is gone away, query will fail\n");
123      //
124      return false;
125      //
126    };
127    
128    void GL_TABLES::ResetCounters(){
129      fNquery = 0;
130    };
131    
132    void GL_TABLES::AddQ(){
133      if ( fSet ) fNquery++;
134    };
135    
136    UInt_t GL_TABLES::GetNqueries(){
137       UInt_t rn = 0;
138       rn += (UInt_t&)fNquery;
139       return(rn);
140    };
141    
142  GL_RUN::GL_RUN() {  GL_RUN::GL_RUN() {
143    ID                         = 0;    ID                         = 0;
144    ID_RUN_FRAG                = 0;    ID_RUN_FRAG                = 0;
# Line 161  GL_TIMESYNC::GL_TIMESYNC(){ Line 272  GL_TIMESYNC::GL_TIMESYNC(){
272    TYPE     = 0;    TYPE     = 0;
273  }  }
274    
 GL_TLE::GL_TLE(){  
 }  
   
275  // ****************************************************  // ****************************************************
276    
277  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 536  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
536    //    //
537    //  printf("1myquery is %s \n",myquery.str().c_str());    //  printf("1myquery is %s \n",myquery.str().c_str());
538    //    //
539      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
540      this->GetGLTABLES()->AddQ();
541    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
542    //    //
543    // retrieve this ID_TRASH    // retrieve this ID_TRASH
544    //    //
545    myquery.str("");    myquery.str("");
546    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";  
547      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
548      this->GetGLTABLES()->AddQ();
549    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
550    //    //
551    UInt_t idtrash = 0;    UInt_t idtrash = 0;
# Line 455  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 567  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
567    //    //
568    //  printf("2myquery is %s \n",myquery.str().c_str());    //  printf("2myquery is %s \n",myquery.str().c_str());
569    //    //
570      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
571      this->GetGLTABLES()->AddQ();
572    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
573    //    //
574    Row = pResult->Next();          Row = pResult->Next();      
# Line 470  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 584  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
584    //    //
585    //  printf("3myquery is %s \n",myquery.str().c_str());    //  printf("3myquery 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());    pResult = dbc->Query(myquery.str().c_str());
590    //    //
591    Row = pResult->Next();          Row = pResult->Next();      
# Line 486  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 602  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
602    //    //
603    //  printf("4myquery is %s \n",myquery.str().c_str());    //  printf("4myquery is %s \n",myquery.str().c_str());
604    //    //
605      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
606      this->GetGLTABLES()->AddQ();
607    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
608    //    //
609    myquery.str("");    myquery.str("");
# Line 495  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 613  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
613    //    //
614    //  printf("4myquery is %s \n",myquery.str().c_str());    //  printf("4myquery is %s \n",myquery.str().c_str());
615    //    //
616      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
617      this->GetGLTABLES()->AddQ();
618    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
619    //    //
620    myquery.str("");    myquery.str("");
# Line 505  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 625  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
625    //  printf("4myquery is %s \n",myquery.str().c_str());    //  printf("4myquery is %s \n",myquery.str().c_str());
626    //    //
627    //    //
628      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
629      this->GetGLTABLES()->AddQ();
630    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
631    //    //
632    myquery.str("");    myquery.str("");
# Line 515  Int_t GL_RUN::DeleteRun(TSQLServer *dbc, Line 637  Int_t GL_RUN::DeleteRun(TSQLServer *dbc,
637    //  printf("5myquery is %s \n",myquery.str().c_str());    //  printf("5myquery is %s \n",myquery.str().c_str());
638    //    //
639    //    //
640      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
641      this->GetGLTABLES()->AddQ();
642    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
643    //    //
644    return 0;    return 0;
# Line 546  Int_t GL_RUN::RestoreRun(TSQLServer *dbc Line 670  Int_t GL_RUN::RestoreRun(TSQLServer *dbc
670      //      //
671      printf(" qui? myquery is %s \n",myquery.str().c_str());      printf(" qui? myquery is %s \n",myquery.str().c_str());
672      //      //
673        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
674        this->GetGLTABLES()->AddQ();
675      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
676      //      //
677      Row = pResult->Next();            Row = pResult->Next();      
# Line 629  Int_t GL_RUN::RestoreRun(TSQLServer *dbc Line 755  Int_t GL_RUN::RestoreRun(TSQLServer *dbc
755    //    //
756    //  printf("5myquery is %s \n",myquery.str().c_str());    //  printf("5myquery is %s \n",myquery.str().c_str());
757    //    //
758      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
759      this->GetGLTABLES()->AddQ();
760    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
761    //    //
762    //    //
# Line 636  Int_t GL_RUN::RestoreRun(TSQLServer *dbc Line 764  Int_t GL_RUN::RestoreRun(TSQLServer *dbc
764    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=";
765    myquery << IDRUN << ";";    myquery << IDRUN << ";";
766    //    //
767      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
768      this->GetGLTABLES()->AddQ();
769    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
770    //    //
771    return 0;    return 0;
# Line 718  Int_t GL_RUN::Fill_GL_RUN(TSQLServer *db Line 848  Int_t GL_RUN::Fill_GL_RUN(TSQLServer *db
848    //    //
849    //  printf("myquery is %s \n",myquery.str().c_str());    //  printf("myquery is %s \n",myquery.str().c_str());
850    //    //
851      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
852      this->GetGLTABLES()->AddQ();
853    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
854    //    //
855    return 0;    return 0;
# Line 794  Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQL Line 926  Int_t GL_RUN::Fill_GL_RUN_FRAGMENTS(TSQL
926    //    //
927    // printf("myquery is %s \n",myquery.str().c_str());    // printf("myquery is %s \n",myquery.str().c_str());
928    //    //
929      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
930      this->GetGLTABLES()->AddQ();
931    dbc->Query(myquery.str().c_str());    dbc->Query(myquery.str().c_str());
932    //    //
933    return 0;    return 0;
# Line 851  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T Line 985  Int_t GL_RUN::Query_GL_RUN(UInt_t run, T
985    myquery << " from GL_RUN where ID=" << run << ";";    myquery << " from GL_RUN where ID=" << run << ";";
986    //    //
987    //  printf(" myquery is %s \n",myquery.str().c_str());    //  printf(" myquery is %s \n",myquery.str().c_str());
988      if ( !this->IsConnected(dbc) ) return -57;  
989      this->AddQ();
990    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
991    //    //
992    //  printf(" getrowcount %i \n",pResult->GetRowCount());    //  printf(" getrowcount %i \n",pResult->GetRowCount());
# Line 949  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt Line 1085  Int_t GL_RUN::Query_GL_RUN_FRAGMENTS(TSt
1085    //    //
1086    //  printf(" query is %s \n",myquery.str().c_str());    //  printf(" query is %s \n",myquery.str().c_str());
1087    //    //
1088      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1089      this->GetGLTABLES()->AddQ();
1090    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1091    if(!pResult->GetRowCount())return(-50);    if(!pResult->GetRowCount())return(-50);
1092    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 1152  Int_t GL_ROOT::Query_GL_ROOT(UInt_t id,
1152    myquery << ",NAME";    myquery << ",NAME";
1153    myquery << " from GL_ROOT where ID=" << id << ";";        myquery << " from GL_ROOT where ID=" << id << ";";    
1154    //    //
1155      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1156      this->GetGLTABLES()->AddQ();
1157    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1158    if(!pResult->GetRowCount())return (-51);    if(!pResult->GetRowCount())return (-51);
1159    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 1163  Int_t GL_ROOT::Query_GL_ROOT(UInt_t id,
1163            if(t==0) ID     = (UInt_t)atoll(Row->GetField(t));            if(t==0) ID     = (UInt_t)atoll(Row->GetField(t));
1164            if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));            if(t==1) ID_RAW = (UInt_t)atoll(Row->GetField(t));
1165            if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));            if(t==2) ID_TIMESYNC = (UInt_t)atoll(Row->GetField(t));
1166            if(t==3) PATH   = Row->GetField(t);            if(t==3) PATH   = (TString)gSystem->ExpandPathName(Row->GetField(t))+'/';
1167            if(t==4) NAME   = Row->GetField(t);            if(t==4) NAME   = Row->GetField(t);
1168        };        };
1169    };    };
# Line 1048  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U Line 1188  Int_t GL_TRK_CALIB::Query_GL_TRK_CALIB(U
1188    // ----------------    // ----------------
1189    myquery.str("");    myquery.str("");
1190    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;
1191    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!!!
1192      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      
1193      myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1194    //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1195      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1196      this->GetGLTABLES()->AddQ();
1197    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1198    if(!pResult->GetRowCount())return (-53);    if(!pResult->GetRowCount())return (-53);
1199    for( r=0; r < 1000; r++){    for( r=0; r < 1000; r++){
# Line 1107  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1251  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1251    myquery << " ;";    myquery << " ;";
1252    //myquery << " and VALIDATION=1;";    //myquery << " and VALIDATION=1;";
1253    //    //
1254      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1255      this->GetGLTABLES()->AddQ();
1256    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1257    //  printf(" mysquery is %s\n",myquery.str().c_str());    //  printf(" mysquery is %s\n",myquery.str().c_str());
1258    //    //
# Line 1126  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1272  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1272      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;
1273      myquery << " and FROM_TIME <= " << time;      myquery << " and FROM_TIME <= " << time;
1274      myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";      myquery << " and VALIDATION=1 ORDER BY FROM_TIME DESC LIMIT 1;";
1275        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1276        this->GetGLTABLES()->AddQ();
1277      pResult = dbc->Query(myquery.str().c_str());      pResult = dbc->Query(myquery.str().c_str());
1278      //    printf(" mysquery is %s\n",myquery.str().c_str());      //    printf(" mysquery is %s\n",myquery.str().c_str());
1279      //      //
# Line 1168  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn Line 1316  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn
1316    myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;    myquery << "select * from GL_S4_CALIB where FROM_TIME <= "<< time;
1317    myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1318    //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1319      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1320      this->GetGLTABLES()->AddQ();
1321    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1322    if(!pResult->GetRowCount())return (-55);//throw -55;    if(!pResult->GetRowCount())return (-55);//throw -55;
1323    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 1358  Int_t GL_PARAM::Query_GL_PARAM(UInt_t ti
1358    // ----------------        // ----------------    
1359    myquery.str("");    myquery.str("");
1360    myquery << " select ";    myquery << " select ";
1361    myquery << " ID, PATH, NAME, DESCR, TYPE, FROM_TIME,TO_TIME ";    myquery << " ID, PATH, NAME, DESCR, FROM_TIME,TO_TIME, TYPE ";
1362    myquery << " from GL_PARAM ";    myquery << " from GL_PARAM ";
1363    myquery << " where TYPE = '"<<type<<"' ";    myquery << " where TYPE = '"<<type<<"' ";
1364    myquery << " and FROM_TIME <= " << time;    myquery << " and FROM_TIME <= " << time;
1365    myquery << " ORDER BY TO_TIME DESC LIMIT 1;";      myquery << " ORDER BY TO_TIME DESC LIMIT 1;";  
1366    //    //
1367      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1368      this->GetGLTABLES()->AddQ();
1369    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1370    if(!pResult->GetRowCount())return (-52);    if(!pResult->GetRowCount())return (-52);
1371    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 1373  Int_t GL_PARAM::Query_GL_PARAM(UInt_t ti
1373        if( Row == NULL ) break;        if( Row == NULL ) break;
1374        for( t = 0; t < pResult->GetFieldCount(); t++){        for( t = 0; t < pResult->GetFieldCount(); t++){
1375          if (t==0) ID        = (UInt_t)atoll(Row->GetField(t));          if (t==0) ID        = (UInt_t)atoll(Row->GetField(t));
1376            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
1377            if (t==2) NAME      = Row->GetField(t);            if (t==2) NAME      = Row->GetField(t);
1378            if (t==3) DESCR     = Row->GetField(t);            if (t==3) DESCR     = Row->GetField(t);
1379            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 1419  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1419    TSQLRow *Row;    TSQLRow *Row;
1420    stringstream myquery;    stringstream myquery;
1421    stringstream rname;    stringstream rname;
1422      //  pcksList packetsNames;
1423      //  pcksList::iterator Iter;
1424      //  getPacketsNames(packetsNames);
1425    rname.str("");    rname.str("");
1426    // ----------------    // ----------------
1427    myquery.str("");    myquery.str("");
# Line 1277  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1432  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1432    myquery << type.Data();    myquery << type.Data();
1433    myquery << "=" << id << ";";        myquery << "=" << id << ";";    
1434    //    //
1435      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1436      this->GetGLTABLES()->AddQ();
1437    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1438    if( pResult->GetRowCount() ){    if( pResult->GetRowCount() ){
1439      Row = pResult->Next();            Row = pResult->Next();      
1440      if( Row ){      if( Row ){
1441        stringstream fname;        stringstream fname;
1442        fname.str("");        fname.str("");
1443        fname << Row->GetField(0) << "/" << Row->GetField(1);        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1444        rname << Row->GetField(1);        rname << Row->GetField(1);
1445        file = new TFile(fname.str().c_str(),"READ");        file = new TFile(fname.str().c_str(),"READ");
1446        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 1457  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1457      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
1458      pktfirst = ph->GetCounter();      pktfirst = ph->GetCounter();
1459      obtfirst = ph->GetOrbitalTime();        obtfirst = ph->GetOrbitalTime();  
1460        //
1461    //     code = eh->GetCounter();
1462    //     UInt_t en = 0;
1463    //     for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
1464    //       en = code->Get(GetPacketType(*Iter));
1465    //       if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){
1466    //      //
1467    //      TTree *TC = 0;
1468    //      TC = (TTree*)file->Get("CalibCalPed");
1469    //      if ( !TC || TC->IsZombie() ) return;
1470    //      EventHeader *ehc = 0;
1471    //      PscuHeader *phc = 0;
1472    //      TC->SetBranchAddress("Header", &ehc);
1473    //      TC->GetEntry(0);
1474    //      phc = ehc->GetPscuHeader();
1475    //      pktfirst = phc->GetCounter();
1476    //      obtfirst = phc->GetOrbitalTime();  
1477    //       //
1478    //       };
1479    //     };  
1480        //
1481    };    };
1482    //    //
1483    // look for Resurs offset    // look for Resurs offset
# Line 1308  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1486  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1486    //    //
1487    //    //
1488    stringstream oss;    stringstream oss;
1489      TString frn = rname.str().c_str();
1490      frn = frn.ReplaceAll(".root",5,".pam",4);
1491    oss.str("");    oss.str("");
1492    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='"
1493        << rname.str().c_str() << "';";        << frn.Data() << "';";
1494      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1495      this->GetGLTABLES()->AddQ();
1496    pResult = dbc->Query(oss.str().c_str());    pResult = dbc->Query(oss.str().c_str());
1497    Row = pResult->Next();    Row = pResult->Next();
1498    //    //
# Line 1329  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1511  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1511      for (Int_t i = 8; i<13; i++){      for (Int_t i = 8; i<13; i++){
1512        dwo.Append(name[i],1);        dwo.Append(name[i],1);
1513      };          };    
1514      if ( dwo.IsDigit() ) dworbit = (UInt_t)dwo.Atoi();      if ( dwo.IsDigit() ){
1515          dworbit = (UInt_t)dwo.Atoi();
1516        } else {
1517          dworbit = 1;
1518        };
1519    };    };
1520    //    //
1521      //
1522    if ( !Row ){    if ( !Row ){
1523      oss.str("");      oss.str("");
1524      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< "
1525          << dworbit << " order by FROM_ORBIT desc limit 1;";          << dworbit << " order by FROM_ORBIT desc limit 1;";
1526        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1527        this->GetGLTABLES()->AddQ();
1528      pResult = dbc->Query(oss.str().c_str());      pResult = dbc->Query(oss.str().c_str());
1529      Row = pResult->Next();      Row = pResult->Next();
1530      if ( !Row ){      if ( !Row ){
# Line 1353  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1542  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1542    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "
1543        << " WHERE ID_RAW = " << idraw        << " WHERE ID_RAW = " << idraw
1544        << ";";        << ";";
1545      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1546      this->GetGLTABLES()->AddQ();
1547    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1548    if ( pResult ){    if ( pResult ){
1549      Row = pResult->Next();      Row = pResult->Next();
# Line 1573  TString GL_TIMESYNC::UnConvertTime(TStri Line 1764  TString GL_TIMESYNC::UnConvertTime(TStri
1764  }  }
1765    
1766    
1767  // ****************************************************  //
1768  /**  // Build a query and call DoQuery.
1769   * Function to query the GL_TLE table of the DB.  //
1770   *  // date it's an SQL datetime date and dbc is the connection to be
1771   * 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
1772   *  // and the immediatly next one.
1773   * Return the pointer to a cTle object that has the closest and  //
1774   * 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){  
1775    stringstream myquery;    stringstream myquery;
1776    myquery.str("");    myquery.str("");
1777    
1778    myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "    myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1779            << "WHERE FROM_TIME < FROM_UNIXTIME(" << time << ") ORDER BY FROM_TIME DESC LIMIT 1;";              << "WHERE FROM_TIME <= '" << date.Data()
1780              << "' ORDER BY FROM_TIME DESC LIMIT 1) "
1781              << "UNION "
1782              << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1783              << "WHERE FROM_TIME > '" << date.Data()
1784              << "' ORDER BY FROM_TIME ASC LIMIT 1)";
1785    
1786    return Query_GL_TLE_go(myquery.str(), dbc);    return DoQuery(myquery.str().c_str(), dbc);
1787  }  }
1788    
1789    
1790  // ****************************************************  //
1791  /**  // Build a query and call DoQuery.
1792   * Function to query the GL_TLE table of the DB.  //
1793   *  // time is the UTC date in unix time (UTC) and dbc is the connection
1794   * 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
1795   * is requested.  // previous date and the immediatly next one.
1796   *  //
1797   * Return the pointer to a cTle object that has the closest and  // Returns the value returned by DoQuery().
1798   * previous date compared with time.  //
1799   *  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){  
1800    stringstream myquery;    stringstream myquery;
1801    myquery.str("");    myquery.str("");
1802    
1803    myquery << "SELECT TLE1, TLE2, TLE3 FROM GL_TLE "    myquery << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1804            << "WHERE FROM_TIME < '" << date.Data() << "' ORDER BY FROM_TIME DESC LIMIT 1;";              << "WHERE FROM_TIME <= FROM_UNIXTIME('" << time
1805              << "') ORDER BY FROM_TIME DESC LIMIT 1) "
1806              << "UNION "
1807              << "(SELECT ID, TLE1, TLE2, TLE3, UNIX_TIMESTAMP(FROM_TIME) FROM GL_TLE "
1808              << "WHERE FROM_TIME > FROM_UNIXTIME('" << time
1809              << "') ORDER BY FROM_TIME ASC LIMIT 1)";
1810    
1811      return DoQuery(myquery.str().c_str(), dbc);
   return Query_GL_TLE_go(myquery.str(), dbc);  
1812  }  }
1813    
1814    
1815  // ****************************************************  //
1816  /**  // Do the query myquery on the connectio dbc.  Initialize tle,
1817   * Private function used by Query_GL_TLE methods.  // tleFromTime and tleToTime.
1818   *  //
1819   * myquery is the query string.  // We should have two rows (unless the table is old).  From the last
1820   *  // one we only take tleToTime.
1821   * Return the pointer to a cTle object that has the closest and  //
1822   * previous date compared with time.  // Returns 0 for success, 1 for failure.
1823   *  //
1824   * 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  
1825    TSQLResult *result;    TSQLResult *result;
1826    TSQLRow *row;    TSQLRow *row;
1827    
1828      // Set the right time_zone (otherwise horrible things will occur! :)
1829      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1830      dbc->Query("SET time_zone = '+0:00'");
1831    
1832      // Do the query
1833      this->GetGLTABLES()->AddQ();
1834    result = dbc->Query(myquery.Data());    result = dbc->Query(myquery.Data());
1835    if(! result->GetRowCount() ) return NULL;    if(! result->GetRowCount() ) {
1836        cerr << "GL_TLE: query failed: " << myquery.Data() << endl;
1837        return 1;
1838      }
1839    
1840      // Get results
1841      row = result->Next(); // first tle row
1842      tle = GiveTle(row);
1843    
1844      tleFromTime = strtol(row->GetField(4), NULL, 10);
1845    
1846      row = result->Next(); // second tle row
1847      if(row)
1848        tleToTime = strtol(row->GetField(4), NULL, 10);
1849      else {
1850        cerr << "GL_TLE: Warning: using last avaible TLE. Please update GL_TLE table!\n";
1851        tleToTime = UINT_MAX;
1852      }
1853    
1854      delete row;
1855      delete result;
1856    
1857    row = result->Next();    return 0;
1858    tle1 = row->GetField(0);  }
   tle2 = row->GetField(1);  
   tle3 = row->GetField(2);  
1859    
   tle = new cTle(tle1, tle2, tle3);  
1860    
1861    delete result;  //
1862    delete row;  // Build a cTle object from the GL_TLE row.
1863    //
1864    cTle* GL_TLE::GiveTle(TSQLRow *row) {
1865      cTle *thistle = NULL;
1866      string tle1, tle2, tle3;
1867    
1868      // Build cTle object
1869      tle1 = row->GetField(1);
1870      tle2 = row->GetField(2);
1871      tle3 = row->GetField(3);
1872    
1873      thistle = new cTle(tle1, tle2, tle3);
1874    
1875    return tle;    return thistle;
1876  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23