--- PamelaLevel2/src/PamLevel2.cpp 2009/06/04 15:10:47 1.82 +++ PamelaLevel2/src/PamLevel2.cpp 2011/12/12 16:11:42 1.89 @@ -464,9 +464,13 @@ soft_obj = 0;// Emiliano irun = -1LL; irunt = -1LL; + totrunentry = 0LL; + totrunentrymax = 0LL; + totrunentrymin = 0LL; runfirstentry = 0LL; runlastentry = 0LL; gltsync = 0; // Emiliano + fUpdateRunInfo = true; // Emiliano l0_file = NULL; l0_tree = NULL; @@ -633,7 +637,7 @@ // TIter next2(contents); TChain *questa = 0; - while (questa = (TChain*) next2()) { + while ( (questa = (TChain*)next2()) ) { TString name = questa->GetName(); questa->Delete(); questa = NULL; @@ -646,13 +650,20 @@ run_tree->Delete();; if (sel_tree) sel_tree->Delete();; - for (Int_t i = 0; i < NCLONES; i++) + + // The following lines are commented out since they may generate a double delete error + // if the file containing the clone trees is closed. This is because the file owns the + // clone trees which are written into it, so it will delete them when it is closed; if + // also PamLevel2 will try to delete these trees, a double delete error will be generated + // when exiting from analysis program. (Nicola 28/11/2011) + + /*for (Int_t i = 0; i < NCLONES; i++) if (pam_tree_clone[i]) pam_tree_clone[i]->Delete();; if (run_tree_clone) run_tree_clone->Delete();; if (sel_tree_clone) - sel_tree_clone->Delete();; + sel_tree_clone->Delete();;*/ if (irunoffset) delete[] irunoffset; @@ -747,7 +758,7 @@ // TIter next2(contents); TChain *questa = 0; - while (questa = (TChain*) next2()) { + while ( (questa = (TChain*) next2()) ) { TString name = questa->GetName(); questa->Delete(); questa = NULL; @@ -792,8 +803,16 @@ soft_obj = 0;// Emiliano irun = -1; irunt = -1; + totrunentry = 0LL; + totrunentrymax = 0LL; + totrunentrymin = 0LL; runfirstentry = 0ULL; runlastentry = 0ULL; + prevabstime = 0ULL; + prevpktnum = 0; + abstime = 0ULL; + pktnum = 0; + isFragment = false; // totdltime[0] = 0LL; totdltime[1] = 0LL; @@ -833,6 +852,20 @@ } ; +void PamLevel2::SkipRunInfoUpdate(){ + printf("\n\n ******** WARNING ******** \n Skip DB connections, DO NOT USE PamLevel2::GetRunInfo() method! \n\n"); + fUpdateRunInfo = false; + this->SetSELLI(2); + printf(" ===============> W A R N I N G <================ \n"); + printf(" in case PamLevel2::CreateCloneTrees() will be called \n"); + printf(" it will be reverted to PadmeAmidala level2 structure , i.e. NO SELECTIONLIST WILL BE CREATED IN THE NEW LEVEL2 FILE! \n\n"); + if ( run_tree_clone ){ + printf(" ===============> W A R N I N G <================ \n"); + printf(" PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() has been called together with PamLevel2::CreateCloneTrees() \n"); + printf(" TO AVOID CRASHES call PamLevel2::CreateCloneTrees() after PamLevel2::SkipRunIndoUpdate or PamLevel2::NoDBconnections() \n"); + }; +} + //-------------------------------------- // // @@ -2113,7 +2146,7 @@ if (file.EndsWith(".root")) { TString filedir; cout << ddir << endl; - if (ddir != "") { + if ( ddir != "" ) { filedir = ddir; // take the input dir } else { @@ -2121,7 +2154,8 @@ filedir = gSystem->DirName(file); // this will take the path if exist in the list otherwise it will return automatically the working dir }; filedir.Append("/"); - char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file)); + // char *fullpath = gSystem->ConcatFileName(gSystem->DirName(filedir), gSystem->BaseName(file)); + char *fullpath = gSystem->ConcatFileName(filedir.Data(), gSystem->BaseName(file)); contents->Add(new TSystemFile(fullpath, gSystem->DirName(fullpath)));// add file to the list cout << fullpath << endl; delete fullpath; @@ -2715,6 +2749,7 @@ return T; } + /** * Update the runinfo informations (to be used to have Run infos event by event basis) * @param run Pointer to the chain/tree which contains run infos @@ -2750,9 +2785,9 @@ return (false); } - ULong64_t abstime = 0; + ULong64_t abstimeu = 0; if (GetOrbitalInfo()) - abstime = GetOrbitalInfo()->absTime; + abstimeu = GetOrbitalInfo()->absTime; // // the first time the routine is called, set run search from the beginning @@ -2773,9 +2808,9 @@ }; // if (ISGP) - abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO + abstimeu = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO // - if (irun == run->GetEntries() - 1LL && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime + if (irun == run->GetEntries() - 1LL && !(abstimeu >= GetRunInfo()->RUNHEADER_TIME && abstimeu <= GetRunInfo()->RUNTRAILER_TIME)) { irun = -1LL; irunt = -1LL; @@ -2787,7 +2822,7 @@ // bool fromfirst = true; // - while (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun + while (!(abstimeu >= GetRunInfo()->RUNHEADER_TIME && abstimeu <= GetRunInfo()->RUNTRAILER_TIME) && irun < run->GetEntries() - 1LL) { // while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){ irun++; @@ -2799,13 +2834,13 @@ // cout << " ))))) UPDATE RUN INFO ((((( @iev "<ID<<" irun "<GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); - // printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME); + // printf(" abstimeu %u trailertime %u \n",abstimeu,GetRunInfo()->RUNTRAILER_TIME); // printf(" IDRUN %u \n",GetRunInfo()->ID); // // prevshift = 0; // - if (irun == (Long64_t)(run->GetEntries() - 1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME - && abstime <= GetRunInfo()->RUNTRAILER_TIME)) { + if (irun == (Long64_t)(run->GetEntries() - 1LL) && fromfirst && !(abstimeu >= GetRunInfo()->RUNHEADER_TIME + && abstimeu <= GetRunInfo()->RUNTRAILER_TIME)) { printf(" resetting irun (it should NOT happen!!!)\n"); fromfirst = false; irun = 0; @@ -2818,8 +2853,8 @@ // }; // - if (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)) { - printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n", abstime); + if (!(abstimeu >= GetRunInfo()->RUNHEADER_TIME && abstimeu <= GetRunInfo()->RUNTRAILER_TIME)) { + printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n", abstimeu); return false; } // @@ -2852,7 +2887,7 @@ return false; // } -; + Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) { @@ -2865,6 +2900,8 @@ return (false); } + if (DBG) printf("ciccio\n"); + Int_t oldrun = irun; // store current run index // ----------------------------------------------------------------------- @@ -2874,8 +2911,16 @@ if (irun < 0) { irun = 0LL; irunt = 0LL; + totrunentry = 0LL; + totrunentrymin = 0LL; + totrunentrymax = 0LL; irunentry = 0; prevshift = 0; + prevabstime = 0; + prevpktnum = 0; + abstime = 0ULL; + pktnum = 0; + isFragment = false; run_tree->GetEntry(irun); if (!GetOrbitalInfo()) cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl; @@ -2886,22 +2931,37 @@ gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here) if (dbc){ dbc->Close();// Emiliano + delete dbc; dbc=0; }; }; // --------------------------------------------------------------- // retrieve OBT and absolute time of the event // --------------------------------------------------------------- - ULong64_t abstime = 0LL; + // ULong64_t abstime = 0LL; // ULong64_t obt = 0LL; // Emiliano Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted + // UInt_t pkt = 0; + prevabstime = abstime; + prevpktnum = pktnum; if (GetOrbitalInfo()) { abstime = GetOrbitalInfo()->absTime; obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano + pktnum = GetOrbitalInfo()->pkt_num; // Emiliano } else { abstime = GetRunInfo()->RUNHEADER_TIME; obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano + pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano + } + + if (DBG){ + printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); + printf("0 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); + printf("0 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); + printf("0 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); + printf("0 bo irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); + printf("0 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); } // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- @@ -2922,26 +2982,331 @@ } // - bool fromfirst = true; // first loop over runs + if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits + || iev == 0 // or it is the first entry + ){ + + // check for a new run (ma prima il primo!) + if (DBG){ + printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); + printf("1 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); + printf("1 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); + printf("1 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); + printf("1 bo irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); + printf("1 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); + } + + totrunentry = 0LL; + for (Int_t r=0; r< run_tree->GetEntries();r++){ + // ------------------------------------------------------------------- + // save the index of the first entry of the run, relative to pam_tree, + // and read a new run + // ------------------------------------------------------------------- + run_tree->GetEntry(r);//update runinfo + if ( r > 0 ){ + totrunentrymin = totrunentrymax+1; + } else { + totrunentrymin = 0LL; + } + totrunentry += GetRunInfo()->NEVENTS; + totrunentrymax = totrunentry - 1; + irun = r; + + //--> needed? + if (irun > 0) + runfirstentry += (GetRunInfo()->NEVENTS) - prevshift; + irunentry = 0; + prevshift = 0; + irunt = irun - irunoffset[run_tree->GetTreeNumber()]; + //<-- needed? + + if ( iev >= totrunentrymin && iev <= totrunentrymax ){ // entry is inside run limits + // + if (gltsync) + delete gltsync; // Emiliano + if (!dbc || (dbc && !dbc->IsConnected())) + SetDBConnection(); //Emiliano + gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano + if (dbc){ + dbc->Close(); // Emiliano + delete dbc; + dbc=0; + } + if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano + cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun + << " has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl; + cout + << " (NB!! in this case some events could be assigned to a wrong run)" + << endl; + } + // + if (DBG) printf(" found \n"); + // + break; + } + } // loop over run + + // -------------------------------------- + // if there was no need to update the run + // ---> exit with FALSE + // -------------------------------------- + if (irun == oldrun) + return (false); + + // -------------------------------------- + // ... otherwise + // ---> exit with TRUE + // -------------------------------------- + + if (SELLI != 2) { + /// decrement counters since this event belongs to a new run + if (GetTrigLevel2()) { + totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time + totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time + } + totdltime[2]--; //event counter + if (DBG) { + cout << endl; + cout << "n.events : " << totdltime[2] << endl; + cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl; + cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl; + } + // add an entry + if (run_tree_clone && totdltime[2] > 0) + if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) + run_tree_clone->GetBranch("DeadLiveTime")->Fill(); + // reset counters + if ( totdltime[2] > 0 ){ + if (GetTrigLevel2()) { + totdltime[0] = GetTrigLevel2()->dltime[0];//live-time + totdltime[1] = 0; //dead-time + } + totdltime[2] = 1; //event counter + } + } + + if (DBG){ + cout << endl << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun + << endl; + + printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); + printf("2 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); + printf("2 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); + printf("2 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); + printf("2 bo irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); + printf("2 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); + } + + return (true); + } // need for run upgrade + if (DBG) printf("return false\n"); + return (false); + }// SELLI = 0 SELLI = 2 + + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + // if it is a preselected file (there is SelectionList) + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + // irun = run entry relative to the chain + // irunt = run entry relative to the tree + if (SELLI == 1) { + sel_tree->GetEntry(iev);// read irunt from SelectionList + irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW + if (irun != oldrun) { + if (irun < run_tree->GetEntries()) + run_tree->GetEntry(irun); + // check if the time is ok (with merged files it is not...) + // if not loop over run and look for the proper entry + bool SECONDO_GIRO = false; + // Long64_t irun_start = irun; + int offset_start = irunoffset[sel_tree->GetTreeNumber()]; + while (((!(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + abstime <= GetRunInfo()->RUNTRAILER_TIME) + // || + // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms) + // obt <= GetRunInfo()->RUNTRAILER_OBT) + ) || GetRunInfo()->NEVENTS == 0) + // && irun < run_tree->GetEntries() + ) { + + if (DBG) { + cout << " (test) "; + cout << " tree " << sel_tree->GetTreeNumber(); + cout << " irunt " << irunt; + cout << " offset " << irunoffset[sel_tree->GetTreeNumber()]; + cout << " abs " << abstime; + cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME; + cout << " obt " << obt; + cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT; + cout << " *** JUMP RUN *** irun " << irun; + cout << endl; + } + // irun++; + irunoffset[sel_tree->GetTreeNumber()]++; + irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW + if (irun == run_tree->GetEntries() && SECONDO_GIRO) { + // if(irun == irun_start ){ + cout << " ...grrrvzzkhhhajsdkj!!!! " << endl; + irunoffset[sel_tree->GetTreeNumber()] = offset_start; + return false; + } + if (irun >= run_tree->GetEntries() || irun < 0) { + cout << "irun = " << irun << " >> search from the beginning... <<" << endl; + SECONDO_GIRO = true; + irun = 0; + irunoffset[sel_tree->GetTreeNumber()] = -irunt; + } + run_tree->GetEntry(irun); + } + + if (DBG) { + cout << " (test) "; + cout << " tree " << sel_tree->GetTreeNumber(); + cout << " irunt " << irunt; + cout << " offset " << irunoffset[sel_tree->GetTreeNumber()]; + cout << " abs " << abstime; + cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME; + cout << " obt " << obt; + cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT; + } + if (DBG) + cout << endl; + if (DBG) + cout << endl << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " (run-entry " + << irun << ")" << endl; + // ---------------------------------------------------- + // update the tracker parameters + // (non ho trovato nessun altro modo sicuro di farlo...) + // ---------------------------------------------------- + if (!dbc || (dbc && !dbc->IsConnected())) + SetDBConnection(); + TrkParams::Set(GetRunInfo(), dbc); + if (dbc){ + dbc->Close(); + delete dbc; + dbc=0; + }; + // cout << endl; + prevshift = 0; + return true; + } + return false; + } + + return false; + // +} + +Bool_t PamLevel2::UpdateRunInfo_bckw_compat(Long64_t iev) { + + if (!run_tree) { + cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl; + return false; + } + if (run_tree->GetEntries() <= 0) { + cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty" << endl; + return (false); + } + + printf("ciccio\n"); + + Int_t oldrun = irun; // store current run index + + // ----------------------------------------------------------------------- + // the first time the routine is called, set run search from the beginning + // ----------------------------------------------------------------------- + + if (irun < 0) { + irun = 0LL; + irunt = 0LL; + irunentry = 0; + prevshift = 0; + prevabstime = 0; + prevpktnum = 0; + abstime = 0ULL; + pktnum = 0; + isFragment = false; + run_tree->GetEntry(irun); + if (!GetOrbitalInfo()) + cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl; + if (gltsync) + delete gltsync; //Emiliano + if (!dbc || (dbc && !dbc->IsConnected())) + SetDBConnection(); //Emiliano + gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here) + if (dbc){ + dbc->Close();// Emiliano + delete dbc; + dbc=0; + }; + }; + // --------------------------------------------------------------- + // retrieve OBT and absolute time of the event + // --------------------------------------------------------------- + // ULong64_t abstime = 0LL; + // ULong64_t obt = 0LL; // Emiliano + Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted + // UInt_t pkt = 0; + prevabstime = abstime; + prevpktnum = pktnum; + if (GetOrbitalInfo()) { + abstime = GetOrbitalInfo()->absTime; + obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano + pktnum = GetOrbitalInfo()->pkt_num; // Emiliano + } + else { + abstime = GetRunInfo()->RUNHEADER_TIME; + obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano + pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano + } + + printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); + printf("0rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); + printf("0rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); + printf("0rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); + printf("0irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); + + + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + // if it is a full file (not preselected) + // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- + if (SELLI == 0 || SELLI == 2) { // Emiliano + // --------------------------------------------------------------- + // increment dead and live-time counters + // (only when reading a file not preselected) + // --------------------------------------------------------------- + if (SELLI == 0) { + if (GetTrigLevel2()) { + totdltime[0] += GetTrigLevel2()->dltime[0]; + totdltime[1] += GetTrigLevel2()->dltime[1]; + } + totdltime[2]++; + } + + // + bool fromfirst = true; // first loop over runs + bool fragmentcheck = true; // ------------------------------------------------------ // loop over runs to find the one that contains the event // ------------------------------------------------------ - while (( - // ( - // !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) - // abstime <= GetRunInfo()->RUNTRAILER_TIME) && - // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms) - // obt <= GetRunInfo()->RUNTRAILER_OBT) - // ) - - !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) - abstime <= GetRunInfo()->RUNTRAILER_TIME) || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano - obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano - || GetRunInfo()->NEVENTS == 0 - // || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento - || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)) && irun < run_tree->GetEntries()) { + while ( + /*( !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + abstime <= GetRunInfo()->RUNTRAILER_TIME) + || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano + obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano + || GetRunInfo()->NEVENTS == 0 + || (isFragment && fragmentcheck && (abstime NEVENTS - 1 - prevshift) + ) && irun < run_tree->GetEntries()) {*/ + (abstime < GetRunInfo()->RUNHEADER_TIME // check on absolute time (s) + || abstime > GetRunInfo()->RUNTRAILER_TIME + || obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) // additional check on OBT (ms) + || obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) // Emiliano + || GetRunInfo()->NEVENTS == 0 + || (isFragment && fragmentcheck && (abstime (GetRunInfo()->NEVENTS - 1 - prevshift) + ) && irun < run_tree->GetEntries()) { // if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME) )cout << "ABS TIME "<RUNTRAILER_TIME <= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl; @@ -2949,13 +3314,37 @@ // if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<NEVENTS-1-prevshift << endl; // - - - - - - - - - - - - - // irunentry = position of current entry, relative to the run - // prevshift = shift needed to synchronize l0 and l2 data (nested events) + // prevshift = shift needed to synchronize L0 and L2 data (nested events) // - - - - - - - - - - - - - + + + if ((( + // ( + // !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + // abstime <= GetRunInfo()->RUNTRAILER_TIME) && + // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms) + // obt <= GetRunInfo()->RUNTRAILER_OBT) + // ) + !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + abstime <= GetRunInfo()->RUNTRAILER_TIME) + || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano + obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano + || GetRunInfo()->NEVENTS == 0 + // || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento + || (isFragment && fragmentcheck && (abstime NEVENTS - 1 - prevshift) + ) && irun < run_tree->GetEntries())) printf(" break \n"); // ----------------------------------------- // store dead and live-time of previous run // ----------------------------------------- // if(SELLI==0){ + // fragmentcheck = false; + printf("abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); + printf("rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); + printf("rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); + printf("rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); + printf("irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); if (SELLI != 2) { if (fromfirst) { if (oldrun == irun) { @@ -3005,6 +3394,7 @@ // ----------------------------------------------------- cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #" << iev << " does not belong to any run (should not happen)" << endl; + irun = 0LL; return false; } // ----------------------------------------- @@ -3034,8 +3424,32 @@ gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano if (dbc){ dbc->Close(); // Emiliano + delete dbc; dbc=0; }; + if (!(( + // ( + // !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + // abstime <= GetRunInfo()->RUNTRAILER_TIME) && + // !(obt >= GetRunInfo()->RUNHEADER_OBT && // additional check on OBT (ms) + // obt <= GetRunInfo()->RUNTRAILER_OBT) + // ) + !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s) + abstime <= GetRunInfo()->RUNTRAILER_TIME) + || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano + obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano + || GetRunInfo()->NEVENTS == 0 + // || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento + || (isFragment && fragmentcheck && (abstime NEVENTS - 1 - prevshift) + ) && irun < run_tree->GetEntries())) printf(" ECCE RUN!!!!!!!!!!!!! \n"); + + printf("Qabstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); + printf("Qrth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); + printf("Qrto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); + printf("Qirunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); + + if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun << " has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl; @@ -3066,6 +3480,9 @@ if (DBG) cout << endl << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun << endl; + + isFragment = false; + if ( GetRunInfo()->ID_RUN_FRAG != 0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID ) isFragment = true; // ---------------------------------------------------- // update the tracker parameters // (non ho trovato nessun altro modo sicuro di farlo...) @@ -3075,6 +3492,7 @@ TrkParams::Set(GetRunInfo(), dbc); if (dbc){ dbc->Close(); + delete dbc; dbc=0; }; @@ -3170,6 +3588,7 @@ TrkParams::Set(GetRunInfo(), dbc); if (dbc){ dbc->Close(); + delete dbc; dbc=0; }; // cout << endl; @@ -3182,7 +3601,7 @@ return false; // } -; + /** * Update the runinfo informations (to be used to have Run infos event by event basis) * @param run Pointer to the chain/tree which contains run infos @@ -3191,7 +3610,7 @@ Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) { return (UpdateRunInfo((TChain*) run, iev)); } -; + //-------------------------------------- // @@ -4104,7 +4523,7 @@ if (GP) { pam_tree_clone[i] = new TTree("h20", "GPAMELA info "); pam_tree_clone[i]->Branch("GPamela", "GPamela", GetPointerTo("GPamela"), 32000, 1);//split - cout << "OrbitalInfo : branch OrbitalInfo" << endl; + cout << "GPamela : branch GPamela" << endl; i++; }; cout << "+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+" << endl; @@ -4222,7 +4641,7 @@ ii = iee; // Bool_t UPDATED = UpdateRunInfo(run_tree,ii); // Bool_t UPDATED = UpdateRunInfo(ii); - UpdateRunInfo(ii); + if ( fUpdateRunInfo ) UpdateRunInfo(ii); // Emiliano if (SELLI == 0 || SELLI == 2) irunentry = iee - runfirstentry; // if(UPDATED && run_tree_clone)run_tree_clone->Fill(); @@ -4350,6 +4769,7 @@ } dbc->Close(); // EMILIANO, do not leave open connections, open only when needed + delete dbc; dbc=0; }; @@ -4371,6 +4791,7 @@ }; if(dbc){ dbc->Close(); // EMILIANO, do not leave open connections, open only when needed + delete dbc; dbc=0; }; }