1212#include " MCHGlobalMapping/DsIndex.h"
1313
1414#include < map>
15+ #include < stdexcept>
1516#include < vector>
17+
18+ #include " Framework/Logger.h"
1619#include " MCHMappingInterface/Segmentation.h"
1720
1821namespace o2 ::mch
@@ -38,12 +41,16 @@ uint8_t numberOfDualSampaChannels(DsIndex dsIndex)
3841 auto dsId = det.dsId ();
3942 auto deId = det.deId ();
4043 const auto & seg = o2::mch::mapping::segmentation (deId);
41- seg.bending ().forEachPadInDualSampa (dsId, [&nch](int /* catPadIndex*/ ) { ++nch; });
42- seg.nonBending ().forEachPadInDualSampa (dsId, [&nch](int /* catPadIndex*/ ) { ++nch; });
44+ seg.forEachPadInDualSampa (dsId, [&nch](int /* dePadIndex*/ ) { ++nch; });
4345 channelsPerDS.emplace_back (nch);
4446 }
4547 }
46- return channelsPerDS[dsIndex];
48+ if (dsIndex < o2::mch::NumberOfDualSampas) {
49+ return channelsPerDS[dsIndex];
50+ } else {
51+ LOGP (error, " invalid Dual Sampa index: {}" , dsIndex);
52+ }
53+ return 0 ;
4754}
4855
4956std::map<uint32_t , uint16_t > buildDetId2DsIndexMap ()
@@ -72,13 +79,23 @@ std::map<uint32_t, uint16_t> buildDetId2DsIndexMap()
7279DsIndex getDsIndex (const o2::mch::raw::DsDetId& dsDetId)
7380{
7481 static std::map<uint32_t , uint16_t > m = buildDetId2DsIndexMap ();
75- return m[encode (dsDetId)];
82+ try {
83+ return m.at (encode (dsDetId));
84+ } catch (const std::exception&) {
85+ LOGP (error, " invalid Dual Sampa Id: {}" , raw::asString (dsDetId));
86+ }
87+ return NumberOfDualSampas;
7688}
7789
7890o2::mch::raw::DsDetId getDsDetId (DsIndex dsIndex)
7991{
8092 static std::map<uint16_t , uint32_t > m = inverseMap (buildDetId2DsIndexMap ());
81- return raw::decodeDsDetId (m[dsIndex]);
93+ try {
94+ return raw::decodeDsDetId (m.at (dsIndex));
95+ } catch (const std::exception&) {
96+ LOGP (error, " invalid Dual Sampa index: {}" , dsIndex);
97+ }
98+ return raw::DsDetId (0 , 0 );
8299}
83100
84101} // namespace o2::mch
0 commit comments