/[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.2 by mocchiut, Thu Sep 25 09:03:19 2008 UTC revision 1.6 by mocchiut, Fri Dec 12 11:07:09 2008 UTC
# Line 218  GL_ROOT::GL_ROOT(){ Line 218  GL_ROOT::GL_ROOT(){
218    NAME   = "";    NAME   = "";
219  }  }
220    
221    GL_RAW::GL_RAW(){
222      ID     = 0;
223      PATH   = "";
224      NAME   = "";
225      BOOT_NUMBER = 0;
226    }
227    
228  GL_PARAM::GL_PARAM(){  GL_PARAM::GL_PARAM(){
229    ID     = 0;    ID     = 0;
230    PATH   = "";    PATH   = "";
# Line 1309  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1316  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1316    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57;  
1317    this->GetGLTABLES()->AddQ();    this->GetGLTABLES()->AddQ();
1318    pResult = dbc->Query(myquery.str().c_str());    pResult = dbc->Query(myquery.str().c_str());
1319    //  printf(" mysquery is %s\n",myquery.str().c_str());    // printf(" mysquery is %s\n",myquery.str().c_str());
1320    //    //
1321    if( !pResult->GetRowCount() ) return(-54);    if( !pResult->GetRowCount() ) return(-54);
1322    Row = pResult->Next();    Row = pResult->Next();
# Line 1347  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB Line 1354  Int_t GL_CALO_CALIB::Query_GL_CALO_CALIB
1354    //    //
1355    // if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one    // if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one
1356    //    //
1357    if ( (time-myfromtime)>28500 ){    if ( (time-myfromtime)>28500 && myfromtime > 0 ){
1358      //      //
1359      myquery.str("");      myquery.str("");
1360      myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section;      myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section;
# Line 1539  void GL_RUN::GetLevel2Struct(cGLRun *l2) Line 1546  void GL_RUN::GetLevel2Struct(cGLRun *l2)
1546  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){
1547    // MySQL variables    // MySQL variables
1548    TFile *file = 0;    TFile *file = 0;
1549    UInt_t idraw = 0;    UInt_t idtsy = 0;
1550    //    //
1551    TSQLResult *pResult;    TSQLResult *pResult;
1552    TSQLRow *Row;    TSQLRow *Row = 0;
1553    stringstream myquery;    stringstream myquery;
1554    stringstream rname;    stringstream rname;
1555    //  pcksList packetsNames;    //  pcksList packetsNames;
# Line 1553  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1560  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1560    myquery.str("");    myquery.str("");
1561    myquery << "select ";    myquery << "select ";
1562    myquery << "PATH";    myquery << "PATH";
1563    myquery << ",NAME,ID_RAW";    myquery << ",NAME,ID_TIMESYNC";
1564    myquery << " from GL_ROOT where ";    myquery << " from GL_ROOT where ";
1565    myquery << type.Data();    myquery << type.Data();
1566    myquery << "=" << id << ";";        myquery << "=" << id << ";";    
# Line 1569  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1576  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1576        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);        fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1);
1577        rname << Row->GetField(1);        rname << Row->GetField(1);
1578        file = new TFile(fname.str().c_str(),"READ");        file = new TFile(fname.str().c_str(),"READ");
1579        idraw = (UInt_t)atoll(Row->GetField(2));        idtsy = (UInt_t)atoll(Row->GetField(2));
1580      };      };
1581    };    };
1582    //    //
# Line 1582  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1589  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1589      T->GetEntry(0);      T->GetEntry(0);
1590      ph = eh->GetPscuHeader();      ph = eh->GetPscuHeader();
1591      pktfirst = ph->GetCounter();      pktfirst = ph->GetCounter();
1592      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();    
 //       //  
 //       };  
 //     };    
1593      //      //
1594    };    };
1595    //    //
# Line 1610  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1597  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1597    //    //
1598    T0 = 0;    T0 = 0;
1599    //    //
   //  
