394 |
PamLevel2::PamLevel2() { |
PamLevel2::PamLevel2() { |
395 |
Initialize(); |
Initialize(); |
396 |
} |
} |
397 |
; |
|
398 |
|
|
399 |
/** |
/** |
400 |
* Constructor |
* Constructor |
417 |
GetPamTree(listf, detlist); |
GetPamTree(listf, detlist); |
418 |
if (listf) |
if (listf) |
419 |
GetRunTree(listf); |
GetRunTree(listf); |
420 |
|
this->SetMaxShift(-1); |
421 |
} |
} |
422 |
; |
|
423 |
|
|
424 |
PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) { |
PamLevel2::PamLevel2(TString ddir, TList *llist, TString detlist) { |
425 |
Initialize(); |
Initialize(); |
426 |
GetPamTree(llist, detlist); |
GetPamTree(llist, detlist); |
427 |
GetRunTree(llist); |
GetRunTree(llist); |
428 |
|
this->SetMaxShift(-1); |
429 |
} |
} |
430 |
; |
|
431 |
/** |
/** |
432 |
* Constructor |
* Constructor |
433 |
* @param ddir Name of directory where level2 files are stored. |
* @param ddir Name of directory where level2 files are stored. |
440 |
TList* listf = GetListOfLevel2Files(ddir, llist); |
TList* listf = GetListOfLevel2Files(ddir, llist); |
441 |
GetPamTree(listf, ""); |
GetPamTree(listf, ""); |
442 |
GetRunTree(listf); |
GetRunTree(listf); |
443 |
|
this->SetMaxShift(-1); |
444 |
} |
} |
445 |
; |
|
446 |
|
|
447 |
void PamLevel2::Initialize() { |
void PamLevel2::Initialize() { |
448 |
|
|
474 |
runlastentry = 0LL; |
runlastentry = 0LL; |
475 |
gltsync = 0; // Emiliano |
gltsync = 0; // Emiliano |
476 |
fUpdateRunInfo = true; // Emiliano |
fUpdateRunInfo = true; // Emiliano |
477 |
|
isSync = false; // by default assume that the level2 file(s) is(are) not sinchronized between L0/DB and L2, that is we miss some packets in L2 due to nested/DV-skipped events |
478 |
|
il0entry = 0LL; |
479 |
|
hasL0EE = true; |
480 |
|
|
481 |
l0_file = NULL; |
l0_file = NULL; |
482 |
l0_tree = NULL; |
l0_tree = NULL; |
484 |
dbc = 0; |
dbc = 0; |
485 |
|
|
486 |
prevshift = 0; |
prevshift = 0; |
487 |
maxshift = 10; //EMILIANO |
yprevshift = 0; |
488 |
|
maxshift = 10; //EMILIANO now overridden by SetMaxShift(-1) called by constructors |
489 |
|
|
490 |
run_tree = NULL; |
run_tree = NULL; |
491 |
run_tree_clone = NULL; |
run_tree_clone = NULL; |
873 |
}; |
}; |
874 |
} |
} |
875 |
|
|
876 |
|
void PamLevel2::SetMaxShift(Int_t sh){ |
877 |
|
if ( sh >= 0 ){ |
878 |
|
printf("PamLevel2::SetMaxShift(Int_t) --WARNING-- the default is optimized by checking the level2 file\n it is strongly suggested to let PamLevel2 choose the max shift!\n"); |
879 |
|
maxshift = sh; |
880 |
|
} else { |
881 |
|
ULong64_t nev = this->GetEntries(); |
882 |
|
ULong64_t runnev = 0ULL; |
883 |
|
for (Int_t r=0; r< run_tree->GetEntries();r++){ |
884 |
|
run_tree->GetEntry(r);//update runinfo |
885 |
|
runnev += GetRunInfo()->NEVENTS; |
886 |
|
} |
887 |
|
maxshift = (Int_t)(runnev-nev) + 10; // +10 just to be conservative |
888 |
|
if ( (runnev-nev) == 0 ) isSync = true; |
889 |
|
if (DBG) printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift); |
890 |
|
// printf("PamLevel2::SetMaxShift(Int_t_) - sh negative %i - nev is %lld runnnev is %lld so maxshift set to %i \n",sh,nev,runnev,maxshift); // TOGLITOGLI |
891 |
|
} |
892 |
|
} |
893 |
|
|
894 |
//-------------------------------------- |
//-------------------------------------- |
895 |
// |
// |
896 |
// |
// |
2451 |
cout << "SelectionList: set branch address RunEntry" << endl; |
cout << "SelectionList: set branch address RunEntry" << endl; |
2452 |
L->SetBranchAddress("EventEntry", &irunentry); |
L->SetBranchAddress("EventEntry", &irunentry); |
2453 |
cout << "SelectionList: set branch address EventEntry" << endl; |
cout << "SelectionList: set branch address EventEntry" << endl; |
2454 |
|
if ( L->GetBranch("L0EventEntry") ){ |
2455 |
|
hasL0EE = true; |
2456 |
|
L->SetBranchAddress("L0EventEntry", &il0entry); |
2457 |
|
cout << "SelectionList: set branch address L0EventEntry" << endl; |
2458 |
|
} else { |
2459 |
|
hasL0EE = false; // backward compatibility with old preselected files... |
2460 |
|
} |
2461 |
sel_tree = L; |
sel_tree = L; |
2462 |
// if(!Trout)Trout=O; |
// if(!Trout)Trout=O; |
2463 |
// else Trout->AddFriend("SelectionList"); |
// else Trout->AddFriend("SelectionList"); |
2782 |
|
|
2783 |
} |
} |
2784 |
|
|
|
/** |
|
|
* 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 |
|
|
* @return true if a new run has been read, false if it is still the same run |
|
|
*/ |
|
|
Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) { |
|
|
// |
|
|
// check if we have already called once GetEntry, if not call it |
|
|
// |
|
|
cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) --- ATTENZIONE --- NON E` MANTENUTA!!!!!!!.... " |
|
|
<< endl; |
|
|
if (!run) { |
|
|
cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing RunInfo tree " << endl; |
|
|
return (false); |
|
|
} |
|
|
if (run->GetEntries() <= 0) |
|
|
return (false); |
|
|
// |
|
|
|
|
|
// Int_t oldrun = irun; |
|
|
Long64_t oldrun = irun; |
|
|
|
|
|
// -------------------------------------- |
|
|
// if it is a full file (not preselected) |
|
|
// -------------------------------------- |
|
|
if (SELLI == 0) { |
|
|
|
|
|
// |
|
|
// the absolute time is necessary to relate the event with the run |
|
|
// |
|
|
if (!GetOrbitalInfo() && !ISGP) { |
|
|
cout << "Bool_t PamLevel2::UpdateRunInfo(TChain *run, ULong64_t iev) -- ERROR -- missing OrbitalInfo " << endl; |
|
|
return (false); |
|
|
} |
|
|
|
|
|
ULong64_t abstimeu = 0; |
|
|
if (GetOrbitalInfo()) |
|
|
abstimeu = GetOrbitalInfo()->absTime; |
|
|
|
|
|
// |
|
|
// the first time the routine is called, set run search from the beginning |
|
|
// |
|
|
if (irun < 0LL) { |
|
|
irun = 0LL; |
|
|
run->GetEntry(irun); |
|
|
runfirstentry = 0LL; |
|
|
runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); |
|
|
if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL) |
|
|
runlastentry -= 1LL; |
|
|
|
|
|
if (ISGP && run->GetEntries() != 1) { |
|
|
cout << "** WARNING ** simulated files are assumed to have 1 single run, not " << run->GetEntries() << endl; |
|
|
cout << "** WARNING ** run will not be updated" << endl; |
|
|
} |
|
|
|
|
|
}; |
|
|
// |
|
|
if (ISGP) |
|
|
abstimeu = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO |
|
|
// |
|
|
if (irun == run->GetEntries() - 1LL && !(abstimeu >= GetRunInfo()->RUNHEADER_TIME && abstimeu |
|
|
<= GetRunInfo()->RUNTRAILER_TIME)) { |
|
|
irun = -1LL; |
|
|
irunt = -1LL; |
|
|
runfirstentry = 0LL; |
|
|
runlastentry = -1LL; |
|
|
}; |
|
|
// modificato il controllo sull'aggiornamento del run, per evitare problemi |
|
|
// dovuti agli eventi annidati (NB! NEVENTS conta anche questi!!) |
|
|
// |
|
|
bool fromfirst = true; |
|
|
// |
|
|
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++; |
|
|
run->GetEntry(irun); |
|
|
runfirstentry = runlastentry; |
|
|
if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL) |
|
|
runfirstentry += 1LL; |
|
|
runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); |
|
|
// cout << " ))))) UPDATE RUN INFO ((((( @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl; |
|
|
// cout << "runfirstentry "<<runfirstentry<<endl; |
|
|
// printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS))); |
|
|
// 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 && !(abstimeu >= GetRunInfo()->RUNHEADER_TIME |
|
|
&& abstimeu <= GetRunInfo()->RUNTRAILER_TIME)) { |
|
|
printf(" resetting irun (it should NOT happen!!!)\n"); |
|
|
fromfirst = false; |
|
|
irun = 0; |
|
|
run->GetEntry(irun); |
|
|
runfirstentry = 0ULL; |
|
|
runlastentry += (Long64_t)(this->GetRunInfo()->NEVENTS); |
|
|
if ((Long64_t)(this->GetRunInfo()->NEVENTS) > 0LL) |
|
|
runlastentry -= 1LL; |
|
|
}; |
|
|
// |
|
|
}; |
|
|
// |
|
|
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; |
|
|
} |
|
|
// |
|
|
if (irun == oldrun || irun >= run->GetEntries()) |
|
|
return (false); |
|
|
// |
|
|
// printf(" iev %llu irun %i nevents %u 1st %llu last %llu \n",iev,irun,this->GetRunInfo()->NEVENTS,(ULong64_t)runfirstentry,(ULong64_t)runlastentry); |
|
|
// |
|
|
prevshift = 0; |
|
|
cout << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun << endl; |
|
|
// cout << "runfirstentry "<<runfirstentry<<endl; |
|
|
return (true); |
|
|
}; |
|
|
// ---------------------------------------------------- |
|
|
// if it is a preselected file (there is SelectionList) |
|
|
// NBNB - the event tree MUST be read first |
|
|
// ---------------------------------------------------- |
|
|
if (SELLI == 1) { |
|
|
sel_tree->GetEntry(iev); |
|
|
// cout << irun << " "<< irunentry << endl; |
|
|
if (irun != oldrun) { |
|
|
run->GetEntry(irun); |
|
|
cout << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun << endl; |
|
|
prevshift = 0; |
|
|
return true; |
|
|
} |
|
|
return false; |
|
|
} |
|
|
|
|
|
return false; |
|
|
// |
|
|
} |
|
|
|
|
|
|
|
2785 |
Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) { |
Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) { |
2786 |
|
|
2787 |
|
if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - inside\n"); |
2788 |
|
|
2789 |
if (!run_tree) { |
if (!run_tree) { |
2790 |
cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl; |
cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl; |
2791 |
return false; |
return false; |
2795 |
return (false); |
return (false); |
2796 |
} |
} |
2797 |
|
|
|
if (DBG) printf("ciccio\n"); |
|
2798 |
|
|
2799 |
Int_t oldrun = irun; // store current run index |
Int_t oldrun = irun; // store current run index |
2800 |
|
|
2808 |
totrunentry = 0LL; |
totrunentry = 0LL; |
2809 |
totrunentrymin = 0LL; |
totrunentrymin = 0LL; |
2810 |
totrunentrymax = 0LL; |
totrunentrymax = 0LL; |
2811 |
irunentry = 0; |
irunentry = 0LL; |
2812 |
|
il0entry = 0LL; |
2813 |
prevshift = 0; |
prevshift = 0; |
2814 |
|
yprevshift = 0; |
2815 |
prevabstime = 0; |
prevabstime = 0; |
2816 |
prevpktnum = 0; |
prevpktnum = 0; |
2817 |
abstime = 0ULL; |
abstime = 0ULL; |
2834 |
// --------------------------------------------------------------- |
// --------------------------------------------------------------- |
2835 |
// retrieve OBT and absolute time of the event |
// retrieve OBT and absolute time of the event |
2836 |
// --------------------------------------------------------------- |
// --------------------------------------------------------------- |
|
// ULong64_t abstime = 0LL; |
|
|
// ULong64_t obt = 0LL; // Emiliano |
|
2837 |
Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted |
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; |
|
2838 |
prevabstime = abstime; |
prevabstime = abstime; |
2839 |
prevpktnum = pktnum; |
prevpktnum = pktnum; |
2840 |
if (GetOrbitalInfo()) { |
if (GetOrbitalInfo()) { |
2853 |
printf("0 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
printf("0 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
2854 |
printf("0 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
printf("0 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
2855 |
printf("0 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
printf("0 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
2856 |
printf("0 bo irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); |
printf("0 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); |
2857 |
printf("0 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); |
printf("0 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); |
2858 |
} |
} |
2859 |
|
|
2877 |
// |
// |
2878 |
if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits |
if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits |
2879 |
|| iev == 0 // or it is the first entry |
|| iev == 0 // or it is the first entry |
2880 |
){ |
|| (!isSync && ( |
2881 |
|
(abstime <= GetRunInfo()->RUNHEADER_TIME && obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) // or it is outside obt limits (and abstime limits for security reasons) |
2882 |
|
|| (abstime >= GetRunInfo()->RUNTRAILER_TIME && obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) ))// or it is outside obt limits (and abstime limits for security reasons) |
2883 |
|
){ // check on abstime and obt needed to handle nested+DV_skipped packets |
2884 |
|
|
2885 |
// check for a new run (ma prima il primo!) |
// check for a new run (ma prima il primo!) |
2886 |
if (DBG){ |
if (DBG){ |
2888 |
printf("1 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
printf("1 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
2889 |
printf("1 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
printf("1 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
2890 |
printf("1 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
printf("1 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
2891 |
printf("1 bo irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); |
printf("1 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); |
2892 |
printf("1 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); |
printf("1 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); |
2893 |
} |
} |
2894 |
|
// printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); |
2895 |
|
// printf("1 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
2896 |
|
// printf("1 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
2897 |
|
// printf("1 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
2898 |
|
// printf("1 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); |
2899 |
|
// printf("1 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI |
2900 |
|
|
2901 |
totrunentry = 0LL; |
totrunentry = 0LL; |
2902 |
|
runfirstentry = 0LL; |
2903 |
for (Int_t r=0; r< run_tree->GetEntries();r++){ |
for (Int_t r=0; r< run_tree->GetEntries();r++){ |
2904 |
// ------------------------------------------------------------------- |
// ------------------------------------------------------------------- |
2905 |
// save the index of the first entry of the run, relative to pam_tree, |
// save the index of the first entry of the run, relative to pam_tree, |
2912 |
totrunentrymin = 0LL; |
totrunentrymin = 0LL; |
2913 |
} |
} |
2914 |
totrunentry += GetRunInfo()->NEVENTS; |
totrunentry += GetRunInfo()->NEVENTS; |
2915 |
totrunentrymax = totrunentry - 1; |
totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets |
2916 |
irun = r; |
irun = r; |
2917 |
|
|
2918 |
//--> needed? |
if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits |
2919 |
if (irun > 0) |
( !isSync && |
2920 |
runfirstentry += (GetRunInfo()->NEVENTS) - prevshift; |
( abstime >= GetRunInfo()->RUNHEADER_TIME && obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) // or it is inside obt limits (and abstime limits for security reasons) |
2921 |
irunentry = 0; |
&& abstime <= GetRunInfo()->RUNTRAILER_TIME && obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT))) // or it is inside obt limits (and abstime limits for security reasons) |
2922 |
prevshift = 0; |
){ // check on abstime and obt needed to handle nested+DV_skipped packets |
2923 |
irunt = irun - irunoffset[run_tree->GetTreeNumber()]; |
if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets) |
2924 |
//<-- needed? |
if ( !isSync ){ |
2925 |
|
if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n"); |
2926 |
|
if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax); |
2927 |
|
// printf("PamLevel2::UpdateRunInfo(Long64_t) - unconsistent iev - nevents, probable DBL0-L2 async\n"); |
2928 |
|
// printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI |
2929 |
|
prevshift += (totrunentrymin-iev); // add the new shift to total shift |
2930 |
|
totrunentrymin -= (totrunentrymin-iev); // shift run position min |
2931 |
|
totrunentrymax -= (totrunentrymin-iev); // shift run position max |
2932 |
|
if (DBG) printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax); |
2933 |
|
// printf("PamLevel2::UpdateRunInfo(Long64_t) - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI |
2934 |
|
} else { |
2935 |
|
printf(" PamLevel2::UpdateRunInfo(Long64_t) ERROR! sync file but unconsistent totrunetrymin %lld and iev %lld!!! \n",totrunentrymin,iev); |
2936 |
|
cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl; |
2937 |
|
cout << "\nFor bug reporting instructions, please see for example:\n"; |
2938 |
|
cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n"; |
2939 |
|
cout << " " << endl; |
2940 |
|
} |
2941 |
|
} |
2942 |
|
runfirstentry = totrunentrymin; // first entry of the run in the level2 |
2943 |
|
|
2944 |
|
|
|
if ( iev >= totrunentrymin && iev <= totrunentrymax ){ // entry is inside run limits |
|
2945 |
// |
// |
2946 |
if (gltsync) |
if (gltsync) |
2947 |
delete gltsync; // Emiliano |
delete gltsync; // Emiliano |
2962 |
} |
} |
2963 |
// |
// |
2964 |
if (DBG) printf(" found \n"); |
if (DBG) printf(" found \n"); |
2965 |
|
// printf(" found \n");//TOGLITOGLI |
2966 |
// |
// |
2967 |
break; |
break; |
2968 |
} |
} |
2972 |
// if there was no need to update the run |
// if there was no need to update the run |
2973 |
// ---> exit with FALSE |
// ---> exit with FALSE |
2974 |
// -------------------------------------- |
// -------------------------------------- |
2975 |
if (irun == oldrun) |
if (irun == oldrun){ |
2976 |
|
if (DBG) printf(" no new run \n"); |
2977 |
|
// printf(" no new run \n");//TOGLITOGLI |
2978 |
return (false); |
return (false); |
2979 |
|
} |
2980 |
// -------------------------------------- |
// -------------------------------------- |
2981 |
// ... otherwise |
// ... otherwise |
2982 |
// ---> exit with TRUE |
// ---> exit with TRUE |
3011 |
|
|
3012 |
if (DBG){ |
if (DBG){ |
3013 |
cout << endl << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun |
cout << endl << " ))))) UPDATE RUN INFO ((((( @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun |
3014 |
<< endl; |
<< endl; |
|
|
|
3015 |
printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); |
printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); |
3016 |
printf("2 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
printf("2 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
3017 |
printf("2 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
printf("2 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
3018 |
printf("2 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
printf("2 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
3019 |
printf("2 bo irunentry %lld prevshift %d irun %lld \n",irunentry,prevshift,irun); |
printf("2 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); |
3020 |
printf("2 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); |
printf("2 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); |
3021 |
} |
} |
3022 |
|
// printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt); |
3023 |
|
// printf("2 rth %d %d nevents %d \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS); |
3024 |
|
// printf("2 rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT); |
3025 |
|
// printf("2 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); |
3026 |
|
// printf("2 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); |
3027 |
|
// printf("2 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);//TOGLITOGLI |
3028 |
|
|
3029 |
return (true); |
return (true); |
3030 |
} // need for run upgrade |
} // need for run upgrade |
3116 |
}; |
}; |
3117 |
// cout << endl; |
// cout << endl; |
3118 |
prevshift = 0; |
prevshift = 0; |
3119 |
|
yprevshift = 0; |
3120 |
return true; |
return true; |
3121 |
} |
} |
3122 |
return false; |
return false; |
3126 |
// |
// |
3127 |
} |
} |
3128 |
|
|
3129 |
Bool_t PamLevel2::UpdateRunInfo_bckw_compat(Long64_t iev) { |
/** |
3130 |
|
* Update the runinfo informations (to be used to have Run infos event by event basis) |
3131 |
if (!run_tree) { |
* @param run Pointer to the chain/tree which contains run infos |
3132 |
cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl; |
* @return true if a new run has been read, false if it is still the same run |
3133 |
return false; |
*/ |
3134 |
} |
Bool_t PamLevel2::UpdateRunInfo(TChain *run, Long64_t iev) { |
3135 |
if (run_tree->GetEntries() <= 0) { |
return (UpdateRunInfo(iev)); |
|
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 >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano |
|
|
obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano |
|
|
|| GetRunInfo()->NEVENTS == 0 |
|
|
|| (isFragment && fragmentcheck && (abstime <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum |
|
|
|| !(irunentry <= GetRunInfo()->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 <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum |
|
|
|| irunentry > (GetRunInfo()->NEVENTS - 1 - prevshift) |
|
|
) && irun < run_tree->GetEntries()) { |
|
|
|
|
|
// if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME) )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl; |
|
|
// if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl; |
|
|
// if( GetRunInfo()->NEVENTS==0 )cout <<"GetRunInfo()->NEVENTS==0 "<<endl; |
|
|
// if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl; |
|
|
// - - - - - - - - - - - - - |
|
|
// irunentry = position of current entry, relative to the run |
|
|
// 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 <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum |
|
|
|| !(irunentry <= GetRunInfo()->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) { |
|
|
/// decrement counters |
|
|
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; |
|
|
} |
|
|
} |
|
|
else { |
|
|
totdltime[0] = 0;//live-time |
|
|
totdltime[1] = 0;//dead-time |
|
|
totdltime[2] = 0; //event counter |
|
|
if (DBG) |
|
|
cout << " *** JUMP RUN *** irun " << irun << endl; |
|
|
} |
|
|
/// add an entry |
|
|
if (run_tree_clone) |
|
|
if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries()) |
|
|
run_tree_clone->GetBranch("DeadLiveTime")->Fill(); |
|
|
/// reset counters |
|
|
if (GetTrigLevel2()) { |
|
|
totdltime[0] = GetTrigLevel2()->dltime[0];//live-time |
|
|
totdltime[1] = 0; //dead-time |
|
|
} |
|
|
totdltime[2] = 1; //event counter |
|
|
} |
|
|
} |
|
|
// } |
|
|
|
|
|
irun++; |
|
|
// ------------------------------------ |
|
|
// if the end of run tree is reached... |
|
|
// ------------------------------------ |
|
|
if (irun == run_tree->GetEntries()) { |
|
|
if (!fromfirst) { |
|
|
// ----------------------------------------------------- |
|
|
// if it happened already once and the run was not found |
|
|
// ---> exit with error |
|
|
// ----------------------------------------------------- |
|
|
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; |
|
|
} |
|
|
// ----------------------------------------- |
|
|
// ...otherwise repeat search from beginning |
|
|
// ----------------------------------------- |
|
|
cout |
|
|
<< "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- reached end of run tree. searchin again from beginning " |
|
|
<< endl; |
|
|
fromfirst = false; |
|
|
irun = 0LL; |
|
|
runfirstentry = 0LL; |
|
|
} |
|
|
// ------------------------------------------------------------------- |
|
|
// save the index of the first entry of the run, relative to pam_tree, |
|
|
// and read a new run |
|
|
// ------------------------------------------------------------------- |
|
|
if (irun > 0) |
|
|
runfirstentry += (GetRunInfo()->NEVENTS) - prevshift; |
|
|
irunentry = 0; |
|
|
prevshift = 0; |
|
|
run_tree->GetEntry(irun);//update runinfo |
|
|
irunt = irun - irunoffset[run_tree->GetTreeNumber()]; |
|
|
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 (!(( |
|
|
// ( |
|
|
// !(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 <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum |
|
|
|| !(irunentry <= GetRunInfo()->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; |
|
|
cout |
|
|
<< " (NB!! in this case some events are assigned to a wrong run)" |
|
|
<< endl; |
|
|
} |
|
|
// if(hasfrag && fragid != GetRunInfo()->ID){ |
|
|
// cout << "... where is the next fragment ??"<<endl; |
|
|
// } |
|
|
}; |
|
|
|
|
|
// -------------------------------------- |
|
|
// if there was no need to update the run |
|
|
// ---> exit with FALSE |
|
|
// -------------------------------------- |
|
|
if (irun == oldrun) |
|
|
return (false); |
|
|
|
|
|
// -------------------------------------- |
|
|
// ... otherwise |
|
|
// -------------------------------------- |
|
|
|
|
|
|
|
|
// -------------------------------------- |
|
|
// ---> exit with TRUE |
|
|
// -------------------------------------- |
|
|
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...) |
|
|
// ---------------------------------------------------- |
|
|
if (!dbc || (dbc && !dbc->IsConnected())) |
|
|
SetDBConnection(); |
|
|
TrkParams::Set(GetRunInfo(), dbc); |
|
|
if (dbc){ |
|
|
dbc->Close(); |
|
|
delete dbc; |
|
|
dbc=0; |
|
|
}; |
|
|
|
|
|
// ---------------------------------------------------- |
|
|
// then check if the run has a fragment |
|
|
// in this case we have to switch to the next fragment |
|
|
// when the end of the first fragment is reached |
|
|
// ---------------------------------------------------- |
|
|
if (GetRunInfo()->ID_RUN_FRAG != 0 && |
|
|
// GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID && |
|
|
DBG && true) { |
|
|
cout << "* fragment *" << endl; |
|
|
} |
|
|
|
|
|
return (true); |
|
|
}; |
|
|
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
|
|
// 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; |
|
|
// |
|
3136 |
} |
} |
3137 |
|
|
3138 |
/** |
/** |
3974 |
// sel_tree_clone->Branch("RunEntry",&irun,"runentry/L"); |
// sel_tree_clone->Branch("RunEntry",&irun,"runentry/L"); |
3975 |
sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW |
sel_tree_clone->Branch("RunEntry", &irunt, "runentry/L");//NEWNEW |
3976 |
sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L"); |
sel_tree_clone->Branch("EventEntry", &irunentry, "eventry/L"); |
3977 |
|
if ( hasL0EE ) sel_tree_clone->Branch("L0EventEntry", &il0entry, "l0eventry/L"); |
3978 |
}; |
}; |
3979 |
|
|
3980 |
Int_t i = 0; |
Int_t i = 0; |
4130 |
/** |
/** |
4131 |
* Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry. |
* Method to get level2-trees entry, the corresponding run entry and (if required) the level0 entry. |
4132 |
*/ |
*/ |
|
//Int_t PamLevel2::GetEntry(Int_t iee){ |
|
4133 |
Int_t PamLevel2::GetEntry(Long64_t iee) { |
Int_t PamLevel2::GetEntry(Long64_t iee) { |
4134 |
|
|
|
// cout << "-------------------------------------"<<endl; |
|
|
// cout << "Int_t PamLevel2::GetEntry("<<iee<<")"<<endl; |
|
|
|
|
4135 |
if (!pam_tree) { |
if (!pam_tree) { |
4136 |
cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded" << endl; |
cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- level2 trees not loaded" << endl; |
4137 |
return 0; |
return 0; |
4145 |
// return 0; |
// return 0; |
4146 |
// } |
// } |
4147 |
|
|
|
Long64_t ii = 0; |
|
4148 |
//------------------------------- |
//------------------------------- |
4149 |
ii = iee; |
if (!pam_tree->GetEntry(iee)) { |
|
if (!pam_tree->GetEntry(ii)) { |
|
4150 |
cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree" << endl; |
cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading pam tree" << endl; |
4151 |
return 0; |
return 0; |
4152 |
} |
} |
4166 |
} |
} |
4167 |
|
|
4168 |
//------------------------------- |
//------------------------------- |
4169 |
ii = iee; |
// |
4170 |
// Bool_t UPDATED = UpdateRunInfo(run_tree,ii); |
if ( fUpdateRunInfo ) UpdateRunInfo(iee); // Emiliano |
4171 |
// Bool_t UPDATED = UpdateRunInfo(ii); |
if (SELLI == 0 || SELLI == 2) irunentry = iee - runfirstentry; |
|
if ( fUpdateRunInfo ) UpdateRunInfo(ii); // Emiliano |
|
|
if (SELLI == 0 || SELLI == 2) |
|
|
irunentry = iee - runfirstentry; |
|
|
// if(UPDATED && run_tree_clone)run_tree_clone->Fill(); |
|
|
|
|
|
// cout << "PamLevel2::GetEntry("<<iee<<") "<<irun<<" "<<runfirstentry<<" "<<irunentry<<endl; |
|
|
|
|
|
// cout << "irunentry "<<irunentry << endl; |
|
|
// cout << "runfirstentry "<<runfirstentry << endl; |
|
|
// cout << "nevents "<<GetRunInfo()->NEVENTS<< endl; |
|
|
|
|
|
// if( TRK0 || CAL0 || TOF0 ){ |
|
|
// if( !GetYodaEntry( ) ){ |
|
|
// cout << " Int_t PamLevel2::GetEntry(Int_t) -- ERROR -- error reading level0 tree"<<endl; |
|
|
// return 0; |
|
|
// } |
|
|
// } |
|
|
|
|
4172 |
|
|
4173 |
return 1; |
return 1; |
4174 |
|
|
4209 |
//=================================== |
//=================================== |
4210 |
if (irun < 0) { |
if (irun < 0) { |
4211 |
cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl; |
cout << "PamLevel2::GetYodaTree() -- ERROR -- irun = " << irun << endl; |
4212 |
// cout << "In order to use this method you have to first load the RunInfo tree "<<endl; |
if (DBG) cout << "In order to use this method you have to first load the RunInfo tree "<<endl; |
4213 |
return NULL; |
return NULL; |
4214 |
} |
} |
4215 |
Int_t irootnew = run_obj->ID_ROOT_L0; |
Int_t irootnew = GetRunInfo()->ID_ROOT_L0; |
4216 |
// cout << "iroot "<<iroot<<endl; |
if (DBG){ |
4217 |
// cout << "irootnew "<<irootnew<<endl; |
cout << "iroot "<<iroot<<endl; |
4218 |
|
cout << "irootnew "<<irootnew<<endl; |
4219 |
|
} |
4220 |
|
|
4221 |
//=================================== |
//=================================== |
4222 |
// load the level0 file |
// load the level0 file |
4254 |
if (!h0_obj) |
if (!h0_obj) |
4255 |
h0_obj = new EventHeader(); |
h0_obj = new EventHeader(); |
4256 |
l0_tree->SetBranchAddress("Header", &h0_obj); |
l0_tree->SetBranchAddress("Header", &h0_obj); |
4257 |
prevshift = 0; |
yprevshift = 0; // yes, yprevshift is the shift in the level0, prevshift is the shift in the level2 |
4258 |
//--------------------------------------------------- |
//--------------------------------------------------- |
4259 |
// TRACKER: |
// TRACKER: |
4260 |
if (TRK0) { |
if (TRK0) { |
4272 |
calo0_obj->Set(); |
calo0_obj->Set(); |
4273 |
}; |
}; |
4274 |
l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent()); |
l0_tree->SetBranchAddress("Calorimeter", calo0_obj->GetPointerToCalorimeterEvent()); |
|
// cout << "PamLevel2::GetYodaTree() --- level0 calorimeter not implemented "<<endl; |
|
4275 |
} |
} |
4276 |
//--------------------------------------------------- |
//--------------------------------------------------- |
4277 |
// TOF: |
// TOF: |
4285 |
|
|
4286 |
}; |
}; |
4287 |
|
|
|
// if(!dbc || (dbc && !dbc->IsConnected())){ |
|
|
// cout << " TTree* PamLevel2::GetYodaTree( ) -- no DB connected... hai fatto qualche cazzata "<<endl; |
|
|
// } |
|
|
|
|
4288 |
if (TRK0) { |
if (TRK0) { |
4289 |
// TrkParams::Load(6); |
if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection(); |
|
// if( !TrkParams::IsLoaded(6) ){ |
|
|
// cout << " TTree* PamLevel2::GetYodaTree( ) -- WARNING -- VK-mask not loaded"<<endl; |
|
|
// }; |
|
|
if(!dbc || (dbc && !dbc->IsConnected()))SetDBConnection(); // PERCHE` ERA COMMENTATA QUESTA RIGA? |
|
4290 |
TrkParams::SetCalib(run_obj, dbc); |
TrkParams::SetCalib(run_obj, dbc); |
4291 |
TrkParams::LoadCalib(); |
TrkParams::LoadCalib(); |
4292 |
if (!TrkParams::CalibIsLoaded()) { |
if (!TrkParams::CalibIsLoaded()) { |
4298 |
dbc=0; |
dbc=0; |
4299 |
}; |
}; |
4300 |
} |
} |
|
|
|
|
// cout << l0_tree << endl; |
|
4301 |
return l0_tree; |
return l0_tree; |
|
|
|
4302 |
} |
} |
4303 |
|
|
4304 |
/** |
/** |
4306 |
*/ |
*/ |
4307 |
Int_t PamLevel2::GetYodaEntry() { |
Int_t PamLevel2::GetYodaEntry() { |
4308 |
|
|
4309 |
// cout << "Int_t PamLevel2::GetYodaEntry()"<<endl; |
Long64_t iev = this->GetReadEntry(); |
|
if (!GetYodaTree()) |
|
|
return 0; |
|
4310 |
|
|
4311 |
// patch |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
4312 |
if (irunentry < 0) { |
// if it is a full file (not preselected) |
4313 |
// cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; |
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- |
4314 |
irunentry = 0LL; |
if (SELLI == 0 || SELLI == 2 || !hasL0EE) { |
|
} |
|
|
// --------------------------------- |
|
|
// if file is NOT a preselected file |
|
|
// --------------------------------- |
|
|
Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); |
|
|
// cout << " irunentry "<<irunentry<<endl; |
|
|
// cout << " EV_FROM "<<run_obj->EV_FROM<<endl; |
|
|
// cout << " quellagiusta = irunentry + EV_FROM "<< quellagiusta << endl; |
|
|
|
|
|
// cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl; |
|
|
// cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl; |
|
|
// cout << " time "<< abstime << endl; |
|
|
// cout << " trk_calib_used "<<run_obj->TRK_CALIB_USED<< endl; |
|
4315 |
|
|
4316 |
ULong64_t obt = 0; |
if (!GetYodaTree()){ |
4317 |
ULong64_t pktn = 0; |
printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n"); |
4318 |
if (GetOrbitalInfo()) { |
return 0; |
4319 |
obt = GetOrbitalInfo()->OBT; |
} |
|
pktn = GetOrbitalInfo()->pkt_num; |
|
|
} |
|
4320 |
|
|
4321 |
if (!GetOrbitalInfo() && !ISGP) { |
if (irunentry < 0) { |
4322 |
cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl; |
if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; |
4323 |
return 0; |
// cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI |
4324 |
} |
irunentry = 0LL; |
4325 |
if (obt == 0 && pktn == 0 && !ISGP) { |
} |
4326 |
cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl; |
// --------------------------------- |
4327 |
return 0; |
// if file is NOT a preselected file |
4328 |
} |
// --------------------------------- |
4329 |
|
Long64_t quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry |
4330 |
|
|
4331 |
|
if (DBG){ |
4332 |
|
cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl; |
4333 |
|
cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl; |
4334 |
|
cout << " time "<< abstime << endl; |
4335 |
|
} |
4336 |
|
|
4337 |
|
ULong64_t obt = 0; |
4338 |
|
ULong64_t pktn = 0; |
4339 |
|
if (GetOrbitalInfo()) { |
4340 |
|
obt = GetOrbitalInfo()->OBT; |
4341 |
|
pktn = GetOrbitalInfo()->pkt_num; |
4342 |
|
} |
4343 |
|
|
4344 |
// --------------------------------------------------------------------- |
if (!GetOrbitalInfo() && !ISGP) { |
4345 |
// ATTENTION!!! |
cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing OrbitalInfo " << endl; |
4346 |
// If data are not pre-processed with cleaner, the level0 tree may contain |
return 0; |
|
// spurious nested physics packets. |
|
|
// The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries |
|
|
// while level2 tree DOES NOT!! |
|
|
// This means that "quellagiusta" in these cases is not correct. |
|
|
// In order to retrieve the correct level0 event, I implemented a check |
|
|
// of the OBT and pkt-number. In case of mismatch, the level0 entry number |
|
|
// is shift forward until when the packets match. |
|
|
// --------------------------------------------------------------------- |
|
|
Int_t answer = 0; |
|
|
Int_t shift = 0; |
|
|
// printf(" siamo qui %i %i \n",shift,prevshift); |
|
|
// Int_t maxshift = 50; // EMILIANO |
|
|
do { |
|
|
if (shift > 0) { |
|
|
cout << " PKTNUM L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl; |
|
|
if (DBG) |
|
|
cout << " RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG " |
|
|
<< GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl; |
|
|
if (DBG) |
|
|
cout << " L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift |
|
|
<< " prevshift " << prevshift << " )" << endl; |
|
4347 |
} |
} |
4348 |
answer = l0_tree->GetEntry(quellagiusta + (Long64_t) shift + (Long64_t) prevshift); |
if (obt == 0 && pktn == 0 && !ISGP) { |
4349 |
shift++; |
cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- level2 event corrupted ?? " << endl; |
|
if (!GetEventHeader()) { |
|
|
cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl; |
|
4350 |
return 0; |
return 0; |
4351 |
} |
} |
4352 |
|
|
4353 |
|
// --------------------------------------------------------------------- |
4354 |
|
// ATTENTION!!! |
4355 |
|
// If data are not pre-processed with cleaner, the level0 tree may contain |
4356 |
|
// spurious nested physics packets. |
4357 |
|
// The GL_RUN variables EV_FROM, EV_TO and NEVENTS counts also these entries |
4358 |
|
// while level2 tree DOES NOT!! |
4359 |
|
// This means that "quellagiusta" in these cases is not correct. |
4360 |
|
// In order to retrieve the correct level0 event, I implemented a check |
4361 |
|
// of the OBT and pkt-number. In case of mismatch, the level0 entry number |
4362 |
|
// is shift forward until when the packets match. |
4363 |
|
// --------------------------------------------------------------------- |
4364 |
|
Long64_t shift = 0LL; |
4365 |
|
Long64_t answer = quellagiusta + shift + yprevshift; |
4366 |
|
Int_t readl0 = 0; |
4367 |
|
readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry |
4368 |
|
|
4369 |
|
if (DBG){ |
4370 |
|
printf(" siamo qui shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer); |
4371 |
|
} |
4372 |
|
|
4373 |
|
|
4374 |
if (ISGP) { |
if (ISGP) { |
4375 |
obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO |
obt = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()); //BARBATRUCCO |
4376 |
pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO |
pktn = (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()); //BARBATRUCCO |
4377 |
} |
} |
4378 |
|
|
4379 |
// cout << "PKTNUM "<<shift<<" == L2 --- "<< pktn << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetCounter()<<endl; |
while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){ |
4380 |
// cout << " L2 --- "<< obt << " --- L0 --- "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime()<<endl; |
if ( isSync && shift == 0LL ){ |
4381 |
// if( (quellagiusta+shift) == l0_tree->GetEntries()+1 )cout << ">>> end of level0 tree <<<"<<endl; |
printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found in place!!! \n"); |
4382 |
// cout << " obt "<< obt << endl; |
cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl; |
4383 |
// cout << " GetEventHeader()->GetPscuHeader()->GetOrbitalTime() "<< GetEventHeader()->GetPscuHeader()->GetOrbitalTime() << endl; |
cout << "\nFor bug reporting instructions, please see for example:\n"; |
4384 |
// cout << " pktn "<< pktn << endl; |
cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n"; |
4385 |
// cout << " GetEventHeader()->GetPscuHeader()->GetCounter() "<< GetEventHeader()->GetPscuHeader()->GetCounter() << endl; |
cout << " " << endl; |
4386 |
// printf(" IDRUN %u \n",GetRunInfo()->ID); |
} |
4387 |
// |
if (shift > 0) { |
4388 |
if (prevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) { |
cout << " PKTNUM L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl; |
4389 |
prevshift = 0; |
if (DBG) |
4390 |
shift = -1; |
cout << " RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG " |
4391 |
}; |
<< GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl; |
4392 |
|
if (DBG) |
4393 |
|
cout << " L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift |
4394 |
|
<< " prevshift " << prevshift << " )" << endl; |
4395 |
|
} |
4396 |
|
answer = quellagiusta + shift+ yprevshift; |
4397 |
|
readl0 = l0_tree->GetEntry(answer); |
4398 |
|
// printf(" inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI |
4399 |
|
|
4400 |
} while ((obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)( |
if (!GetEventHeader()) { |
4401 |
GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) |
cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl; |
4402 |
< GetYodaTree()->GetEntries() && shift < maxshift); |
return 0; |
4403 |
|
} |
4404 |
|
|
4405 |
if ((quellagiusta + (Long64_t) shift + (Long64_t) prevshift) > GetYodaTree()->GetEntries() || shift == maxshift) { |
// |
4406 |
cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl; |
if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) { |
4407 |
return 0; |
if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer); |
4408 |
} |
// printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI |
4409 |
// cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl; |
yprevshift = 0LL; |
4410 |
// return GetYodaTree()->GetEntry(quellagiusta); |
shift = -1LL; |
4411 |
if (shift > 1) |
}; |
4412 |
prevshift += (shift - 1); |
|
4413 |
|
shift++; |
4414 |
|
} |
4415 |
|
|
4416 |
|
|
4417 |
return answer; |
if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){ |
4418 |
|
if ( isSync ){ |
4419 |
|
printf(" PamLevel2::GetYodaEntry() ERROR! sync file but the level0 entry not found AT ALL!!! \n"); |
4420 |
|
cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl; |
4421 |
|
cout << "\nFor bug reporting instructions, please see for example:\n"; |
4422 |
|
cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n"; |
4423 |
|
cout << " " << endl; |
4424 |
|
} |
4425 |
|
cout << "Int_t PamLevel2::GetYodaEntry() -- WARNING -- " << endl; |
4426 |
|
cout << " Big trouble here, no such event in Level0 data! (NB maxshift set to " << maxshift << " )" << endl; |
4427 |
|
cout << " Nested and/or DarthVader skipped packets in fragmented run? checking and trying to fix " <<endl; |
4428 |
|
// query the DB for runs containing the event, loop over LEVEL0 files which could contain the level0 event and try to find it |
4429 |
|
// ma nel mezzo del cammin per ogni run che pesco devo vedere la posizione relativa di iev rispetto al runheader nel livello2 per andare a cercare nel posto giusto |
4430 |
|
// connect to db |
4431 |
|
if (!dbc || (dbc && !dbc->IsConnected())) SetDBConnection(); //Emiliano |
4432 |
|
// |
4433 |
|
if (GetOrbitalInfo()){ |
4434 |
|
abstime = GetOrbitalInfo()->absTime; |
4435 |
|
} else { |
4436 |
|
printf(" PamLevel2::GetYodaEntry() ERROR! no OrbitalInfo, cannot get the absolute time for event \n"); |
4437 |
|
return 0; |
4438 |
|
} |
4439 |
|
// query DB looking for runs containing the processed event |
4440 |
|
TSQLResult *pResult; |
4441 |
|
TSQLRow *Row = NULL; |
4442 |
|
TString myquery = Form("select ID,NEVENTS from GL_RUN where RUNHEADER_TIME<=%lld and RUNTRAILER_TIME>=%lld;",abstime,abstime); |
4443 |
|
if ( DBG ) printf(" query is %s \n",myquery.Data()); |
4444 |
|
// printf(" query is %s \n",myquery.Data());// TOGLITOGLI |
4445 |
|
pResult = dbc->Query(myquery.Data()); |
4446 |
|
if (!pResult->GetRowCount()){ |
4447 |
|
printf(" PamLevel2::GetYodaEntry() ERROR! event is not included in any run!!! \n"); |
4448 |
|
cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl; |
4449 |
|
cout << "\nFor bug reporting instructions, please see for example:\n"; |
4450 |
|
cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n"; |
4451 |
|
cout << " " << endl; |
4452 |
|
return 0; |
4453 |
|
} |
4454 |
|
if ( pResult->GetRowCount() == 1 ){ |
4455 |
|
if (DBG) printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n"); |
4456 |
|
// printf(" PamLevel2::GetYodaEntry() - WARNING - YodaEntry not found but only one run containing the event, it should not happen \n");//TOGLITOGLI |
4457 |
|
} |
4458 |
|
for( Int_t ru=0; ru < pResult->GetRowCount(); ru++){ // loop over runs containing the event |
4459 |
|
if (Row) delete Row; |
4460 |
|
Row = pResult->Next(); |
4461 |
|
if( Row == NULL ) break; |
4462 |
|
UInt_t idrun = (UInt_t)atoll(Row->GetField(0)); |
4463 |
|
UInt_t nev = (UInt_t)atoll(Row->GetField(1)); |
4464 |
|
if (DBG) printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev); |
4465 |
|
// printf(" inside loop over runs: ru %i idrun %i nev %i \n",ru,idrun,nev);//TOGLITOGLI |
4466 |
|
|
4467 |
|
// now look for this run in the level2 file, it must be present! code is taken from updateruninfo of course |
4468 |
|
Bool_t rfound = false; |
4469 |
|
totrunentry = 0LL; |
4470 |
|
runfirstentry = 0LL; |
4471 |
|
for (Int_t r=0; r< run_tree->GetEntries();r++){ |
4472 |
|
run_tree->GetEntry(r);//update runinfo |
4473 |
|
if ( r > 0 ){ |
4474 |
|
totrunentrymin = totrunentrymax+1; |
4475 |
|
} else { |
4476 |
|
totrunentrymin = 0LL; |
4477 |
|
} |
4478 |
|
totrunentry += GetRunInfo()->NEVENTS; |
4479 |
|
totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets |
4480 |
|
irun = r; |
4481 |
|
|
4482 |
|
if (idrun == GetRunInfo()->ID){ |
4483 |
|
if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets) |
4484 |
|
if (DBG) printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n"); |
4485 |
|
if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax); |
4486 |
|
// printf("PamLevel2::GetYodaEntry - unconsistent iev - nevents, probable DBL0-L2 async\n"); |
4487 |
|
// printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI |
4488 |
|
prevshift += (totrunentrymin-iev); // add the new shift to total shift |
4489 |
|
totrunentrymin -= (totrunentrymin-iev); // shift run position min |
4490 |
|
totrunentrymax -= (totrunentrymin-iev); // shift run position max |
4491 |
|
if (DBG) printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax); |
4492 |
|
// printf("PamLevel2::GetYodaEntry - totrunentrymin %lld iev %lld prevshift %lld totrunentrymax %lld \n",totrunentrymin,iev,prevshift,totrunentrymax);//TOGLITOGLI |
4493 |
|
} |
4494 |
|
runfirstentry = totrunentrymin; // first entry of the run in the level2 |
4495 |
|
|
4496 |
|
|
4497 |
|
// |
4498 |
|
if (gltsync) |
4499 |
|
delete gltsync; // Emiliano |
4500 |
|
if (!dbc || (dbc && !dbc->IsConnected())) |
4501 |
|
SetDBConnection(); //Emiliano |
4502 |
|
gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano |
4503 |
|
if (dbc){ |
4504 |
|
dbc->Close(); // Emiliano |
4505 |
|
delete dbc; |
4506 |
|
dbc=0; |
4507 |
|
} |
4508 |
|
if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano |
4509 |
|
cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun |
4510 |
|
<< " has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl; |
4511 |
|
cout |
4512 |
|
<< " (NB!! in this case some events could be assigned to a wrong run)" |
4513 |
|
<< endl; |
4514 |
|
} |
4515 |
|
// |
4516 |
|
if (DBG) printf(" found \n"); |
4517 |
|
// printf(" found \n");//TOGLITOGLI |
4518 |
|
rfound = true; |
4519 |
|
// |
4520 |
|
break; |
4521 |
|
} |
4522 |
|
} // loop over run |
4523 |
|
if ( !rfound ){ |
4524 |
|
printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level2 file!!! \n"); |
4525 |
|
cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl; |
4526 |
|
cout << "\nFor bug reporting instructions, please see for example:\n"; |
4527 |
|
cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n"; |
4528 |
|
cout << " " << endl; |
4529 |
|
return 0; |
4530 |
|
} |
4531 |
|
|
4532 |
|
// here we got the first run and we can check if it contains the level0 event |
4533 |
|
if (!GetYodaTree()){ |
4534 |
|
printf(" PamLevel2::GetYodaEntry() : ERROR no level0 file loaded!\n"); |
4535 |
|
return 0; |
4536 |
|
} |
4537 |
|
|
4538 |
|
// get the current run entry |
4539 |
|
irunentry = iev - runfirstentry; |
4540 |
|
if (irunentry < 0) { |
4541 |
|
if (DBG) cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; |
4542 |
|
// cout << "Int_t PamLevel2::GetYodaEntry() -- ATTENZIONE -- irunentry negativo?!?! "<<(Int_t)irunentry<<endl; // TOGLITOGLI |
4543 |
|
irunentry = 0LL; |
4544 |
|
} |
4545 |
|
// --------------------------------- |
4546 |
|
// if file is NOT a preselected file |
4547 |
|
// --------------------------------- |
4548 |
|
quellagiusta = irunentry + (Long64_t)(run_obj->EV_FROM); // prevshift already included in irunentry |
4549 |
|
|
4550 |
|
if (DBG){ |
4551 |
|
cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl; |
4552 |
|
cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl; |
4553 |
|
cout << " time "<< abstime << endl; |
4554 |
|
} |
4555 |
|
// cout << " irun "<< irun << " irunentry "<< irunentry<<" run_obj->EV_FROM "<<run_obj->EV_FROM <<" quella giusta "<<quellagiusta << endl; |
4556 |
|
// cout << " iroot "<<iroot<<" run_obj->ID_ROOT_L0 "<<run_obj->ID_ROOT_L0<<endl; |
4557 |
|
// cout << " time "<< abstime << endl; // TOGLITOGLI |
4558 |
|
|
4559 |
|
shift = 0; |
4560 |
|
answer = quellagiusta + shift + yprevshift; // prevshift already included in irunentry |
4561 |
|
readl0 = l0_tree->GetEntry(answer); // prevshift already included in irunentry |
4562 |
|
|
4563 |
|
if (DBG){ |
4564 |
|
printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer); |
4565 |
|
} |
4566 |
|
// printf(" siamo qua shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI |
4567 |
|
|
4568 |
|
while ( (obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter())) && (quellagiusta + (Long64_t) shift) < GetYodaTree()->GetEntries() && shift < maxshift ){ |
4569 |
|
if (shift > 0) { |
4570 |
|
cout << " PKTNUM L2 --- " << pktn << " --- L0 --- " << GetEventHeader()->GetPscuHeader()->GetCounter() << endl; |
4571 |
|
if (DBG) |
4572 |
|
cout << " RUN: ID " << GetRunInfo()->ID << " ID_ROOT_L0 " << run_obj->ID_ROOT_L0 << " ID_RUN_FRAG " |
4573 |
|
<< GetRunInfo()->ID_RUN_FRAG << " EV_FROM " << GetRunInfo()->EV_FROM << endl; |
4574 |
|
if (DBG) |
4575 |
|
cout << " L2 <--> L0 mismatch ( irun " << irun << " irunentry " << irunentry << " shift " << shift |
4576 |
|
<< " prevshift " << prevshift << " )" << endl; |
4577 |
|
} |
4578 |
|
answer = quellagiusta + shift+ yprevshift; |
4579 |
|
readl0 = l0_tree->GetEntry(answer); |
4580 |
|
// printf(" inside inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI |
4581 |
|
|
4582 |
|
if (!GetEventHeader()) { |
4583 |
|
cout << "Int_t PamLevel2::GetYodaEntry() -- ERROR -- missing EventHeader " << endl; |
4584 |
|
return 0; |
4585 |
|
} |
4586 |
|
// |
4587 |
|
if (yprevshift != 0 && (quellagiusta + (Long64_t) shift) == GetYodaTree()->GetEntries()) { |
4588 |
|
if (DBG) printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer); |
4589 |
|
// printf(" reset inside while shift %lld yprevshift %lld answer %lld \n",shift,yprevshift,answer);//TOGLITOGLI |
4590 |
|
yprevshift = 0; |
4591 |
|
shift = -1; |
4592 |
|
}; |
4593 |
|
|
4594 |
|
shift++; |
4595 |
|
} |
4596 |
|
|
4597 |
|
if ( obt != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) || pktn != (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ){ |
4598 |
|
//still not the good run... continue with the nex one! |
4599 |
|
printf("still not the good run... continue with the nex one!\n"); |
4600 |
|
} else { |
4601 |
|
if (DBG) cout << "LA ENTRY GIUSTA E`: "<<quellagiusta<<" (spero...)"<<endl; |
4602 |
|
// cout << "LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl;//TOGLITOGLI |
4603 |
|
if (shift > 1) yprevshift = (shift - 1); |
4604 |
|
if (Row) delete Row; |
4605 |
|
delete pResult; |
4606 |
|
if (dbc){ |
4607 |
|
dbc->Close(); // Emiliano |
4608 |
|
delete dbc; |
4609 |
|
dbc=0; |
4610 |
|
} |
4611 |
|
il0entry = answer; |
4612 |
|
return readl0; |
4613 |
|
} |
4614 |
|
// perhaps it is all |
4615 |
|
}// loop over runs containing the event |
4616 |
|
if (Row) delete Row; |
4617 |
|
delete pResult; |
4618 |
|
if (dbc){ |
4619 |
|
dbc->Close(); // Emiliano |
4620 |
|
delete dbc; |
4621 |
|
dbc=0; |
4622 |
|
} |
4623 |
|
// arriving here it means no run found, cannot be! error! |
4624 |
|
printf(" PamLevel2::GetYodaEntry() ERROR! run is not present in the level0 files!!! \n"); |
4625 |
|
cout << " OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl; |
4626 |
|
cout << "\nFor bug reporting instructions, please see for example:\n"; |
4627 |
|
cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n"; |
4628 |
|
cout << " " << endl; |
4629 |
|
return 0; |
4630 |
|
} else { |
4631 |
|
if (DBG) cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl; |
4632 |
|
// cout << "=> LA ENTRY GIUSTA E`: "<<answer<<" (spero...)"<<endl; |
4633 |
|
// printf("obt %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()) %i pktn %lld (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter() %i \n",obt,(UInt_t)(GetEventHeader()->GetPscuHeader()->GetOrbitalTime()), pktn, (UInt_t)(GetEventHeader()->GetPscuHeader()->GetCounter()) ); |
4634 |
|
if (shift > 1) yprevshift = (shift - 1); |
4635 |
|
il0entry = answer; |
4636 |
|
return readl0; |
4637 |
|
} |
4638 |
|
|
4639 |
|
} // if selli 0 || 2 |
4640 |
|
if ( SELLI == 1 && hasL0EE ){ |
4641 |
|
sel_tree->GetEntry(iev); |
4642 |
|
Long64_t answer = il0entry; |
4643 |
|
Int_t readl0 = 0; |
4644 |
|
readl0 = l0_tree->GetEntry(answer); |
4645 |
|
return readl0; |
4646 |
|
} |
4647 |
|
printf(" PamLevel2::GetYodaEntry() ERROR! \n"); |
4648 |
|
cout << " Entry not found! OK this is a bug, write to Emiliano, Emiliano.Mocchiutti@ts.infn.it " << endl; |
4649 |
|
cout << "\nFor bug reporting instructions, please see for example:\n"; |
4650 |
|
cout << " <http://www.ts.infn.it/~mocchiut/bugs/bugs.html>.\n"; |
4651 |
|
cout << " " << endl; |
4652 |
|
return 0; |
4653 |
} |
} |
4654 |
|
|
4655 |
/** |
/** |
4656 |
* \Brief Set DB connection |
* \Brief Set DB connection |
4657 |
*/ |
*/ |