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

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

  ViewVC Help
Powered by ViewVC 1.1.23