ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonConditions
MuonCondGeneral
MuonCondAlg
src
NswUncertDbAlg.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 "
NswUncertDbAlg.h
"
5
6
#include <
StoreGate/WriteCondHandle.h
>
7
#include <
StoreGate/ReadCondHandle.h
>
8
#include <
AthenaKernel/IOVInfiniteRange.h
>
9
#include <
PathResolver/PathResolver.h
>
10
#include <CoralBase/Blob.h>
11
#include <
CoralUtilities/blobaccess.h
>
12
#include <fstream>
13
14
15
namespace
Muon
{
16
StatusCode
NswUncertDbAlg::initialize
() {
17
ATH_CHECK
(
m_readKeysDb
.initialize(
m_readFromJSON
.value().empty()));
18
if
(
m_readFromJSON
.value().size()) {
19
ATH_MSG_INFO
(
"Read the uncertainty data from a JSON file "
<<
m_readFromJSON
);
20
}
else
if
(
m_readKeysDb
.size()) {
21
std::stringstream folderStr{};
22
for
(
const
SG::ReadCondHandleKey<CondAttrListCollection>
& key :
m_readKeysDb
) {
23
folderStr<<
" **** "
<<key.fullKey()<<std::endl;
24
}
25
ATH_MSG_INFO
(
"Read the parametrized NSW uncertainties from COOL: "
<<std::endl<<folderStr.str());
26
}
else
{
27
ATH_MSG_FATAL
(
"Neither an extrenal JSON nor a COOL folder were defined. Please check"
);
28
return
StatusCode::FAILURE;
29
}
30
ATH_CHECK
(
m_writeKey
.initialize());
31
ATH_CHECK
(
m_idHelperSvc
.retrieve());
32
return
StatusCode::SUCCESS;
33
}
34
35
StatusCode
NswUncertDbAlg::execute
(
const
EventContext& ctx)
const
{
36
ATH_MSG_DEBUG
(
"execute "
<< name());
37
SG::WriteCondHandle
writeHandle{
m_writeKey
, ctx};
38
if
(writeHandle.
isValid
()) {
39
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
40
<<
". In theory this should not be called, but may happen"
41
<<
" if multiple concurrent events are being processed out of order."
);
42
return
StatusCode::SUCCESS;
43
}
44
45
std::unique_ptr<NswErrorCalibData> writeCdo = std::make_unique<NswErrorCalibData>(
m_idHelperSvc
.get());
46
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteTime
()));
47
48
if
(!
m_readFromJSON
.value().empty()) {
49
std::ifstream inStream{
PathResolverFindCalibFile
(
m_readFromJSON
)};
50
if
(!inStream.good()) {
51
ATH_MSG_FATAL
(
"No such file or directory"
);
52
return
StatusCode::FAILURE;
53
}
54
nlohmann::json lines;
55
inStream >> lines;
56
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
57
}
else
{
58
for
(
const
SG::ReadCondHandleKey<CondAttrListCollection>
& key :
m_readKeysDb
) {
59
SG::ReadCondHandle
readHandle{key, ctx};
60
if
(!readHandle.
isValid
()) {
61
ATH_MSG_FATAL
(
"Failed to load NSW error calibration folder from "
<<key.fullKey());
62
return
StatusCode::FAILURE;
63
}
64
for
(
CondAttrListCollection::const_iterator
itr = readHandle->begin();
65
itr != readHandle->end(); ++itr) {
66
const
coral::AttributeList& atr = itr->second;
67
std::string data{};
68
if
(atr[
"data"
].specification().
type
() ==
typeid
(coral::Blob)) {
69
ATH_MSG_VERBOSE
(
"Loading data as a BLOB, uncompressing..."
);
70
if
(!
CoralUtilities::readBlobAsString
(atr[
"data"
].data<coral::Blob>(), data)) {
71
ATH_MSG_FATAL
(
"Cannot uncompress BLOB! Aborting..."
);
72
return
StatusCode::FAILURE;
73
}
74
}
else
{
75
data = *(
static_cast<
const
std::string*
>
((atr[
"data"
]).addressOfData()));
76
}
77
nlohmann::json lines = nlohmann::json::parse(data);
78
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
79
}
80
}
81
}
82
ATH_CHECK
(writeHandle.
record
(std::move(writeCdo)));
83
return
StatusCode::SUCCESS;
84
}
85
86
StatusCode
NswUncertDbAlg::parseDataFromJSON
(
const
nlohmann::json& lines,
87
NswErrorCalibData
& nswErrorCalib)
const
{
88
89
for
(
auto
& corr : lines.items()) {
90
nlohmann::json line = corr.value();
92
const
std::string stationType = line[
"station"
];
93
const
int
stationPhi
= line[
"phi"
];
94
const
int
stationEta
= line[
"eta"
];
95
const
int
multilayer = line[
"multilayer"
];
96
const
int
gasGap = line[
"gasGap"
];
97
Identifier
errorCalibId{};
98
bool
isValid
{
true
};
99
if
(stationType[0] ==
'M'
) {
100
if
(!
m_idHelperSvc
->hasMM())
continue
;
101
errorCalibId =
m_idHelperSvc
->mmIdHelper().channelID(stationType,
stationEta
,
stationPhi
,
102
multilayer, gasGap, 1
103
#ifndef NDEBUG
104
,
isValid
105
#endif
106
);
107
}
else
if
(stationType[0] ==
'S'
) {
108
if
(!
m_idHelperSvc
->hasSTGC())
continue
;
109
errorCalibId =
m_idHelperSvc
->stgcIdHelper().channelID (stationType,
stationEta
,
stationPhi
,
110
multilayer, gasGap,
111
sTgcIdHelper::sTgcChannelTypes::Strip
, 1
112
#ifndef NDEBUG
113
,
isValid
114
#endif
115
);
116
117
}
else
{
118
isValid
=
false
;
119
}
120
if
(!
isValid
) {
121
ATH_MSG_ERROR
(
"Failed to construct a valid Identifier from "
122
<<stationType<<
", "
<<
stationEta
<<
", "
<<
stationPhi
<<
", "
123
<<multilayer<<
", "
<<gasGap);
124
return
StatusCode::FAILURE;
125
}
126
127
const
uint16_t minStrip = line[
"minStrip"
];
128
const
uint16_t maxStrip = line[
"maxStrip"
];
129
const
uint8_t author = line[
"clusterAuthor"
];
130
const
std::string modelName = line[
"modelName"
];
131
std::vector<double> modelPars = line[
"modelPars"
];
132
133
ATH_MSG_VERBOSE
(
"Load uncertainties for channel "
<<
m_idHelperSvc
->toString(errorCalibId)<<
" "
<<modelPars
134
<<
"model name: "
<<modelName<<
" author: "
<<
static_cast<
int
>
(author));
135
136
137
NswErrorCalibData::ErrorConstants
constants
{modelName, author,
138
minStrip, maxStrip, std::move(modelPars)};
139
140
ATH_CHECK
(nswErrorCalib.
storeConstants
(errorCalibId, std::move(
constants
)));
141
}
142
143
return
StatusCode::SUCCESS;
144
}
145
}
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_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
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
NswUncertDbAlg.h
PathResolver.h
PathResolverFindCalibFile
std::string PathResolverFindCalibFile(const std::string &logical_file_name)
Definition
PathResolver.cxx:325
ReadCondHandle.h
WriteCondHandle.h
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::NswUncertDbAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, NswErrorCalibData &errorCalibData) const
Load the Jitter constants from the JSON format.
Definition
NswUncertDbAlg.cxx:86
Muon::NswUncertDbAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
NswUncertDbAlg.h:41
Muon::NswUncertDbAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Use an external JSON file to load the Jitter constants from.
Definition
NswUncertDbAlg.h:39
Muon::NswUncertDbAlg::m_writeKey
SG::WriteCondHandleKey< NswErrorCalibData > m_writeKey
Definition
NswUncertDbAlg.h:44
Muon::NswUncertDbAlg::execute
virtual StatusCode execute(const EventContext &) const override
Definition
NswUncertDbAlg.cxx:35
Muon::NswUncertDbAlg::initialize
virtual StatusCode initialize() override
Definition
NswUncertDbAlg.cxx:16
Muon::NswUncertDbAlg::m_readKeysDb
SG::ReadCondHandleKeyArray< CondAttrListCollection > m_readKeysDb
Definition
NswUncertDbAlg.h:47
NswErrorCalibData::ErrorConstants
Helper struct to store different error calibrations for a certain channel range & also for seperate C...
Definition
NswErrorCalibData.h:50
NswErrorCalibData
Definition
NswErrorCalibData.h:19
NswErrorCalibData::storeConstants
StatusCode storeConstants(const Identifier &gasGapId, ErrorConstants &&newConstants)
Definition
NswErrorCalibData.cxx:130
SG::ReadCondHandleKey
Definition
ReadCondHandleKey.h:21
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
sTgcIdHelper::Strip
@ Strip
Definition
sTgcIdHelper.h:190
CoralUtilities::readBlobAsString
bool readBlobAsString(const coral::Blob &, std::string &)
Definition
blobaccess.cxx:87
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
constants
Definition
Calorimeter/CaloClusterCorrection/python/constants.py:1
type
Generated on
for ATLAS Offline Software by
1.17.0