Skip to content

Commit 3bf08c0

Browse files
sawenzelclaude
andcommitted
Honour O2SIM_RESTRICT_EVENTPART and skip the master hit buffers in MT
This aligns the multithreaded worker with the forked one in two details. - O2SIM_RESTRICT_EVENTPART now selects the sub-event to transport, as in the forked workers. - The master no longer creates hit buffers in multithreaded mode, since only the thread clones fill them. - A named flag replaces the missing data channel as the sign of a thread's first sub-event. https://its.cern.ch/jira/browse/O2-7305 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a826643 commit 3bf08c0

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎Steer/include/Steer/O2MCApplication.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class O2MCApplication : public O2MCApplicationBase
123123
void fetchWorkerChunk();
124124
bool mIsMTWorker = false; //! this is the application of a multithreaded Geant4 worker
125125
bool mIsEndOfWork = false; //! the current event is the empty one ending the worker's loop
126+
bool mWorkerInitialized = false; //! this worker's detectors and data channel are set up
126127
o2::data::SubEventInfo mWorkerSubEventInfo; //! sub-event being transported by this worker
127128
std::unique_ptr<TRandom> mWorkerRandom; //! this worker's transport random generator
128129

‎Steer/src/O2MCApplication.cxx‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
1111

12+
#include <cstdio>
1213
#include <cstdlib>
1314

1415
#include <Steer/O2MCApplication.h>
@@ -1847,6 +1848,9 @@ void O2MCApplication::initLate()
18471848
}
18481849
}
18491850
o2::utils::ShmManager::Instance().occupySegment(fRun && fRun->IsMT());
1851+
if (fRun && fRun->IsMT()) {
1852+
return; // the hit buffers belong to the detector clones of the worker threads
1853+
}
18501854
for (auto det : listActiveDetectors) {
18511855
if (dynamic_cast<o2::base::Detector*>(det)) {
18521856
((o2::base::Detector*)det)->initializeLate();
@@ -1999,13 +2003,14 @@ void O2MCApplication::BeginEvent()
19992003
void O2MCApplication::fetchWorkerChunk()
20002004
{
20012005
auto& hooks = o2::base::MTWorkerHooks::instance();
2002-
if (!mSimDataChannel) {
2006+
if (!mWorkerInitialized) { // the first sub-event of this thread
20032007
mSimDataChannel = hooks.dataChannel();
20042008
for (auto det : listActiveDetectors) {
20052009
if (auto o2det = dynamic_cast<o2::base::Detector*>(det)) {
20062010
o2det->initializeLate();
20072011
}
20082012
}
2013+
mWorkerInitialized = true;
20092014
}
20102015
auto chunk = hooks.fetchChunk();
20112016
mIsEndOfWork = !chunk;
@@ -2018,7 +2023,15 @@ void O2MCApplication::fetchWorkerChunk()
20182023
return;
20192024
}
20202025
mWorkerSubEventInfo = chunk->mSubEventInfo;
2021-
setPrimaries(chunk->mParticles);
2026+
// as in a worker process, O2SIM_RESTRICT_EVENTPART="event:part" transports only that sub-event
2027+
int focusEvent = -1, focusPart = -1;
2028+
auto selection = getenv("O2SIM_RESTRICT_EVENTPART");
2029+
if (selection && (std::sscanf(selection, "%d:%d", &focusEvent, &focusPart) != 2 || focusEvent != mWorkerSubEventInfo.eventID || focusPart != mWorkerSubEventInfo.part)) {
2030+
setPrimaries(std::vector<TParticle>{});
2031+
LOG(info) << "This chunk will be skipped";
2032+
} else {
2033+
setPrimaries(chunk->mParticles);
2034+
}
20222035
setSubEventInfo(&mWorkerSubEventInfo);
20232036
LOG(info) << "Processing " << mPrimaries.size() << " primary particles for event " << mWorkerSubEventInfo.eventID << "/"
20242037
<< mWorkerSubEventInfo.maxEvents << " part " << mWorkerSubEventInfo.part << "/" << mWorkerSubEventInfo.nparts;

0 commit comments

Comments
 (0)