/[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.13 by mocchiut, Tue Dec 15 10:23:28 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      this->Open(host,user,psw);
37    };
38    
39    void Q2TH::Open(TString host, TString user, TString psw){
40      fh = gSystem->ExpandPathName(host.Data());
41      fu = gSystem->ExpandPathName(user.Data());
42      fp = gSystem->ExpandPathName(psw.Data());
43      printf(" Connecting to DB %s \n",fh.Data());
44      dbc = TSQLServer::Connect(fh.Data(),fu.Data(),fp.Data());
45      if ( dbc && dbc->IsConnected() ){
46        printf(" connected! \n");
47      } else {
48        printf(" ERROR! not connected... :( \n");
49      };
50    };
51    
52    TObject *Q2TH::Draw(TString query, Bool_t verbose, TString hname){
53      //
54      if ( !strcmp(query.Data(),"help") ){
55        printf(" USAGE: \n");
56        printf(" 1) start root and create Q2TH object with  \n");
57        printf("    Q2TH *qt = new Q2TH()  \n");
58        printf("    or \n");
59        printf("    Q2TH *qt = new Q2TH(\"mysql://srvg-g2-01.ts.infn.it/pamelaProcessing9_TS\",\"pamelaprod_ro\",\"mypassword\")  \n");
60        printf(" 2) query the DB with  \n");
61        printf("    qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\");  \n");
62        printf("    qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",true); this will print numbers on screen \n");
63        printf("    qt->Draw(\"select REAL_TIME_INIT from ROOT_TABLE_MERGING;\",true,\"myhisto\"); this will print numbers on screen and create histo \"myhisto\"\n");
64        printf(" 3) to use your own THxD create it and then query the DB giving as argument the name of histo:   \n");
65        printf("    TH2D *myhisto=new TH2D(\"myhisto\",\"myhisto\",5000,1140000000.,1240000000.,10000,0.,1.) \n");
66        printf("    qt->Draw(\"select REAL_TIME_INIT,BAD_PKT_PERCENTAGE from ROOT_TABLE_MERGING;\",false,\"myhisto\")\n\n\n");
67    
68        return NULL;
69      };
70      //
71      pResult = dbc->Query(query.Data());
72      //
73      Row = pResult->Next();      
74      //
75      Int_t dim = pResult->GetFieldCount();
76      if ( dim < 1 || dim > 2 ){
77        printf(" Dim == %i not supported yet \n",dim);
78        return NULL;
79      };  
80      //
81      TH1D *h1 = NULL;
82      TH2D *h2 = NULL;
83      Double_t f1 = 0.;
84      Double_t minf1 = numeric_limits<Double_t>::max();
85      Double_t maxf1 = numeric_limits<Double_t>::min();
86      Double_t f2 = 0.;  
87      Double_t minf2 = numeric_limits<Double_t>::max();
88      Double_t maxf2 = numeric_limits<Double_t>::min();
89      //
90      while ( Row ){    
91        f1 = (Double_t)atof(Row->GetField(0));
92        if ( f1 > maxf1 ) maxf1 = f1;
93        if ( f1 < minf1 ) minf1 = f1;
94        if ( dim == 2 ){
95          f2 = (Double_t)atof(Row->GetField(1));
96          if ( f2 > maxf2 ) maxf2 = f2;
97          if ( f2 < minf2 ) minf2 = f2;
98    
99        };
100        Row = pResult->Next();
101      };
102      pResult->Delete();
103      //
104            
105      //
106      Int_t f1bin = 70;
107      Int_t f2bin = 70;
108      if ( dim == 1 ){
109        f1bin = int((maxf1-minf1)/1000.);
110        if ( f1bin < 70 ) f1bin = 70;
111        if ( f1bin > 1000 ) f1bin = 1000;
112            if ( !strcmp(hname.Data(),"q2th") ) hname += "1";
113            //      h1 =  dynamic_cast<TH1D*>(gDirectory->FindObject(hname.Data()));
114            h1 = (TH1D*)(gDirectory->FindObject(hname.Data()));
115            if ( !strcmp(hname.Data(),"q2th1") ){
116             if ( h1 ) h1->Delete();
117            };
118            if ( !h1 ) h1 = new TH1D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02);
119        //    h1->SetBit(TH1::kCanRebin);
120        if ( verbose ) printf("\n\n Row     %s \n",pResult->GetFieldName(0));
121      };
122      if ( dim == 2 ){
123        f2bin = int((maxf2-minf2)/1000.);
124        if ( f2bin < 70 ) f2bin = 70;
125        if ( f2bin > 1000 ) f2bin = 1000;
126            if ( !strcmp(hname.Data(),"q2th") ) hname += "2";
127            //      h2 =  dynamic_cast<TH2D*>(gDirectory->FindObject(hname.Data()));
128            h2 =  (TH2D*)(gDirectory->FindObject(hname.Data()));
129            if ( !strcmp(hname.Data(),"q2th2") ){
130             if ( h2 ) h2->Delete();
131            };
132            if ( !h2 ) h2 = new TH2D(hname.Data(),hname.Data(),f1bin,minf1*0.98,maxf1*1.02,f2bin,minf2*0.98,maxf2*1.02);
133        //    h2->SetBit(TH2::kCanRebin);
134        if ( verbose ) printf("\n\n Row     %s     %s \n",pResult->GetFieldName(0),pResult->GetFieldName(1));
135      };
136      //
137      pResult = dbc->Query(query.Data());
138      //
139      Row = pResult->Next();      
140      //
141      Int_t r = 0;
142      //
143      while ( Row ){    
144        f1 = (Double_t)atof(Row->GetField(0));
145        if ( dim == 1 ){
146          if ( verbose ) printf(" %i     %f \n",r,f1);
147          h1->Fill(f1);
148        } else {
149          f2 = (Double_t)atof(Row->GetField(1));
150          if ( verbose ) printf(" %i     %f     %f \n",r,f1,f2);
151          h2->Fill(f1,f2);
152        };
153        r++;
154        Row = pResult->Next();
155      };
156      //
157      TCanvas *c = NULL;
158      TString cname = Form("%sc",hname.Data());
159      //  c =  dynamic_cast<TCanvas*>(gDirectory->FindObject(hname.Data()));
160      c =  (TCanvas*)(gDirectory->FindObject(cname.Data()));
161      if ( !c ) c = new TCanvas(Form("%sc",cname.Data()));
162      c->Clear();
163      c->cd();
164      if ( dim == 1 ) h1->Draw();
165      if ( dim == 2 ) h2->Draw();
166      //
167      pResult->Delete();
168      if ( dim == 1 ) return h1;
169      if ( dim == 2 ) return h2;
170      //
171      return NULL;
172    };
173    
174  GL_TABLES::GL_TABLES(){  GL_TABLES::GL_TABLES(){
175  };  };
176    
# Line 56  void GL_TABLES::Set(TString host, TStrin Line 197  void GL_TABLES::Set(TString host, TStrin
197    mp = psw.Data();    mp = psw.Data();
198  };  };
199    
200  Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){  //Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){
201    Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){
202    //    //
203    //    //
204    //    //
# Line 92  Bool_t GL_TABLES::IsConnected(TSQLServer Line 234  Bool_t GL_TABLES::IsConnected(TSQLServer
234      TString host = fHost->Data();      TString host = fHost->Data();
235      TString user = fUser->Data();      TString user = fUser->Data();
236      TString psw = fPsw->Data();      TString psw = fPsw->Data();
237      dbc->Close();      if ( dbc ){
238      delete dbc;        dbc->Close();
239          delete dbc;
240        };
241      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());      dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
242      //      //
243      myquery.str("");      myquery.str("");
# Line 1316  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1460  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1460    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1461    this->GetGLTABLES()->AddQ();    this->GetGLTABLES()->AddQ();
1462    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1463    //  printf(" mysquery is %s\n",myquery.str().c_str());    // printf(" mysquery is %s\n",myquery.str().c_str());
1464    //    //
1465    if( !pResult->GetRowCount() ) return(-54);    if( !pResult->GetRowCount() ) return(-54);
1466    Row = pResult->Next();    Row = pResult->Next();
# Line 1546  void GL_RUN::GetLevel2Struct(cGLRun *l2) Line 1690  void GL_RUN::GetLevel2Struct(cGLRun *l2)
1690  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
1691    // MySQL variables    // MySQL variables
1692    TFile *file = 0;    TFile *file = 0;
1693    UInt_t idraw = 0;    UInt_t idtsy = 0;
1694    //    //
1695    TSQLResult *pResult;    TSQLResult *pResult;
1696    TSQLRow *Row;    TSQLRow *Row = 0;
1697    stringstream myquery;    stringstream myquery;
1698    stringstream rname;    stringstream rname;
1699    //  pcksList packetsNames;    //  pcksList packetsNames;
# Line 1560  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1704  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1704    myquery.str("");    myquery.str("");
1705    myquery << "select ";    myquery << "select ";
1706    myquery << "PATH";    myquery << "PATH";
1707    myquery << ",NAME,ID_RAW";    myquery << ",NAME,ID_TIMESYNC";
1708    myquery << " from GL_ROOT where ";    myquery << " from GL_ROOT where ";
1709    myquery << type.Data();    myquery << type.Data();
1710    myquery << "=" << id << ";";        myquery << "=" << id << ";";    
# Line 1576  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1720  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1720        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1721        rname << Row->GetField(1);        rname << Row->GetField(1);
1722        file = new TFile(fname.str().c_str(),"READ");        file = new TFile(fname.str().c_str(),"READ");
1723        idraw = (UInt_t)atoll(Row->GetField(2));        idtsy = (UInt_t)atoll(Row->GetField(2));
1724      };      };
1725    };    };
1726    //    //
# Line 1589  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1733  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1733      T->GetEntry(0);      T->GetEntry(0);
1734      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
1735      pktfirst = ph->GetCounter();      pktfirst = ph->GetCounter();
1736      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();    
 //       //  
 //       };  
 //     };    
