ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonConditions
MuonCondGeneral
MuonCondAlg
src
RpcDigitEffiCondAlg.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 "
RpcDigitEffiCondAlg.h
"
6
7
#include <
StoreGate/WriteCondHandle.h
>
8
#include <
AthenaKernel/IOVInfiniteRange.h
>
9
#include <
PathResolver/PathResolver.h
>
10
#include <fstream>
11
12
namespace
Muon
{
13
// Initialize
14
StatusCode
RpcDigitEffiCondAlg::initialize
() {
15
ATH_MSG_DEBUG
(
"initializing "
<< name());
16
ATH_CHECK
(
m_idHelperSvc
.retrieve());
17
ATH_CHECK
(
m_writeKey
.initialize());
18
if
(
m_readKeyDb
.empty() &&
m_readFromJSON
.value().empty()){
19
ATH_MSG_FATAL
(
"No data source is given to load efficiency maps from. Please provide either a COOL folder or a json file"
);
20
return
StatusCode::FAILURE;
21
}
else
if
(
m_readKeyDb
.empty()) {
22
ATH_MSG_INFO
(
"Load efficiency maps from a JSON file "
<<
m_readFromJSON
);
23
}
else
{
24
ATH_MSG_INFO
(
"Load efficiency maps list from COOL "
<<
m_readKeyDb
.fullKey());
25
}
26
return
StatusCode::SUCCESS;
27
}
28
29
// execute
30
StatusCode
RpcDigitEffiCondAlg::execute
(
const
EventContext& ctx)
const
{
31
ATH_MSG_DEBUG
(
"execute "
<< name());
32
// launching Write Cond Handle
33
SG::WriteCondHandle
writeHandle{
m_writeKey
, ctx};
34
if
(writeHandle.
isValid
()) {
35
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
36
<<
" In theory this should not be called, but may happen"
37
<<
" if multiple concurrent events are being processed out of order."
);
38
return
StatusCode::SUCCESS;
39
}
40
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteTime
()));
41
auto
writeCdo{std::make_unique<Muon::DigitEffiData>(
m_idHelperSvc
.get(),
m_defaultEffi
)};
42
if
(!
m_readKeyDb
.empty()) {
43
SG::ReadCondHandle
readHandle{
m_readKeyDb
, ctx};
44
if
(!readHandle.
isValid
()) {
45
ATH_MSG_FATAL
(
"Failed to initialize the COOL folder "
<<
m_readKeyDb
.fullKey());
46
return
StatusCode::FAILURE;
47
}
48
writeHandle.
addDependency
(readHandle);
49
for
(
CondAttrListCollection::const_iterator
itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
50
const
coral::AttributeList& atr = itr->second;
51
const
std::string data{*(
static_cast<
const
std::string*
>
((atr[
"data"
]).addressOfData()))};
52
nlohmann::json lines = nlohmann::json::parse(data);
53
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
54
}
55
}
else
{
56
std::ifstream inStream{
PathResolverFindCalibFile
(
m_readFromJSON
)};
57
if
(!inStream.good()) {
58
ATH_MSG_FATAL
(
"No such file or directory"
);
59
return
StatusCode::FAILURE;
60
}
61
nlohmann::json lines;
62
inStream >> lines;
63
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
64
}
65
ATH_CHECK
(writeHandle.
record
(std::move(writeCdo)));
66
ATH_MSG_DEBUG
(
"Recorded new "
<< writeHandle.
key
() <<
" with range "
<< writeHandle.
getRange
() <<
" into Conditions Store"
);
67
return
StatusCode::SUCCESS;
68
}
69
StatusCode
RpcDigitEffiCondAlg::parseDataFromJSON
(
const
nlohmann::json& lines,
70
Muon::DigitEffiData
& effiData)
const
{
71
for
(
auto
& corr : lines.items()) {
72
nlohmann::json line = corr.value();
74
const
std::string stationType = line[
"station"
];
75
const
int
stationPhi
= line[
"phi"
];
76
const
int
stationEta
= line[
"eta"
];
77
const
int
doubletR = line[
"doubletR"
];
78
const
int
doubletZ = line[
"doubletZ"
];
79
const
int
doubletPhi = line[
"doubletPhi"
];
80
const
int
gasGap = line[
"gasGap"
];
81
const
int
measuresPhi = line[
"measuresPhi"
];
82
const
double
efficiency
= line[
"efficiency"
];
83
bool
is_valid{
false
};
84
const
Identifier
id
=
m_idHelperSvc
->rpcIdHelper().channelID(stationType,
stationEta
,
stationPhi
, doubletR, doubletZ, doubletPhi, gasGap, measuresPhi, 1 ,is_valid);
85
if
(!is_valid) {
86
ATH_MSG_FATAL
(
"The Identifier identifier "
<<stationType<<
", "
<<
stationEta
<<
", "
<<
stationPhi
87
<<
", "
<<doubletR<<
", "
<<doubletZ<<
", "
<<doubletPhi<<
", "
<<gasGap<<
", "
<<measuresPhi<<
" is invalid"
);
88
return
StatusCode::FAILURE;
89
}
90
ATH_CHECK
(effiData.
setEfficiency
(
id
,
efficiency
));
91
}
92
return
StatusCode::SUCCESS;
93
}
94
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
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
IOVInfiniteRange.h
PathResolver.h
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition
PathResolver.cxx:325
RpcDigitEffiCondAlg.h
WriteCondHandle.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::DigitEffiData
Definition
DigitEffiData.h:23
Muon::DigitEffiData::setEfficiency
StatusCode setEfficiency(const Identifier §ionId, const double effi, bool isInnerQ1=false)
Sets the efficiency for a given minimal section of the dector.
Definition
DigitEffiData.cxx:48
Muon::RpcDigitEffiCondAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, Muon::DigitEffiData &effiData) const
Parse efficiency data from COOL.
Definition
RpcDigitEffiCondAlg.cxx:69
Muon::RpcDigitEffiCondAlg::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition
RpcDigitEffiCondAlg.h:40
Muon::RpcDigitEffiCondAlg::m_defaultEffi
Gaudi::Property< double > m_defaultEffi
Definition
RpcDigitEffiCondAlg.h:42
Muon::RpcDigitEffiCondAlg::m_writeKey
SG::WriteCondHandleKey< Muon::DigitEffiData > m_writeKey
Definition
RpcDigitEffiCondAlg.h:39
Muon::RpcDigitEffiCondAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Load the gasGap efficiencies from a JSON file.
Definition
RpcDigitEffiCondAlg.h:37
Muon::RpcDigitEffiCondAlg::initialize
virtual StatusCode initialize() override
Definition
RpcDigitEffiCondAlg.cxx:14
Muon::RpcDigitEffiCondAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
RpcDigitEffiCondAlg.h:34
Muon::RpcDigitEffiCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
RpcDigitEffiCondAlg.cxx:30
SG::ReadCondHandle
Definition
ReadCondHandle.h:40
SG::ReadCondHandle::isValid
bool isValid()
Definition
ReadCondHandle.h:205
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
efficiency
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
Definition
dependence.cxx:128
Identifier
Definition
IdentifierFieldParser.cxx:14
Muon::nsw::STGTPSegments::ModuleIDProperty::stationEta
@ stationEta
Definition
NSWSTGTPDecodeBitmaps.h:166
Muon::nsw::STGTPSegments::ModuleIDProperty::stationPhi
@ stationPhi
Definition
NSWSTGTPDecodeBitmaps.h:167
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