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

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

  ViewVC Help
Powered by ViewVC 1.1.23