ATLAS Offline Software
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 
11 MdtCablingTestAlg::MdtCablingTestAlg(const std::string& name, ISvcLocator* pSvcLocator):
12  AthAlgorithm(name,pSvcLocator) {}
13 
14 
16  ATH_CHECK(m_idHelperSvc.retrieve());
20  return StatusCode::SUCCESS;
21 }
22 
24  const EventContext& ctx = Gaudi::Hive::currentContext();
25  std::unique_ptr<std::fstream> f_dump = !m_dumpFile.value().empty() ?
26  std::make_unique<std::fstream>(m_dumpFile, std::fstream::out) : nullptr;
27  ATH_MSG_INFO("Start validation of the Mdt cabling. Dump complete mapping into "<<m_dumpFile);
28  {
29  using Mapping = MdtMezzanineCard::Mapping;
30  using OffChnl = MdtMezzanineCard::OfflineCh;
31  Mapping staggering{};
32  for (unsigned i = 0 ; i < staggering.size(); ++i){
33  staggering[i] = (staggering.size() -1) -i;
34  }
35  for (unsigned i = 0 ; i < staggering.size() ; i+=2){
36  std::swap(staggering[i], staggering[i+1]);
37  }
38  for (unsigned nLay : {3,4}){
39  MdtMezzanineCard testCard(staggering, nLay , 0);
40  if (!testCard.checkConsistency(msgStream())) return StatusCode::FAILURE;
41  ATH_MSG_INFO("Test mezzanine "<<testCard);
43  for (unsigned ch = 0 ; ch < staggering.size() ; ++ch) {
44  OffChnl off = testCard.offlineTube(ch, msgStream());
45  if (!off.isValid) {
46  ATH_MSG_FATAL("Failed to load tube & layer for channel "<<ch);
47  return StatusCode::FAILURE;
48  }
49  unsigned back_ch = testCard.tdcChannel(off.layer, off.tube +1 , msgStream());
50  if (ch != back_ch) {
51  ATH_MSG_FATAL("Forward conversion of "<<ch<<" lead to "
52  <<static_cast<int>(off.layer)<<","
53  <<static_cast<int>(off.tube +1)<<" and then back to "
54  <<back_ch);
55  return StatusCode::FAILURE;
56  }
57  }
59  for (unsigned lay = 1 ; lay <= nLay ; ++lay) {
60  for (unsigned int tube = 1 ; tube <= testCard.numTubesPerLayer() ; ++tube) {
61  const unsigned ch1 = testCard.tdcChannel(lay,tube,msgStream());
62  const unsigned ch2 = testCard.tdcChannel(lay,tube + testCard.numTubesPerLayer(),msgStream());
63 
64  if(ch1 != ch2) {
65  ATH_MSG_FATAL("The tube "<<tube<<" in layer "<<lay
66  <<" leads to 2 different answers "<<ch1<<" vs. "<<ch2);
67  return StatusCode::FAILURE;
68  }
69  }
70  }
71  }
72  }
73 
75  if (!detectorMgr.isValid()){
76  ATH_MSG_FATAL("Failed to retrieve the Detector manager "<<m_DetectorManagerKey.fullKey());
77  return StatusCode::FAILURE;
78  }
79 
81  if (!cabling.isValid()) {
82  ATH_MSG_ERROR("Failed to retrieve the Mdt cabling "<<m_cablingKey.fullKey());
83  return StatusCode::FAILURE;
84  }
85 
86  const MdtCondDbData* deadChan{nullptr};
87  if (!m_deadChanKey.empty()) {
89  if (!deadChanHandle.isValid()) {
90  ATH_MSG_FATAL("Failed to retrieve Mdt conditions "<<m_deadChanKey.fullKey());
91  return StatusCode::FAILURE;
92  }
93  deadChan = deadChanHandle.cptr();
94 
95  }
96 
97  const MdtIdHelper& idHelper = m_idHelperSvc->mdtIdHelper();
98  unsigned int n_elements{0}, n_success{0};
99  bool failure{false};
100 
101  for (auto det_itr = idHelper.detectorElement_begin(); det_itr != idHelper.detectorElement_end(); ++det_itr){
102  const MuonGM::MdtReadoutElement* readEle = detectorMgr->getMdtReadoutElement(*det_itr);
103 
104  if (!readEle) {
105  ATH_MSG_DEBUG("Detector element does not exist. ");
106  continue;
107  }
108  if (deadChan && !deadChan->isGoodChamber(readEle->identify())) {
109  ATH_MSG_ALWAYS("Dead station found "<<m_idHelperSvc->toStringChamber(readEle->identify()));
110  continue;
111  }
112  ATH_MSG_DEBUG("Check station "<<m_idHelperSvc->toStringChamber(readEle->identify()));
113  for (int layer = 1 ; layer <= readEle->getNLayers(); ++layer){
114  for (int tube = 1 ; tube <= readEle->getNtubesperlayer(); ++tube){
115  bool is_valid{false};
116  const Identifier tube_id = idHelper.channelID(readEle->identify(), readEle->getMultilayer(), layer, tube, is_valid);
117  if (!is_valid){
118  ATH_MSG_VERBOSE("Invalid element");
119  continue;
120  }
121  if (deadChan && !deadChan->isGood(tube_id)) {
122  ATH_MSG_ALWAYS("Dead dube detected "<<m_idHelperSvc->toString(tube_id));
123  continue;
124  }
125  ++n_elements;
128  cabling->convert(tube_id,cabling_data);
130  if (!cabling->getOnlineId(cabling_data,msgStream())){
131  ATH_MSG_ERROR("Could no retrieve a valid online channel for "<<m_idHelperSvc->toString(tube_id)<<" from station ID "<<m_idHelperSvc->toString(readEle->identify()));
132  failure = true;
133  continue;
134  }
135  if (f_dump) (*f_dump)<<cabling_data<<std::endl;
137 
139  const MdtCablingOffData off_data{};
140  static_cast<MdtCablingOffData&> (cabling_data) = off_data;
141  if (!cabling->getOfflineId(cabling_data, msgStream())){
142  ATH_MSG_ERROR("Could not convert the online cabling "<<cabling_data<<" to an offline identifier. Initial identifier "<<m_idHelperSvc->toString(tube_id));
143  failure = true;
144  continue;
145  }
146 
147  Identifier test_id{};
148  if (!cabling->convert(cabling_data, test_id, true)){
149  ATH_MSG_ERROR("The extracted offline identifier "<<cabling_data<<" does not make sense");
150  failure = true;
151  continue;
152  }
153  if (test_id != tube_id){
154  ATH_MSG_ERROR("The forward -> backward conversion failed. Started with "<<m_idHelperSvc->toString(tube_id)<<" ended with "<<m_idHelperSvc->toString(test_id));
155  failure = true;
156  continue;
157  }
158 
160  static_cast<MdtCablingOffData&>(cabling_data) = off_data;
161 
163  cabling_data.tdcId = 0xff;
164  cabling_data.channelId =0xff;
165  if (!cabling->getOfflineId(cabling_data, msgStream()) || !cabling->convert(cabling_data, test_id, true)) {
166  ATH_MSG_ERROR("Failed to decode Mdt module "<<m_idHelperSvc->toString(tube_id));
167  failure = true;
168  continue;
169  }
170  MdtCablingData mrod_module{cabling_data};
171  if (!cabling->getOnlineId(mrod_module,msgStream())){
172  ATH_MSG_ERROR("Could no retrieve a valid online channel for "<<m_idHelperSvc->toString(tube_id));
173  failure = true;
174  continue;
175  }
177  if (idHelper.elementID(test_id) != idHelper.elementID(readEle->identify()) && static_cast<const MdtCablingOnData&>(mrod_module)!=(cabling_data)) {
178  ATH_MSG_ERROR("Failed to decode module "<<m_idHelperSvc->toString(tube_id)<<" got "<<m_idHelperSvc->toString(test_id) );
179  failure = true;
180  } else ++n_success;
181  }
182  }
183  }
184  ATH_MSG_INFO( n_success<<" out of "<<n_elements<<" channels were successfully validated.");
185  return failure ? StatusCode::FAILURE: StatusCode::SUCCESS;
186 }
187 
MdtMezzanineCard.h
MdtReadoutElement.h
MuonGM::MdtReadoutElement::getNLayers
int getNLayers() const
Returns the number of tube layers inside the multilayer.
MdtCablingTestAlg::m_DetectorManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
Definition: MdtCablingTestAlg.h:34
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
MuonIdHelper::detectorElement_begin
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
Definition: MuonIdHelper.cxx:762
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
MdtMezzanineCard::checkConsistency
bool checkConsistency(MsgStream &msg) const
checks whether the tdc mapping is complete.
Definition: MdtMezzanineCard.cxx:52
MdtCablingOnData
Definition: MdtCablingData.h:50
MdtMezzanineCard::numTubesPerLayer
uint8_t numTubesPerLayer() const
returns the number of tubes per layer;
Definition: MdtMezzanineCard.h:68
MdtCablingTestAlg::MdtCablingTestAlg
MdtCablingTestAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MdtCablingTestAlg.cxx:11
MdtMezzanineCard::tdcChannel
uint8_t tdcChannel(uint8_t tubeLay, uint8_t tube, MsgStream &msg) const
returns the tdc channel number
Definition: MdtMezzanineCard.cxx:106
MdtMezzanineCard::Mapping
std::array< uint8_t, 24 > Mapping
Definition: MdtMezzanineCard.h:39
MdtMezzanineCard::offlineTube
OfflineCh offlineTube(uint8_t tdc, MsgStream &msg) const
Definition: MdtMezzanineCard.cxx:126
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
createCablingJSON.cabling_data
dictionary cabling_data
Definition: createCablingJSON.py:18
MdtCondDbData
Definition: MdtCondDbData.h:21
MuonIdHelper::detectorElement_end
const_id_iterator detectorElement_end() const
Definition: MuonIdHelper.cxx:764
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::empty
bool empty() const
Test if the key is blank.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:150
MdtCablingTestAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MdtCablingTestAlg.h:32
ReadCondHandle.h
MdtMezzanineCard
MdtMezzanineCard - Helper struct to represent the structure of a mezzanine card in a consistent way E...
Definition: MdtMezzanineCard.h:34
MdtCablingTestAlg::m_cablingKey
SG::ReadCondHandleKey< MuonMDT_CablingMap > m_cablingKey
Definition: MdtCablingTestAlg.h:37
calibdata.tube_id
tube_id
Definition: calibdata.py:30
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MdtCablingOffData
Split the offline part of the cabling apart to use it later for sorting.
Definition: MdtCablingData.h:16
MdtMezzanineCard::OfflineCh
Helper struct to pipe the result from the tdc -> offline channel translation.
Definition: MdtMezzanineCard.h:72
MuonGM::MdtReadoutElement
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MdtReadoutElement.h:50
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
MdtIdHelper
Definition: MdtIdHelper.h:61
ATH_MSG_ALWAYS
#define ATH_MSG_ALWAYS(x)
Definition: AthMsgStreamMacros.h:35
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MdtCablingData
Definition: MdtCablingData.h:82
MuonGM::MdtReadoutElement::getMultilayer
int getMultilayer() const
Returns the multilayer represented by the readout element.
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
AthAlgorithm
Definition: AthAlgorithm.h:47
MdtCablingTestAlg::initialize
virtual StatusCode initialize() override
Definition: MdtCablingTestAlg.cxx:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MdtIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
Definition: MdtIdHelper.cxx:659
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MdtIdHelper::elementID
Identifier elementID(int stationName, int stationEta, int stationPhi) const
Definition: MdtIdHelper.cxx:630
MdtCablingTestAlg::m_deadChanKey
SG::ReadCondHandleKey< MdtCondDbData > m_deadChanKey
Definition: MdtCablingTestAlg.h:39
MuonGM::MuonReadoutElement::identify
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonReadoutElement.h:184
MdtCablingTestAlg.h
MdtCablingTestAlg::execute
virtual StatusCode execute() override
Definition: MdtCablingTestAlg.cxx:23
MdtCablingTestAlg::m_dumpFile
Gaudi::Property< std::string > m_dumpFile
Definition: MdtCablingTestAlg.h:41
MuonGM::MdtReadoutElement::getNtubesperlayer
int getNtubesperlayer() const
Returns the number of tubes in each tube layer.
calibdata.tube
tube
Definition: calibdata.py:31