ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonCablings
MuonMDT_Cabling
src
TwinTubeMappingCondAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
TwinTubeMappingCondAlg.h
"
5
6
#include <fstream>
7
8
#include "
StoreGate/ReadCondHandle.h
"
9
#include "
StoreGate/WriteCondHandle.h
"
10
#include "
AthenaKernel/IOVInfiniteRange.h
"
11
#include "nlohmann/json.hpp"
12
namespace
Muon
{
13
using
HedgehogBoardPtr
=
HedgehogBoard::HedgehogBoardPtr
;
14
StatusCode
TwinTubeMappingCondAlg::initialize
() {
15
ATH_CHECK
(
m_idHelperSvc
.retrieve());
16
ATH_CHECK
(
m_readKey
.initialize(
m_extJSONFile
.value().empty()));
17
ATH_CHECK
(
m_writeKey
.initialize());
18
19
return
StatusCode::SUCCESS;
20
}
21
StatusCode
TwinTubeMappingCondAlg::execute
(
const
EventContext& ctx)
const
{
22
ATH_MSG_VERBOSE
(
"execute()"
);
23
// Write Cond Handle
24
SG::WriteCondHandle
writeHandle{
m_writeKey
, ctx};
25
if
(writeHandle.
isValid
()) {
26
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
27
<<
". In theory this should not be called, but may happen"
28
<<
" if multiple concurrent events are being processed out of order."
);
29
return
StatusCode::SUCCESS;
30
}
31
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteRunLB
()));
32
33
nlohmann::json blob{};
34
if
(
m_extJSONFile
.value().size()){
35
std::ifstream in_json{
m_extJSONFile
};
36
if
(!in_json.good()) {
37
ATH_MSG_FATAL
(
"Failed to open external JSON file "
<<
m_extJSONFile
);
38
return
StatusCode::FAILURE;
39
}
40
in_json >> blob;
41
}
else
{
42
SG::ReadCondHandle
readHandle{
m_readKey
, ctx};
43
44
if
(!readHandle.
isValid
()) {
45
ATH_MSG_FATAL
(
"Failed to load cabling map from COOL "
<<
m_readKey
.fullKey());
46
return
StatusCode::FAILURE;
47
}
48
writeHandle.
addDependency
(readHandle);
49
//coverity[UNREACHABLE]
50
for
(
const
auto
& itr : **readHandle) {
51
const
coral::AttributeList& atr = itr.second;
52
blob = nlohmann::json::parse(*(
static_cast<
const
std::string*
>
((atr[
"data"
]).addressOfData())));
54
break
;
55
}
56
}
57
auto
condObj = std::make_unique<TwinTubeMap>(
m_idHelperSvc
.get());
58
condObj->setDefaultHVDelay(
m_hvDelay
);
59
const
MdtIdHelper
& idHelper{
m_idHelperSvc
->mdtIdHelper()};
60
61
std::unordered_map<unsigned int, HedgehogBoardPtr> hedgeHogBoards{};
62
using
Mapping =
HedgehogBoard::Mapping
;
63
for
(
const
auto
& boardMapping : blob[
"HedgehogBoards"
].items()) {
64
nlohmann::json payLoad = boardMapping.value();
65
ATH_MSG_VERBOSE
(
"Parse payload "
<<payLoad);
66
const
unsigned
boardId = payLoad[
"boardId"
];
67
const
Mapping mapping = payLoad[
"hedgeHogPins"
];
68
const
unsigned
tubeLayers = payLoad[
"nTubeLayers"
];
69
auto
newBoard = std::make_unique<HedgehogBoard>(mapping, tubeLayers, boardId);
70
if
(payLoad.find(
"hvDelayTime"
) != payLoad.end()) {
71
newBoard->setHVDelayTime(payLoad[
"hvDelayTime"
]);
72
}
73
HedgehogBoardPtr
& storeMe = hedgeHogBoards[newBoard->boardId()];
74
if
(storeMe) {
75
ATH_MSG_FATAL
(
"There's already a board registered under "
<<storeMe->boardId()<<
"."
);
76
return
StatusCode::FAILURE;
77
}
78
storeMe = std::move(newBoard);
79
}
80
for
(
const
auto
& twinMapping : blob[
"TwinTubeMapping"
].items()) {
81
nlohmann::json payLoad = twinMapping.value();
82
ATH_MSG_VERBOSE
(
"Parse "
<<payLoad);
83
const
int
stIndex = idHelper.
stationNameIndex
(payLoad[
"station"
]);
84
const
int
eta
= payLoad[
"eta"
];
85
const
int
phi
= payLoad[
"phi"
];
86
const
int
ml = payLoad[
"ml"
];
87
bool
isValid
{
false
};
88
const
Identifier
detElId{idHelper.
channelID
(stIndex,
eta
,
phi
, ml, 1, 1,
isValid
)};
89
if
(!
isValid
) {
90
ATH_MSG_FATAL
(
"Failed to build valid identifier from "
<<payLoad);
91
return
StatusCode::FAILURE;
92
};
93
const
std::vector<unsigned int> boardMounting = payLoad[
"mountedBoards"
];
94
for
(
unsigned
int
place = 0; place < boardMounting.size(); ++place) {
95
ATH_CHECK
(condObj->addHedgeHogBoard(detElId, hedgeHogBoards[boardMounting[place]], place));
96
}
97
}
98
ATH_CHECK
(writeHandle.
record
(std::move(condObj)));
99
return
StatusCode::SUCCESS;
100
}
101
}
eta
Scalar eta() const
pseudorapidity method
Definition
AmgMatrixBasePlugin.h:83
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
isValid
bool isValid() const
Test to see if the link can be dereferenced.
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
IOVInfiniteRange.h
ReadCondHandle.h
TwinTubeMappingCondAlg.h
WriteCondHandle.h
IOVInfiniteRange::infiniteRunLB
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
Definition
IOVInfiniteRange.h:39
MdtIdHelper
Definition
MdtIdHelper.h:61
MdtIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int tubeLayer, int tube) const
Definition
MdtIdHelper.cxx:663
MuonIdHelper::stationNameIndex
int stationNameIndex(const std::string &name) const
Definition
MuonIdHelper.cxx:827
Muon::HedgehogBoard::HedgehogBoardPtr
std::shared_ptr< const HedgehogBoard > HedgehogBoardPtr
Definition
HedgehogBoard.h:34
Muon::HedgehogBoard::Mapping
std::array< uint8_t, nChPerBoard > Mapping
Definition
HedgehogBoard.h:37
Muon::TwinTubeMappingCondAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
TwinTubeMappingCondAlg.h:28
Muon::TwinTubeMappingCondAlg::execute
StatusCode execute(const EventContext &ctx) const override final
Definition
TwinTubeMappingCondAlg.cxx:21
Muon::TwinTubeMappingCondAlg::m_readKey
SG::ReadCondHandleKey< CondAttrListCollection > m_readKey
Definition
TwinTubeMappingCondAlg.h:29
Muon::TwinTubeMappingCondAlg::m_writeKey
SG::WriteCondHandleKey< TwinTubeMap > m_writeKey
Definition
TwinTubeMappingCondAlg.h:30
Muon::TwinTubeMappingCondAlg::initialize
StatusCode initialize() override final
Definition
TwinTubeMappingCondAlg.cxx:14
Muon::TwinTubeMappingCondAlg::m_extJSONFile
Gaudi::Property< std::string > m_extJSONFile
Definition
TwinTubeMappingCondAlg.h:32
Muon::TwinTubeMappingCondAlg::m_hvDelay
Gaudi::Property< double > m_hvDelay
Definition
TwinTubeMappingCondAlg.h:35
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::isValid
bool isValid()
Definition
ReadCondHandle.h:205
SG::WriteCondHandle
Definition
WriteCondHandle.h:26
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition
WriteCondHandle.h:279
SG::WriteCondHandle::record
StatusCode record(const EventIDRange &range, T *t)
record handle, with explicit range DEPRECATED
Definition
WriteCondHandle.h:161
SG::WriteCondHandle::isValid
bool isValid() const
Definition
WriteCondHandle.h:252
SG::WriteCondHandle::fullKey
const DataObjID & fullKey() const
Definition
WriteCondHandle.h:45
Identifier
Definition
IdentifierFieldParser.cxx:14
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition
TrackSystemController.h:46
Muon::HedgehogBoardPtr
HedgehogBoard::HedgehogBoardPtr HedgehogBoardPtr
Definition
TwinTubeMappingCondAlg.cxx:13
Generated on
for ATLAS Offline Software by
1.17.0