ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonConditions
MuonCondGeneral
MuonCondAlg
src
sTGCAsBuiltCondAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
sTGCAsBuiltCondAlg.h
"
6
7
#include <
StoreGate/WriteCondHandle.h
>
8
#include <
AthenaKernel/IOVInfiniteRange.h
>
9
#include <
PathResolver/PathResolver.h
>
10
#include <fstream>
11
12
13
namespace
Muon
{
14
// Initialize
15
StatusCode
sTGCAsBuiltCondAlg::initialize
() {
16
ATH_MSG_DEBUG
(
"initializing "
<< name());
17
ATH_CHECK
(
m_idHelperSvc
.retrieve());
18
ATH_CHECK
(
m_writeKey
.initialize());
19
if
(
m_readKeyDb
.empty() &&
m_readFromJSON
.value().empty()){
20
ATH_MSG_FATAL
(
"No data source is given to load the as build parameters. Please provide either a COOL folder or a json file"
);
21
return
StatusCode::FAILURE;
22
}
else
if
(
m_readKeyDb
.empty()) {
23
ATH_MSG_INFO
(
"Load the as built parameters from a JSON file "
<<
m_readFromJSON
);
24
}
else
{
25
ATH_MSG_INFO
(
"Load the as built parameters from COOL "
<<
m_readKeyDb
.fullKey());
26
}
27
ATH_CHECK
(
m_readKeyDb
.initialize(!
m_readKeyDb
.empty() &&
m_readFromJSON
.value().empty()));
28
return
StatusCode::SUCCESS;
29
}
30
31
// execute
32
StatusCode
sTGCAsBuiltCondAlg::execute
(
const
EventContext& ctx)
const
{
33
ATH_MSG_DEBUG
(
"execute "
<< name());
34
// launching Write Cond Handle
35
SG::WriteCondHandle
writeHandle{
m_writeKey
, ctx};
36
if
(writeHandle.
isValid
()) {
37
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
38
<<
" In theory this should not be called, but may happen"
39
<<
" if multiple concurrent events are being processed out of order."
);
40
return
StatusCode::SUCCESS;
41
}
42
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteTime
()));
43
auto
writeCdo{std::make_unique<sTGCAsBuiltData>(
m_idHelperSvc
.get())};
44
if
(!
m_readKeyDb
.empty()) {
45
SG::ReadCondHandle
readHandle{
m_readKeyDb
, ctx};
46
if
(!readHandle.
isValid
()) {
47
ATH_MSG_FATAL
(
"Failed to initialize the COOL folder "
<<
m_readKeyDb
.fullKey());
48
return
StatusCode::FAILURE;
49
}
50
writeHandle.
addDependency
(readHandle);
51
for
(
CondAttrListCollection::const_iterator
itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
52
const
coral::AttributeList& atr = itr->second;
53
const
std::string data{*(
static_cast<
const
std::string*
>
((atr[
"data"
]).addressOfData()))};
54
nlohmann::json lines = nlohmann::json::parse(data);
55
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
56
}
57
}
else
{
58
std::ifstream inStream{
PathResolverFindCalibFile
(
m_readFromJSON
)};
59
if
(!inStream.good()) {
60
ATH_MSG_FATAL
(
"No such file or directory"
);
61
return
StatusCode::FAILURE;
62
}
63
nlohmann::json lines;
64
inStream >> lines;
65
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
66
}
67
ATH_CHECK
(writeHandle.
record
(std::move(writeCdo)));
68
ATH_MSG_DEBUG
(
"Recorded new "
<< writeHandle.
key
() <<
" with range "
<< writeHandle.
getRange
() <<
" into Conditions Store"
);
69
return
StatusCode::SUCCESS;
70
}
71
StatusCode
sTGCAsBuiltCondAlg::parseDataFromJSON
(
const
nlohmann::json& lines,
72
sTGCAsBuiltData
& asBuiltData)
const
{
73
for
(
auto
& corr : lines.items()) {
74
nlohmann::json line = corr.value();
76
const
std::string stationType = line[
"station"
];
77
const
int
stationPhi
= line[
"phi"
];
78
const
int
stationEta
= line[
"eta"
];
79
const
int
multiLayer = line[
"multilayer"
];
80
const
int
gasGap = line[
"gasGap"
];
81
bool
is_valid{
false
};
82
Identifier
id;
83
if
(stationType.substr(0,2)==
"ST"
){
84
id
=
m_idHelperSvc
->stgcIdHelper().channelID(stationType,
stationEta
,
stationPhi
,
85
multiLayer, gasGap,
sTgcIdHelper::Strip
, 1, is_valid);
86
}
else
if
(stationType.substr(0,2)==
"MM"
){
87
const
int
pcb = line[
"pcb"
];
88
id
=
m_idHelperSvc
->mmIdHelper().pcbID(stationType,
stationEta
,
stationPhi
,
89
multiLayer, gasGap, pcb, is_valid);
90
}
else
{
91
ATH_MSG_FATAL
(
"Unknown station type "
<<stationType);
92
return
StatusCode::FAILURE;
93
}
94
95
if
(!is_valid) {
96
ATH_MSG_FATAL
(
"The Identifier identifier "
<<stationType<<
", "
<<
stationEta
<<
", "
<<
stationPhi
97
<<
", "
<<multiLayer<<
", "
<<gasGap<<
" is invalid"
);
98
return
StatusCode::FAILURE;
99
}
100
101
sTGCAsBuiltData::Parameters
pars;
102
pars.
offset
= line[
"offset"
];
103
pars.
rotation
= line[
"rotation"
];
104
pars.
scale
= line[
"scale"
];
105
pars.
nonPara
= line[
"nonPara"
];
106
107
ATH_CHECK
(asBuiltData.
setParameters
(
id
, pars));
108
}
109
return
StatusCode::SUCCESS;
110
}
111
}
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
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::sTGCAsBuiltCondAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
sTGCAsBuiltCondAlg.h:34
Muon::sTGCAsBuiltCondAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, sTGCAsBuiltData &effiData) const
Parse efficiency data from COOL.
Definition
sTGCAsBuiltCondAlg.cxx:71
Muon::sTGCAsBuiltCondAlg::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition
sTGCAsBuiltCondAlg.h:40
Muon::sTGCAsBuiltCondAlg::m_writeKey
SG::WriteCondHandleKey< sTGCAsBuiltData > m_writeKey
Definition
sTGCAsBuiltCondAlg.h:39
Muon::sTGCAsBuiltCondAlg::initialize
virtual StatusCode initialize() override
Definition
sTGCAsBuiltCondAlg.cxx:15
Muon::sTGCAsBuiltCondAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Load the gasGap efficiencies from a JSON file.
Definition
sTGCAsBuiltCondAlg.h:37
Muon::sTGCAsBuiltCondAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
sTGCAsBuiltCondAlg.cxx:32
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
sTGCAsBuiltData
Class holding the sTGC as built conditions data and applying it.
Definition
sTGCAsBuiltData.h:27
sTGCAsBuiltData::setParameters
StatusCode setParameters(const Identifier &gasGapId, const Parameters &pars)
Definition
sTGCAsBuiltData.cxx:45
sTgcIdHelper::Strip
@ Strip
Definition
sTgcIdHelper.h:190
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
sTGCAsBuiltCondAlg.h
sTGCAsBuiltData::Parameters
Definition
sTGCAsBuiltData.h:35
sTGCAsBuiltData::Parameters::scale
double scale
Definition
sTGCAsBuiltData.h:38
sTGCAsBuiltData::Parameters::offset
double offset
Definition
sTGCAsBuiltData.h:36
sTGCAsBuiltData::Parameters::rotation
double rotation
Definition
sTGCAsBuiltData.h:37
sTGCAsBuiltData::Parameters::nonPara
double nonPara
Definition
sTGCAsBuiltData.h:39
Generated on
for ATLAS Offline Software by
1.17.0