/[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.5 by mocchiut, Fri Nov 28 09:10:15 2008 UTC revision 1.10 by pam-fi, Wed Aug 5 18:48:44 2009 UTC
# Line 7  Line 7 
7  //  //
8  #include <sstream>  #include <sstream>
9  #include <iostream>  #include <iostream>
10    #include <limits.h>
11  //  //
12  #include <TFile.h>  #include <TFile.h>
13  #include <TTree.h>  #include <TTree.h>
# Line 56  void GL_TABLES::Set(TString host, TStrin Line 57  void GL_TABLES::Set(TString host, TStrin
57    mp = psw.Data();    mp = psw.Data();
58  };  };
59    
60  Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){  //Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){
61    Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){
62    //    //
63    //    //
64    //    //
# Line 92  Bool_t GL_TABLES::IsConnected(TSQLServer Line 94  Bool_t GL_TABLES::IsConnected(TSQLServer
94      TString host = fHost->Data();      TString host = fHost->Data();
95      TString user = fUser->Data();      TString user = fUser->Data();
96      TString psw = fPsw->Data();      TString psw = fPsw->Data();
97      dbc->Close();      if ( dbc ){
98      delete dbc;        dbc->Close();
99          delete dbc;
100        };
101      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
102      //      //
103      myquery.str("");      myquery.str("");
# Line 1589  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1593  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1593      T->GetEntry(0);      T->GetEntry(0);
1594      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
1595      pktfirst = ph->GetCounter();      pktfirst = ph->GetCounter();
1596      obtfirst = ph->GetOrbitalTime();        //    obtfirst = ph->GetOrbitalTime();  
1597        //
1598      };
1599      //
1600      // look for Resurs offset
1601      //
1602      T0 = 0;
1603      //
1604      stringstream oss;
1605      //
1606      TString name=rname.str().c_str();
1607      UInt_t dworbit = 0;
1608      //  Int_t nlength = name.Length();
1609      delete pResult;      
1610      //
1611      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1612      //
1613      oss.str("");
1614      oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1615      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1616      this->GetGLTABLES()->AddQ();
1617      pResult = dbc->Query(oss.str().c_str());
1618      Bool_t fndit = false;
1619      if ( pResult ){
1620        Row = pResult->Next();
1621        if ( Row ){
1622          //
1623          OBT0 = (UInt_t)atoll(Row->GetField(0));
1624          obtfirst = OBT0;
1625          TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1626          TYPE = (UInt_t)atoll(Row->GetField(2));      
1627          //
1628          oss.str("");
1629          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="
1630              << Row->GetField(3) << ";";
1631          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1632          this->GetGLTABLES()->AddQ();
1633          delete pResult;
1634          pResult = dbc->Query(oss.str().c_str());
1635          if ( pResult ){
1636            Row = pResult->Next();
1637            if ( Row ){
1638              //        printf(" GREAT! the DB structure is the new one! \n");
1639              fndit = true;
1640              dworbit = 1;
1641            };
1642          };
1643        };
1644      };
1645      if ( !fndit ){
1646        //
1647        printf(" ERROR OLD DB! \n");
1648        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1649        //
1650      };
1651      //
1652      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);
1653      T0 = (UInt_t)tu.GetSec();
1654      //
1655      toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1656      //
1657      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1658      //
1659      if ( file ) file->Close();
1660      delete pResult;      
1661    };
1662    
1663    GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){
1664      // MySQL variables
1665      TFile *file = 0;
1666      UInt_t idtsy = 0;
1667      //
1668      TSQLResult *pResult;
1669      TSQLRow *Row = 0;
1670      stringstream myquery;
1671      stringstream rname;
1672      //  pcksList packetsNames;
1673      //  pcksList::iterator Iter;
1674      //  getPacketsNames(packetsNames);
1675      rname.str("");
1676      // ----------------
1677      myquery.str("");
1678      myquery << "select ";
1679      myquery << "PATH";
1680      myquery << ",NAME,ID_TIMESYNC";
1681      myquery << " from GL_ROOT where ";
1682      myquery << type.Data();
1683      myquery << "=" << id << ";";    
1684      //
1685      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1686      this->GetGLTABLES()->AddQ();
1687      pResult = dbc->Query(myquery.str().c_str());
1688      if( pResult->GetRowCount() ){
1689        Row = pResult->Next();      
1690        if( Row ){
1691          stringstream fname;
1692          fname.str("");
1693          fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1694          rname << Row->GetField(1);
1695          if ( usel0file ) file = new TFile(fname.str().c_str(),"READ");
1696          idtsy = (UInt_t)atoll(Row->GetField(2));
1697        };
1698      };
1699      //
1700      if ( usel0file && file && file->IsOpen() ){
1701        TTree *T=(TTree*)file->Get("Physics");
1702        pamela::EventHeader *eh = 0;
1703        pamela::PscuHeader *ph = 0;
1704        T->SetBranchAddress("Header", &eh);
1705        //
1706        T->GetEntry(0);
1707        ph = eh->GetPscuHeader();
1708        pktfirst = ph->GetCounter();
1709        //    obtfirst = ph->GetOrbitalTime();  
1710      //      //
1711    };    };
1712      if ( !usel0file ) pktfirst = 0;
1713    //    //
1714    // look for Resurs offset    // look for Resurs offset
1715    //    //
# Line 1617  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1735  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1735      if ( Row ){      if ( Row ){
1736        //        //
1737        OBT0 = (UInt_t)atoll(Row->GetField(0));        OBT0 = (UInt_t)atoll(Row->GetField(0));
1738          obtfirst = OBT0;
1739        TIMESYNC = (UInt_t)atoll(Row->GetField(1));        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1740        TYPE = (UInt_t)atoll(Row->GetField(2));              TYPE = (UInt_t)atoll(Row->GetField(2));      
1741        //        //
# Line 1647  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1766  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1766    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);
1767    T0 = (UInt_t)tu.GetSec();    T0 = (UInt_t)tu.GetSec();
1768    //    //
1769    toffset = TIMESYNC - (UInt_t)(this->DBobt(OBT0/1000)) + T0;    toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1770    //    //
1771    //  printf(" T0 %u toffset is %u \n",T0,toffset);    //  printf(" T0 %u toffset is %u \n",T0,toffset);
1772    //    //
1773    file->Close();    if ( file ) file->Close();
1774    delete pResult;          delete pResult;      
1775  };  };
1776    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.10

  ViewVC Help
Powered by ViewVC 1.1.23