1737      //      //
1738    };    };
1739    //    //
# Line 1617  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1741  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1741    //    //
1742    T0 = 0;    T0 = 0;
1743    //    //
   //  
1744    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();  
1745    //    //
1746    TString name=rname.str().c_str();    TString name=rname.str().c_str();
1747    UInt_t dworbit = 0;    UInt_t dworbit = 0;
1748    Int_t nlength = name.Length();    //  Int_t nlength = name.Length();
1749      delete pResult;      
1750    //    //
1751    // 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
1752    //    //
1753    if ( !Row ){    oss.str("");
1754      delete pResult;          oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1755      //    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1756      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset    this->GetGLTABLES()->AddQ();
1757      //    pResult = dbc->Query(oss.str().c_str());
1758      oss.str("");    Bool_t fndit = false;
1759      oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";";    if ( pResult ){
1760      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;        Row = pResult->Next();
1761      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  
1762        //        //
1763        if ( nlength < 5 ) return;        OBT0 = (UInt_t)atoll(Row->GetField(0));
1764        TString dwo = 0;        obtfirst = OBT0;
1765        for (Int_t i = 0; i<5; i++){        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1766          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;  
         };  
       };      
1767        //        //
1768        oss.str("");        oss.str("");
1769        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="
1770            << dworbit << " order by FROM_ORBIT desc limit 1;";            << Row->GetField(3) << ";";
1771        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1772        this->GetGLTABLES()->AddQ();        this->GetGLTABLES()->AddQ();
1773          delete pResult;
1774        pResult = dbc->Query(oss.str().c_str());        pResult = dbc->Query(oss.str().c_str());
1775        Row = pResult->Next();        if ( pResult ){
1776        if ( !Row ){          Row = pResult->Next();
1777          printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");          if ( Row ){
1778          return;            //        printf(" GREAT! the DB structure is the new one! \n");
1779              fndit = true;
1780              dworbit = 1;
1781            };
1782        };        };
1783      };      };
1784    };    };
1785      if ( !fndit ){
1786        //
1787        printf(" ERROR OLD DB! \n");
1788        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1789        //
1790      };
1791    //    //
1792    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);
1793    T0 = (UInt_t)tu.GetSec();    T0 = (UInt_t)tu.GetSec();
1794    //    //
1795    // look for the correct timesync entry    toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1796    //    //
1797      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1798      //
1799      if ( file ) file->Close();
1800      delete pResult;      
1801    };
1802    
1803    GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){
1804      // MySQL variables
1805      TFile *file = 0;
1806      UInt_t idtsy = 0;
1807      //
1808      TSQLResult *pResult;
1809      TSQLRow *Row = 0;
1810      stringstream myquery;
1811      stringstream rname;
1812      //  pcksList packetsNames;
1813      //  pcksList::iterator Iter;
1814      //  getPacketsNames(packetsNames);
1815      rname.str("");
1816      // ----------------
1817    myquery.str("");    myquery.str("");
1818    myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "    myquery << "select ";
1819        << " WHERE ID_RAW = " << idraw    myquery << "PATH";
1820        << ";";    myquery << ",NAME,ID_TIMESYNC";
1821      myquery << " from GL_ROOT where ";
1822      myquery << type.Data();
1823      myquery << "=" << id << ";";    
1824      //
1825    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1826    this->GetGLTABLES()->AddQ();    this->GetGLTABLES()->AddQ();
1827    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1828      if( pResult->GetRowCount() ){
1829        Row = pResult->Next();      
1830        if( Row ){
1831          stringstream fname;
1832          fname.str("");
1833          fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1834          rname << Row->GetField(1);
1835          if ( usel0file ) file = new TFile(fname.str().c_str(),"READ");
1836          idtsy = (UInt_t)atoll(Row->GetField(2));
1837        };
1838      };
1839      //
1840      if ( usel0file && file && file->IsOpen() ){
1841        TTree *T=(TTree*)file->Get("Physics");
1842        pamela::EventHeader *eh = 0;
1843        pamela::PscuHeader *ph = 0;
1844        T->SetBranchAddress("Header", &eh);
1845        //
1846        T->GetEntry(0);
1847        ph = eh->GetPscuHeader();
1848        pktfirst = ph->GetCounter();
1849        //    obtfirst = ph->GetOrbitalTime();  
1850        //
1851      };
1852      if ( !usel0file ) pktfirst = 0;
1853      //
1854      // look for Resurs offset
1855      //
1856      T0 = 0;
1857      //
1858      stringstream oss;
1859      //
1860      TString name=rname.str().c_str();
1861      UInt_t dworbit = 0;
1862      //  Int_t nlength = name.Length();
1863      delete pResult;      
1864      //
1865      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset
1866      //
1867      oss.str("");
1868      oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1869      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1870      this->GetGLTABLES()->AddQ();
1871      pResult = dbc->Query(oss.str().c_str());
1872      Bool_t fndit = false;
1873    if ( pResult ){    if ( pResult ){
1874      Row = pResult->Next();      Row = pResult->Next();
1875      if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){      if ( Row ){
1876          //
1877        OBT0 = (UInt_t)atoll(Row->GetField(0));        OBT0 = (UInt_t)atoll(Row->GetField(0));
1878          obtfirst = OBT0;
1879        TIMESYNC = (UInt_t)atoll(Row->GetField(1));        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1880        TYPE = (UInt_t)atoll(Row->GetField(2));        TYPE = (UInt_t)atoll(Row->GetField(2));      
1881        toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0;        //
1882          oss.str("");
1883          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="
1884              << Row->GetField(3) << ";";
1885          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1886          this->GetGLTABLES()->AddQ();
1887          delete pResult;
1888          pResult = dbc->Query(oss.str().c_str());
1889          if ( pResult ){
1890            Row = pResult->Next();
1891            if ( Row ){
1892              //        printf(" GREAT! the DB structure is the new one! \n");
1893              fndit = true;
1894              dworbit = 1;
1895            };
1896          };
1897      };      };
1898    };    };
1899      if ( !fndit ){
1900        //
1901        printf(" ERROR OLD DB! \n");
1902        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1903        //
1904      };
1905      //
1906      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);
1907      T0 = (UInt_t)tu.GetSec();
1908      //
1909      toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1910      //
1911      //  printf(" T0 %u toffset is %u \n",T0,toffset);
1912    //    //
1913    file->Close();    if ( file ) file->Close();
1914    delete pResult;          delete pResult;      
1915  };  };
1916    
# Line 1738  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1921  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1921   */   */
1922  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){    UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){  
1923    //    //
1924      //  printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1925    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1926    //    //
1927  };  };
# Line 1776  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n Line 1960  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n
1960   */   */
1961  Long64_t GL_TIMESYNC::DBobt(UInt_t obt){    Long64_t GL_TIMESYNC::DBobt(UInt_t obt){  
1962    //    //
1963    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){
1964      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1965    };    };
1966    //    //
1967    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1968      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
1969    };    };
1970    //    //

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

  ViewVC Help
Powered by ViewVC 1.1.23