/[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.31 by mocchiut, Sun Sep 9 18:59:41 2007 UTC revision 1.36 by mocchiut, Mon Nov 26 07:58:00 2007 UTC
# Line 24  ClassImp(GL_ROOT); Line 24  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);  ClassImp(GL_TLE);
30  //  //
# Line 63  Bool_t GL_TABLES::IsConnected(TSQLServer Line 64  Bool_t GL_TABLES::IsConnected(TSQLServer
64      return true;      return true;
65    };    };
66    //    //
   //  
   //  
67    //    printf(" host is %s \n",fHost->Data());    //    printf(" host is %s \n",fHost->Data());
68    //    //
69    stringstream myquery;      stringstream myquery;  
# Line 85  Bool_t GL_TABLES::IsConnected(TSQLServer Line 84  Bool_t GL_TABLES::IsConnected(TSQLServer
84        };        };
85      };      };
86    };    };
87    //  printf("porca di quella \n");    //
88    if ( true ) {    if ( true ) {
89      //      //
90      printf(" WARNING: Lost connection to DB! try to recover... \n");      printf(" WARNING: Lost connection to DB! try to recover... \n");
# Line 93  Bool_t GL_TABLES::IsConnected(TSQLServer Line 92  Bool_t GL_TABLES::IsConnected(TSQLServer
92      TString host = fHost->Data();      TString host = fHost->Data();
93      TString user = fUser->Data();      TString user = fUser->Data();
94      TString psw = fPsw->Data();      TString psw = fPsw->Data();
95        dbc->Close();
96      delete dbc;      delete dbc;
97      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
98      //      //
# Line 100  Bool_t GL_TABLES::IsConnected(TSQLServer Line 100  Bool_t GL_TABLES::IsConnected(TSQLServer
100      myquery << "show databases;";      myquery << "show databases;";
101      dbc->Query(myquery.str().c_str());      dbc->Query(myquery.str().c_str());
102      fNquery++;      fNquery++;
     //    printf(" e riporca di quella \n");  
     //  
103      //    if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){      //    if ( dbc->GetErrorCode() != 2013 && dbc->GetErrorCode() != 2006 ){
104      if ( !(dbc->GetErrorCode()) ){      if ( !(dbc->GetErrorCode()) ){
105        //        //
# Line 174  GL_RUN::GL_RUN() { Line 172  GL_RUN::GL_RUN() {
172  }  }
173    
174    
175  void GL_RUN::Clear() {  void GL_RUN::Clear(Option_t *t) {
176    ID                         = 0;    ID                         = 0;
177    ID_RUN_FRAG                = 0;    ID_RUN_FRAG                = 0;
178    ID_ROOT_L0                 = 0;    ID_ROOT_L0                 = 0;
# Line 249  GL_CALO_CALIB::GL_CALO_CALIB(){ Line 247  GL_CALO_CALIB::GL_CALO_CALIB(){
247    FROM_TIME = 0;    FROM_TIME = 0;
248    TO_TIME   = 0;    TO_TIME   = 0;
249    SECTION   = 0;    SECTION   = 0;
250      OBT = 0;
251      PKT = 0;
252      BOOT_NUMBER                = 0;
253      VALIDATION                 = 0;
254    }
255    
256    GL_CALOPULSE_CALIB::GL_CALOPULSE_CALIB(){
257      ID        = 0;
258      ID_ROOT_L0  = 0;
259      EV_ROOT = 0;
260      FROM_TIME = 0;
261      TO_TIME   = 0;
262      SECTION   = 0;
263      PULSED_STRIP = 0;
264      PULSE_AMPLITUDE = 0;
265      OBT = 0;
266      PKT = 0;
267      BOOT_NUMBER                = 0;
268      VALIDATION                 = 0;
269  }  }
270    
271  GL_S4_CALIB::GL_S4_CALIB(){  GL_S4_CALIB::GL_S4_CALIB(){
# Line 257  GL_S4_CALIB::GL_S4_CALIB(){ Line 274  GL_S4_CALIB::GL_S4_CALIB(){
274    EV_ROOT = 0;    EV_ROOT = 0;
275    FROM_TIME = 0;    FROM_TIME = 0;
276    TO_TIME   = 0;    TO_TIME   = 0;
277    PARAM_FIT0 = 0.;    OBT = 0;
278    PARAM_FIT1 = 0.;    PKT = 0;
279      BOOT_NUMBER                = 0;
280  }  }
281    
282  GL_TIMESYNC::GL_TIMESYNC(){  GL_TIMESYNC::GL_TIMESYNC(){
283    obtfirst = 0;    obtfirst = 0;
284    pktfirst = 0;    pktfirst = 0;
285    toffset  = 0;    ID_RESURS_OFFSET  = 0;
286    //  ID       = 0;    ID       = 0;
287    //  ID_RAW   = 0;    ID_RAW   = 0;
288    OBT0     = 0;    OBT0     = 0;
289    TIMESYNC = 0;    TIMESYNC = 0;
290    TYPE     = 0;    TYPE     = 0;
# Line 1297  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1315  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1315    pResult->Delete();    pResult->Delete();
1316    return 0;    return 0;
1317  };  };
1318    
1319    
1320    // ****************************************************
1321    /**
1322     * Function to query the GL_CALOPULSE_CALIB table of the DB.
1323     *
1324     * \param  run starting time
1325     * \return struct of type GL_CALOPULSE_CALIB_data, which stores the query result
1326     */
1327    Int_t GL_CALOPULSE_CALIB::Query_GL_CALOPULSE_CALIB(UInt_t time, UInt_t section, UInt_t pampli, TSQLServer *dbc){
1328      // MySQL variables
1329      TSQLResult *pResult;
1330      TSQLRow *Row;
1331      int t;
1332      stringstream myquery;
1333      //
1334      // select the correct calibration i.e. the closest to our time
1335      //
1336      myquery.str("");
1337      myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALOPULSE_CALIB where SECTION=" << section;
1338      myquery << " and PULSE_AMPLITUDE=" << pampli;
1339      myquery << " and VALIDATION=1 and (PULSED_STRIP IS NULL OR PULSED_STRIP<100) ORDER BY ABS(" << time << "-FROM_TIME) asc limit 1;";
1340      //  printf(" myq is %s \n",myquery.str().c_str());
1341      //
1342      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1343      this->GetGLTABLES()->AddQ();
1344      pResult = dbc->Query(myquery.str().c_str());
1345      //
1346      if( !pResult ) return(-54);
1347      //
1348      Row = pResult->Next();
1349      //
1350      if( !Row ) return (-54);
1351      //
1352      // store infos and exit
1353      //
1354      for( t = 0; t < pResult->GetFieldCount(); t++){
1355        //    printf(" field %i is %s \n",t,Row->GetField(t));
1356        if (t==0) ID_ROOT_L0  = (UInt_t)atoll(Row->GetField(t));
1357        if (t==1) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1358        if (t==2) TO_TIME   = (UInt_t)atoll(Row->GetField(t));            
1359        if (t==3) EV_ROOT = (UInt_t)atoll(Row->GetField(t));
1360      };
1361      pResult->Delete();
1362      return 0;
1363    };
1364    
1365    
1366  // ****************************************************  // ****************************************************
1367  /**  /**
1368   * Function to query the GL_S4_CALIB table of the DB.   * Function to query the GL_S4_CALIB table of the DB.
# Line 1313  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn Line 1379  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn
1379    stringstream myquery;    stringstream myquery;
1380    // ----------------    // ----------------
1381    myquery.str("");    myquery.str("");
1382    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;
1383    myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1384    //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";          //  myquery << " ORDER BY FROM_TIME DESC LIMIT 1;";      
1385    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
# Line 1325  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn Line 1391  Int_t GL_S4_CALIB::Query_GL_S4_CALIB(UIn
1391        if( Row == NULL ) break;        if( Row == NULL ) break;
1392        for( t = 0; t < pResult->GetFieldCount(); t++){        for( t = 0; t < pResult->GetFieldCount(); t++){
1393          if (t==0) ID               = (UInt_t)atoll(Row->GetField(t));          if (t==0) ID               = (UInt_t)atoll(Row->GetField(t));
1394            if (t==1) ID_ROOT_L0  = (UInt_t)atoll(Row->GetField(t));          if (t==1) ID_ROOT_L0  = (UInt_t)atoll(Row->GetField(t));
1395            if (t==2) EV_ROOT    = (UInt_t)atoll(Row->GetField(t));          if (t==2) EV_ROOT    = (UInt_t)atoll(Row->GetField(t));
1396            if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t));          if (t==3) FROM_TIME = (UInt_t)atoll(Row->GetField(t));
1397            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));  
1398        };        };
1399    };    };
1400    delete pResult;        delete pResult;    
# Line 1499  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1563  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1563    TString name=rname.str().c_str();    TString name=rname.str().c_str();
1564    UInt_t dworbit = 0;    UInt_t dworbit = 0;
1565    Int_t nlength = name.Length();    Int_t nlength = name.Length();
   if ( nlength < 5 ) return;  
   TString dwo = 0;  
   for (Int_t i = 0; i<5; i++){  
     dwo.Append(name[i],1);  
   };  
   if ( dwo.IsDigit() ){  
     dworbit = (UInt_t)dwo.Atoi();  
   } else {  
     dwo="";  
     for (Int_t i = 8; i<13; i++){  
       dwo.Append(name[i],1);  
     };      
     if ( dwo.IsDigit() ){  
       dworbit = (UInt_t)dwo.Atoi();  
     } else {  
       dworbit = 1;  
     };  
   };  
1566    //    //
1567      // Is not a special file
1568    //    //
1569    if ( !Row ){    if ( !Row ){
1570        delete pResult;      
1571        //
1572        // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1573        //
1574      oss.str("");      oss.str("");
1575      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 ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";";
         << dworbit << " order by FROM_ORBIT desc limit 1;";  
1576      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1577      this->GetGLTABLES()->AddQ();      this->GetGLTABLES()->AddQ();
1578      pResult = dbc->Query(oss.str().c_str());      pResult = dbc->Query(oss.str().c_str());
1579      Row = pResult->Next();      Bool_t fndit = false;
1580      if ( !Row ){      if ( pResult ){
1581        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");        Row = pResult->Next();
1582        return;        if ( Row ){
1583            oss.str("");
1584            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="
1585                << Row->GetField(0) << ";";
1586            if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1587            this->GetGLTABLES()->AddQ();
1588            pResult = dbc->Query(oss.str().c_str());
1589            if ( pResult ){
1590              Row = pResult->Next();
1591              if ( Row ){
1592                //      printf(" GREAT! the DB structure is the new one! \n");
1593                fndit = true;
1594                dworbit = 1;
1595              };
1596            };
1597          };
1598        };
1599        if ( !fndit ){
1600          delete pResult;      
1601          //
1602          printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n");
1603          //
1604          // Old code, we must trust the filename
1605          //
1606          if ( nlength < 5 ) return;
1607          TString dwo = 0;
1608          for (Int_t i = 0; i<5; i++){
1609            dwo.Append(name[i],1);
1610          };
1611          if ( dwo.IsDigit() ){
1612            dworbit = (UInt_t)dwo.Atoi();
1613          } else {
1614            dwo="";
1615            for (Int_t i = 8; i<13; i++){
1616              dwo.Append(name[i],1);
1617            };    
1618            if ( dwo.IsDigit() ){
1619              dworbit = (UInt_t)dwo.Atoi();
1620            } else {
1621              dworbit = 1;
1622            };
1623          };    
1624          //
1625          oss.str("");
1626          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< "
1627              << dworbit << " order by FROM_ORBIT desc limit 1;";
1628          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1629          this->GetGLTABLES()->AddQ();
1630          pResult = dbc->Query(oss.str().c_str());
1631          Row = pResult->Next();
1632          if ( !Row ){
1633            printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1634            return;
1635          };
1636      };      };
1637    };    };
1638    //    //

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

  ViewVC Help
Powered by ViewVC 1.1.23