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

Diff of /chewbacca/YodaProfiler/src/GLTables.cpp

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

revision 1.2 by mocchiut, Thu Sep 25 09:03:19 2008 UTC revision 1.8 by mocchiut, Mon Jun 15 11:20:33 2009 UTC
# Line 92  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();      if ( dbc ){
96      delete dbc;        dbc->Close();
97          delete dbc;
98        };
99      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
100      //      //
101      myquery.str("");      myquery.str("");
# Line 218  GL_ROOT::GL_ROOT(){ Line 220  GL_ROOT::GL_ROOT(){
220    NAME   = "";    NAME   = "";
221  }  }
222    
223    GL_RAW::GL_RAW(){
224      ID     = 0;
225      PATH   = "";
226      NAME   = "";
227      BOOT_NUMBER = 0;
228    }
229    
230  GL_PARAM::GL_PARAM(){  GL_PARAM::GL_PARAM(){
231    ID     = 0;    ID     = 0;
232    PATH   = "";    PATH   = "";
# Line 1309  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1318  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1318    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1319    this->GetGLTABLES()->AddQ();    this->GetGLTABLES()->AddQ();
1320    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1321    //  printf(" mysquery is %s\n",myquery.str().c_str());    // printf(" mysquery is %s\n",myquery.str().c_str());
1322    //    //
1323    if( !pResult->GetRowCount() ) return(-54);    if( !pResult->GetRowCount() ) return(-54);
1324    Row = pResult->Next();    Row = pResult->Next();
# Line 1347  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1356  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1356    //    //
1357    // if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one    // if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one
1358    //    //
1359    if ( (time-myfromtime)>28500 ){    if ( (time-myfromtime)>28500 && myfromtime > 0 ){
1360      //      //
1361      myquery.str("");      myquery.str("");
1362      myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section;      myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section;
# Line 1539  void GL_RUN::GetLevel2Struct(cGLRun *l2) Line 1548  void GL_RUN::GetLevel2Struct(cGLRun *l2)
1548  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
1549    // MySQL variables    // MySQL variables
1550    TFile *file = 0;    TFile *file = 0;
1551    UInt_t idraw = 0;    UInt_t idtsy = 0;
1552    //    //
1553    TSQLResult *pResult;    TSQLResult *pResult;
1554    TSQLRow *Row;    TSQLRow *Row = 0;
1555    stringstream myquery;    stringstream myquery;
1556    stringstream rname;    stringstream rname;
1557    //  pcksList packetsNames;    //  pcksList packetsNames;
# Line 1553  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1562  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1562    myquery.str("");    myquery.str("");
1563    myquery << "select ";    myquery << "select ";
1564    myquery << "PATH";    myquery << "PATH";
1565    myquery << ",NAME,ID_RAW";    myquery << ",NAME,ID_TIMESYNC";
1566    myquery << " from GL_ROOT where ";    myquery << " from GL_ROOT where ";
1567    myquery << type.Data();    myquery << type.Data();
1568    myquery << "=" << id << ";";        myquery << "=" << id << ";";    
# Line 1569  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1578  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1578        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1579        rname << Row->GetField(1);        rname << Row->GetField(1);
1580        file = new TFile(fname.str().c_str(),"READ");        file = new TFile(fname.str().c_str(),"READ");
1581        idraw = (UInt_t)atoll(Row->GetField(2));        idtsy = (UInt_t)atoll(Row->GetField(2));
1582      };      };
1583    };    };
1584    //    //
# Line 1582  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1591  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1591      T->GetEntry(0);      T->GetEntry(0);
1592      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
1593      pktfirst = ph->GetCounter();      pktfirst = ph->GetCounter();
1594      obtfirst = ph->GetOrbitalTime();        //    obtfirst = ph->GetOrbitalTime();  
     //  
 //     code = eh->GetCounter();  
 //     UInt_t en = 0;  
 //     for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){  
 //       en = code->Get(GetPacketType(*Iter));  
 //       if ( !strcmp("CalibCalPed",*Iter) || !strcmp("CalibTrk1",*Iter) || !strcmp("CalibTrk2",*Iter) || !strcmp("CalibS4",*Iter) ){  
 //      //  
 //      TTree *TC = 0;  
 //      TC = (TTree*)file->Get("CalibCalPed");  
 //      if ( !TC || TC->IsZombie() ) return;  
 //      EventHeader *ehc = 0;  
 //      PscuHeader *phc = 0;  
 //      TC->SetBranchAddress("Header", &ehc);  
 //      TC->GetEntry(0);  
 //      phc = ehc->GetPscuHeader();  
 //      pktfirst = phc->GetCounter();  
 //      obtfirst = phc->GetOrbitalTime();    
 //       //  
 //       };  
 //     };    
