Skip to content

Commit c372745

Browse files
sawenzelclaude
andcommitted
Fix the event-flush loop of the o2-sim hit merger
This fixes how the hit merger advances to the next event while flushing. - The skip paths advanced the event counter but then carried on with the current event. - With --noemptyevents, an event without hits was written when the next event was already complete, and that next event was then skipped. - An event without buffered info dereferenced the end iterator. - The loop now iterates over flushable event IDs and every skip path is a plain continue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0d35160 commit c372745

1 file changed

Lines changed: 10 additions & 25 deletions

File tree

‎run/O2HitMerger.h‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -654,34 +654,24 @@ class O2HitMerger : public fair::mq::Device
654654
// The method can be called asynchronously to data collection
655655
bool mergeAndFlushData()
656656
{
657-
auto checkIfNextFlushable = [this]() -> bool {
658-
mNextFlushID++;
659-
return mFlushableEvents.find(mNextFlushID) != mFlushableEvents.end() && mFlushableEvents[mNextFlushID] == true;
657+
auto isFlushable = [this](int eventID) {
658+
auto iter = mFlushableEvents.find(eventID);
659+
return iter != mFlushableEvents.end() && iter->second;
660660
};
661661

662662
LOG(info) << "Launching merge kernel ";
663-
bool canflush = mFlushableEvents.find(mNextFlushID) != mFlushableEvents.end() && mFlushableEvents[mNextFlushID] == true;
664-
if (!canflush) {
663+
if (!isFlushable(mNextFlushID)) {
665664
return false;
666665
}
667-
while (canflush == true) {
666+
for (; isFlushable(mNextFlushID); ++mNextFlushID) {
668667
auto flusheventID = mNextFlushID;
669668
LOG(info) << "Merge and flush event " << flusheventID;
670669
auto iter = mSubEventInfoBuffer.find(flusheventID);
671-
if (iter == mSubEventInfoBuffer.end()) {
672-
LOG(error) << "No info/data found for event " << flusheventID;
673-
if (!checkIfNextFlushable()) {
674-
return false;
675-
}
676-
}
677-
678-
auto& subEventInfoList = (*iter).second;
679-
if (subEventInfoList.size() == 0 || mNExpectedEvents == 0) {
670+
if (iter == mSubEventInfoBuffer.end() || iter->second.size() == 0 || mNExpectedEvents == 0) {
680671
LOG(error) << "No data entries found for event " << flusheventID;
681-
if (!checkIfNextFlushable()) {
682-
return false;
683-
}
672+
continue;
684673
}
674+
auto& subEventInfoList = iter->second;
685675

686676
TStopwatch timer;
687677
timer.Start();
@@ -716,9 +706,7 @@ class O2HitMerger : public fair::mq::Device
716706
if (eventheader && eventheader->getMCEventStats().getNHits() == 0) {
717707
LOG(info) << " Taking out event " << flusheventID << " due to no hits ";
718708
cleanEvent(flusheventID);
719-
if (!checkIfNextFlushable()) {
720-
return true;
721-
}
709+
continue;
722710
}
723711
}
724712

@@ -834,10 +822,7 @@ class O2HitMerger : public fair::mq::Device
834822

835823
cleanEvent(flusheventID);
836824
LOG(info) << "Merge/flush for event " << flusheventID << " took " << timer.RealTime();
837-
if (!checkIfNextFlushable()) {
838-
break;
839-
}
840-
} // end while
825+
}
841826
if (mWriteToDisc && mOutFile) {
842827
LOG(info) << "Writing TTrees";
843828
mOutFile->Write("", TObject::kOverwrite);

0 commit comments

Comments
 (0)