ATLAS Offline Software
RpcCablingTestAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #include "RpcCablingTestAlg.h"
8 
9 namespace Muon {
11  ATH_CHECK(m_idHelperSvc.retrieve());
13  ATH_CHECK(m_cablingKey.initialize());
14  for (const std::string &statName : m_considStat)
15  {
16  m_cabStat.insert(m_idHelperSvc->rpcIdHelper().stationNameIndex(statName));
17  }
18  return StatusCode::SUCCESS;
19  }
20 
22  const EventContext &ctx = Gaudi::Hive::currentContext();
23  ATH_MSG_INFO("Start validation of the Rpc cabling");
24  {
25  RpcFlatCableTranslator flatCable{0};
26  constexpr unsigned halfCard = RpcFlatCableTranslator::readStrips / 2;
27  for (size_t n = 1; n <= RpcFlatCableTranslator::readStrips; ++n) {
28  if (n <= halfCard && !flatCable.mapChannels(n, RpcFlatCableTranslator::readStrips-n, msgStream())) {
29  return StatusCode::FAILURE;
30  } else if (n > halfCard && !flatCable.mapChannels(n, n - halfCard - 1, msgStream())) {
31  return StatusCode::FAILURE;
32  }
33  }
34  ATH_MSG_INFO("Test flat cable map " << flatCable);
35  for (size_t n = 1; n <= RpcFlatCableTranslator::readStrips; ++n) {
36  const unsigned forthCh = flatCable.tdcChannel(n, msgStream()).value_or(0);
37  if (const unsigned backCh = flatCable.stripChannel(forthCh, msgStream()).value_or(0);
38  backCh != n) {
39  ATH_MSG_FATAL("Forward backward conversion of channel " << n << " failed. Ended up with " << backCh);
40  return StatusCode::FAILURE;
41  }
42  }
43  ATH_MSG_INFO("Back <-> forth test is a great success");
44  }
45 
46  SG::ReadCondHandle detectorMgr{m_DetectorManagerKey, ctx};
47  if (!detectorMgr.isValid()) {
48  ATH_MSG_FATAL("Failed to retrieve the Detector manager " << m_DetectorManagerKey.fullKey());
49  return StatusCode::FAILURE;
50  }
51 
53  if (!cabling.isValid()) {
54  ATH_MSG_ERROR("Failed to retrieve the Rpc cabling " << m_cablingKey.fullKey());
55  return StatusCode::FAILURE;
56  }
57  const RpcIdHelper &idHelper{m_idHelperSvc->rpcIdHelper()};
58  unsigned int n_elements{0}, n_success{0};
59  for (auto det_itr = idHelper.detectorElement_begin(); det_itr != idHelper.detectorElement_end(); ++det_itr) {
60 
61  const MuonGM::RpcReadoutElement *readEle = detectorMgr->getRpcReadoutElement(*det_itr);
62  if (!readEle) {
63  ATH_MSG_VERBOSE("Detector element does not exist. ");
64  continue;
65  }
66  if (!m_cabStat.empty() && !m_cabStat.count(m_idHelperSvc->stationName(readEle->identify()))) {
67  ATH_MSG_VERBOSE("Do not test station " << m_idHelperSvc->toString(readEle->identify()));
68  continue;
69  }
70  const Identifier station_id = idHelper.elementID(readEle->identify());
71  ATH_MSG_DEBUG("Check station " << m_idHelperSvc->toString(station_id));
72 
73  for (bool measPhi : {true, false}) {
74  for (int gap = 1; gap <= readEle->numberOfLayers(measPhi); ++gap) {
75  for (int strip = 1; strip <= readEle->Nstrips(measPhi); ++strip) {
76  bool is_valid{false};
77  const Identifier chanId = idHelper.channelID(station_id,
78  readEle->getDoubletZ(),
79  readEle->getDoubletPhi(),
80  gap, measPhi, strip, is_valid);
81  if (!is_valid) {
82  ATH_MSG_VERBOSE("Invalid Identifier");
83  continue;
84  }
85  bool failure{false};
86 
87  ++n_elements;
88  RpcCablingData cabl_data{};
89  if (!cabling->convert(chanId, cabl_data, false)) {
90  ATH_MSG_ERROR("Invalid identifier " << m_idHelperSvc->toString(chanId));
91  return StatusCode::FAILURE;
92  }
94  if (!cabling->getOnlineId(cabl_data, msgStream())) {
95  return StatusCode::FAILURE;
96  }
97  ATH_MSG_DEBUG("Offline channel has an associated online channel " << cabl_data);
98  RpcCablingData onl_data{};
100  onl_data.RpcCablingOnlineID::operator=(cabl_data);
101  onl_data.channelId = cabl_data.channelId;
102  if (!cabling->getOfflineId(onl_data, msgStream())) {
103  return StatusCode::FAILURE;
104  }
105  if (onl_data != cabl_data) {
106  ATH_MSG_FATAL("Back translation of the cabling failed for hit " << m_idHelperSvc->toString(chanId) << std::endl
107  << " -- started with: " << cabl_data << std::endl
108  << " -- got back: " << onl_data);
109  failure = true;
110  }
111  Identifier backChanId{0};
112  if (!cabling->convert(onl_data, backChanId, true)) {
113  ATH_MSG_FATAL("Failed to translate back the cabling object" << onl_data << " to an Identifier");
114  return StatusCode::FAILURE;
115  }
116  if (backChanId != chanId) {
117  ATH_MSG_FATAL("Detected a silent messenger. Started with "
118  << m_idHelperSvc->toString(chanId) << " ended up with " << m_idHelperSvc->toString(backChanId));
119  failure = true;
120  }
121  n_success += (!failure);
122  if (failure)
123  return StatusCode::FAILURE;
124  }
125  }
126  }
127  }
128  ATH_MSG_INFO(n_success << " out of " << n_elements << " channels were successfully validated.");
129  return n_success == n_elements ? StatusCode::SUCCESS : StatusCode::FAILURE;
130  }
131 
132 }
Muon::RpcFlatCableTranslator::readStrips
static constexpr uint8_t readStrips
Number of channels covered by one chip.
Definition: RpcFlatCableTranslator.h:21
Muon::RpcCablingTestAlg::m_cablingKey
SG::ReadCondHandleKey< RpcCablingMap > m_cablingKey
Definition: RpcCablingTestAlg.h:29
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Muon::RpcCablingTestAlg::initialize
virtual StatusCode initialize() override
Definition: RpcCablingTestAlg.cxx:10
Muon::RpcCablingTestAlg::execute
virtual StatusCode execute() override
Definition: RpcCablingTestAlg.cxx:21
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Muon::RpcCablingTestAlg::m_cabStat
std::set< int > m_cabStat
Definition: RpcCablingTestAlg.h:33
Muon::RpcCablingData::channelId
uint8_t channelId
Online tdc channel number.
Definition: RpcCablingData.h:100
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
MuonGM::RpcReadoutElement
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/RpcReadoutElement.h:55
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
CaloSwCorrections.gap
def gap(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:212
RpcIdHelper
Definition: RpcIdHelper.h:51
ReadCondHandle.h
Muon::RpcCablingTestAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: RpcCablingTestAlg.h:24
RpcCablingTestAlg.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MuonGM::RpcReadoutElement::getDoubletPhi
int getDoubletPhi() const
return DoubletPhi value for the given readout element, be aware that one RE can contain two DoubletPh...
Muon::RpcCablingData
Helper struct that is parsed to the cabling map to translate between the offline & online Identifiers...
Definition: RpcCablingData.h:94
Muon::RpcCablingTestAlg::m_DetectorManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
Definition: RpcCablingTestAlg.h:26
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
MuonGM::RpcReadoutElement::numberOfLayers
virtual int numberOfLayers(bool measphi=true) const override final
number of layers in phi/eta projection, same for eta/phi planes
Muon::RpcCablingTestAlg::m_considStat
Gaudi::Property< std::vector< std::string > > m_considStat
Definition: RpcCablingTestAlg.h:31
RpcFlatCableTranslator.h
MuonGM::MuonReadoutElement::identify
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonReadoutElement.h:184
MuonGM::RpcReadoutElement::Nstrips
int Nstrips(bool measphi) const
returns the number of strips for the phi or eta plane
MuonGM::RpcReadoutElement::getDoubletZ
int getDoubletZ() const
return DoubletZ value for the given readout element
Muon::RpcFlatCableTranslator
Definition: RpcFlatCableTranslator.h:18
RpcReadoutElement.h
Identifier
Definition: IdentifierFieldParser.cxx:14