/[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.4 by pam-fi, Fri Oct 31 11:21:43 2008 UTC revision 1.12 by mocchiut, Tue Dec 15 09:58:25 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 17  Line 18 
18  #include <GLTables.h>  #include <GLTables.h>
19  #include <sgp4.h>  #include <sgp4.h>
20  //  //
21    ClassImp(Q2TH);
22  ClassImp(GL_TABLES);  ClassImp(GL_TABLES);
23  ClassImp(GL_TRK_CALIB);  ClassImp(GL_TRK_CALIB);
24  ClassImp(GL_RUN);  ClassImp(GL_RUN);
# Line 30  ClassImp(GL_TLE); Line 32  ClassImp(GL_TLE);
32  //  //
33  using namespace std;  using namespace std;
34    
35    Q2TH::Q2TH(TString host, TString user, TString psw){
36      fh = gSystem->ExpandPathName(host.Data());
37      fu = gSystem->ExpandPathName(user.Data());
38      fp = gSystem->ExpandPathName(psw.Data());
39      dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data());
40    };
41    
42    TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){
43      //
44      if ( !strcmp(query.Data(),"help") ){
45        printf(" USAGE: \n");
46        printf(" 1) start root and create Q2TH object with  \n");
47        printf("    Q2TH *qt = new Q2TH()  \n");
48        printf("    or \n");
49        printf("    Q2TH *qt = new Q2TH(\"mysql://srvg-g2-01.ts.infn.it/pamelaProcessing9_TS\",\"pamelaprod_ro\",\"mypassword\")  \n");
50        printf(" 2) query the DB with  \n");
51        printf("    qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\");  \n");
52        printf("    qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",true); this will print numbers on screen \n");
53        printf("    qt->Draw(\"select REAL_TIME_INIT from ROOT_TABLE_MERGING;\",true,\"myhisto\"); this will print numbers on screen and create histo \"myhisto\"\n");
54        printf(" 3) to use your own THxD create it and then query the DB giving as argument the name of histo:   \n");
55        printf("    TH2D *myhisto=new TH2D(\"myhisto\",\"myhisto\",5000,1140000000.,1240000000.,10000,0.,1.) \n");
56        printf("    qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",false,\"myhisto\")\n\n\n");
57    
58        return NULL;
59      };
60      //
61      pResult = dbc->Query(query.Data());
62      //
63      Row = pResult->Next();      
64      //
65      Int_t dim = pResult->GetFieldCount();
66      if ( dim < 1 || dim > 2 ){
67        printf(" Dim == %i not supported yet \n",dim);
68        return NULL;
69      };  
70      //
71      TH1D *h1 = NULL;
72      TH2D *h2 = NULL;
73      Double_t f1 = 0.;
74      Double_t minf1 = numeric_limits<Double_t>::max();
75      Double_t maxf1 = numeric_limits<Double_t>::min();
76      Double_t f2 = 0.;  
77      Double_t minf2 = numeric_limits<Double_t>::max();
78      Double_t maxf2 = numeric_limits<Double_t>::min();
79      //
80      while ( Row ){    
81        f1 = (Double_t)atof(Row->GetField(0));
82        if ( f1 > maxf1 ) maxf1 = f1;
83        if ( f1 < minf1 ) minf1 = f1;
84        if ( dim == 2 ){
85          f2 = (Double_t)atof(Row->GetField(1));
86          if ( f2 > maxf2 ) maxf2 = f2;
87          if ( f2 < minf2 ) minf2 = f2;
88    
89        };
90        Row = pResult->Next();
91      };
92      pResult->Delete();
93      //
94            
95      //
96      Int_t f1bin = 70;
97      Int_t f2bin = 70;
98      if ( dim == 1 ){
99        f1bin = int((maxf1-minf1)/1000.);
100        if ( f1bin < 70 ) f1bin = 70;
101        if ( f1bin > 1000 ) f1bin = 1000;
102            if ( !strcmp(hname.Data(),"q2th") ) hname += "1";
103            //      h1 =  dynamic_cast<TH1D*>(gDirectory->FindObject(hname.Data()));
104            h1 = (TH1D*)(gDirectory->FindObject(hname.Data()));
105            if ( !strcmp(hname.Data(),"q2th1") ){
106             if ( h1 ) h1->Delete();
107            };
108            if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02);
109        //    h1->SetBit(TH1::kCanRebin);
110        if ( verbose ) printf("\n\n Row     %s \n",pResult->GetFieldName(0));
111      };
112      if ( dim == 2 ){
113        f2bin = int((maxf2-minf2)/1000.);
114        if ( f2bin < 70 ) f2bin = 70;
115        if ( f2bin > 1000 ) f2bin = 1000;
116            if ( !strcmp(hname.Data(),"q2th") ) hname += "2";
117            //      h2 =  dynamic_cast<TH2D*>(gDirectory->FindObject(hname.Data()));
118            h2 =  (TH2D*)(gDirectory->FindObject(hname.Data()));
119            if ( !strcmp(hname.Data(),"q2th2") ){
120             if ( h2 ) h2->Delete();
121            };
122            if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02);
123        //    h2->SetBit(TH2::kCanRebin);
124        if ( verbose ) printf("\n\n Row     %s     %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1));
125      };
126      //
127      pResult = dbc->Query(query.Data());
128      //
129      Row = pResult->Next();      
130      //
131      Int_t r = 0;
132      //
133      while ( Row ){    
134        f1 = (Double_t)atof(Row->GetField(0));
135        if ( dim == 1 ){
136          if ( verbose ) printf(" %i     %f \n",r,f1);
137          h1->Fill(f1);
138        } else {
139          f2 = (Double_t)atof(Row->GetField(1));
140          if ( verbose ) printf(" %i     %f     %f \n",r,f1,f2);
141          h2->Fill(f1,f2);
142        };
143        r++;
144        Row = pResult->Next();
145      };
146      //
147      TCanvas *c = NULL;
148      TString cname = Form("%sc",hname.Data());
149      //  c =  dynamic_cast<TCanvas*>(gDirectory->FindObject(hname.Data()));
150      c =  (TCanvas*)(gDirectory->FindObject(cname.Data()));
151      if ( !c ) c = new TCanvas(Form("%sc",cname.Data()));
152      c->Clear();
153      c->cd();
154      if ( dim == 1 ) h1->Draw();
155      if ( dim == 2 ) h2->Draw();
156      //
157      pResult->Delete();
158      if ( dim == 1 ) return h1;
159      if ( dim == 2 ) return h2;
160      //
161      return NULL;
162    };
163    
164  GL_TABLES::GL_TABLES(){  GL_TABLES::GL_TABLES(){
165  };  };
166    
# Line 56  void GL_TABLES::Set(TString host, TStrin Line 187  void GL_TABLES::Set(TString host, TStrin
187    mp = psw.Data();    mp = psw.Data();
188  };  };
189    
190  Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){  //Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){
191    Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){
192    //    //
193    //    //
194    //    //
# Line 92  Bool_t GL_TABLES::IsConnected(TSQLServer Line 224  Bool_t GL_TABLES::IsConnected(TSQLServer
224      TString host = fHost->Data();      TString host = fHost->Data();
225      TString user = fUser->Data();      TString user = fUser->Data();
226      TString psw = fPsw->Data();      TString psw = fPsw->Data();
227      dbc->Close();      if ( dbc ){
228      delete dbc;        dbc->Close();
229          delete dbc;
230        };
231      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
232      //      //
233      myquery.str("");      myquery.str("");
# Line 1316  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1450  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1450    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1451    this->GetGLTABLES()->AddQ();    this->GetGLTABLES()->AddQ();
1452    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1453    //  printf(" mysquery is %s\n",myquery.str().c_str());    // printf(" mysquery is %s\n",myquery.str().c_str());
1454    //    //
1455    if( !pResult->GetRowCount() ) return(-54);    if( !pResult->GetRowCount() ) return(-54);
1456    Row = pResult->Next();    Row = pResult->Next();
# Line 1546  void GL_RUN::GetLevel2Struct(cGLRun *l2) Line 1680  void GL_RUN::GetLevel2Struct(cGLRun *l2)
1680  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
1681    // MySQL variables    // MySQL variables
1682    TFile *file = 0;    TFile *file = 0;
1683    UInt_t idraw = 0;    UInt_t idtsy = 0;
1684    //    //
1685    TSQLResult *pResult;    TSQLResult *pResult;
1686    TSQLRow *Row;    TSQLRow *Row = 0;
1687    stringstream myquery;    stringstream myquery;
1688    stringstream rname;    stringstream rname;
1689    //  pcksList packetsNames;    //  pcksList packetsNames;
# Line 1560  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1694  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1694    myquery.str("");    myquery.str("");
1695    myquery << "select ";    myquery << "select ";
1696    myquery << "PATH";    myquery << "PATH";
1697    myquery << ",NAME,ID_RAW";    myquery << ",NAME,ID_TIMESYNC";
1698    myquery << " from GL_ROOT where ";    myquery << " from GL_ROOT where ";
1699    myquery << type.Data();    myquery << type.Data();
1700    myquery << "=" << id << ";";        myquery << "=" << id << ";";    
# Line 1576  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1710  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1710        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1711        rname << Row->GetField(1);        rname << Row->GetField(1);
1712        file = new TFile(fname.str().c_str(),"READ");        file = new TFile(fname.str().c_str(),"READ");
1713        idraw = (UInt_t)atoll(Row->GetField(2));        idtsy = (UInt_t)atoll(Row->GetField(2));
1714      };      };
1715    };    };
1716    //    //
# Line 1589  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1723  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1723      T->GetEntry(0);      T->GetEntry(0);
1724      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
1725      pktfirst = ph->GetCounter();      pktfirst = ph->GetCounter();
1726      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();    
 //       //  
 //       };  
 //     };    
