@@ -27,12 +27,14 @@ using namespace o2::tpc;
2727ResidualsContainer::~ResidualsContainer ()
2828{
2929 // trees must be deleted before the file is closed, otherwise segfaults
30+ LOGP (debug, " Deleting ResidualsContainer with {} entries. File name is {}" , getNEntries (), fileName);
3031 treeOutResidualsUnbinned.reset ();
3132 treeOutTrackData.reset ();
3233 treeOutResiduals.reset ();
3334 treeOutStats.reset ();
3435 treeOutRecords.reset ();
3536 if (fileOut) {
37+ LOG (debug) << " Removing output file of discarded slot" ;
3638 // this slot was not finalized, need to close and remove the file
3739 fileOut->Close ();
3840 fileOut.reset ();
@@ -52,26 +54,30 @@ ResidualsContainer::ResidualsContainer(const ResidualsContainer& rhs)
5254
5355ResidualsContainer::ResidualsContainer (ResidualsContainer&& rhs)
5456{
57+ LOGP (debug, " Move operator called for rhs with {} entries" , rhs.nResidualsTotal );
5558 trackResiduals = rhs.trackResiduals ;
5659 fileOut = std::move (rhs.fileOut );
5760 fileName = std::move (rhs.fileName );
5861 treeOutResidualsUnbinned = std::move (rhs.treeOutResidualsUnbinned );
5962 treeOutTrackData = std::move (rhs.treeOutTrackData );
6063 treeOutResiduals = std::move (rhs.treeOutResiduals );
6164 treeOutStats = std::move (rhs.treeOutStats );
65+ treeOutRecords = std::move (rhs.treeOutRecords );
6266 for (int iSec = 0 ; iSec < SECTORSPERSIDE * SIDES ; ++iSec) {
6367 residuals[iSec] = std::move (rhs.residuals [iSec]);
6468 stats[iSec] = std::move (rhs.stats [iSec]);
6569 }
66- runNumber = rhs.runNumber ;
6770 tfOrbits = std::move (rhs.tfOrbits );
6871 sumOfResiduals = std::move (rhs.sumOfResiduals );
6972 lumi = std::move (rhs.lumi );
7073 unbinnedRes = std::move (rhs.unbinnedRes );
7174 trackInfo = std::move (rhs.trackInfo );
7275 trkData = std::move (rhs.trkData );
76+ orbitReset = rhs.orbitReset ;
77+ firstTForbit = rhs.firstTForbit ;
7378 firstSeenTF = rhs.firstSeenTF ;
7479 lastSeenTF = rhs.lastSeenTF ;
80+ nResidualsTotal = rhs.nResidualsTotal ;
7581}
7682
7783void ResidualsContainer::init (const TrackResiduals* residualsEngine, std::string outputDir, bool wFile, bool wBinnedResid, bool wUnbinnedResid, bool wTrackData, int autosave, int compression)
@@ -98,9 +104,9 @@ void ResidualsContainer::init(const TrackResiduals* residualsEngine, std::string
98104 treeOutTrackData->Branch (" trk" , &trkDataPtr);
99105 }
100106 if (writeBinnedResid) {
101- treeOutResiduals = std::make_unique<TTree>(treeNameResiduals. c_str () , " TPC binned residuals" );
102- treeOutStats = std::make_unique<TTree>(treeNameStats. c_str () , " Voxel statistics mean position and nEntries" );
103- treeOutRecords = std::make_unique<TTree>(treeNameRecords. c_str () , " Statistics per TF slot" );
107+ treeOutResiduals = std::make_unique<TTree>(" resid " , " TPC binned residuals" );
108+ treeOutStats = std::make_unique<TTree>(" stats " , " Voxel statistics mean position and nEntries" );
109+ treeOutRecords = std::make_unique<TTree>(" records " , " Statistics per TF slot" );
104110 for (int iSec = 0 ; iSec < SECTORSPERSIDE * SIDES ; ++iSec) {
105111 residualsPtr[iSec] = &residuals[iSec];
106112 statsPtr[iSec] = &stats[iSec];
@@ -122,6 +128,7 @@ void ResidualsContainer::init(const TrackResiduals* residualsEngine, std::string
122128 treeOutRecords->Branch (" sumOfResiduals" , &sumOfResidualsPtr);
123129 treeOutRecords->Branch (" lumi" , &lumiPtr);
124130 }
131+ LOG (debug) << " Done initializing residuals container for file named " << fileName;
125132}
126133
127134void ResidualsContainer::fillStatisticsBranches ()
@@ -135,7 +142,7 @@ void ResidualsContainer::fillStatisticsBranches()
135142 }
136143}
137144
138- void ResidualsContainer::fill (const o2::dataformats::TFIDInfo& ti, const gsl::span<const UnbinnedResid> resid, const gsl::span<const o2::tpc::TrackDataCompact> trkRefsIn, const gsl::span<const o2::tpc::TrackData>* trkDataIn, const o2::ctp::LumiInfo* lumiInput)
145+ void ResidualsContainer::fill (const o2::dataformats::TFIDInfo& ti, const gsl::span<const UnbinnedResid> resid, const gsl::span<const o2::tpc::TrackDataCompact> trkRefsIn, long orbitResetTime, const gsl::span<const o2::tpc::TrackData>* trkDataIn, const o2::ctp::LumiInfo* lumiInput)
139146{
140147 // receives large vector of unbinned residuals and fills the sector-wise vectors
141148 // with binned residuals and statistics
@@ -145,6 +152,8 @@ void ResidualsContainer::fill(const o2::dataformats::TFIDInfo& ti, const gsl::sp
145152 lastSeenTF = ti.tfCounter ;
146153 }
147154 if (ti.tfCounter < firstSeenTF) {
155+ orbitReset = orbitResetTime;
156+ firstTForbit = ti.firstTForbit ;
148157 firstSeenTF = ti.tfCounter ;
149158 }
150159 for (const auto & residIn : resid) {
@@ -206,7 +215,6 @@ void ResidualsContainer::fill(const o2::dataformats::TFIDInfo& ti, const gsl::sp
206215 treeOutResidualsUnbinned->Fill ();
207216 unbinnedRes.clear ();
208217 }
209- runNumber = ti.runNumber ;
210218 tfOrbits.push_back (ti.firstTForbit );
211219 if (lumiInput) {
212220 lumi.push_back (*lumiInput);
@@ -255,7 +263,7 @@ void ResidualsContainer::merge(ResidualsContainer* prev)
255263{
256264 // the previous slot is merged to this one and afterwards
257265 // the previous one will be deleted
258- LOG (info) << " Merging previous slot into current one" ;
266+ LOGP (debug, " Merging previous slot with {} entries into current one with {} entries " , prev-> getNEntries (), getNEntries ()) ;
259267 if (writeBinnedResid) {
260268 for (int iSec = 0 ; iSec < SECTORSPERSIDE * SIDES ; ++iSec) {
261269 // merge statistics
@@ -275,8 +283,9 @@ void ResidualsContainer::merge(ResidualsContainer* prev)
275283 stat.nEntries += statPrev.nEntries ;
276284 }
277285 // prepare merging of residuals
278- prev->treeOutResiduals ->SetBranchAddress (Form (" sec%d" , iSec), &residualsPtr);
286+ prev->treeOutResiduals ->SetBranchAddress (Form (" sec%d" , iSec), &residualsPtr[iSec] );
279287 }
288+ prev->treeOutResiduals ->SetBranchAddress (" trackInfo" , &trackInfoPtr);
280289 // We append the entries of the tree of the following slot to the
281290 // previous slot and afterwards move the merged tree to this slot.
282291 // This way the order of the entries is preserved
@@ -305,6 +314,12 @@ void ResidualsContainer::merge(ResidualsContainer* prev)
305314 treeOutTrackData = std::move (prev->treeOutTrackData );
306315 treeOutResidualsUnbinned = std::move (prev->treeOutResidualsUnbinned );
307316
317+ // since we want to continue using the TTrees of the previous slot, we must
318+ // avoid that ROOT deletes them when the TFile of the previous slot is erased
319+ treeOutResiduals->SetDirectory (fileOut.get ());
320+ treeOutTrackData->SetDirectory (fileOut.get ());
321+ treeOutResidualsUnbinned->SetDirectory (fileOut.get ());
322+
308323 nResidualsTotal += prev->nResidualsTotal ;
309324
310325 // append the current vector to the vector of the previous container and afterwards swap them,
@@ -317,6 +332,7 @@ void ResidualsContainer::merge(ResidualsContainer* prev)
317332 std::swap (prev->lumi , lumi);
318333
319334 firstSeenTF = prev->firstSeenTF ;
335+ LOGP (debug, " Done with the merge. Current slot has {} entries" , getNEntries ());
320336}
321337
322338void ResidualsContainer::print ()
@@ -334,8 +350,9 @@ ResidualAggregator::~ResidualAggregator()
334350
335351bool ResidualAggregator::hasEnoughData (const Slot& slot) const
336352{
337- LOG (debug) << " There are " << slot.getContainer ()->getNEntries () << " entries currently. Min entries prt voxel: " << mMinEntries ;
353+ LOG (debug) << " There are " << slot.getContainer ()->getNEntries () << " entries currently. Min entries per voxel: " << mMinEntries ;
338354 auto entriesPerVoxel = slot.getContainer ()->getNEntries () / (mTrackResiduals .getNVoxelsPerSector () * SECTORSPERSIDE * SIDES );
355+ LOGP (debug, " Slot has {} entries per voxel, at least {} are required" , entriesPerVoxel, mMinEntries );
339356 return entriesPerVoxel >= mMinEntries ;
340357}
341358
@@ -350,13 +367,17 @@ void ResidualAggregator::finalizeSlot(Slot& slot)
350367 auto finalizeStartTime = std::chrono::high_resolution_clock::now ();
351368 auto cont = slot.getContainer ();
352369 cont->print ();
353- if (!mWriteOutput ) {
354- LOG (info) << " Skip writing output, since file output is disabled" ;
370+ if (!mWriteOutput || cont-> getNEntries () == 0 ) {
371+ LOGP (info, " Skip writing output with {} entries , since file output is disabled or slot is empty " , cont-> getNEntries ()) ;
355372 return ;
356373 }
357374 cont->writeToFile (true );
358375
359- auto fileName = fmt::format (" o2tpc_residuals_{}_{}_{}_{}.root" , slot.getTFStart (), slot.getTFEnd (), cont->firstSeenTF , cont->lastSeenTF );
376+ long orbitOffsetStart = (cont->firstSeenTF - slot.getTFStart ()) * o2::base::GRPGeomHelper::getNHBFPerTF ();
377+ long orbitOffsetEnd = (slot.getTFEnd () - cont->firstSeenTF ) * o2::base::GRPGeomHelper::getNHBFPerTF ();
378+ long timeStartMS = cont->orbitReset + (cont->firstTForbit - orbitOffsetStart) * o2::constants::lhc::LHCOrbitMUS * 1 .e -3 ;
379+ long timeEndMS = cont->orbitReset + (cont->firstTForbit + orbitOffsetEnd) * o2::constants::lhc::LHCOrbitMUS * 1 .e -3 ;
380+ auto fileName = fmt::format (" o2tpc_residuals_{}_{}_{}_{}.root" , timeStartMS, timeEndMS, slot.getTFStart (), slot.getTFEnd ());
360381 auto fileNameWithPath = mOutputDir + fileName;
361382 std::filesystem::rename (o2::utils::Str::concat_string (mOutputDir , cont->fileName , " .part" ), fileNameWithPath);
362383 if (mStoreMetaData ) {
0 commit comments