/[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.6 by mocchiut, Fri Dec 12 11:07:09 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 1652  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1656  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1656    //    //
1657    //  printf(" T0 %u toffset is %u \n",T0,toffset);    //  printf(" T0 %u toffset is %u \n",T0,toffset);
1658    //    //
1659    file->Close();    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
1715      //
1716      T0 = 0;
1717      //
1718      stringstream oss;
1719      //
1720      TString name=rname.str().c_str();
1721      UInt_t dworbit = 0;
1722      //  Int_t nlength = name.Length();
1723      delete pResult;      
1724      //
1725      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1726      //
1727      oss.str("");
1728      oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1729      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1730      this->GetGLTABLES()->AddQ();
1731      pResult = dbc->Query(oss.str().c_str());
1732      Bool_t fndit = false;
1733      if ( pResult ){
1734        Row = pResult->Next();
1735        if ( Row ){
1736          //
1737          OBT0 = (UInt_t)atoll(Row->GetField(0));
1738          obtfirst = OBT0;
1739          TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1740          TYPE = (UInt_t)atoll(Row->GetField(2));      
1741          //
1742          oss.str("");
1743          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="
1744              << Row->GetField(3) << ";";
1745          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1746          this->GetGLTABLES()->AddQ();
1747          delete pResult;
1748          pResult = dbc->Query(oss.str().c_str());
1749          if ( pResult ){
1750            Row = pResult->Next();
1751            if ( Row ){
1752              //        printf(" GREAT! the DB structure is the new one! \n");
1753              fndit = true;
1754              dworbit = 1;
1755            };
1756          };
1757        };
1758      };
1759      if ( !fndit ){
1760        //
1761        printf(" ERROR OLD DB! \n");
1762        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1763        //
1764      };
1765      //
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);
1767      T0 = (UInt_t)tu.GetSec();
1768      //
1769      toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1770      //
1771      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1772      //
1773      if ( file ) file->Close();
1774    delete pResult;          delete pResult;      
1775  };  };
1776    

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

  ViewVC Help
Powered by ViewVC 1.1.23