1600    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();  
1601    //    //
1602    TString name=rname.str().c_str();    TString name=rname.str().c_str();
1603    UInt_t dworbit = 0;    UInt_t dworbit = 0;
1604    Int_t nlength = name.Length();    //  Int_t nlength = name.Length();
1605      delete pResult;      
1606    //    //
1607    // 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
1608    //    //
1609    if ( !Row ){    oss.str("");
1610      delete pResult;          oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";";
1611      //    if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1612      // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset    this->GetGLTABLES()->AddQ();
1613      //    pResult = dbc->Query(oss.str().c_str());
1614      oss.str("");    Bool_t fndit = false;
1615      oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";";    if ( pResult ){
1616      if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;        Row = pResult->Next();
1617      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  
1618        //        //
1619        if ( nlength < 5 ) return;        OBT0 = (UInt_t)atoll(Row->GetField(0));
1620        TString dwo = 0;        obtfirst = OBT0;
1621        for (Int_t i = 0; i<5; i++){        TIMESYNC = (UInt_t)atoll(Row->GetField(1));
1622          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;  
         };  
       };      
1623        //        //
1624        oss.str("");        oss.str("");
1625        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="
1626            << dworbit << " order by FROM_ORBIT desc limit 1;";            << Row->GetField(3) << ";";
1627        if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;          if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;  
1628        this->GetGLTABLES()->AddQ();        this->GetGLTABLES()->AddQ();
1629          delete pResult;
1630        pResult = dbc->Query(oss.str().c_str());        pResult = dbc->Query(oss.str().c_str());
1631        Row = pResult->Next();        if ( pResult ){
1632        if ( !Row ){          Row = pResult->Next();
1633          printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");          if ( Row ){
1634          return;            //        printf(" GREAT! the DB structure is the new one! \n");
1635              fndit = true;
1636              dworbit = 1;
1637            };
1638        };        };
1639      };      };
1640    };    };
1641      if ( !fndit ){
1642        //
1643        printf(" ERROR OLD DB! \n");
1644        printf(" ERROR FROM GLTables! cannot determine Resurs offset \n");
1645        //
1646      };
1647    //    //
1648    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);
1649    T0 = (UInt_t)tu.GetSec();    T0 = (UInt_t)tu.GetSec();
1650    //    //
1651    // look for the correct timesync entry    toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0;
1652    //    //
1653    myquery.str("");    //  printf(" T0 %u toffset is %u \n",T0,toffset);
   myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC "  
       << " WHERE ID_RAW = " << idraw  
       << ";";  
   if ( !this->GetGLTABLES()->IsConnected(dbc) ) return;    
   this->GetGLTABLES()->AddQ();  
   pResult = dbc->Query(myquery.str().c_str());  
   if ( pResult ){  
     Row = pResult->Next();  
     if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){  
       OBT0 = (UInt_t)atoll(Row->GetField(0));  
       TIMESYNC = (UInt_t)atoll(Row->GetField(1));  
       TYPE = (UInt_t)atoll(Row->GetField(2));  
       toffset = (UInt_t)atoll(Row->GetField(1)) - (UInt_t)(this->DBobt((UInt_t)atoll(Row->GetField(0)))/1000) + T0;  
     };  
   };  
1654    //    //
1655    file->Close();    file->Close();
1656    delete pResult;          delete pResult;      
# Line 1731  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr Line 1663  GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TStr
1663   */   */
1664  UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){    UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){  
1665    //    //
1666      //  printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1667    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));    return(((UInt_t)(this->DBobt(OBT)/1000)+toffset));
1668    //    //
1669  };  };
# Line 1769  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n Line 1702  Long64_t GL_TIMESYNC::DBpkt(UInt_t pkt_n
1702   */   */
1703  Long64_t GL_TIMESYNC::DBobt(UInt_t obt){    Long64_t GL_TIMESYNC::DBobt(UInt_t obt){  
1704    //    //
1705    if ( obt < (obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){    if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits<UInt_t>::max()/2) ){
1706      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt+(Long64_t)numeric_limits<UInt_t>::max());
1707    };    };
1708    //    //
1709    if ( obt > (obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){    if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits<UInt_t>::max()/2) ){
1710      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());      return((Long64_t)obt-(Long64_t)numeric_limits<UInt_t>::max());
1711    };    };
1712    //    //

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

  ViewVC Help
Powered by ViewVC 1.1.23