ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonConditions
MuonCondGeneral
MuonCondAlg
src
NswPassivationDbAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
NswPassivationDbAlg.h
"
6
7
#include "CoralBase/Blob.h"
8
#include "
CoralUtilities/blobaccess.h
"
9
#include "
AthenaKernel/IOVInfiniteRange.h
"
10
#include "
PathResolver/PathResolver.h
"
11
12
#include <fstream>
13
14
namespace
Muon
{
15
StatusCode
NswPassivationDbAlg::initialize
() {
16
ATH_MSG_DEBUG
(
"initializing "
<< name() );
17
ATH_CHECK
(
m_idHelperSvc
.retrieve());
18
ATH_CHECK
(
m_readKey_data_mm
.initialize(
m_readFromJSON
.value().empty()));
19
ATH_CHECK
(
m_writeKey
.initialize());
20
return
StatusCode::SUCCESS;
21
}
22
23
StatusCode
NswPassivationDbAlg::execute
(
const
EventContext& ctx)
const
{
24
25
// set up write handle
26
SG::WriteCondHandle
writeHandle{
m_writeKey
, ctx};
27
if
(writeHandle.
isValid
()) {
28
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
29
<<
" In theory this should not be called, but may happen"
30
<<
" if multiple concurrent events are being processed out of order."
);
31
return
StatusCode::SUCCESS;
32
}
33
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteTime
()));
34
auto
writeCdo{std::make_unique<NswPassivationDbData>(
m_idHelperSvc
->mmIdHelper())};
35
if
(!
m_readFromJSON
.empty()) {
36
std::ifstream inStream{
PathResolverFindCalibFile
(
m_readFromJSON
)};
37
if
(!inStream.good()) {
38
ATH_MSG_FATAL
(
"No such file or directory"
);
39
return
StatusCode::FAILURE;
40
}
41
nlohmann::json lines;
42
inStream >> lines;
43
ATH_CHECK
(
parseData
(lines, *writeCdo));
44
}
else
{
45
// set up read handle
46
SG::ReadCondHandle
readHandle{
m_readKey_data_mm
, ctx};
47
if
(!readHandle.
isValid
()){
48
ATH_MSG_ERROR
(
"Null pointer to the read conditions object"
);
49
return
StatusCode::FAILURE;
50
}
51
writeHandle.
addDependency
(readHandle);
52
ATH_MSG_DEBUG
(
"Size of CondAttrListCollection "
<< readHandle.
fullKey
() <<
" readCdo->size()= "
<< readHandle->size());
53
ATH_MSG_DEBUG
(
"Range of input is "
<< readHandle.
getRange
() <<
", range of output is "
<< writeHandle.
getRange
());
54
55
// iterate through data
56
unsigned
int
nObjs = 0;
57
for
(
CondAttrListCollection::const_iterator
itr = readHandle->begin();
58
itr != readHandle->end(); ++itr) {
59
// retrieve data
60
const
coral::AttributeList& atr = itr->second;
61
const
std::string& data{*(
static_cast<
const
std::string *
>
((atr[
"data"
]).addressOfData()))};
62
63
// unwrap the json and process the data
64
ATH_CHECK
(
parseData
(nlohmann::json::parse(data), *writeCdo));
65
++nObjs;
66
}
67
ATH_MSG_VERBOSE
(
"Retrieved data for "
<<nObjs<<
" objects."
);
68
}
69
// insert/write data
70
if
(writeHandle.
record
(std::move(writeCdo)).isFailure()) {
71
ATH_MSG_FATAL
(
"Could not record NswPassivationDbData "
<< writeHandle.
key
()
72
<<
" with EventRange "
<< writeHandle.
getRange
()
73
<<
" into Conditions Store"
);
74
return
StatusCode::FAILURE;
75
}
76
ATH_MSG_DEBUG
(
"Recorded new "
<< writeHandle.
key
() <<
" with range "
<< writeHandle.
getRange
() <<
" into Conditions Store"
);
77
78
return
StatusCode::SUCCESS;
79
}
80
StatusCode
NswPassivationDbAlg::parseData
(
const
nlohmann::json &
json
,
81
NswPassivationDbData
& writeCdo)
const
{
82
unsigned
int
nChns = 0;
83
for
(
const
auto
&kt :
json
.items()) {
84
nlohmann::json jt = kt.value();
85
bool
isValid
=
false
;
86
Identifier
channelId =
m_idHelperSvc
->mmIdHelper().pcbID(
int
(jt[
"stationName"
]), jt[
"stationEta"
], jt[
"stationPhi"
], jt[
"multiLayer"
], jt[
"gasGap"
], jt[
"pcbPos"
],
isValid
);
87
if
(!
isValid
){
88
ATH_MSG_FATAL
(
"Cannot find PCB Id!"
);
89
return
StatusCode::FAILURE;
90
}
91
writeCdo.
setData
(channelId, jt[
"pcbPos"
], jt[
"indiv"
], jt[
"extra"
], jt[
"position"
]);
92
++nChns;
93
}
94
ATH_MSG_VERBOSE
(
"Retrieved data for "
<<nChns<<
" channels."
);
95
return
StatusCode::SUCCESS;
96
}
97
}
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_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
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
json
nlohmann::json json
Definition
HistogramDef.cxx:9
IOVInfiniteRange.h
NswPassivationDbAlg.h
PathResolver.h
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition
PathResolver.cxx:325
blobaccess.h
CondAttrListCollection::const_iterator
ChanAttrListMap::const_iterator const_iterator
Definition
CondAttrListCollection.h:62
IOVInfiniteRange::infiniteTime
static EventIDRange infiniteTime()
Produces an EventIDRange that is inifinite in Time and invalid in RunLumi.
Definition
IOVInfiniteRange.h:47
Muon::NswPassivationDbAlg::initialize
virtual StatusCode initialize() override
Definition
NswPassivationDbAlg.cxx:15
Muon::NswPassivationDbAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
NswPassivationDbAlg.h:41
Muon::NswPassivationDbAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition
NswPassivationDbAlg.cxx:23
Muon::NswPassivationDbAlg::m_readKey_data_mm
readKey_t m_readKey_data_mm
Definition
NswPassivationDbAlg.h:45
Muon::NswPassivationDbAlg::m_writeKey
writeKey_t m_writeKey
Definition
NswPassivationDbAlg.h:43
Muon::NswPassivationDbAlg::parseData
StatusCode parseData(const nlohmann::json &json, NswPassivationDbData &writeCdo) const
Definition
NswPassivationDbAlg.cxx:80
Muon::NswPassivationDbAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Definition
NswPassivationDbAlg.h:47
NswPassivationDbData
Definition
NswPassivationDbData.h:20
NswPassivationDbData::setData
void setData(const Identifier &chnlId, const int pcb, const float indiv, const float extra, const std::string &position)
Definition
NswPassivationDbData.cxx:11
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
Identifier
Definition
IdentifierFieldParser.cxx:14
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition
TrackSystemController.h:46
Generated on
for ATLAS Offline Software by
1.17.0