ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonCablings
MuonNSW_Cabling
src
MuonNSW_CablingAlg.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 "
MuonNSW_CablingAlg.h
"
6
7
#include <stdlib.h>
8
9
#include <fstream>
10
#include <map>
11
#include <string>
12
13
#include "
AthenaPoolUtilities/AthenaAttributeList.h
"
14
#include "
AthenaPoolUtilities/CondAttrListCollection.h
"
15
#include "CoralBase/Attribute.h"
16
#include "CoralBase/AttributeListSpecification.h"
17
#include "
MuonIdHelpers/MdtIdHelper.h
"
18
#include "
PathResolver/PathResolver.h
"
19
#include "
SGTools/TransientAddress.h
"
20
#include "nlohmann/json.hpp"
21
#include "
AthenaKernel/IOVInfiniteRange.h
"
22
23
MuonNSW_CablingAlg::MuonNSW_CablingAlg
(
const
std::string& name,
24
ISvcLocator* pSvcLocator)
25
:
AthCondAlgorithm
(name, pSvcLocator) {}
26
27
StatusCode
MuonNSW_CablingAlg::initialize
() {
28
ATH_MSG_DEBUG
(
"initialize "
<< name());
29
ATH_CHECK
(
m_readCablingKeys
.initialize(
m_JSONFile
.value().empty()));
30
ATH_CHECK
(
m_writeKey
.initialize());
31
ATH_CHECK
(
m_idHelperSvc
.retrieve());
32
return
StatusCode::SUCCESS;
33
}
34
35
StatusCode
MuonNSW_CablingAlg::execute
(
const
EventContext& ctx)
const
{
36
ATH_MSG_DEBUG
(
"Load the Micro mega cabling map"
);
37
// Write Cond Handle
38
SG::WriteCondHandle<Nsw_CablingMap>
writeHandle{
m_writeKey
, ctx};
39
if
(writeHandle.
isValid
()) {
40
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
41
<<
". In theory this should not be called, but may happen"
42
<<
" if multiple concurrent events are being processed out of order."
);
43
return
StatusCode::SUCCESS;
44
}
45
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteRunLB
()));
46
47
std::unique_ptr<Nsw_CablingMap> writeCdo{std::make_unique<Nsw_CablingMap>(
m_idHelperSvc
.get())};
48
50
if
(!
m_JSONFile
.value().empty()) {
51
std::ifstream
inf
{
m_JSONFile
};
52
if
(!
inf
.good()) {
53
ATH_MSG_FATAL
(
"Cannot locate external JSON file "
<<
m_JSONFile
);
54
return
StatusCode::FAILURE;
55
}
56
std::string payload{};
57
while
(std::getline(
inf
, payload)) {
58
ATH_CHECK
(
loadCablingSchema
(payload, *writeCdo));
59
}
60
}
61
63
else
if
(!
m_readCablingKeys
.empty()) {
64
for
(
const
SG::ReadCondHandleKey<CondAttrListCollection>
& key :
m_readCablingKeys
){
65
SG::ReadCondHandle<CondAttrListCollection>
readHandle{key, ctx};
66
if
(!readHandle.
isValid
()) {
67
ATH_MSG_FATAL
(
"Failed to retrieve the cabling data from the database "
68
<< key.fullKey());
69
return
StatusCode::FAILURE;
70
}
71
72
writeHandle.
addDependency
(readHandle);
73
ATH_MSG_DEBUG
(
"Size of CondAttrListCollection "
<< readHandle.
fullKey
()
74
<<
" readCdo->size()= "
<< readHandle->size());
75
ATH_MSG_DEBUG
(
"Range of input is "
<< readHandle.
getRange
()
76
<<
", range of output is "
<< writeHandle.
getRange
());
77
78
// iterate through data
79
CondAttrListCollection::const_iterator
itr;
80
for
(itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
81
const
coral::AttributeList& atr = itr->second;
82
std::string payload = *(
static_cast<
const
std::string *
>
((atr[
"data"
]).addressOfData()));
83
ATH_CHECK
(
loadCablingSchema
(payload, *writeCdo));
84
}
85
}
86
}
87
88
ATH_CHECK
(writeHandle.
record
(std::move(writeCdo)));
89
ATH_MSG_INFO
(
"recorded new "
<< writeHandle.
key
() <<
" with range "
90
<< writeHandle.
getRange
()
91
<<
" into Conditions Store"
);
92
return
StatusCode::SUCCESS;
93
}
94
95
StatusCode
MuonNSW_CablingAlg::loadCablingSchema
(
const
std::string& theJSON,
96
Nsw_CablingMap
& cabling_map)
const
{
97
98
if
(theJSON.empty())
99
return
StatusCode::SUCCESS;
100
nlohmann::json payload = nlohmann::json::parse(theJSON);
101
const
MmIdHelper
& mm_helper{
m_idHelperSvc
->mmIdHelper()};
102
const
sTgcIdHelper
& sTgc_helper{
m_idHelperSvc
->stgcIdHelper()};
103
for
(
const
auto
& db_channel : payload.items()) {
104
nlohmann::json cabling_payload = db_channel.value();
105
106
std::string stName = cabling_payload[
"station"
];
107
const
int
eta
= cabling_payload[
"eta"
];
108
const
int
phi
= cabling_payload[
"phi"
];
109
const
int
multilayer = cabling_payload[
"multilayer"
];
110
const
int
gap = cabling_payload[
"gasgap"
];
111
bool
isValid
{
false
};
112
Identifier
gap_id{};
113
if
(stName[0] ==
'M'
) {
114
gap_id = mm_helper.
channelID
(stName,
eta
,
phi
, multilayer, gap, 1,
isValid
);
115
}
else
{
116
const
int
chType
{cabling_payload[
"channeltype"
]};
117
gap_id = sTgc_helper.
channelID
(stName,
eta
,
phi
, multilayer,gap,
chType
, 1,
isValid
);
118
}
119
if
(!
isValid
) {
120
ATH_MSG_FATAL
(
"Failed to deduce a valid identifier from st:"
121
<< stName <<
" eta: "
<<
eta
<<
" phi: "
<<
phi
122
<<
" multilayer: "
<< multilayer
123
<<
" gasgap: "
<< gap);
124
return
StatusCode::FAILURE;
125
}
126
127
NswZebraData
zebra_connector{};
128
zebra_connector.
firstChannel
= cabling_payload[
"FirstZebra"
];
129
zebra_connector.
lastChannel
= cabling_payload[
"LastZebra"
];
130
zebra_connector.
shiftChannel
= cabling_payload[
"ZebraShift"
];
131
if
(!cabling_map.
addConnector
(gap_id, zebra_connector, msgStream()))
132
return
StatusCode::FAILURE;
133
}
134
return
StatusCode::SUCCESS;
135
}
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_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
AthenaAttributeList.h
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
IOVInfiniteRange.h
MdtIdHelper.h
MuonNSW_CablingAlg.h
chType
sTgcIdHelper::sTgcChannelTypes chType
Definition
MuonPhaseII/MuonDetDescr/MuonGeoModelTestR4/src/NSWGeoPlottingAlg.cxx:21
PathResolver.h
TransientAddress.h
AthCondAlgorithm
Base class for conditions algorithms.
Definition
AthCondAlgorithm.h:22
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition
CondAttrListCollection.h:62
IOVInfiniteRange::infiniteRunLB
static EventIDRange infiniteRunLB()
Produces an EventIDRange that is infinite in RunLumi and invalid in Time.
Definition
IOVInfiniteRange.h:39
MmIdHelper
Definition
MmIdHelper.h:54
MmIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channel) const
Definition
MmIdHelper.cxx:768
MuonNSW_CablingAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
MuonNSW_CablingAlg.h:31
MuonNSW_CablingAlg::m_JSONFile
Gaudi::Property< std::string > m_JSONFile
Definition
MuonNSW_CablingAlg.h:36
MuonNSW_CablingAlg::loadCablingSchema
StatusCode loadCablingSchema(const std::string &payload, Nsw_CablingMap &cabling_map) const
Definition
MuonNSW_CablingAlg.cxx:95
MuonNSW_CablingAlg::MuonNSW_CablingAlg
MuonNSW_CablingAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
MuonNSW_CablingAlg.cxx:23
MuonNSW_CablingAlg::m_readCablingKeys
SG::ReadCondHandleKeyArray< CondAttrListCollection > m_readCablingKeys
Definition
MuonNSW_CablingAlg.h:32
MuonNSW_CablingAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
MuonNSW_CablingAlg.cxx:35
MuonNSW_CablingAlg::m_writeKey
SG::WriteCondHandleKey< Nsw_CablingMap > m_writeKey
Definition
MuonNSW_CablingAlg.h:34
MuonNSW_CablingAlg::initialize
virtual StatusCode initialize() override
Definition
MuonNSW_CablingAlg.cxx:27
Nsw_CablingMap
Definition
Nsw_CablingMap.h:18
Nsw_CablingMap::addConnector
bool addConnector(const Identifier &gapID, const NswZebraData &connector, MsgStream &msg)
Definition
Nsw_CablingMap.cxx:76
SG::ReadCondHandleKey
Definition
ReadCondHandleKey.h:21
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::isValid
bool isValid()
Definition
ReadCondHandle.h:205
SG::ReadCondHandle::fullKey
const DataObjID & fullKey() const
Definition
ReadCondHandle.h:60
SG::ReadCondHandle::getRange
const EventIDRange & getRange()
Definition
ReadCondHandle.h:241
SG::WriteCondHandle
Definition
WriteCondHandle.h:26
SG::WriteCondHandle::key
const std::string & key() const
Definition
WriteCondHandle.h:44
SG::WriteCondHandle::addDependency
void addDependency(const EventIDRange &range)
Definition
WriteCondHandle.h:279
SG::WriteCondHandle::getRange
const EventIDRange & getRange() const
Definition
WriteCondHandle.h:93
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
sTgcIdHelper
Definition
sTgcIdHelper.h:55
sTgcIdHelper::channelID
Identifier channelID(int stationName, int stationEta, int stationPhi, int multilayer, int gasGap, int channelType, int channel) const
Definition
sTgcIdHelper.cxx:894
inf
TStreamerInfo * inf
Definition
liststreamerinfos.cxx:12
Identifier
Definition
IdentifierFieldParser.cxx:14
NswZebraData
Definition
NswZebraData.h:18
NswZebraData::lastChannel
int16_t lastChannel
Definition
NswZebraData.h:21
NswZebraData::firstChannel
int16_t firstChannel
Definition
NswZebraData.h:20
NswZebraData::shiftChannel
int16_t shiftChannel
Definition
NswZebraData.h:22
Generated on
for ATLAS Offline Software by
1.17.0