ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
MuonSpectrometer
MuonConditions
MuonCondGeneral
MuonCondAlg
src
TgcCondDbAlg.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 "
TgcCondDbAlg.h
"
6
#include <
AthenaKernel/IOVInfiniteRange.h
>
7
#include <
PathResolver/PathResolver.h
>
8
#include <fstream>
9
10
namespace
Muon
{
11
// Initialize
12
StatusCode
TgcCondDbAlg::initialize
() {
13
ATH_MSG_DEBUG
(
"initializing "
<< name());
14
ATH_CHECK
(
m_idHelperSvc
.retrieve());
15
ATH_CHECK
(
m_writeKey
.initialize());
16
ATH_CHECK
(
m_readKeyDb
.initialize(!
m_readKeyDb
.empty()));
17
if
(
m_readKeyDb
.empty() &&
m_readFromJSON
.value().empty()){
18
ATH_MSG_FATAL
(
"No data source is given to load the dead chamber data from. Please provide either a COOL folder or a json file"
);
19
return
StatusCode::FAILURE;
20
}
else
if
(
m_readKeyDb
.empty()) {
21
ATH_MSG_INFO
(
"Load the chamber status from a JSON file "
<<
m_readFromJSON
);
22
}
else
{
23
ATH_MSG_INFO
(
"Load the dead chamber list from COOL "
<<
m_readKeyDb
.fullKey());
24
}
25
return
StatusCode::SUCCESS;
26
}
27
28
// execute
29
StatusCode
TgcCondDbAlg::execute
(
const
EventContext& ctx)
const
{
30
ATH_MSG_DEBUG
(
"execute "
<< name());
31
// launching Write Cond Handle
32
SG::WriteCondHandle
writeHandle{
m_writeKey
, ctx};
33
if
(writeHandle.
isValid
()) {
34
ATH_MSG_DEBUG
(
"CondHandle "
<< writeHandle.
fullKey
() <<
" is already valid."
35
<<
" In theory this should not be called, but may happen"
36
<<
" if multiple concurrent events are being processed out of order."
);
37
return
StatusCode::SUCCESS;
38
}
39
writeHandle.
addDependency
(EventIDRange(
IOVInfiniteRange::infiniteTime
()));
40
auto
writeCdo{std::make_unique<TgcCondDbData>(
m_idHelperSvc
.get())};
41
if
(!
m_readKeyDb
.empty()) {
42
SG::ReadCondHandle
readHandle{
m_readKeyDb
, ctx};
43
if
(!readHandle.
isValid
()) {
44
ATH_MSG_FATAL
(
"Failed to initialize the COOL folder "
<<
m_readKeyDb
.fullKey());
45
return
StatusCode::FAILURE;
46
}
47
writeHandle.
addDependency
(readHandle);
48
for
(
CondAttrListCollection::const_iterator
itr = readHandle->begin(); itr != readHandle->end(); ++itr) {
49
const
coral::AttributeList& atr = itr->second;
50
const
std::string data{*(
static_cast<
const
std::string*
>
((atr[
"data"
]).addressOfData()))};
51
nlohmann::json lines = nlohmann::json::parse(data);
52
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
53
}
54
}
else
{
55
std::ifstream inStream{
PathResolverFindCalibFile
(
m_readFromJSON
)};
56
if
(!inStream.good()) {
57
ATH_MSG_FATAL
(
"No such file or directory"
);
58
return
StatusCode::FAILURE;
59
}
60
nlohmann::json lines;
61
inStream >> lines;
62
ATH_CHECK
(
parseDataFromJSON
(lines, *writeCdo));
63
}
64
ATH_CHECK
(writeHandle.
record
(std::move(writeCdo)));
65
ATH_MSG_DEBUG
(
"Recorded new "
<< writeHandle.
key
() <<
" with range "
<< writeHandle.
getRange
() <<
" into Conditions Store"
);
66
67
return
StatusCode::SUCCESS;
68
}
69
70
StatusCode
TgcCondDbAlg::parseDataFromJSON
(
const
nlohmann::json& lines,
71
TgcCondDbData
& deadChannels)
const
{
72
for
(
auto
& corr : lines.items()) {
73
nlohmann::json line = corr.value();
75
const
std::string stationType = line[
"station"
];
76
const
int
stationPhi
= line[
"phi"
];
77
const
int
stationEta
= line[
"eta"
];
78
const
int
gasGap = line[
"gasGap"
];
79
bool
is_valid{
false
};
80
const
Identifier
id
=
m_idHelperSvc
->tgcIdHelper().channelID(stationType,
stationEta
,
stationPhi
, gasGap,
false
, 1, is_valid);
81
if
(!is_valid) {
82
ATH_MSG_FATAL
(
"The Identifier identifier "
<<stationType<<
", "
<<
stationEta
<<
", "
<<
stationPhi
<<
", "
<<gasGap<<
" is invalid"
);
83
return
StatusCode::FAILURE;
84
}
85
deadChannels.
setDeadGasGap
(
id
);
86
}
87
return
StatusCode::SUCCESS;
88
}
89
}
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
TgcCondDbAlg.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::TgcCondDbAlg::initialize
virtual StatusCode initialize() override
Definition
TgcCondDbAlg.cxx:12
Muon::TgcCondDbAlg::parseDataFromJSON
StatusCode parseDataFromJSON(const nlohmann::json &lines, TgcCondDbData &deadChannels) const
Load the detector status from cool.
Definition
TgcCondDbAlg.cxx:70
Muon::TgcCondDbAlg::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition
TgcCondDbAlg.h:41
Muon::TgcCondDbAlg::m_writeKey
SG::WriteCondHandleKey< TgcCondDbData > m_writeKey
Definition
TgcCondDbAlg.h:43
Muon::TgcCondDbAlg::m_readFromJSON
Gaudi::Property< std::string > m_readFromJSON
Load the detector status from a JSON file.
Definition
TgcCondDbAlg.h:39
Muon::TgcCondDbAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
TgcCondDbAlg.cxx:29
Muon::TgcCondDbAlg::m_readKeyDb
SG::ReadCondHandleKey< CondAttrListCollection > m_readKeyDb
Definition
TgcCondDbAlg.h:44
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
TgcCondDbData
Conditions object to mark switched-off Tgc gasGaps.
Definition
TgcCondDbData.h:20
TgcCondDbData::setDeadGasGap
void setDeadGasGap(const Identifier &id)
Declare all channels wires + strips in a gasGap as dead.
Definition
TgcCondDbData.cxx:10
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