1727      //      //
1728    };    };
1729    //    //
# Line 1617  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1731  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1731    //    //
1732    T0 = 0;    T0 = 0;
1733    //    //
   //  
1734    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();  
1735    //    //
1736    TString name=rname.str().c_str();    TString name=rname.str().c_str();
1737    UInt_t dworbit = 0;    UInt_t dworbit = 0;
1738    Int_t nlength = name.Length();    //  Int_t nlength = name.Length();
1739      delete pResult;      
1740    //    //
1741    // 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
1742    //    //
1743    if ( !Row ){    oss.str("");
1744      delete pResult;          oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1745      //    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1746      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset    this->GetGLTABLES()->AddQ();
1747      //    pResult = dbc->Query(oss.str().c_str());
1748      oss.str("");    Bool_t fndit = false;
1749      oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";";    if ( pResult ){
1750      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;        Row = pResult->Next();
1751      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  
1752        //        //
1753        if ( nlength < 5 ) return;        OBT0 = (UInt_t)atoll(Row->GetField(0));
1754        TString dwo = 0;        obtfirst = OBT0;
1755        for (Int_t i = 0; i<5; i++){        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1756          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;  
         };  
       };      
1757        //        //
1758        oss.str("");        oss.str("");
1759        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="
1760            << dworbit << " order by FROM_ORBIT desc limit 1;";            << Row->GetField(3) << ";";
1761        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1762        this->GetGLTABLES()->AddQ();        this->GetGLTABLES()->AddQ();
1763          delete pResult;
1764        pResult = dbc->Query(oss.str().c_str());        pResult = dbc->Query(oss.str().c_str());
1765        Row = pResult->Next();        if ( pResult ){
1766        if ( !Row ){          Row = pResult->Next();
1767          printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");          if ( Row ){
1768          return;            //        printf(" GREAT! the DB structure is the new one! \n");
1769              fndit = true;
1770              dworbit = 1;
1771            };
1772        };        };
1773      };      };
1774    };    };
1775      if ( !fndit ){
1776        //
1777        printf(" ERROR OLD DB! \n");
1778        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1779        //
1780      };
1781    //    //
1782    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);
1783    T0 = (UInt_t)tu.GetSec();    T0 = (UInt_t)tu.GetSec();
1784    //    //
1785    // look for the correct timesync entry    toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1786      //
1787      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1788      //
1789      if ( file ) file->Close();
1790      delete pResult;      
1791    };
1792    
1793    GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){
1794      // MySQL variables
1795      TFile *file = 0;
1796      UInt_t idtsy = 0;
1797    //    //
1798      TSQLResult *pResult;
1799      TSQLRow *Row = 0;
1800      stringstream myquery;
1801      stringstream rname;
1802      //  pcksList packetsNames;
1803      //  pcksList::iterator Iter;
1804      //  getPacketsNames(packetsNames);
1805      rname.str("");
1806      // ----------------
1807    myquery.str("");    myquery.str("");
1808    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "    myquery << "select ";
1809        << " WHERE ID_RAW = " << idraw    myquery << "PATH";
1810        << ";";    myquery << ",NAME,ID_TIMESYNC";
1811      myquery << " from GL_ROOT where ";
1812      myquery << type.Data();
1813      myquery << "=" << id << ";";    
1814      //
1815    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1816    this->GetGLTABLES()->AddQ();    this->GetGLTABLES()->AddQ();
1817    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1818      if( pResult->GetRowCount() ){
1819        Row = pResult->Next();      
1820        if( Row ){
1821          stringstream fname;
1822          fname.str("");
1823          fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1824          rname << Row->GetField(1);
1825          if ( usel0file ) file = new TFile(fname.str().c_str(),"READ");
1826          idtsy = (UInt_t)atoll(Row->GetField(2));
1827        };
1828      };
1829      //
1830      if ( usel0file && file && file->IsOpen() ){
1831        TTree *T=(TTree*)file->Get("Physics");
1832        pamela::EventHeader *eh = 0;
1833        pamela::PscuHeader *ph = 0;
1834        T->SetBranchAddress("Header", &eh);
1835        //
1836        T->GetEntry(0);
1837        ph = eh->GetPscuHeader();
1838        pktfirst = ph->GetCounter();
1839        //    obtfirst = ph->GetOrbitalTime();  
1840        //
1841      };
1842      if ( !usel0file ) pktfirst = 0;
1843      //
1844      // look for Resurs offset
1845      //
1846      T0 = 0;
1847      //
1848      stringstream oss;
1849      //
1850      TString name=rname.str().c_str();
1851      UInt_t dworbit = 0;
1852      //  Int_t nlength = name.Length();
1853      delete pResult;      
1854      //
1855      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1856      //
1857      oss.str("");
1858      oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1859      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1860      this->GetGLTABLES()->AddQ();
1861      pResult = dbc->Query(oss.str().c_str());
1862      Bool_t fndit = false;
1863    if ( pResult ){    if ( pResult ){
1864      Row = pResult->Next();      Row = pResult->Next();
1865      if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){      if ( Row ){
1866          //
1867        OBT0 = (UInt_t)atoll(Row->GetField(0));        OBT0 = (UInt_t)atoll(Row->GetField(0));
1868          obtfirst = OBT0;
1869        TIMESYNC = (UInt_t)atoll(Row->GetField(1));        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1870        TYPE = (UInt_t)atoll(Row->GetField(2));        TYPE = (UInt_t)atoll(Row->GetField(2));      
1871        toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0;        //
1872          oss.str("");
1873          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="
1874              << Row->GetField(3) << ";";
1875          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1876          this->GetGLTABLES()->AddQ();
1877          delete pResult;
1878          pResult = dbc->Query(oss.str().c_str());
1879          if ( pResult ){
1880            Row = pResult->Next();
1881            if ( Row ){
1882              //        printf(" GREAT! the DB structure is the new one! \n");
1883              fndit = true;
1884              dworbit = 1;
1885            };
1886          };
1887      };      };
1888    };    };
1889      if ( !fndit ){
1890        //
1891        printf(" ERROR OLD DB! \n");
1892        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1893        //
1894      };
1895      //
1896      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);
1897      T0 = (UInt_t)tu.GetSec();
1898      //
1899      toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1900      //
1901      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1902    //    //
1903    file->Close();    if ( file ) file->Close();
1904    delete pResult;          delete pResult;      
1905  };  };
1906    
# Line 1738  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1911  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1911   */   */
1912  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){    UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){  
1913    //    //
1914      //  printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1915    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1916    //    //
1917  };  };
# Line 1776  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n Line 1950  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n
1950   */   */
1951  Long64_t GL_TIMESYNC::DBobt(UInt_t obt){    Long64_t GL_TIMESYNC::DBobt(UInt_t obt){  
1952    //    //
1953    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){
1954      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1955    };    };
1956    //    //
1957    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1958      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
1959    };    };
1960    //    //

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.12

  ViewVC Help
Powered by ViewVC 1.1.23