--- chewbacca/YodaProfiler/src/GLTables.cpp 2008/09/23 07:20:33 1.1 +++ chewbacca/YodaProfiler/src/GLTables.cpp 2009/08/05 18:48:44 1.10 @@ -7,6 +7,7 @@ // #include #include +#include // #include #include @@ -56,7 +57,8 @@ mp = psw.Data(); }; -Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ +//Bool_t GL_TABLES::IsConnected(TSQLServer *&dbc){ +Bool_t GL_TABLES::IsConnected(TSQLServer *dbc){ // // // @@ -92,8 +94,10 @@ TString host = fHost->Data(); TString user = fUser->Data(); TString psw = fPsw->Data(); - dbc->Close(); - delete dbc; + if ( dbc ){ + dbc->Close(); + delete dbc; + }; dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data()); // myquery.str(""); @@ -168,6 +172,8 @@ TRK_CALIB_USED = 0; CAL_DSP_MASK = 0; BOOT_NUMBER = 0; + PHYSENDRUN_MASK_S3S2S12 = 0; + PHYSENDRUN_MASK_S11CRC = 0; VALIDATION = 0; } @@ -203,6 +209,8 @@ TRK_CALIB_USED = 0; CAL_DSP_MASK = 0; BOOT_NUMBER = 0; + PHYSENDRUN_MASK_S3S2S12 = 0; + PHYSENDRUN_MASK_S11CRC = 0; VALIDATION = 0; } @@ -214,6 +222,13 @@ NAME = ""; } +GL_RAW::GL_RAW(){ + ID = 0; + PATH = ""; + NAME = ""; + BOOT_NUMBER = 0; +} + GL_PARAM::GL_PARAM(){ ID = 0; PATH = ""; @@ -368,6 +383,15 @@ COMPILATIONTIMESTAMP = value; }; +void GL_RUN:: SetPHYSENDRUN_MASK_S3S2S12(UInt_t value){ + PHYSENDRUN_MASK_S3S2S12 = value; +}; + +void GL_RUN:: SetPHYSENDRUN_MASK_S11CRC(UInt_t value){ + PHYSENDRUN_MASK_S11CRC = value; +}; + + void GL_RUN:: SetFAV_WRK_SCHEDULE(UInt_t value){ FAV_WRK_SCHEDULE = value; }; @@ -435,7 +459,7 @@ RM_ACQ_AFTER_CALIB = runh->RM_ACQ_AFTER_CALIB; RM_ACQ_SETTING_MODE = runh->RM_ACQ_SETTING_MODE; TRK_CALIB_USED = runh->TRK_CALIB_USED; - CAL_DSP_MASK = runh->CAL_DSP_MASK; + CAL_DSP_MASK = runh->CAL_DSP_MASK; }; void GL_RUN::Set_GL_RUNT0(){ @@ -465,7 +489,7 @@ }; void GL_RUN::Set_GL_RUN(TSQLRow *Row){ - for( Int_t t = 0; t < 30; t++){ + for( Int_t t = 0; t < 32; t++){ if (t== 0) ID = (UInt_t)atoll(Row->GetField(t)); if (t== 1) ID_RUN_FRAG = (UInt_t)atoll(Row->GetField(t)); if (t== 2) ID_ROOT_L0 = (UInt_t)atoll(Row->GetField(t)); @@ -495,7 +519,9 @@ if (t==26) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); if (t==27) LAST_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); if (t==28) OBT_TIMESYNC = (UInt_t)atoll(Row->GetField(t)); - if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); + if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); + if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); + if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); }; } @@ -545,6 +571,8 @@ myquery << ",CAL_DSP_MASK"; myquery << ",LAST_TIMESYNC"; myquery << ",OBT_TIMESYNC"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ",INSERT_TIME"; myquery << ") SELECT * FROM "; @@ -733,6 +761,8 @@ myquery << ",CAL_DSP_MASK"; myquery << ",LAST_TIMESYNC"; myquery << ",OBT_TIMESYNC"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ",INSERT_TIME"; myquery << ") SELECT "; @@ -765,6 +795,8 @@ myquery << ",CAL_DSP_MASK"; myquery << ",LAST_TIMESYNC"; myquery << ",OBT_TIMESYNC"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ",INSERT_TIME"; myquery << " FROM GL_RUN_TRASH "; @@ -830,6 +862,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << ") VALUES ('"; @@ -862,6 +896,8 @@ myquery << (UInt_t)TRK_CALIB_USED << "','"; myquery << (UInt_t)CAL_DSP_MASK << "','"; myquery << (UInt_t)BOOT_NUMBER << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S3S2S12 << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S11CRC << "','"; myquery << (UInt_t)VALIDATION << "');"; // // printf("myquery is %s \n",myquery.str().c_str()); @@ -913,6 +949,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ") VALUES ('"; myquery << (UInt_t)ID << "','"; myquery << (UInt_t)ID_ROOT_L0 << "','"; @@ -940,7 +978,9 @@ myquery << (UInt_t)PKT_READY_COUNTER << "','"; myquery << (UInt_t)TRK_CALIB_USED << "','"; myquery << (UInt_t)CAL_DSP_MASK << "','"; - myquery << (UInt_t)BOOT_NUMBER << "');"; + myquery << (UInt_t)BOOT_NUMBER << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S3S2S12 << "','"; + myquery << (UInt_t)PHYSENDRUN_MASK_S11CRC << "');"; // // printf("myquery is %s \n",myquery.str().c_str()); // @@ -999,6 +1039,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << " from GL_RUN where ID=" << run << ";"; // @@ -1045,7 +1087,9 @@ if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); - if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); + if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); + if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); + if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); }; }; // delete pResult; @@ -1098,6 +1142,8 @@ myquery << ",TRK_CALIB_USED"; myquery << ",CAL_DSP_MASK"; myquery << ",BOOT_NUMBER"; + myquery << ",PHYSENDRUN_MASK_S3S2S12"; + myquery << ",PHYSENDRUN_MASK_S11CRC"; myquery << ",VALIDATION"; myquery << " from GL_RUN_FRAGMENTS where " << where.Data() << ";"; // @@ -1140,7 +1186,9 @@ if (t==26) TRK_CALIB_USED = (UInt_t)atoll(Row->GetField(t)); if (t==27) CAL_DSP_MASK = (UInt_t)atoll(Row->GetField(t)); if (t==28) BOOT_NUMBER = (UInt_t)atoll(Row->GetField(t)); - if (t==29) VALIDATION = (UInt_t)atoll(Row->GetField(t)); + if (t==29) PHYSENDRUN_MASK_S3S2S12 = (UInt_t)atoll(Row->GetField(t)); + if (t==30) PHYSENDRUN_MASK_S11CRC = (UInt_t)atoll(Row->GetField(t)); + if (t==31) VALIDATION = (UInt_t)atoll(Row->GetField(t)); }; }; // delete pResult; @@ -1272,7 +1320,7 @@ if ( !this->GetGLTABLES()->IsConnected(dbc) ) return -57; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); - // printf(" mysquery is %s\n",myquery.str().c_str()); + // printf(" mysquery is %s\n",myquery.str().c_str()); // if( !pResult->GetRowCount() ) return(-54); Row = pResult->Next(); @@ -1310,7 +1358,7 @@ // // if the selected calibration is too old (more than 5 orbits old) try to take the closest not corrupted one // - if ( (time-myfromtime)>28500 ){ + if ( (time-myfromtime)>28500 && myfromtime > 0 ){ // myquery.str(""); myquery << "select ID_ROOT_L0, FROM_TIME, TO_TIME, EV_ROOT from GL_CALO_CALIB where SECTION=" << section; @@ -1502,10 +1550,10 @@ GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc){ // MySQL variables TFile *file = 0; - UInt_t idraw = 0; + UInt_t idtsy = 0; // TSQLResult *pResult; - TSQLRow *Row; + TSQLRow *Row = 0; stringstream myquery; stringstream rname; // pcksList packetsNames; @@ -1516,7 +1564,7 @@ myquery.str(""); myquery << "select "; myquery << "PATH"; - myquery << ",NAME,ID_RAW"; + myquery << ",NAME,ID_TIMESYNC"; myquery << " from GL_ROOT where "; myquery << type.Data(); myquery << "=" << id << ";"; @@ -1532,7 +1580,7 @@ fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); rname << Row->GetField(1); file = new TFile(fname.str().c_str(),"READ"); - idraw = (UInt_t)atoll(Row->GetField(2)); + idtsy = (UInt_t)atoll(Row->GetField(2)); }; }; // @@ -1545,27 +1593,7 @@ T->GetEntry(0); ph = eh->GetPscuHeader(); pktfirst = ph->GetCounter(); - 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(); -// // -// }; -// }; + // obtfirst = ph->GetOrbitalTime(); // }; // @@ -1573,117 +1601,176 @@ // T0 = 0; // - // 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(); // TString name=rname.str().c_str(); UInt_t dworbit = 0; - Int_t nlength = name.Length(); + // Int_t nlength = name.Length(); + delete pResult; // - // 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 // - if ( !Row ){ - delete pResult; - // - // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset - // - oss.str(""); - oss << "SELECT ID_RESURS_OFFSET from GL_TIMESYNC where ID_RAW=" << idraw <<";"; - if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; - this->GetGLTABLES()->AddQ(); - 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 + oss.str(""); + oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + this->GetGLTABLES()->AddQ(); + pResult = dbc->Query(oss.str().c_str()); + Bool_t fndit = false; + if ( pResult ){ + Row = pResult->Next(); + if ( Row ){ // - if ( nlength < 5 ) return; - TString dwo = 0; - for (Int_t i = 0; i<5; i++){ - dwo.Append(name[i],1); - }; - 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; - }; - }; + OBT0 = (UInt_t)atoll(Row->GetField(0)); + obtfirst = OBT0; + TIMESYNC = (UInt_t)atoll(Row->GetField(1)); + TYPE = (UInt_t)atoll(Row->GetField(2)); // 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 FROM_ORBIT< " - << dworbit << " order by FROM_ORBIT desc limit 1;"; + 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(3) << ";"; if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; this->GetGLTABLES()->AddQ(); + delete pResult; pResult = dbc->Query(oss.str().c_str()); - Row = pResult->Next(); - if ( !Row ){ - printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); - return; + if ( pResult ){ + Row = pResult->Next(); + if ( Row ){ + // printf(" GREAT! the DB structure is the new one! \n"); + fndit = true; + dworbit = 1; + }; }; }; }; + if ( !fndit ){ + // + printf(" ERROR OLD DB! \n"); + printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); + // + }; // 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); T0 = (UInt_t)tu.GetSec(); // - // look for the correct timesync entry + toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; + // + // printf(" T0 %u toffset is %u \n",T0,toffset); + // + if ( file ) file->Close(); + delete pResult; +}; + +GL_TIMESYNC::GL_TIMESYNC(UInt_t id, TString type, TSQLServer *dbc, Bool_t usel0file){ + // MySQL variables + TFile *file = 0; + UInt_t idtsy = 0; // + TSQLResult *pResult; + TSQLRow *Row = 0; + stringstream myquery; + stringstream rname; + // pcksList packetsNames; + // pcksList::iterator Iter; + // getPacketsNames(packetsNames); + rname.str(""); + // ---------------- myquery.str(""); - myquery << " SELECT OBT0,TIMESYNC,TYPE FROM GL_TIMESYNC " - << " WHERE ID_RAW = " << idraw - << ";"; + myquery << "select "; + myquery << "PATH"; + myquery << ",NAME,ID_TIMESYNC"; + myquery << " from GL_ROOT where "; + myquery << type.Data(); + myquery << "=" << id << ";"; + // if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; this->GetGLTABLES()->AddQ(); pResult = dbc->Query(myquery.str().c_str()); + if( pResult->GetRowCount() ){ + Row = pResult->Next(); + if( Row ){ + stringstream fname; + fname.str(""); + fname << gSystem->ExpandPathName(Row->GetField(0)) << "/" << Row->GetField(1); + rname << Row->GetField(1); + if ( usel0file ) file = new TFile(fname.str().c_str(),"READ"); + idtsy = (UInt_t)atoll(Row->GetField(2)); + }; + }; + // + if ( usel0file && file && file->IsOpen() ){ + TTree *T=(TTree*)file->Get("Physics"); + pamela::EventHeader *eh = 0; + pamela::PscuHeader *ph = 0; + T->SetBranchAddress("Header", &eh); + // + T->GetEntry(0); + ph = eh->GetPscuHeader(); + pktfirst = ph->GetCounter(); + // obtfirst = ph->GetOrbitalTime(); + // + }; + if ( !usel0file ) pktfirst = 0; + // + // look for Resurs offset + // + T0 = 0; + // + stringstream oss; + // + TString name=rname.str().c_str(); + UInt_t dworbit = 0; + // Int_t nlength = name.Length(); + delete pResult; + // + // New code, we have one more column on GL_TIMESYNC so we can trust that one for the Resurs offset + // + oss.str(""); + oss << "SELECT OBT0,TIMESYNC,TYPE,ID_RESURS_OFFSET from GL_TIMESYNC where ID=" << idtsy <<";"; + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + this->GetGLTABLES()->AddQ(); + pResult = dbc->Query(oss.str().c_str()); + Bool_t fndit = false; if ( pResult ){ Row = pResult->Next(); - if ( (Row != NULL) && ((UInt_t)atoll(Row->GetField(0)) > 0 ) ){ + if ( Row ){ + // OBT0 = (UInt_t)atoll(Row->GetField(0)); + obtfirst = OBT0; 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; + TYPE = (UInt_t)atoll(Row->GetField(2)); + // + 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(3) << ";"; + if ( !this->GetGLTABLES()->IsConnected(dbc) ) return; + this->GetGLTABLES()->AddQ(); + delete pResult; + 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 ){ + // + printf(" ERROR OLD DB! \n"); + printf(" ERROR FROM GLTables! cannot determine Resurs offset \n"); + // + }; + // + 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); + T0 = (UInt_t)tu.GetSec(); + // + toffset = (UInt_t)TIMESYNC - (UInt_t)(this->DBobt(OBT0)/1000) + T0; + // + // printf(" T0 %u toffset is %u \n",T0,toffset); // - file->Close(); + if ( file ) file->Close(); delete pResult; }; @@ -1694,6 +1781,7 @@ */ UInt_t GL_TIMESYNC::DBabsTime(UInt_t OBT){ // + // printf(" OBT %u DBobt %llu toffset %u dbabstime %u\n",OBT,this->DBobt(OBT),toffset,((UInt_t)(this->DBobt(OBT)/1000)+toffset)); return(((UInt_t)(this->DBobt(OBT)/1000)+toffset)); // }; @@ -1732,11 +1820,11 @@ */ Long64_t GL_TIMESYNC::DBobt(UInt_t obt){ // - if ( obt < (obtfirst/2) && obtfirst > (numeric_limits::max()/2) ){ + if ( obt < ((Long64_t)obtfirst/2) && obtfirst > (numeric_limits::max()/2) ){ return((Long64_t)obt+(Long64_t)numeric_limits::max()); }; // - if ( obt > (obtfirst*2) && obt > (numeric_limits::max()/2) ){ + if ( obt > ((Long64_t)obtfirst*2) && obt > (numeric_limits::max()/2) ){ return((Long64_t)obt-(Long64_t)numeric_limits::max()); }; //