ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonConditions
MuonCondGeneral
MuonCondAlg
src
MmCTPCondDbAlg.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 "
MmCTPCondDbAlg.h
"
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
// Initialize
17
StatusCode
MmCTPCondDbAlg::initialize
() {
18
19
ATH_CHECK
(
m_idHelperSvc
.retrieve());
20
if
( !
m_idHelperSvc
->hasMM() ){
21
ATH_MSG_ERROR
(
"MuonIdHelperSvc does not have MM, the CTP calibration should not be run!"
);
22
return
StatusCode::FAILURE;
23
}
24
25
ATH_CHECK
(
m_readKeyDb
.initialize(
m_readFromJSON
.value().empty()));
26
if
(
m_readFromJSON
.value().size()) {
27
ATH_MSG_INFO
(
"Read the uncertainty data from a JSON file "
<<
m_readFromJSON
);
28
}
else
if
(!
m_readKeyDb
.empty()) {
29
ATH_MSG_INFO
(
"Read the uncertainty data from a COOL databse: "
<<
m_readKeyDb
.fullKey() );
30
}
else
{
31
ATH_MSG_FATAL
(
"Neither an extrenal JSON nor a COOL folder were defined. Please check"
);
32
return
StatusCode::FAILURE;
33
}
34
ATH_CHECK
(
m_writeKey
.initialize());
35
36
37
38
return
StatusCode::SUCCESS;
39
}
40
41
StatusCode
MmCTPCondDbAlg::execute
(
const
EventContext& ctx)
const
{
42
ATH_MSG_DEBUG
(
"execute "
<< name());
43
// launching Write Cond Handle
44
SG::WriteCondHandle
writeHandle{
m_writeKey
, ctx};
45
if
(writeHandle.
isValid
()) {
46
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
47
<<
" In theory this should not be called, but may happen"
48
<<
" if multiple concurrent events are being processed out of order."
);
49
return
StatusCode::SUCCESS;
50
}
51
52
std::unique_ptr<Muon::MmCTPClusterCalibData> writeCdo{std::make_unique<Muon::MmCTPClusterCalibData>(
m_idHelperSvc
.get())};
53
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteTime
()));
54
55
if
(!
m_readFromJSON
.value().empty()) {
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
}
else
{
65
66
SG::ReadCondHandle
readHandle{
m_readKeyDb
, ctx};
67
if
(!readHandle.
isValid
()) {
68
ATH_MSG_FATAL
(
"Failed to load NSW error calibration folder from "
<<
m_readKeyDb
.fullKey());
69
return
StatusCode::FAILURE;
70
}
71
72
for
(
CondAttrListCollection::const_iterator
itr = readHandle->begin();
73
itr != readHandle->end(); ++itr) {
74
const
coral::AttributeList& atr = itr->second;
75
std::string data = *(
static_cast<
const
std::string*
>
((atr[
"data"
]).addressOfData()));
76
nlohmann::json lines = nlohmann::json::parse(data);
77
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
78
}
79
}
80
81
ATH_CHECK
(writeHandle.
record
(std::move(writeCdo)));
82
return
StatusCode::SUCCESS;
83
}
84
85
StatusCode
MmCTPCondDbAlg::parseDataFromJSON
(
const
nlohmann::json& lines,
86
Muon::MmCTPClusterCalibData
& ctpClusterCondData)
const
{
87
for
(
auto
& corr : lines.items()) {
88
nlohmann::json line = corr.value();
89
90
//Check entry keys, shall we make it to just check the first entry and then assume the rest is okay? maybe it doesn't take that much time to do it on the whole thing...
91
if
(!line.contains(
"station"
) || !line.contains(
"phi"
) || !line.contains(
"eta"
) || !line.contains(
"multilayer"
) || !line.contains(
"gasGap"
)) {
92
ATH_MSG_ERROR
(
"Missing expected keys in the JSON file"
);
93
return
StatusCode::FAILURE;
// Handle error appropriately
94
}
95
96
// Ensure the JSON array exists and has exactly 2 elements
97
if
(!line.contains(
"P1Parameters"
) || !line[
"P1Parameters"
].is_array() || line[
"P1Parameters"
].size() != 2) {
98
ATH_MSG_ERROR
(
"Get unexpected size of the P1Parameters array"
);
99
return
StatusCode::FAILURE;
// Handle error appropriately
100
}
101
103
const
std::string stationType = line[
"station"
];
104
const
int
stationPhi
= line[
"phi"
];
105
const
int
stationEta
= line[
"eta"
];
106
const
int
multiLayer = line[
"multilayer"
];
107
const
int
gasGap = line[
"gasGap"
];
108
109
// Convert JSON array to std::array<double, 2>
110
std::array<double, 2> modelPars;
111
std::copy_n(line[
"P1Parameters"
].begin(), 2, modelPars.begin());
112
113
Identifier
errorCalibId{};
114
115
//Using PCB 1 as default
116
errorCalibId =
m_idHelperSvc
->mmIdHelper().channelID(stationType,
stationEta
,
stationPhi
, multiLayer, gasGap, 1 );
117
118
Muon::MmCTPClusterCalibData::CTPParameters
constants
{std::move(modelPars)};
119
120
ATH_CHECK
(ctpClusterCondData.
storeConstants
(errorCalibId, std::move(
constants
)));
121
122
123
}
124
return
StatusCode::SUCCESS;
125
}
126
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
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_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
IOVInfiniteRange.h
MmCTPCondDbAlg.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::MmCTPClusterCalibData
Definition
MmCTPClusterCalibData.h:16
Muon::MmCTPClusterCalibData::CTPParameters
std::array< double, 2 > CTPParameters
Definition
MmCTPClusterCalibData.h:19
Muon::MmCTPClusterCalibData::storeConstants
StatusCode storeConstants(const Identifier &gasGapId, CTPParameters &&newConstants)
Definition
MmCTPClusterCalibData.cxx:26
Muon::MmCTPCondDbAlg::initialize
virtual StatusCode initialize() override final
Definition
MmCTPCondDbAlg.cxx:17
Muon::MmCTPCondDbAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, Muon::MmCTPClusterCalibData &ctpClusterCondData) const
Definition
MmCTPCondDbAlg.cxx:85
Muon::MmCTPCondDbAlg::m_writeKey
SG::WriteCondHandleKey< Muon::MmCTPClusterCalibData > m_writeKey
Definition
MmCTPCondDbAlg.h:36
Muon::MmCTPCondDbAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Parse data from COOL.
Definition
MmCTPCondDbAlg.h:28
Muon::MmCTPCondDbAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition
MmCTPCondDbAlg.cxx:41
Muon::MmCTPCondDbAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
MmCTPCondDbAlg.h:32
Muon::MmCTPCondDbAlg::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition
MmCTPCondDbAlg.h:37
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
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
Generated on
for ATLAS Offline Software by
1.17.0