/[PAMELA software]/PamelaLevel2/src/PamLevel2.cpp
ViewVC logotype

Diff of /PamelaLevel2/src/PamLevel2.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.88 by pam-fi, Tue Nov 29 15:34:12 2011 UTC revision 1.89 by mocchiut, Mon Dec 12 16:11:42 2011 UTC
# Line 464  void PamLevel2::Initialize() { Line 464  void PamLevel2::Initialize() {
464    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
465    irun = -1LL;    irun = -1LL;
466    irunt = -1LL;    irunt = -1LL;
467      totrunentry = 0LL;
468      totrunentrymax = 0LL;
469      totrunentrymin = 0LL;
470    runfirstentry = 0LL;    runfirstentry = 0LL;
471    runlastentry = 0LL;    runlastentry = 0LL;
472    gltsync = 0; // Emiliano    gltsync = 0; // Emiliano
# Line 800  void PamLevel2::Reset() { Line 803  void PamLevel2::Reset() {
803    soft_obj = 0;// Emiliano    soft_obj = 0;// Emiliano
804    irun = -1;    irun = -1;
805    irunt = -1;    irunt = -1;
806      totrunentry = 0LL;
807      totrunentrymax = 0LL;
808      totrunentrymin = 0LL;
809    runfirstentry = 0ULL;    runfirstentry = 0ULL;
810    runlastentry = 0ULL;    runlastentry = 0ULL;
811      prevabstime = 0ULL;
812      prevpktnum = 0;
813      abstime = 0ULL;
814      pktnum = 0;
815      isFragment = false;
816    //    //
817    totdltime[0] = 0LL;    totdltime[0] = 0LL;
818    totdltime[1] = 0LL;    totdltime[1] = 0LL;
# Line 2738  TTree *PamLevel2::GetRunTree(TFile *f) { Line 2749  TTree *PamLevel2::GetRunTree(TFile *f) {
2749    return T;    return T;
2750    
2751  }  }
2752    
2753  /**  /**
2754   * Update the runinfo informations (to be used to have Run infos event by event basis)   * Update the runinfo informations (to be used to have Run infos event by event basis)
2755   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
# Line 2773  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2785  Bool_t PamLevel2::UpdateRunInfo(TChain *
2785        return (false);        return (false);
2786      }      }
2787    
2788      ULong64_t abstime = 0;      ULong64_t abstimeu = 0;
2789      if (GetOrbitalInfo())      if (GetOrbitalInfo())
2790        abstime = GetOrbitalInfo()->absTime;        abstimeu = GetOrbitalInfo()->absTime;
2791    
2792      //      //
2793      // the first time the routine is called, set run search from the beginning      // the first time the routine is called, set run search from the beginning
# Line 2796  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2808  Bool_t PamLevel2::UpdateRunInfo(TChain *
2808      };      };
2809      //      //
2810      if (ISGP)      if (ISGP)
2811        abstime = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO        abstimeu = GetRunInfo()->RUNHEADER_TIME; // BARBATRUCCO
2812      //      //
2813      if (irun == run->GetEntries() - 1LL && !(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime      if (irun == run->GetEntries() - 1LL && !(abstimeu >= GetRunInfo()->RUNHEADER_TIME && abstimeu
2814          <= GetRunInfo()->RUNTRAILER_TIME)) {          <= GetRunInfo()->RUNTRAILER_TIME)) {
2815        irun = -1LL;        irun = -1LL;
2816        irunt = -1LL;        irunt = -1LL;
# Line 2810  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2822  Bool_t PamLevel2::UpdateRunInfo(TChain *
2822      //      //
2823      bool fromfirst = true;      bool fromfirst = true;
2824      //      //
2825      while (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME) && irun      while (!(abstimeu >= GetRunInfo()->RUNHEADER_TIME && abstimeu <= GetRunInfo()->RUNTRAILER_TIME) && irun
2826          < run->GetEntries() - 1LL) {          < run->GetEntries() - 1LL) {
2827        //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){        //      while ( iev > (runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS-1)) && irun < run->GetEntries() ){
2828        irun++;        irun++;
# Line 2822  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2834  Bool_t PamLevel2::UpdateRunInfo(TChain *
2834        //          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;        //          cout << " ))))) UPDATE RUN INFO (((((  @iev "<<iev<<" run "<<GetRunInfo()->ID<<" irun "<<irun<<endl;
2835        //          cout << "runfirstentry "<<runfirstentry<<endl;        //          cout << "runfirstentry "<<runfirstentry<<endl;
2836        //          printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));        //          printf(" iev %llu %u %llu \n",iev,this->GetRunInfo()->NEVENTS,(ULong64_t)(runfirstentry+(ULong64_t)(this->GetRunInfo()->NEVENTS)));
2837        //          printf(" abstime %u trailertime %u \n",abstime,GetRunInfo()->RUNTRAILER_TIME);        //          printf(" abstimeu %u trailertime %u \n",abstimeu,GetRunInfo()->RUNTRAILER_TIME);
2838        //          printf(" IDRUN %u \n",GetRunInfo()->ID);        //          printf(" IDRUN %u \n",GetRunInfo()->ID);
2839        //        //
2840        //          prevshift = 0;        //          prevshift = 0;
2841        //        //
2842        if (irun == (Long64_t)(run->GetEntries() - 1LL) && fromfirst && !(abstime >= GetRunInfo()->RUNHEADER_TIME        if (irun == (Long64_t)(run->GetEntries() - 1LL) && fromfirst && !(abstimeu >= GetRunInfo()->RUNHEADER_TIME
2843            && abstime <= GetRunInfo()->RUNTRAILER_TIME)) {            && abstimeu <= GetRunInfo()->RUNTRAILER_TIME)) {
2844          printf(" resetting irun  (it should NOT happen!!!)\n");          printf(" resetting irun  (it should NOT happen!!!)\n");
2845          fromfirst = false;          fromfirst = false;
2846          irun = 0;          irun = 0;
# Line 2841  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2853  Bool_t PamLevel2::UpdateRunInfo(TChain *
2853        //        //
2854      };      };
2855      //      //
2856      if (!(abstime >= GetRunInfo()->RUNHEADER_TIME && abstime <= GetRunInfo()->RUNTRAILER_TIME)) {      if (!(abstimeu >= GetRunInfo()->RUNHEADER_TIME && abstimeu <= GetRunInfo()->RUNTRAILER_TIME)) {
2857        printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n", abstime);        printf(" Something very wrong here: cannot find RUN containing absolute time %llu \n", abstimeu);
2858        return false;        return false;
2859      }      }
2860      //      //
# Line 2875  Bool_t PamLevel2::UpdateRunInfo(TChain * Line 2887  Bool_t PamLevel2::UpdateRunInfo(TChain *
2887    return false;    return false;
2888    //    //
2889  }  }
2890  ;  
2891    
2892  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) {
2893    
# Line 2888  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2900  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2900      return (false);      return (false);
2901    }    }
2902    
2903      if (DBG) printf("ciccio\n");
2904    
2905    Int_t oldrun = irun; // store current run index    Int_t oldrun = irun; // store current run index
2906    
2907    // -----------------------------------------------------------------------    // -----------------------------------------------------------------------
# Line 2897  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2911  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2911    if (irun < 0) {    if (irun < 0) {
2912      irun = 0LL;      irun = 0LL;
2913      irunt = 0LL;      irunt = 0LL;
2914        totrunentry = 0LL;
2915        totrunentrymin = 0LL;
2916        totrunentrymax = 0LL;
2917      irunentry = 0;      irunentry = 0;
2918      prevshift = 0;      prevshift = 0;
2919        prevabstime = 0;
2920        prevpktnum = 0;
2921        abstime = 0ULL;
2922        pktnum = 0;
2923        isFragment = false;
2924      run_tree->GetEntry(irun);      run_tree->GetEntry(irun);
2925      if (!GetOrbitalInfo())      if (!GetOrbitalInfo())
2926        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;        cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
# Line 2916  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2938  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2938    // ---------------------------------------------------------------    // ---------------------------------------------------------------
2939    // retrieve OBT and absolute time of the event    // retrieve OBT and absolute time of the event
2940    // ---------------------------------------------------------------    // ---------------------------------------------------------------
2941    ULong64_t abstime = 0LL;    //  ULong64_t abstime = 0LL;
2942    //    ULong64_t obt     = 0LL; // Emiliano    //    ULong64_t obt     = 0LL; // Emiliano
2943    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
2944      // UInt_t pkt = 0;
2945      prevabstime = abstime;
2946      prevpktnum = pktnum;
2947    if (GetOrbitalInfo()) {    if (GetOrbitalInfo()) {
2948      abstime = GetOrbitalInfo()->absTime;      abstime = GetOrbitalInfo()->absTime;
2949      obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano      obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
2950        pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
2951    }    }
2952    else {    else {
2953      abstime = GetRunInfo()->RUNHEADER_TIME;      abstime = GetRunInfo()->RUNHEADER_TIME;
2954      obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano      obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
2955        pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
2956      }
2957    
2958      if (DBG){
2959        printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
2960        printf("0        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
2961        printf("0        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
2962        printf("0        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
2963        printf("0        bo irunentry %lld prevshift %d irun %lld  \n",irunentry,prevshift,irun);
2964        printf("0        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
2965    }    }
2966    
2967    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-    // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# Line 2946  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 2982  Bool_t PamLevel2::UpdateRunInfo(Long64_t
2982      }      }
2983    
2984      //      //
2985      bool fromfirst = true; // first loop over runs      if ( iev < totrunentrymin || iev > totrunentrymax // entry is outside run limits
2986             || iev == 0 // or it is the first entry
2987             ){
2988          
2989          // check for a new run (ma prima il primo!)
2990          if (DBG){
2991            printf("1abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
2992            printf("1        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
2993            printf("1        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
2994            printf("1        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
2995            printf("1        bo irunentry %lld prevshift %d irun %lld  \n",irunentry,prevshift,irun);
2996            printf("1        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
2997          }
2998    
2999          totrunentry = 0LL;
3000          for (Int_t r=0; r< run_tree->GetEntries();r++){
3001            // -------------------------------------------------------------------
3002            // save the index of the first entry of the run, relative to pam_tree,
3003            // and read a new run
3004            // -------------------------------------------------------------------
3005            run_tree->GetEntry(r);//update runinfo
3006            if ( r > 0 ){
3007              totrunentrymin = totrunentrymax+1;
3008            } else {
3009              totrunentrymin = 0LL;
3010            }
3011            totrunentry += GetRunInfo()->NEVENTS;
3012            totrunentrymax = totrunentry - 1;
3013            irun = r;        
3014    
3015            //-->  needed?
3016            if (irun > 0)
3017              runfirstentry += (GetRunInfo()->NEVENTS) - prevshift;
3018            irunentry = 0;
3019            prevshift = 0;
3020            irunt = irun - irunoffset[run_tree->GetTreeNumber()];
3021            //<-- needed?
3022    
3023            if ( iev >= totrunentrymin && iev <= totrunentrymax ){ // entry is inside run limits
3024              //
3025              if (gltsync)
3026                delete gltsync; // Emiliano
3027              if (!dbc || (dbc && !dbc->IsConnected()))
3028                SetDBConnection(); //Emiliano
3029              gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); // Emiliano
3030              if (dbc){
3031                dbc->Close(); // Emiliano
3032                delete dbc;
3033                dbc=0;
3034              }          
3035              if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
3036                cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
3037                     << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
3038                cout
3039                  << "                                                            (NB!! in this case some events could be assigned to a wrong run)"
3040                  << endl;
3041              }
3042              //
3043              if (DBG) printf(" found \n");
3044              //
3045              break;
3046            }
3047          } // loop over run
3048          
3049          // --------------------------------------
3050          // if there was no need to update the run
3051          // ---> exit with FALSE
3052          // --------------------------------------
3053          if (irun == oldrun)
3054            return (false);
3055          
3056          // --------------------------------------
3057          // ... otherwise
3058          // ---> exit with TRUE
3059          // --------------------------------------
3060    
3061          if (SELLI != 2) {
3062            /// decrement counters since this event belongs to a new run
3063            if (GetTrigLevel2()) {
3064              totdltime[0] -= GetTrigLevel2()->dltime[0];//live-time
3065              totdltime[1] -= GetTrigLevel2()->dltime[1];//dead-time
3066            }
3067            totdltime[2]--; //event counter
3068            if (DBG) {
3069              cout << endl;
3070              cout << "n.events     : " << totdltime[2] << endl;
3071              cout << "RUN LIVE-TIME: " << totdltime[0] * 0.16 << " ms" << endl;
3072              cout << "RUN DEAD-TIME: " << totdltime[1] * 0.01 << " ms" << endl;
3073            }
3074            // add an entry
3075            if (run_tree_clone && totdltime[2] > 0)
3076              if (run_tree_clone->GetBranch("DeadLiveTime")->GetEntries() < run_tree->GetEntries())
3077                run_tree_clone->GetBranch("DeadLiveTime")->Fill();
3078            // reset counters
3079            if ( totdltime[2] > 0 ){
3080              if (GetTrigLevel2()) {
3081                totdltime[0] = GetTrigLevel2()->dltime[0];//live-time
3082                totdltime[1] = 0; //dead-time
3083              }
3084              totdltime[2] = 1; //event counter
3085            }
3086          }
3087    
3088          if (DBG){
3089            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
3090                 << endl;
3091            
3092            printf("2abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
3093            printf("2        rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
3094            printf("2        rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
3095            printf("2        rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
3096            printf("2        bo irunentry %lld prevshift %d irun %lld  \n",irunentry,prevshift,irun);
3097            printf("2        min %lld iev %lld max %lld tot %lld \n",totrunentrymin,iev,totrunentrymax,totrunentry);
3098          }
3099    
3100          return (true);
3101        } // need for run upgrade
3102        if (DBG) printf("return false\n");
3103        return (false);
3104      }// SELLI = 0 SELLI = 2
3105      
3106      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
3107      // if it is a preselected file (there is SelectionList)
3108      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
3109      // irun  = run entry relative to the chain
3110      // irunt = run entry relative to the tree
3111      if (SELLI == 1) {
3112        sel_tree->GetEntry(iev);// read irunt from SelectionList
3113        irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
3114        if (irun != oldrun) {
3115          if (irun < run_tree->GetEntries())
3116            run_tree->GetEntry(irun);
3117          // check if the time is ok (with merged files it is not...)
3118          // if not loop over run and look for the proper entry
3119          bool SECONDO_GIRO = false;
3120          //            Long64_t irun_start   = irun;
3121          int offset_start = irunoffset[sel_tree->GetTreeNumber()];
3122          while (((!(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
3123              abstime <= GetRunInfo()->RUNTRAILER_TIME)
3124          //                        ||
3125          //                        !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
3126          //                          obt <= GetRunInfo()->RUNTRAILER_OBT)
3127          ) || GetRunInfo()->NEVENTS == 0)
3128          //                && irun < run_tree->GetEntries()
3129          ) {
3130    
3131            if (DBG) {
3132              cout << " (test) ";
3133              cout << " tree " << sel_tree->GetTreeNumber();
3134              cout << " irunt " << irunt;
3135              cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
3136              cout << " abs " << abstime;
3137              cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
3138              cout << " obt " << obt;
3139              cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
3140              cout << " *** JUMP RUN *** irun " << irun;
3141              cout << endl;
3142            }
3143            //              irun++;
3144            irunoffset[sel_tree->GetTreeNumber()]++;
3145            irun = irunt + irunoffset[sel_tree->GetTreeNumber()];//NEWNEW
3146            if (irun == run_tree->GetEntries() && SECONDO_GIRO) {
3147              //            if(irun == irun_start ){
3148              cout << " ...grrrvzzkhhhajsdkj!!!! " << endl;
3149              irunoffset[sel_tree->GetTreeNumber()] = offset_start;
3150              return false;
3151            }
3152            if (irun >= run_tree->GetEntries() || irun < 0) {
3153              cout << "irun = " << irun << " >>  search from the beginning... <<" << endl;
3154              SECONDO_GIRO = true;
3155              irun = 0;
3156              irunoffset[sel_tree->GetTreeNumber()] = -irunt;
3157            }
3158            run_tree->GetEntry(irun);
3159          }
3160    
3161          if (DBG) {
3162            cout << " (test) ";
3163            cout << " tree " << sel_tree->GetTreeNumber();
3164            cout << " irunt " << irunt;
3165            cout << " offset " << irunoffset[sel_tree->GetTreeNumber()];
3166            cout << " abs " << abstime;
3167            cout << " >> " << GetRunInfo()->RUNHEADER_TIME << " " << GetRunInfo()->RUNTRAILER_TIME;
3168            cout << " obt " << obt;
3169            cout << " >> " << GetRunInfo()->RUNHEADER_OBT << " " << GetRunInfo()->RUNTRAILER_OBT;
3170          }
3171          if (DBG)
3172            cout << endl;
3173          if (DBG)
3174            cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " (run-entry "
3175                << irun << ")" << endl;
3176          // ----------------------------------------------------
3177          // update the tracker parameters
3178          // (non ho trovato nessun altro modo sicuro di farlo...)
3179          // ----------------------------------------------------
3180          if (!dbc || (dbc && !dbc->IsConnected()))
3181            SetDBConnection();
3182          TrkParams::Set(GetRunInfo(), dbc);
3183          if (dbc){
3184            dbc->Close();
3185            delete dbc;
3186            dbc=0;
3187          };
3188          //            cout << endl;
3189          prevshift = 0;
3190          return true;
3191        }
3192        return false;
3193      }
3194    
3195      return false;
3196      //
3197    }
3198    
3199    Bool_t PamLevel2::UpdateRunInfo_bckw_compat(Long64_t iev) {
3200    
3201      if (!run_tree) {
3202        cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree not loaded" << endl;
3203        return false;
3204      }
3205      if (run_tree->GetEntries() <= 0) {
3206        cout << " Bool_t PamLevel2::UpdateRunInfo(ULong64_t iev) -- ERROR -- run tree is empty" << endl;
3207        return (false);
3208      }
3209    
3210      printf("ciccio\n");
3211    
3212      Int_t oldrun = irun; // store current run index
3213    
3214      // -----------------------------------------------------------------------
3215      // the first time the routine is called, set run search from the beginning
3216      // -----------------------------------------------------------------------
3217    
3218      if (irun < 0) {
3219        irun = 0LL;
3220        irunt = 0LL;
3221        irunentry = 0;
3222        prevshift = 0;
3223        prevabstime = 0;
3224        prevpktnum = 0;
3225        abstime = 0ULL;
3226        pktnum = 0;
3227        isFragment = false;
3228        run_tree->GetEntry(irun);
3229        if (!GetOrbitalInfo())
3230          cout << "** WARNING ** missing OrbitalInfo ---> run info might be not correctly updated " << endl;
3231        if (gltsync)
3232          delete gltsync; //Emiliano
3233        if (!dbc || (dbc && !dbc->IsConnected()))
3234          SetDBConnection(); //Emiliano
3235        gltsync = new GL_TIMESYNC(GetRunInfo()->ID_ROOT_L0, "ID", dbc, false); //Emiliano // the "false" means not to use level0 file (not necessary here)
3236        if (dbc){
3237          dbc->Close();// Emiliano
3238          delete dbc;
3239          dbc=0;
3240        };
3241      };
3242      // ---------------------------------------------------------------
3243      // retrieve OBT and absolute time of the event
3244      // ---------------------------------------------------------------
3245      //  ULong64_t abstime = 0LL;
3246      //    ULong64_t obt     = 0LL; // Emiliano
3247      Long64_t obt = 0LL; // Emiliano, Long64_t GL_TIMESYNC::DBobt(UInt_t obt) since depending on the situation OBT is lowered or boosted
3248      // UInt_t pkt = 0;
3249      prevabstime = abstime;
3250      prevpktnum = pktnum;
3251      if (GetOrbitalInfo()) {
3252        abstime = GetOrbitalInfo()->absTime;
3253        obt = gltsync->DBobt(GetOrbitalInfo()->OBT); // Emiliano
3254        pktnum = GetOrbitalInfo()->pkt_num; // Emiliano
3255      }
3256      else {
3257        abstime = GetRunInfo()->RUNHEADER_TIME;
3258        obt = gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT); // Emiliano
3259        pktnum = GetRunInfo()->RUNHEADER_PKT; // Emiliano
3260      }
3261    
3262      printf("0abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
3263          printf("0rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
3264          printf("0rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
3265          printf("0rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
3266          printf("0irunentry %lld prevshift %d irun %lld  \n",irunentry,prevshift,irun);
3267    
3268    
3269      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
3270      // if it is a full file (not preselected)
3271      // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
3272      if (SELLI == 0 || SELLI == 2) { // Emiliano
3273    
3274        // ---------------------------------------------------------------
3275        // increment dead and live-time counters
3276        // (only when reading a file not preselected)
3277        // ---------------------------------------------------------------
3278        if (SELLI == 0) {
3279          if (GetTrigLevel2()) {
3280            totdltime[0] += GetTrigLevel2()->dltime[0];
3281            totdltime[1] += GetTrigLevel2()->dltime[1];
3282          }
3283          totdltime[2]++;
3284        }
3285    
3286        //
3287        bool fromfirst = true; // first loop over runs
3288        bool fragmentcheck = true;
3289    
3290      // ------------------------------------------------------      // ------------------------------------------------------
3291      // loop over runs to find the one that contains the event      // loop over runs to find the one that contains the event
3292      // ------------------------------------------------------      // ------------------------------------------------------
3293      while ((      while (
3294      //          (              /*(            !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
3295      //              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)                 abstime <= GetRunInfo()->RUNTRAILER_TIME)
3296      //                abstime <= GetRunInfo()->RUNTRAILER_TIME) &&              || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano
3297      //              !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)                    obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano
3298      //                obt <= GetRunInfo()->RUNTRAILER_OBT)              || GetRunInfo()->NEVENTS == 0
3299      //              )              || (isFragment && fragmentcheck && (abstime <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum            
3300                || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)
3301      !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)              ) && irun < run_tree->GetEntries()) {*/        
3302          abstime <= GetRunInfo()->RUNTRAILER_TIME) || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano             (abstime < GetRunInfo()->RUNHEADER_TIME  // check on absolute time (s)
3303          obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano             || abstime > GetRunInfo()->RUNTRAILER_TIME
3304          || GetRunInfo()->NEVENTS == 0             || obt < gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) // additional check on OBT (ms)
3305      //          || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento             || obt > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT) // Emiliano
3306          || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)) && irun < run_tree->GetEntries()) {             || GetRunInfo()->NEVENTS == 0
3307               || (isFragment && fragmentcheck && (abstime <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum            
3308               || irunentry > (GetRunInfo()->NEVENTS - 1 - prevshift)
3309                ) && irun < run_tree->GetEntries()) {
3310    
3311        //            if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;        //            if( !(abstime >= GetRunInfo()->RUNHEADER_TIME &&abstime <= GetRunInfo()->RUNTRAILER_TIME)  )cout << "ABS TIME "<<abstime << " " <<GetRunInfo()->RUNTRAILER_TIME <<endl;
3312        //            if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;        //            if( !(obt >= GetRunInfo()->RUNHEADER_OBT && obt <= GetRunInfo()->RUNTRAILER_OBT) )cout << "OBT TIME "<< obt <<" "<< GetRunInfo()->RUNTRAILER_OBT << endl;
# Line 2973  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3314  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3314        //            if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;        //            if( !(irunentry <= GetRunInfo()->NEVENTS-1-prevshift) ) cout << "irunentry > "<<GetRunInfo()->NEVENTS-1-prevshift << endl;
3315        // - - - - - - - - - - - - -        // - - - - - - - - - - - - -
3316        // irunentry = position of current entry, relative to the run        // irunentry = position of current entry, relative to the run
3317        // prevshift = shift needed to synchronize l0 and l2 data (nested events)        // prevshift = shift needed to synchronize L0 and L2 data (nested events)
3318        // - - - - - - - - - - - - -        // - - - - - - - - - - - - -
3319    
3320    
3321          if (((
3322                //          (
3323                //              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
3324                //                abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
3325                //              !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
3326                //                obt <= GetRunInfo()->RUNTRAILER_OBT)
3327                //              )            
3328                !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
3329                  abstime <= GetRunInfo()->RUNTRAILER_TIME)
3330                || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano
3331                     obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano
3332                || GetRunInfo()->NEVENTS == 0
3333                //          || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
3334                || (isFragment && fragmentcheck && (abstime <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum            
3335                || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)
3336                ) && irun < run_tree->GetEntries()))  printf(" break \n");
3337    
3338        // -----------------------------------------        // -----------------------------------------
3339        // store dead and live-time of previous run        // store dead and live-time of previous run
3340        // -----------------------------------------        // -----------------------------------------
3341        //            if(SELLI==0){        //            if(SELLI==0){
3342          //      fragmentcheck = false;
3343          printf("abstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
3344          printf("rth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
3345          printf("rto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
3346          printf("rto2 %lld %lld \n",gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT),gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT));
3347          printf("irunentry %lld prevshift %d irun %lld  \n",irunentry,prevshift,irun);
3348        if (SELLI != 2) {        if (SELLI != 2) {
3349          if (fromfirst) {          if (fromfirst) {
3350            if (oldrun == irun) {            if (oldrun == irun) {
# Line 3029  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3394  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3394            // -----------------------------------------------------            // -----------------------------------------------------
3395            cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #" << iev            cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- ERROR -- event entry #" << iev
3396                << " does not belong to any run (should not happen)" << endl;                << " does not belong to any run (should not happen)" << endl;
3397              irun = 0LL;
3398            return false;            return false;
3399          }          }
3400          // -----------------------------------------          // -----------------------------------------
# Line 3061  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3427  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3427          delete dbc;          delete dbc;
3428          dbc=0;          dbc=0;
3429        };        };
3430          if (!((
3431                //          (
3432                //              !(abstime >= GetRunInfo()->RUNHEADER_TIME &&    // check on absolute time (s)
3433                //                abstime <= GetRunInfo()->RUNTRAILER_TIME) &&
3434                //              !(obt >= GetRunInfo()->RUNHEADER_OBT &&         // additional check on OBT (ms)
3435                //                obt <= GetRunInfo()->RUNTRAILER_OBT)
3436                //              )            
3437                !(abstime >= GetRunInfo()->RUNHEADER_TIME && // check on absolute time (s)
3438                  abstime <= GetRunInfo()->RUNTRAILER_TIME)
3439                || !(obt >= gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) && // additional check on OBT (ms) // Emiliano
3440                     obt <= gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) // Emiliano
3441                || GetRunInfo()->NEVENTS == 0
3442                //          || !(irunentry < GetRunInfo()->NEVENTS-1-prevshift) // ERRORE!!! fa saltare i run con 1 evento
3443                || (isFragment && fragmentcheck && (abstime <prevabstime && pktnum < prevpktnum) ) // or it is a fragment and there is a jump in abstime and pktnum            
3444                || !(irunentry <= GetRunInfo()->NEVENTS - 1 - prevshift)
3445                ) && irun < run_tree->GetEntries()))  printf(" ECCE RUN!!!!!!!!!!!!! \n");
3446    
3447          printf("Qabstime %lld %lld pktnum %d %d obt %lld \n",abstime,prevabstime,pktnum,prevpktnum,obt);
3448          printf("Qrth %d %d nevents %d  \n",GetRunInfo()->RUNHEADER_TIME,GetRunInfo()->RUNTRAILER_TIME,GetRunInfo()->NEVENTS);
3449          printf("Qrto %d %d \n",GetRunInfo()->RUNHEADER_OBT,GetRunInfo()->RUNTRAILER_OBT);
3450          printf("Qirunentry %lld prevshift %d irun %lld  \n",irunentry,prevshift,irun);
3451    
3452    
3453        if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano        if (gltsync->DBobt(GetRunInfo()->RUNHEADER_OBT) > gltsync->DBobt(GetRunInfo()->RUNTRAILER_OBT)) { // Emiliano
3454          cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun          cout << "Bool_t PamLevel2::UpdateRunInfo(Long64_t iev) -- WARNING -- irun " << irun
3455              << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;              << "  has RUNHEADER_OBT>=RUNTRAILER_OBT " << endl;
# Line 3091  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3480  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3480      if (DBG)      if (DBG)
3481        cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun        cout << endl << " ))))) UPDATE RUN INFO (((((  @iev " << iev << " run " << GetRunInfo()->ID << " irun " << irun
3482            << endl;            << endl;
3483    
3484        isFragment = false;
3485        if ( GetRunInfo()->ID_RUN_FRAG != 0 && GetRunInfo()->ID_RUN_FRAG != GetRunInfo()->ID ) isFragment = true;
3486      // ----------------------------------------------------      // ----------------------------------------------------
3487      // update the tracker parameters      // update the tracker parameters
3488      // (non ho trovato nessun altro modo sicuro di farlo...)      // (non ho trovato nessun altro modo sicuro di farlo...)
# Line 3209  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3601  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3601    return false;    return false;
3602    //    //
3603  }  }
3604  ;  
3605  /**  /**
3606   * Update the runinfo informations (to be used to have Run infos event by event basis)   * Update the runinfo informations (to be used to have Run infos event by event basis)
3607   * @param run Pointer to the chain/tree which contains run infos   * @param run Pointer to the chain/tree which contains run infos
# Line 3218  Bool_t PamLevel2::UpdateRunInfo(Long64_t Line 3610  Bool_t PamLevel2::UpdateRunInfo(Long64_t
3610  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {  Bool_t PamLevel2::UpdateRunInfo(TTree *run, Long64_t iev) {
3611    return (UpdateRunInfo((TChain*) run, iev));    return (UpdateRunInfo((TChain*) run, iev));
3612  }  }
3613  ;  
3614    
3615  //--------------------------------------  //--------------------------------------
3616  //  //

Legend:
Removed from v.1.88  
changed lines
  Added in v.1.89

  ViewVC Help
Powered by ViewVC 1.1.23