--- PamelaLevel2/src/PamLevel2.cpp 2014/01/16 15:36:32 1.93 +++ PamelaLevel2/src/PamLevel2.cpp 2014/03/12 16:37:29 1.94 @@ -474,6 +474,7 @@ runlastentry = 0LL; gltsync = 0; // Emiliano fUpdateRunInfo = true; // Emiliano + fUseDBinRunInfo = true; // Emiliano 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 il0entry = 0LL; // hasL0EE = true; @@ -2820,17 +2821,19 @@ 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; - }; - }; + if ( fUseDBinRunInfo ){ + 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 // --------------------------------------------------------------- @@ -2839,12 +2842,12 @@ prevpktnum = pktnum; if (GetOrbitalInfo()) { abstime = GetOrbitalInfo()->absTime; - obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano + if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano pktnum = GetOrbitalInfo()->pkt_num; // Emiliano } else { abstime = GetRunInfo()->RUNHEADER_TIME; - obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano + if ( fUseDBinRunInfo ) obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano } @@ -2852,7 +2855,7 @@ 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)); + if ( fUseDBinRunInfo ) printf("0 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); printf("0 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); printf("0 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); } @@ -2875,11 +2878,19 @@ } // + bool a = true; + bool b = true; + if ( fUseDBinRunInfo ){ + a = false; + b = false; + if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true; + if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true; + } if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits || iev == 0 // or it is the first entry || (!isSync && ( - (abstime <= GetRunInfo()->RUNHEADER_TIME && obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) // or it is outside obt limits (and abstime limits for security reasons) - || (abstime >= GetRunInfo()->RUNTRAILER_TIME && obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) ))// or it is outside obt limits (and abstime limits for security reasons) + (abstime <= GetRunInfo()->RUNHEADER_TIME && a ) // or it is outside obt limits (and abstime limits for security reasons) + || (abstime >= GetRunInfo()->RUNTRAILER_TIME && b ) ))// or it is outside obt limits (and abstime limits for security reasons) ){ // check on abstime and obt needed to handle nested+DV_skipped packets // check for a new run (ma prima il primo!) @@ -2887,7 +2898,7 @@ 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)); + if ( fUseDBinRunInfo ) printf("1 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); printf("1 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); printf("1 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); } @@ -2914,11 +2925,16 @@ totrunentry += GetRunInfo()->NEVENTS; totrunentrymax = totrunentry - 1 - prevshift; // prevshift is needed to handle nested+DV_skipped packets irun = r; - + if ( fUseDBinRunInfo ){ + a = false; + b = false; + if ( obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) ) a = true; + if ( obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) ) b = true; + } if ( (iev >= totrunentrymin && iev <= totrunentrymax) || // entry is inside run limits ( !isSync && - ( abstime >= GetRunInfo()->RUNHEADER_TIME && obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) // or it is inside obt limits (and abstime limits for security reasons) - && abstime <= GetRunInfo()->RUNTRAILER_TIME && obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT))) // or it is inside obt limits (and abstime limits for security reasons) + ( abstime >= GetRunInfo()->RUNHEADER_TIME && a // or it is inside obt limits (and abstime limits for security reasons) + && abstime <= GetRunInfo()->RUNTRAILER_TIME && b)) // or it is inside obt limits (and abstime limits for security reasons) ){ // check on abstime and obt needed to handle nested+DV_skipped packets if ( totrunentrymin > iev ){ // there is a shift (nested+DV_skipped packets) if ( !isSync ){ @@ -2943,23 +2959,25 @@ // - if (gltsync) - delete gltsync; // Emiliano - if (!dbc || (dbc && !dbc->IsConnected())) - SetDBConnection(); //Emiliano - gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano - TrkParams::Set(GetRunInfo(), dbc); - 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 ( fUseDBinRunInfo ){ + if (gltsync) + delete gltsync; // Emiliano + if (!dbc || (dbc && !dbc->IsConnected())) + SetDBConnection(); //Emiliano + gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano + TrkParams::Set(GetRunInfo(), dbc); + 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"); @@ -3016,7 +3034,7 @@ 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)); + if ( fUseDBinRunInfo ) printf("2 rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)); printf("2 bo irunentry %lld prevshift %lld irun %lld \n",irunentry,prevshift,irun); printf("2 min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry); } @@ -3107,14 +3125,16 @@ // 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; - }; + if ( fUseDBinRunInfo ){ + if (!dbc || (dbc && !dbc->IsConnected())) + SetDBConnection(); + TrkParams::Set(GetRunInfo(), dbc); + if (dbc){ + dbc->Close(); + delete dbc; + dbc=0; + } + } // cout << endl; prevshift = 0; yprevshift = 0;