1595      //      //
1596    };    };
1597    //    //
# Line 1610  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1599  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1599    //    //
1600    T0 = 0;    T0 = 0;
1601    //    //
   //  
1602    stringstream oss;    stringstream oss;
   TString frn = rname.str().c_str();  
   frn = frn.ReplaceAll(".root",5,".pam",4);  
   oss.str("");  
   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='"  
       << frn.Data() << "';";  
   if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;    
   this->GetGLTABLES()->AddQ();  
   pResult = dbc->Query(oss.str().c_str());  
   Row = pResult->Next();  
1603    //    //
1604    TString name=rname.str().c_str();    TString name=rname.str().c_str();
1605    UInt_t dworbit = 0;    UInt_t dworbit = 0;
1606    Int_t nlength = name.Length();    //  Int_t nlength = name.Length();
1607      delete pResult;      
1608    //    //
1609    // Is not a special file    // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1610    //    //
1611    if ( !Row ){    oss.str("");
1612      delete pResult;          oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1613      //    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1614      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset    this->GetGLTABLES()->AddQ();
1615      //    pResult = dbc->Query(oss.str().c_str());
1616      oss.str("");    Bool_t fndit = false;
1617      oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";";    if ( pResult ){
1618      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;        Row = pResult->Next();
1619      this->GetGLTABLES()->AddQ();      if ( Row ){
     pResult = dbc->Query(oss.str().c_str());  
     Bool_t fndit = false;  
     if ( pResult ){  
       Row = pResult->Next();  
       if ( Row ){  
         oss.str("");  
         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="  
             << Row->GetField(0) << ";";  
         if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;    
         this->GetGLTABLES()->AddQ();  
         pResult = dbc->Query(oss.str().c_str());  
         if ( pResult ){  
           Row = pResult->Next();  
           if ( Row ){  
             //      printf(" GREAT! the DB structure is the new one! \n");  
             fndit = true;  
             dworbit = 1;  
           };  
         };  
       };  
     };  
     if ( !fndit ){  
       delete pResult;        
       //  
       printf(" OK, you got an error because this is the old database\n Using backward compability code, hence you can continue safetly \n");  
       //  
       // Old code, we must trust the filename  
1620        //        //
1621        if ( nlength < 5 ) return;        OBT0 = (UInt_t)atoll(Row->GetField(0));
1622        TString dwo = 0;        obtfirst = OBT0;
1623        for (Int_t i = 0; i<5; i++){        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1624          dwo.Append(name[i],1);        TYPE = (UInt_t)atoll(Row->GetField(2));      
       };  
       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;  
         };  
       };      
1625        //        //
1626        oss.str("");        oss.str("");
1627        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 ID="
1628            << dworbit << " order by FROM_ORBIT desc limit 1;";            << Row->GetField(3) << ";";
1629        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1630        this->GetGLTABLES()->AddQ();        this->GetGLTABLES()->AddQ();
1631          delete pResult;
1632        pResult = dbc->Query(oss.str().c_str());        pResult = dbc->Query(oss.str().c_str());
1633        Row = pResult->Next();        if ( pResult ){
1634        if ( !Row ){          Row = pResult->Next();
1635          printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");          if ( Row ){
1636          return;            //        printf(" GREAT! the DB structure is the new one! \n");
1637              fndit = true;
1638              dworbit = 1;
1639            };
1640        };        };
1641      };      };
1642    };    };
1643      if ( !fndit ){
1644        //
1645        printf(" ERROR OLD DB! \n");
1646        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1647        //
1648      };
1649    //    //
1650    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);    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);
1651    T0 = (UInt_t)tu.GetSec();    T0 = (UInt_t)tu.GetSec();
1652    //    //
1653    // look for the correct timesync entry    toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1654      //
1655      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1656      //
1657      if ( file ) file->Close();
1658      delete pResult;      
1659    };
1660    
1661    GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){
1662      // MySQL variables
1663      TFile *file = 0;
1664      UInt_t idtsy = 0;
1665    //    //
1666      TSQLResult *pResult;
1667      TSQLRow *Row = 0;
1668      stringstream myquery;
1669      stringstream rname;
1670      //  pcksList packetsNames;
1671      //  pcksList::iterator Iter;
1672      //  getPacketsNames(packetsNames);
1673      rname.str("");
1674      // ----------------
1675    myquery.str("");    myquery.str("");
1676    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "    myquery << "select ";
1677        << " WHERE ID_RAW = " << idraw    myquery << "PATH";
1678        << ";";    myquery << ",NAME,ID_TIMESYNC";
1679      myquery << " from GL_ROOT where ";
1680      myquery << type.Data();
1681      myquery << "=" << id << ";";    
1682      //
1683    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1684    this->GetGLTABLES()->AddQ();    this->GetGLTABLES()->AddQ();
1685    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1686      if( pResult->GetRowCount() ){
1687        Row = pResult->Next();      
1688        if( Row ){
1689          stringstream fname;
1690          fname.str("");
1691          fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1692          rname << Row->GetField(1);
1693          if ( usel0file ) file = new TFile(fname.str().c_str(),"READ");
1694          idtsy = (UInt_t)atoll(Row->GetField(2));
1695        };
1696      };
1697      //
1698      if ( usel0file && file && file->IsOpen() ){
1699        TTree *T=(TTree*)file->Get("Physics");
1700        pamela::EventHeader *eh = 0;
1701        pamela::PscuHeader *ph = 0;
1702        T->SetBranchAddress("Header", &eh);
1703        //
1704        T->GetEntry(0);
1705        ph = eh->GetPscuHeader();
1706        pktfirst = ph->GetCounter();
1707        //    obtfirst = ph->GetOrbitalTime();  
1708        //
1709      };
1710      if ( !usel0file ) pktfirst = 0;
1711      //
1712      // look for Resurs offset
1713      //
1714      T0 = 0;
1715      //
1716      stringstream oss;
1717      //
1718      TString name=rname.str().c_str();
1719      UInt_t dworbit = 0;
1720      //  Int_t nlength = name.Length();
1721      delete pResult;      
1722      //
1723      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1724      //
1725      oss.str("");
1726      oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1727      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1728      this->GetGLTABLES()->AddQ();
1729      pResult = dbc->Query(oss.str().c_str());
1730      Bool_t fndit = false;
1731    if ( pResult ){    if ( pResult ){
1732      Row = pResult->Next();      Row = pResult->Next();
1733      if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){      if ( Row ){
1734          //
1735        OBT0 = (UInt_t)atoll(Row->GetField(0));        OBT0 = (UInt_t)atoll(Row->GetField(0));
1736          obtfirst = OBT0;
1737        TIMESYNC = (UInt_t)atoll(Row->GetField(1));        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1738        TYPE = (UInt_t)atoll(Row->GetField(2));        TYPE = (UInt_t)atoll(Row->GetField(2));      
1739        toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0;        //
1740          oss.str("");
1741          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="
1742              << Row->GetField(3) << ";";
1743          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1744          this->GetGLTABLES()->AddQ();
1745          delete pResult;
1746          pResult = dbc->Query(oss.str().c_str());
1747          if ( pResult ){
1748            Row = pResult->Next();
1749            if ( Row ){
1750              //        printf(" GREAT! the DB structure is the new one! \n");
1751              fndit = true;
1752              dworbit = 1;
1753            };
1754          };
1755      };      };
1756    };    };
1757      if ( !fndit ){
1758        //
1759        printf(" ERROR OLD DB! \n");
1760        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1761        //
1762      };
1763      //
1764      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);
1765      T0 = (UInt_t)tu.GetSec();
1766      //
1767      toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1768      //
1769      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1770    //    //
1771    file->Close();    if ( file ) file->Close();
1772    delete pResult;          delete pResult;      
1773  };  };
1774    
# Line 1731  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1779  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1779   */   */
1780  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){    UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){  
1781    //    //
1782      //  printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1783    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1784    //    //
1785  };  };
# Line 1769  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n Line 1818  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n
1818   */   */
1819  Long64_t GL_TIMESYNC::DBobt(UInt_t obt){    Long64_t GL_TIMESYNC::DBobt(UInt_t obt){  
1820    //    //
1821    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){
1822      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1823    };    };
1824    //    //
1825    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1826      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
1827    };    };
1828    //    //

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.23