ATLAS Offline Software
Loading...
Searching...
No Matches
MdtCablingTestAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4#include "MdtCablingTestAlg.h"
8
9#include <fstream>
10
11MdtCablingTestAlg::MdtCablingTestAlg(const std::string& name, ISvcLocator* pSvcLocator):
12 AthAlgorithm(name,pSvcLocator) {}
13
14
16 ATH_CHECK(m_idHelperSvc.retrieve());
17 ATH_CHECK(m_DetectorManagerKey.initialize());
18 ATH_CHECK(m_cablingKey.initialize());
19 ATH_CHECK(m_deadChanKey.initialize(!m_deadChanKey.empty()));
20 return StatusCode::SUCCESS;
21}
22
23StatusCode MdtCablingTestAlg::execute(const EventContext& ctx){
24 std::unique_ptr<std::fstream> f_dump = !m_dumpFile.value().empty() ?
25 std::make_unique<std::fstream>(m_dumpFile, std::fstream::out) : nullptr;
26 ATH_MSG_INFO("Start validation of the Mdt cabling. Dump complete mapping into "<<m_dumpFile);
27 {
28 using Mapping = MdtMezzanineCard::Mapping;
29 using OffChnl = MdtMezzanineCard::OfflineCh;
30 Mapping staggering{};
31 for (unsigned i = 0 ; i < staggering.size(); ++i){
32 staggering[i] = (staggering.size() -1) -i;
33 }
34 for (unsigned i = 0 ; i < staggering.size() ; i+=2){
35 std::swap(staggering[i], staggering[i+1]);
36 }
37 for (unsigned nLay : {3,4}){
38 MdtMezzanineCard testCard(staggering, nLay , 0);
39 if (!testCard.checkConsistency(msgStream())) return StatusCode::FAILURE;
40 ATH_MSG_INFO("Test mezzanine "<<testCard);
42 for (unsigned ch = 0 ; ch < staggering.size() ; ++ch) {
43 OffChnl off = testCard.offlineTube(ch, msgStream());
44 if (!off.isValid) {
45 ATH_MSG_FATAL("Failed to load tube & layer for channel "<<ch);
46 return StatusCode::FAILURE;
47 }
48 unsigned back_ch = testCard.tdcChannel(off.layer, off.tube +1 , msgStream());
49 if (ch != back_ch) {
50 ATH_MSG_FATAL("Forward conversion of "<<ch<<" lead to "
51 <<static_cast<int>(off.layer)<<","
52 <<static_cast<int>(off.tube +1)<<" and then back to "
53 <<back_ch);
54 return StatusCode::FAILURE;
55 }
56 }
58 for (unsigned lay = 1 ; lay <= nLay ; ++lay) {
59 for (unsigned int tube = 1 ; tube <= testCard.numTubesPerLayer() ; ++tube) {
60 const unsigned ch1 = testCard.tdcChannel(lay,tube,msgStream());
61 const unsigned ch2 = testCard.tdcChannel(lay,tube + testCard.numTubesPerLayer(),msgStream());
62
63 if(ch1 != ch2) {
64 ATH_MSG_FATAL("The tube "<<tube<<" in layer "<<lay
65 <<" leads to 2 different answers "<<ch1<<" vs. "<<ch2);
66 return StatusCode::FAILURE;
67 }
68 }
69 }
70 }
71 }
72
74 if (!detectorMgr.isValid()){
75 ATH_MSG_FATAL("Failed to retrieve the Detector manager "<<m_DetectorManagerKey.fullKey());
76 return StatusCode::FAILURE;
77 }
78
80 if (!cabling.isValid()) {
81 ATH_MSG_ERROR("Failed to retrieve the Mdt cabling "<<m_cablingKey.fullKey());
82 return StatusCode::FAILURE;
83 }
84
85 const MdtCondDbData* deadChan{nullptr};
86 if (!m_deadChanKey.empty()) {
88 if (!deadChanHandle.isValid()) {
89 ATH_MSG_FATAL("Failed to retrieve Mdt conditions "<<m_deadChanKey.fullKey());
90 return StatusCode::FAILURE;
91 }
92 deadChan = deadChanHandle.cptr();
93
94 }
95
96 const MdtIdHelper& idHelper = m_idHelperSvc->mdtIdHelper();
97 unsigned int n_elements{0}, n_success{0};
98 bool failure{false};
99
100 for (auto det_itr = idHelper.detectorElement_begin(); det_itr != idHelper.detectorElement_end(); ++det_itr){
101 const MuonGM::MdtReadoutElement* readEle = detectorMgr->getMdtReadoutElement(*det_itr);
102
103 if (!readEle) {
104 ATH_MSG_DEBUG("Detector element does not exist. ");
105 continue;
106 }
107 if (deadChan && !deadChan->isGoodChamber(readEle->identify())) {
108 ATH_MSG_ALWAYS("Dead station found "<<m_idHelperSvc->toStringChamber(readEle->identify()));
109 continue;
110 }
111 ATH_MSG_DEBUG("Check station "<<m_idHelperSvc->toStringChamber(readEle->identify()));
112 for (int layer = 1 ; layer <= readEle->getNLayers(); ++layer){
113 for (int tube = 1 ; tube <= readEle->getNtubesperlayer(); ++tube){
114 bool is_valid{false};
115 const Identifier tube_id = idHelper.channelID(readEle->identify(), readEle->getMultilayer(), layer, tube, is_valid);
116 if (!is_valid){
117 ATH_MSG_VERBOSE("Invalid element");
118 continue;
119 }
120 if (deadChan && !deadChan->isGood(tube_id)) {
121 ATH_MSG_ALWAYS("Dead dube detected "<<m_idHelperSvc->toString(tube_id));
122 continue;
123 }
124 ++n_elements;
126 MdtCablingData cabling_data{};
127 cabling->convert(tube_id,cabling_data);
129 if (!cabling->getOnlineId(cabling_data,msgStream())){
130 ATH_MSG_ERROR("Could no retrieve a valid online channel for "<<m_idHelperSvc->toString(tube_id)<<" from station ID "<<m_idHelperSvc->toString(readEle->identify()));
131 failure = true;
132 continue;
133 }
134 if (f_dump) (*f_dump)<<cabling_data<<std::endl;
136
138 const MdtCablingOffData off_data{};
139 static_cast<MdtCablingOffData&> (cabling_data) = off_data;
140 if (!cabling->getOfflineId(cabling_data, msgStream())){
141 ATH_MSG_ERROR("Could not convert the online cabling "<<cabling_data<<" to an offline identifier. Initial identifier "<<m_idHelperSvc->toString(tube_id));
142 failure = true;
143 continue;
144 }
145
146 Identifier test_id{};
147 if (!cabling->convert(cabling_data, test_id, true)){
148 ATH_MSG_ERROR("The extracted offline identifier "<<cabling_data<<" does not make sense");
149 failure = true;
150 continue;
151 }
152 if (test_id != tube_id){
153 ATH_MSG_ERROR("The forward -> backward conversion failed. Started with "<<m_idHelperSvc->toString(tube_id)<<" ended with "<<m_idHelperSvc->toString(test_id));
154 failure = true;
155 continue;
156 }
157
159 static_cast<MdtCablingOffData&>(cabling_data) = off_data;
160
162 cabling_data.tdcId = 0xff;
163 cabling_data.channelId =0xff;
164 if (!cabling->getOfflineId(cabling_data, msgStream()) || !cabling->convert(cabling_data, test_id, true)) {
165 ATH_MSG_ERROR("Failed to decode Mdt module "<<m_idHelperSvc->toString(tube_id));
166 failure = true;
167 continue;
168 }
169 MdtCablingData mrod_module{cabling_data};
170 if (!cabling->getOnlineId(mrod_module,msgStream())){
171 ATH_MSG_ERROR("Could no retrieve a valid online channel for "<<m_idHelperSvc->toString(tube_id));
172 failure = true;
173 continue;
174 }
176 if (idHelper.elementID(test_id) != idHelper.elementID(readEle->identify()) && static_cast<const MdtCablingOnData&>(mrod_module)!=(cabling_data)) {
177 ATH_MSG_ERROR("Failed to decode module "<<m_idHelperSvc->toString(tube_id)<<" got "<<m_idHelperSvc->toString(test_id) );
178 failure = true;
179 } else ++n_success;
180 }
181 }
182 }
183 ATH_MSG_INFO( n_success<<" out of "<<n_elements<<" channels were successfully validated.");
184 return failure ? StatusCode::FAILURE: StatusCode::SUCCESS;
185}
186
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_ALWAYS(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_dumpFile
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
MdtCablingTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadCondHandleKey< MdtCondDbData > m_deadChanKey
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_cablingKey
bool isGood(const Identifier &Id) const
Returns if the identifier (tube/multiLayer/chamber) is masked in the conditions database.
bool isGoodChamber(const Identifier &Id) const
Returns true if the complete chamber has not dead channels.
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
MdtMezzanineCard - Helper struct to represent the structure of a mezzanine card in a consistent way E...
bool checkConsistency(MsgStream &msg) const
checks whether the tdc mapping is complete.
OfflineCh offlineTube(uint8_t tdc, MsgStream &msg) const
uint8_t numTubesPerLayer() const
returns the number of tubes per layer;
uint8_t tdcChannel(uint8_t tubeLay, uint8_t tube, MsgStream &msg) const
returns the tdc channel number
std::array< uint8_t, 24 > Mapping
int getNLayers() const
Returns the number of tube layers inside the multilayer.
int getMultilayer() const
Returns the multilayer represented by the readout element.
int getNtubesperlayer() const
Returns the number of tubes in each tube layer.
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
const_id_iterator detectorElement_end() const
const_pointer_type cptr()
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)
Split the offline part of the cabling apart to use it later for sorting.
Helper struct to pipe the result from the tdc -> offline channel translation.