Skip to content

Commit 038d046

Browse files
sawenzelclaude
andcommitted
Create the hit-merger detector instances from a table
This replaces the chain of per-detector conditions in the hit merger with a table of factories. - Each detector that can be merged now has one entry mapping its DetID to a factory. - The warning compared the number of active detectors with DetID::nDetectors and fired in practically every run. - It now names an active readout detector that has no merger instance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 9a567e6 commit 038d046

1 file changed

Lines changed: 41 additions & 110 deletions

File tree

‎run/O2HitMerger.cxx‎

Lines changed: 41 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -858,122 +858,53 @@ void O2HitMerger::initDetInstances()
858858
auto active = std::find(modulelist.begin(), modulelist.end(), s) != modulelist.end();
859859
return active; };
860860

861-
mDetectorInstances.resize(DetID::nDetectors);
862-
// like a factory of detector objects
861+
// readout-only detector instances able to interpret and write the hits of each detector
862+
using Factory = std::function<std::unique_ptr<o2::base::Detector>()>;
863+
const std::map<int, Factory> factories{
864+
{DetID::TPC, [] { return std::make_unique<o2::tpc::Detector>(true); }},
865+
{DetID::ITS, [] { return std::make_unique<o2::its::Detector>(true); }},
866+
{DetID::MFT, [] { return std::make_unique<o2::mft::Detector>(true); }},
867+
{DetID::TRD, [] { return std::make_unique<o2::trd::Detector>(true); }},
868+
{DetID::PHS, [] { return std::make_unique<o2::phos::Detector>(true); }},
869+
{DetID::CPV, [] { return std::make_unique<o2::cpv::Detector>(true); }},
870+
{DetID::EMC, [] { return std::make_unique<o2::emcal::Detector>(true); }},
871+
{DetID::HMP, [] { return std::make_unique<o2::hmpid::Detector>(true); }},
872+
{DetID::TOF, [] { return std::make_unique<o2::tof::Detector>(true); }},
873+
{DetID::FT0, [] { return std::make_unique<o2::ft0::Detector>(true); }},
874+
{DetID::FV0, [] { return std::make_unique<o2::fv0::Detector>(true); }},
875+
{DetID::FDD, [] { return std::make_unique<o2::fdd::Detector>(true); }},
876+
{DetID::MCH, [] { return std::make_unique<o2::mch::Detector>(true); }},
877+
{DetID::MID, [] { return std::make_unique<o2::mid::Detector>(true); }},
878+
{DetID::ZDC, [] { return std::make_unique<o2::zdc::Detector>(true); }},
879+
{DetID::FOC, [] {
880+
TString sName = "$O2_ROOT/share/Detectors/Geometry/FOC/geometryFiles/geometry_Sheets.txt";
881+
gSystem->ExpandPathName(sName);
882+
return std::make_unique<o2::focal::Detector>(true, sName.Data());
883+
}},
884+
#ifdef ENABLE_UPGRADES
885+
{DetID::IT3, [] { return std::make_unique<o2::its::Detector>(true, "IT3"); }},
886+
{DetID::TRK, [] { return std::make_unique<o2::trk::Detector>(true); }},
887+
{DetID::FT3, [] { return std::make_unique<o2::ft3::Detector>(true); }},
888+
{DetID::FCT, [] { return std::make_unique<o2::fct::Detector>(true); }},
889+
{DetID::TF3, [] { return std::make_unique<o2::iotof::Detector>(true); }},
890+
{DetID::RCH, [] { return std::make_unique<o2::rich::Detector>(true); }},
891+
{DetID::MI3, [] { return std::make_unique<o2::mi3::Detector>(true); }},
892+
{DetID::ECL, [] { return std::make_unique<o2::ecal::Detector>(true); }},
893+
{DetID::FD3, [] { return std::make_unique<o2::fd3::Detector>(true); }},
894+
#endif
895+
};
863896

