ATLAS Offline Software
MM_ROD_Decoder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <memory>
6 #include <unordered_map>
7 
11 
16 
18 #include "eformat/Issue.h"
19 #include "MM_ROD_Decoder.h"
20 
21 //===============================================================================
22 Muon::MM_ROD_Decoder::MM_ROD_Decoder( const std::string& type, const std::string& name,const IInterface* parent )
24 {
25  declareInterface<IMM_ROD_Decoder>( this );
26 }
27 
28 
29 //===============================================================================
31 {
32  ATH_CHECK(detStore()->retrieve(m_MmIdHelper, "MMIDHELPER"));
33  ATH_CHECK(m_cablingKey.initialize(!m_cablingKey.empty()));
34  ATH_CHECK(m_dscKey.initialize(!m_dscKey.empty()));
35  return StatusCode::SUCCESS;
36 }
37 
38 
39 //===============================================================================
40 // Processes a ROB fragment and fills the RDO container.
41 // If the vector of IdentifierHashes is not empty, then seeded mode is assumed
42 // (only requested modules are decoded). This must be made here, because the
43 // trigger granularity is a module, whereas ROB granularity is a whole sector.
44 // Therefore, refined selection is needed with decoded information.
45 StatusCode Muon::MM_ROD_Decoder::fillCollection(const EventContext& ctx, const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment& robFrag, const std::vector<IdentifierHash>& rdoIdhVect, std::unordered_map<IdentifierHash, std::unique_ptr<MM_RawDataCollection>> &rdo_map) const
46 {
47  // check fragment for errors
48  try {
49  robFrag.check();
50  } catch (const eformat::Issue &ex) {
51  ATH_MSG_WARNING(ex.what());
52  return StatusCode::SUCCESS;
53  }
54  const Nsw_CablingMap* mmCablingMap{nullptr};
55  if (!m_cablingKey.empty()) {
56  SG::ReadCondHandle<Nsw_CablingMap> readCondHandle{m_cablingKey, ctx};
57  if(!readCondHandle.isValid()){
58  ATH_MSG_ERROR("Cannot find Micromegas cabling map!");
59  return StatusCode::FAILURE;
60  }
61  mmCablingMap = readCondHandle.cptr();
62  }
63  const NswDcsDbData* dcsData{nullptr};
64  if(!m_dscKey.empty()) {
65  SG::ReadCondHandle<NswDcsDbData> readCondHandle{m_dscKey, ctx};
66  if(!readCondHandle.isValid()){
67  ATH_MSG_ERROR("Cannot find the NSW DcsCondDataObj "<<m_dscKey.fullKey());
68  return StatusCode::FAILURE;
69  }
70  dcsData = readCondHandle.cptr();
71  }
72 
73 
74  // if the vector of hashes is not empty, then we are in seeded mode
75  bool seeded_mode(!rdoIdhVect.empty());
76 
77  // have the NSWCommonDecoder take care of the decoding
78  Muon::nsw::NSWCommonDecoder common_decoder(robFrag);
79  const std::vector<Muon::nsw::NSWElink *>& elinks = common_decoder.get_elinks();
80  ATH_MSG_DEBUG("Retrieved "<<elinks.size()<<" elinks");
81  if (elinks.empty()) return StatusCode::SUCCESS;
82 
83 
84  // loop on elinks. we need an RDO (collection) per quadruplet!
85  for (auto* elink : elinks) {
86 
87  // skip null packets
88  if (elink->isNull()) continue;
89 
90  // get the offline ID hash (module ctx) to be passed to the RDO
91  // also specifies the index of the RDO in the container.
92  const char* station_name = elink->elinkId()->is_large_station() ? "MML" : "MMS";
93  int station_eta = (int)elink->elinkId()->station_eta();
94  unsigned int station_phi = (unsigned int)elink->elinkId()->station_phi();
95  unsigned int multi_layer = (unsigned int)elink->elinkId()->multi_layer();
96  unsigned int gas_gap = (unsigned int)elink->elinkId()->gas_gap();
97  Identifier module_ID = m_MmIdHelper->elementID(station_name, station_eta, station_phi);
98 
99  IdentifierHash module_hashID{0};
100  m_MmIdHelper->get_module_hash(module_ID, module_hashID);
101 
102  // if we are in ROI-seeded mode, check if this hashID is requested
103  if (seeded_mode && std::find(rdoIdhVect.begin(), rdoIdhVect.end(), module_hashID) == rdoIdhVect.end()) continue;
104 
105  std::unique_ptr<MM_RawDataCollection>& rdo = rdo_map[module_hashID];
106  if (!rdo) rdo = std::make_unique<MM_RawDataCollection>(module_hashID);
107 
108  // loop on all channels of this elink to fill the collection
109  const std::vector<Muon::nsw::VMMChannel *>& channels = elink->get_channels();
110  for (auto *channel : channels) {
111  unsigned int channel_number = channel->channel_number();
112  if (channel_number == 0) continue; // skip disconnected vmm channels
113  Identifier channel_ID = m_MmIdHelper->channelID(module_ID, multi_layer, gas_gap, channel_number); // not validating the IDs (too slow)
114  // now we have to check if for this channel there is a correction of the cabling needed
115  if (mmCablingMap) {
116  std::optional<Identifier> correctedChannelId = mmCablingMap->correctChannel(channel_ID, msgStream());
117  if (!correctedChannelId) {
118  ATH_MSG_DEBUG("Channel was shifted outside its connector and is therefore not decoded into and RDO");
119  continue;
120  }
121  channel_ID = (*correctedChannelId);
122  channel_number = m_MmIdHelper->channel(channel_ID);
123  }
124  if (dcsData && !dcsData->isGood(ctx,channel_ID)) continue;
125 
126  rdo->push_back(new MM_RawData(channel_ID, channel_number, channel->tdo(),
127  channel->pdo(), channel->rel_bcid(), true));
128  }
129  }
130 
131  return StatusCode::SUCCESS;
132 }
133 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Muon::MM_ROD_Decoder::MM_ROD_Decoder
MM_ROD_Decoder(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MM_ROD_Decoder.cxx:22
Nsw_CablingMap
Definition: Nsw_CablingMap.h:18
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Issue
Configuration Issue
Definition: PscIssues.h:31
Muon::MM_ROD_Decoder::initialize
virtual StatusCode initialize() override
Definition: MM_ROD_Decoder.cxx:30
ReadCondHandle.h
dq_defect_copy_defect_database.channels
def channels
Definition: dq_defect_copy_defect_database.py:56
Muon::nsw::NSWCommonDecoder
Definition: NSWCommonDecoder.h:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
Muon::MM_RawData
Temporary class to hold the MM RDO.
Definition: MM_RawData.h:20
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MM_ROD_Decoder.h
createCablingJSON.station_name
int station_name
Simple script to generate a BIS78 cabling map as used for the Monte Carlo processing.
Definition: createCablingJSON.py:8
VMMChannel.h
NSWCommonDecoder.h
MmIdHelper.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::MM_ROD_Decoder::fillCollection
virtual StatusCode fillCollection(const EventContext &, const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &, const std::vector< IdentifierHash > &, std::unordered_map< IdentifierHash, std::unique_ptr< MM_RawDataCollection >> &) const override
Convert ROBFragments to RDOs.
Definition: MM_ROD_Decoder.cxx:45
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
Muon::nsw::NSWCommonDecoder::get_elinks
const std::vector< Muon::nsw::NSWElink * > & get_elinks() const
Definition: NSWCommonDecoder.h:25
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
IdentifierHash.h
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
NswDcsDbData
Definition: NswDcsDbData.h:19
NSWResourceId.h
CalibCoolCompareRT.station_eta
station_eta
Definition: CalibCoolCompareRT.py:88
MM_RawDataContainer.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthAlgTool
Definition: AthAlgTool.h:26
IdentifierHash
Definition: IdentifierHash.h:38
CalibCoolCompareRT.station_phi
station_phi
Definition: CalibCoolCompareRT.py:87