@@ -35,7 +35,6 @@ constexpr o2::header::DataDescription ddCalib{"CALIBDATA"}, ddCalib_tpc{"CALIBDA
3535
3636void CalibInfoReader::init (InitContext& ic)
3737{
38- mDiagnostic = ic.options ().get <bool >(" enable-dia" );
3938 LOG (debug) << " Init CalibInfo reader!" ;
4039 auto fname = o2::utils::Str::concat_string (o2::utils::Str::rectifyDirectory (ic.options ().get <std::string>(" input-dir" )), mFileName );
4140 mFile = fopen (fname.c_str (), " r" );
@@ -61,34 +60,39 @@ void CalibInfoReader::run(ProcessingContext& pc)
6160 mTree = (TTree*)fin->Get (" calibTOF" );
6261 mCurrentEntry = 0 ;
6362 mTree ->SetBranchAddress (" TOFCalibInfo" , &mPvect );
64-
65- if (mDiagnostic ) {
66- mTree ->SetBranchAddress (" TOFDiaInfo" , &mPdia );
67- }
63+ mTree ->SetBranchAddress (" TOFDiaInfo" , &mPdia );
6864
6965 LOG (debug) << " Open " << filename;
70- }
71- if ((mGlobalEntry % mNinstances ) == mInstance ) {
72- mTree ->GetEvent (mCurrentEntry );
7366
74- if (mDiagnostic ) {
75- // add TFIDInfo
67+ mIndices .clear ();
68+ for (unsigned long i = 0 ; i < mTree ->GetEntries (); i++) { // check time order inside the tree
69+ mTree ->GetEvent (i);
7670 const auto & info = mDia .getTFIDInfo ();
77- timingInfo.firstTForbit = info.firstTForbit ;
78- timingInfo.tfCounter = info.tfCounter ;
79- timingInfo.runNumber = info.runNumber ;
80- timingInfo.timeslice = info.startTime ;
81- timingInfo.creation = info.creation ;
82- } else if (mVect .size ()) {
83- timingInfo.creation = uint64_t (mVect [0 ].getTimestamp ()) * 1000 ;
71+ mIndices .push_back (std::make_pair (i, info.tfCounter ));
8472 }
73+ std::sort (mIndices .begin (), mIndices .end (),
74+ [&](const auto & a, const auto & b) {
75+ return a.second < b.second ;
76+ });
77+ }
78+ if ((mGlobalEntry % mNinstances ) == mInstance ) {
79+ mTree ->GetEvent (mIndices [mCurrentEntry ].first );
80+
81+ // add TFIDInfo
82+ const auto & info = mDia .getTFIDInfo ();
83+ timingInfo.firstTForbit = info.firstTForbit ;
84+ timingInfo.tfCounter = info.tfCounter ;
85+ timingInfo.runNumber = info.runNumber ;
86+ // timingInfo.timeslice = info.startTime; // NOT TO BE SET (done by DPL)
87+ timingInfo.creation = info.creation ;
88+ // printf("TF=%ld, creationTime=%ld: firstTForbit=%ld, runNumber=%d, startTime=%ld\n",timingInfo.tfCounter,timingInfo.creation,timingInfo.firstTForbit,timingInfo.runNumber,timingInfo.timeslice);
8589
8690 LOG (debug) << " Current entry " << mCurrentEntry ;
8791 LOG (debug) << " Send " << mVect .size () << " calib infos" ;
92+
8893 pc.outputs ().snapshot (Output{o2::header::gDataOriginTOF , mTOFTPC ? ddCalib_tpc : ddCalib, 0 , Lifetime::Timeframe}, mVect );
8994
9095 pc.outputs ().snapshot (Output{o2::header::gDataOriginTOF , ddDia, 0 , Lifetime::Timeframe}, mDia );
91-
9296 usleep (100 );
9397 }
9498 mGlobalEntry ++;
@@ -120,7 +124,7 @@ DataProcessorSpec getCalibInfoReaderSpec(int instance, int ninstances, const cha
120124 Inputs{},
121125 outputs,
122126 AlgorithmSpec{adaptFromTask<CalibInfoReader>(instance, ninstances, filename)},
123- Options{{" input-dir" , VariantType::String, " none" , {" Input directory" }}, { " enable-dia " , VariantType::Bool, false , { " read also diagnostic frequency " }} }};
127+ Options{{" input-dir" , VariantType::String, " none" , {" Input directory" }}}};
124128}
125129} // namespace tof
126130} // namespace o2
0 commit comments