864-
int counter = 0;
897+
mDetectorInstances.resize(DetID::nDetectors);
865898
for (int i = DetID::First; i <= DetID::Last; ++i) {
866899
if (!isActivated(DetID::getName(i))) {
867900
continue;
868901
}
869-
870-
if (i == DetID::TPC) {
871-
mDetectorInstances[i] = std::move(std::make_unique<o2::tpc::Detector>(true));
872-
counter++;
873-
}
874-
if (i == DetID::ITS) {
875-
mDetectorInstances[i] = std::move(std::make_unique<o2::its::Detector>(true));
876-
counter++;
877-
}
878-
if (i == DetID::MFT) {
879-
mDetectorInstances[i] = std::move(std::make_unique<o2::mft::Detector>(true));
880-
counter++;
881-
}
882-
if (i == DetID::TRD) {
883-
mDetectorInstances[i] = std::move(std::make_unique<o2::trd::Detector>(true));
884-
counter++;
885-
}
886-
if (i == DetID::PHS) {
887-
mDetectorInstances[i] = std::move(std::make_unique<o2::phos::Detector>(true));
888-
counter++;
889-
}
890-
if (i == DetID::CPV) {
891-
mDetectorInstances[i] = std::move(std::make_unique<o2::cpv::Detector>(true));
892-
counter++;
893-
}
894-
if (i == DetID::EMC) {
895-
mDetectorInstances[i] = std::move(std::make_unique<o2::emcal::Detector>(true));
896-
counter++;
897-
}
898-
if (i == DetID::HMP) {
899-
mDetectorInstances[i] = std::move(std::make_unique<o2::hmpid::Detector>(true));
900-
counter++;
901-
}
902-
if (i == DetID::TOF) {
903-
mDetectorInstances[i] = std::move(std::make_unique<o2::tof::Detector>(true));
904-
counter++;
905-
}
906-
if (i == DetID::FT0) {
907-
mDetectorInstances[i] = std::move(std::make_unique<o2::ft0::Detector>(true));
908-
counter++;
909-
}
910-
if (i == DetID::FV0) {
911-
mDetectorInstances[i] = std::move(std::make_unique<o2::fv0::Detector>(true));
912-
counter++;
913-
}
914-
if (i == DetID::FDD) {
915-
mDetectorInstances[i] = std::move(std::make_unique<o2::fdd::Detector>(true));
916-
counter++;
917-
}
918-
if (i == DetID::MCH) {
919-
mDetectorInstances[i] = std::move(std::make_unique<o2::mch::Detector>(true));
920-
counter++;
921-
}
922-
if (i == DetID::MID) {
923-
mDetectorInstances[i] = std::move(std::make_unique<o2::mid::Detector>(true));
924-
counter++;
925-
}
926-
if (i == DetID::ZDC) {
927-
mDetectorInstances[i] = std::move(std::make_unique<o2::zdc::Detector>(true));
928-
counter++;
929-
}
930-
if (i == DetID::FOC) {
931-
TString sName = "$O2_ROOT/share/Detectors/Geometry/FOC/geometryFiles/geometry_Sheets.txt";
932-
gSystem->ExpandPathName(sName);
933-
mDetectorInstances[i] = std::move(std::make_unique<o2::focal::Detector>(true, sName.Data()));
934-
counter++;
935-
}
936-
#ifdef ENABLE_UPGRADES
937-
if (i == DetID::IT3) {
938-
mDetectorInstances[i] = std::move(std::make_unique<o2::its::Detector>(true, "IT3"));
939-
counter++;
940-
}
941-
if (i == DetID::TRK) {
942-
mDetectorInstances[i] = std::move(std::make_unique<o2::trk::Detector>(true));
943-
counter++;
944-
}
945-
if (i == DetID::FT3) {
946-
mDetectorInstances[i] = std::move(std::make_unique<o2::ft3::Detector>(true));
947-
counter++;
948-
}
949-
if (i == DetID::FCT) {
950-
mDetectorInstances[i] = std::move(std::make_unique<o2::fct::Detector>(true));
951-
counter++;
952-
}
953-
if (i == DetID::TF3) {
954-
mDetectorInstances[i] = std::move(std::make_unique<o2::iotof::Detector>(true));
955-
counter++;
956-
}
957-
if (i == DetID::RCH) {
958-
mDetectorInstances[i] = std::move(std::make_unique<o2::rich::Detector>(true));
959-
counter++;
960-
}
961-
if (i == DetID::MI3) {
962-
mDetectorInstances[i] = std::move(std::make_unique<o2::mi3::Detector>(true));
963-
counter++;
964-
}
965-
if (i == DetID::ECL) {
966-
mDetectorInstances[i] = std::move(std::make_unique<o2::ecal::Detector>(true));
967-
counter++;
968-
}
969-
if (i == DetID::FD3) {
970-
mDetectorInstances[i] = std::move(std::make_unique<o2::fd3::Detector>(true));
971-
counter++;
902+
auto factory = factories.find(i);
903+
if (factory == factories.end()) {
904+
LOG(warning) << "O2HitMerger: no hit merging available for readout detector " << DetID::getName(i);
905+
continue;
972906
}
973-
#endif
974-
}
975-
if (counter != DetID::nDetectors) {
976-
LOG(warning) << " O2HitMerger: Some Detectors are potentially missing in this initialization ";
907+
mDetectorInstances[i] = factory->second();
977908
}
978909

979910
// also register external (CAD-derived) sensitive detectors so their hits are persisted

0 commit comments

Comments
 (0)