Skip to content

Commit 35c4f5c

Browse files
sawenzelclaude
andcommitted
Send the hit transport mode with the hits in o2-sim
This makes the hit merger decode each detector's hits the way the worker sent them. - Worker and merger each read the global ShmManager::isOperational() to choose between shared memory and TMessage. - That flag lives in the segment and flips when any late worker fails to attach, so hits already in flight could be decoded the wrong way. - The per-detector header message is now a HitsHeader carrying the DetID and the mode, decided once per detector in attachHits. - collectHits takes the mode from the header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e4b6438 commit 35c4f5c

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

‎Detectors/Base/include/DetectorsBase/Detector.h‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class Detector : public FairDetector
187187
// and to decode it
188188
virtual void attachHits(fair::mq::Channel&, fair::mq::Parts&) = 0;
189189
virtual void fillHitBranch(TTree& tr, fair::mq::Parts& parts, int& index) = 0;
190-
virtual void collectHits(int eventID, fair::mq::Parts& parts, int& index) = 0;
190+
virtual void collectHits(int eventID, fair::mq::Parts& parts, int& index, bool shm) = 0;
191191
virtual void mergeHitEntriesAndFlush(int eventID,
192192
TTree& target,
193193
std::vector<int> const& trackoffsets,
@@ -298,7 +298,13 @@ T decodeTMessage(fair::mq::Parts& dataparts, int index)
298298
return static_cast<T>(decodeTMessageCore(dataparts, index));
299299
}
300300

301-
void attachDetIDHeaderMessage(int id, fair::mq::Channel& channel, fair::mq::Parts& parts);
301+
// header message preceding the hits of one detector
302+
struct HitsHeader {
303+
int detID;
304+
bool shm; // whether the hits follow as shared-memory references or as TMessages
305+
};
306+
307+
void attachHitsHeaderMessage(HitsHeader const& header, fair::mq::Channel& channel, fair::mq::Parts& parts);
302308

303309
template <typename T>
304310
TBranch* getOrMakeBranch(TTree& tree, const char* brname, T* ptr)
@@ -360,10 +366,12 @@ class DetImpl : public o2::base::Detector
360366
return;
361367
}
362368

363-
attachDetIDHeaderMessage(GetDetId(), channel, parts); // the DetId s are universal as they come from o2::detector::DetID
369+
// decide the transport once, so that the header and all hit messages agree
370+
const bool shm = UseShm<Det>::value && o2::utils::ShmManager::Instance().isOperational();
371+
attachHitsHeaderMessage({GetDetId(), shm}, channel, parts); // the DetId s are universal as they come from o2::detector::DetID
364372

365373
while (auto hits = static_cast<Det*>(this)->Det::getHits(probe++)) {
366-
if (!UseShm<Det>::value || !o2::utils::ShmManager::Instance().isOperational()) {
374+
if (!shm) {
367375
attachTMessage(*hits, channel, parts);
368376
} else {
369377
// this is the shared mem variant
@@ -542,7 +550,7 @@ class DetImpl : public o2::base::Detector
542550
/// Collect Hits available as incoming message (shared mem or not)
543551
/// inside this process for later streaming to output. A function needed
544552
/// by the hit-merger process (not for direct use by users)
545-
void collectHits(int eventID, fair::mq::Parts& parts, int& index) override
553+
void collectHits(int eventID, fair::mq::Parts& parts, int& index, bool shm) override
546554
{
547555
using Hit_t = typename std::remove_pointer<decltype(static_cast<Det*>(this)->Det::getHits(0))>::type;
548556
using Collector_t = tbb::concurrent_unordered_map<int, std::vector<std::vector<std::unique_ptr<Hit_t>>>>;
@@ -582,7 +590,7 @@ class DetImpl : public o2::base::Detector
582590
};
583591

584592
while (name.size() > 0) {
585-
if (!UseShm<Det>::value || !o2::utils::ShmManager::Instance().isOperational()) {
593+
if (!shm) {
586594
// for each branch name we extract/decode hits from the message parts ...
587595
auto hitsptr = decodeTMessage<HitPtr_t>(parts, index++);
588596
if (hitsptr) {

‎Detectors/Base/src/Detector.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ void attachMessageBufferToParts(fair::mq::Parts& parts, fair::mq::Channel& chann
215215
o2::framework::TMessageSerializer::serialize(buffer, data, cl);
216216
parts.AddPart(std::move(msg));
217217
}
218-
void attachDetIDHeaderMessage(int id, fair::mq::Channel& channel, fair::mq::Parts& parts)
218+
void attachHitsHeaderMessage(HitsHeader const& header, fair::mq::Channel& channel, fair::mq::Parts& parts)
219219
{
220-
std::unique_ptr<fair::mq::Message> message(channel.NewSimpleMessage(id));
220+
std::unique_ptr<fair::mq::Message> message(channel.NewSimpleMessage(header));
221221
parts.AddPart(std::move(message));
222222
}
223223
void attachShmMessage(void* hits_ptr, fair::mq::Channel& channel, fair::mq::Parts& parts, ShmBusyFlag* busy_ptr)

‎Detectors/Base/test/testStack.cxx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class TestDetector : public o2::base::Detector
117117
std::string getHitBranchNames(int) const override { return {}; }
118118
void attachHits(fair::mq::Channel&, fair::mq::Parts&) override {}
119119
void fillHitBranch(TTree&, fair::mq::Parts&, int&) override {}
120-
void collectHits(int, fair::mq::Parts&, int&) override {}
120+
void collectHits(int, fair::mq::Parts&, int&, bool) override {}
121121
void mergeHitEntriesAndFlush(int, TTree&, std::vector<int> const&, std::vector<int> const&,
122122
std::vector<int> const&) override {}
123123
void mergeHitEntries(TTree&, TTree&, std::vector<int> const&, std::vector<int> const&,

‎run/O2HitMerger.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,18 @@ class O2HitMerger : public fair::mq::Device
297297

298298
void consumeHits(int eventID, fair::mq::Parts& data, int& index)
299299
{
300-
auto detIDmessage = std::move(data.At(index++));
301-
// this should be a detector ID
302-
if (detIDmessage->GetSize() == 4) {
303-
auto ptr = (int*)detIDmessage->GetData();
304-
o2::detectors::DetID id(ptr[0]);
305-
LOG(debug2) << "I1 " << ptr[0] << " NAME " << id.getName() << " MB "
300+
auto headermessage = std::move(data.At(index++));
301+
// this should be the header announcing the hits of one detector
302+
if (headermessage->GetSize() == sizeof(o2::base::HitsHeader)) {
303+
auto header = *static_cast<o2::base::HitsHeader const*>(headermessage->GetData());
304+
o2::detectors::DetID id(header.detID);
305+
LOG(debug2) << "I1 " << header.detID << " NAME " << id.getName() << " MB "
306306
<< data.At(index)->GetSize() / 1024. / 1024.;
307307

308308
// get the detector that can interpret it
309309
auto detector = mDetectorInstances[id].get();
310310
if (detector) {
311-
detector->collectHits(eventID, data, index);
311+
detector->collectHits(eventID, data, index, header.shm);
312312
}
313313
}
314314
}

0 commit comments

Comments
 (0)