ATLAS Offline Software
Loading...
Searching...
No Matches
NRpcCablingAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "NRpcCablingAlg.h"
6
7
8#include <fstream>
9#include <map>
10
14#include "CoralBase/Attribute.h"
15#include "CoralBase/AttributeListSpecification.h"
19
20namespace Muon{
22 ATH_MSG_DEBUG("initialize " << name());
23 ATH_CHECK(m_writeKey.initialize());
24 ATH_CHECK(m_idHelperSvc.retrieve());
25 const bool ext_json = !m_extJSONFile.value().empty();
27 ATH_CHECK(m_readKeyMap.initialize(!ext_json));
28 return StatusCode::SUCCESS;
29}
30
31StatusCode NRpcCablingAlg::execute(const EventContext& ctx) const {
32 ATH_MSG_VERBOSE("NRpcCablingAlg::execute()");
33
34 // Write Cond Handle
35 SG::WriteCondHandle writeCablingHandle{m_writeKey, ctx};
36
37 if (writeCablingHandle.isValid()) {
38 ATH_MSG_DEBUG("CondHandle "<< writeCablingHandle.fullKey() << " is already valid."
39 << ". In theory this should not be called, but may happen"
40 << " if multiple concurrent events are being processed out of order.");
41 return StatusCode::SUCCESS;
42 }
43 writeCablingHandle.addDependency(EventIDRange(IOVInfiniteRange::infiniteRunLB()));
44
45 ATH_MSG_INFO("Load the Nrpc cabling");
46 auto writeCdo{std::make_unique<RpcCablingMap>(m_idHelperSvc.get())};
47
49 if (!m_extJSONFile.value().empty()) {
50 std::ifstream in_json{m_extJSONFile};
51 if (!in_json.good()) {
52 ATH_MSG_FATAL("Failed to open external JSON file " << m_extJSONFile);
53 return StatusCode::FAILURE;
54 }
55 nlohmann::json payload;
56 in_json>>payload;
57 ATH_CHECK(parsePayload(*writeCdo, payload));
58 } else {
59 SG::ReadCondHandle coolHandle{m_readKeyMap, ctx};
60 if (!coolHandle.isValid()) {
61 ATH_MSG_FATAL("Failed to load cabling map from COOL "<< m_readKeyMap.fullKey());
62 return StatusCode::FAILURE;
63 }
64 writeCablingHandle.addDependency(coolHandle);
65 for (const auto& itr : **coolHandle) {
66 const coral::AttributeList& atr = itr.second;
67 nlohmann::json payload = nlohmann::json::parse(*(static_cast<const std::string*>((atr["data"]).addressOfData())));
68 ATH_CHECK(parsePayload(*writeCdo, payload));
69 }
70 }
71 if (!writeCdo->finalize(msgStream()))
72 return StatusCode::FAILURE;
73
74 ATH_CHECK(writeCablingHandle.record(std::move(writeCdo)));
75 return StatusCode::SUCCESS;
76}
78 const nlohmann::json& payload) const {
79
80
81 using CablingData = RpcCablingMap::CoolDBEntry;
82 using FlatCablePtr = RpcCablingMap::FlatCablePtr;
83
84 std::map<unsigned, FlatCablePtr> readoutCards{};
85 for (const auto& flatCable : payload["readoutCards"].items()) {
86 nlohmann::json cabl_payload = flatCable.value();
87 const unsigned id = cabl_payload["flatCableId"];
88 FlatCablePtr& newCard = readoutCards[id];
89 newCard = std::make_unique<RpcFlatCableTranslator>(id);
90 for (const auto& pinAssign : cabl_payload["pinAssignment"]) {
91 const std::array<unsigned, 2> pin = pinAssign;
92 if (!newCard->mapChannels(pin[0], pin[1], msgStream())){
93 return StatusCode::FAILURE;
94 }
95 }
96 ATH_MSG_DEBUG("Add new card "<<(*newCard));
97 }
98 constexpr int8_t phiBit = CablingData::measPhiBit;
99 constexpr int8_t sideBit = CablingData::stripSideBit;
100 for (const auto& cabl_chan : payload["chamberMap"].items()) {
101 nlohmann::json cabl_payload = cabl_chan.value();
102 CablingData cabl_data{};
103 const std::string stName{cabl_payload["station"]};
104 cabl_data.stationIndex = m_idHelperSvc->rpcIdHelper().stationNameIndex(stName);
105 cabl_data.eta = cabl_payload["eta"];
106 cabl_data.phi = cabl_payload["phi"];
107 cabl_data.doubletR = cabl_payload["doubletR"];
108 cabl_data.doubletPhi = cabl_payload["doubletPhi"];
109 cabl_data.doubletZ = cabl_payload["doubletZ"];
110 const int8_t phiAndStrip = cabl_payload["measPhi"];
111 cabl_data.setMeasPhiAndSide(phiAndStrip & phiBit, phiAndStrip & sideBit);
112 cabl_data.gasGap = cabl_payload["gasGap"];
114 cabl_data.subDetector = cabl_payload["subDetector"];
115 cabl_data.boardSector = cabl_payload["boardSector"];
116 cabl_data.board = cabl_payload["board"];
117 cabl_data.firstStrip = cabl_payload["firstStrip"];
118 unsigned int flatCable = cabl_payload["flatCableId"];
119 if (!readoutCards[flatCable]) {
120 ATH_MSG_FATAL("Failed to find a valid flat cable for "<<static_cast<const RpcCablingOfflineID&>(cabl_data)<<", flatCableId "<<flatCable);
121 return StatusCode::FAILURE;
122 }
123 cabl_data.flatCable = readoutCards[flatCable];
124 if (!cabling_map.insertChannels(std::move(cabl_data), msgStream())) {
125 return StatusCode::FAILURE;
126 }
127 }
128 return StatusCode::SUCCESS;
129}
130}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
Gaudi::Property< std::string > m_extJSONFile
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyMap
SG::WriteCondHandleKey< RpcCablingMap > m_writeKey
ServiceHandle< IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode initialize() override
StatusCode parsePayload(RpcCablingMap &cablingMap, const nlohmann::json &payload) const
Load the payload of the actual cabling map from offline <-> online.
virtual StatusCode execute(const EventContext &ctx) const override
GeoModel::TransientConstSharedPtr< Muon::RpcFlatCableTranslator > FlatCablePtr
bool insertChannels(CoolDBEntry &&dbEntry, MsgStream &log)
Inserts a new dbEntry into the map.
void addDependency(const EventIDRange &range)
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
const DataObjID & fullKey() const
const std::string & stName(StIndex index)
convert StIndex into a string
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Helper struct to ship all information from the Database.
Struct to represent the offline identifier of the Rpc measurement decomposed into the particular fiel...