ATLAS Offline Software
Loading...
Searching...
No Matches
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
9namespace Muon {
11 ATH_CHECK(m_idHelperSvc.retrieve());
12 ATH_CHECK(m_DetectorManagerKey.initialize());
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
47 if (!detectorMgr.isValid()) {
48 ATH_MSG_FATAL("Failed to retrieve the Detector manager " << m_DetectorManagerKey.fullKey());
49 return StatusCode::FAILURE;
50 }
51
52 SG::ReadCondHandle cabling{m_cablingKey, ctx};
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}
#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_DEBUG(x)
Identifier identify() const override final
Returns the ATLAS Identifier of the MuonReadOutElement.
An RpcReadoutElement corresponds to a single RPC module; therefore typicaly a barrel muon station con...
int getDoubletPhi() const
return DoubletPhi value for the given readout element, be aware that one RE can contain two DoubletPh...
int getDoubletZ() const
return DoubletZ value for the given readout element
int Nstrips(bool measphi) const
returns the number of strips for the phi or eta plane
virtual int numberOfLayers(bool measphi=true) const override final
number of layers in phi/eta projection, same for eta/phi planes
const_id_iterator detectorElement_begin() const
Iterators over full set of ids.
const_id_iterator detectorElement_end() const
virtual StatusCode execute() override
virtual StatusCode initialize() override
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
Gaudi::Property< std::vector< std::string > > m_considStat
SG::ReadCondHandleKey< RpcCablingMap > m_cablingKey
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
bool mapChannels(uint8_t strip, uint8_t tdc, MsgStream &log)
Connect the strip with a tdc channel.
std::optional< uint8_t > tdcChannel(uint8_t strip, MsgStream &log) const
Returns the connected tdc channel connected to a strip.
static constexpr uint8_t readStrips
Number of channels covered by one chip.
std::optional< uint8_t > stripChannel(uint8_t tdcChannel, MsgStream &log) const
Returns the strip channel connected to a strip.
Identifier channelID(int stationName, int stationEta, int stationPhi, int doubletR, int doubletZ, int doubletPhi, int gasGap, int measuresPhi, int strip) const
Identifier elementID(int stationName, int stationEta, int stationPhi, int doubletR) const
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Helper struct that is parsed to the cabling map to translate between the offline & online Identifiers...
uint8_t channelId
Online board channel number.