/[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.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 1589  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();  
1596        //
1597      };
1598      //
1599      // look for Resurs offset
1600      //
1601      T0 = 0;
1602      //
1603      stringstream oss;
1604      //
1605      TString name=rname.str().c_str();
1606      UInt_t dworbit = 0;
1607      //  Int_t nlength = name.Length();
1608      delete pResult;      
1609      //
1610      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1611      //
1612      oss.str("");
1613      oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1614      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1615      this->GetGLTABLES()->AddQ();
1616      pResult = dbc->Query(oss.str().c_str());
1617      Bool_t fndit = false;
1618      if ( pResult ){
1619        Row = pResult->Next();
1620        if ( Row ){
1621          //
1622          OBT0 = (UInt_t)atoll(Row->GetField(0));
1623          obtfirst = OBT0;
1624          TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1625          TYPE = (UInt_t)atoll(Row->GetField(2));      
1626          //
1627          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 ID="
1629              << Row->GetField(3) << ";";
1630          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1631          this->GetGLTABLES()->AddQ();
1632          delete pResult;
1633          pResult = dbc->Query(oss.str().c_str());
1634          if ( pResult ){
1635            Row = pResult->Next();
1636            if ( Row ){
1637              //        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);
1652      T0 = (UInt_t)tu.GetSec();
1653      //
1654      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("");
1677      myquery << "select ";
1678      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;  
1685      this->GetGLTABLES()->AddQ();
1686      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    // look for Resurs offset
1714    //    //
# Line 1617  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1734  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1734      if ( Row ){      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        //        //
# Line 1647  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1765  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
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);    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();    T0 = (UInt_t)tu.GetSec();
1767    //    //
1768    toffset = TIMESYNC - (UInt_t)(this->DBobt(OBT0/1000)) + T0;    toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1769    //    //
1770    //  printf(" T0 %u toffset is %u \n",T0,toffset);    //  printf(" T0 %u toffset is %u \n",T0,toffset);
1771    //    //
1772    file->Close();    if ( file ) file->Close();
1773    delete pResult;          delete pResult;      
1774  };  };
1775    

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

  ViewVC Help
Powered by ViewVC 1.1.23