ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArCalibUtils
src
LArRampAdHocPatchingAlg.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
//Dear emacs, this is -*-c++-*-
6
7
#include "
LArCalibUtils/LArRampAdHocPatchingAlg.h
"
8
9
LArRampAdHocPatchingAlg::LArRampAdHocPatchingAlg
(
const
std::string& name, ISvcLocator* pSvcLocator)
10
:
AthAlgorithm
(name,pSvcLocator),
11
m_contIn
(nullptr),
12
m_contOut
(nullptr)
13
{
14
declareProperty
(
"ContainerKey"
,
m_containerKey
=
""
);
15
declareProperty
(
"NewContainerKey"
,
m_newContainerKey
=
""
);
16
17
declareProperty
(
"ChannelsToBePatchedHG"
,
m_channelsToBePatchedHG
);
18
declareProperty
(
"ChannelsToBePatchedMG"
,
m_channelsToBePatchedMG
);
19
declareProperty
(
"ChannelsToBePatchedLG"
,
m_channelsToBePatchedLG
);
20
21
declareProperty
(
"PatchesToBeAppliedHG"
,
m_patchesToBeAppliedHG
);
22
declareProperty
(
"PatchesToBeAppliedMG"
,
m_patchesToBeAppliedMG
);
23
declareProperty
(
"PatchesToBeAppliedLG"
,
m_patchesToBeAppliedLG
);
24
25
declareProperty
(
"ValuesToBeAppliedHG"
,
m_valuesToBeAppliedHG
);
26
declareProperty
(
"ValuesToBeAppliedMG"
,
m_valuesToBeAppliedMG
);
27
declareProperty
(
"ValuesToBeAppliedLG"
,
m_valuesToBeAppliedLG
);
28
29
declareProperty
(
"UseCorrChannels"
,
m_useCorrChannel
,
30
"True: Use separate correction COOL channel, False: Correction + data in the same channel"
);
31
}
32
33
34
LArRampAdHocPatchingAlg::~LArRampAdHocPatchingAlg
()
35
=
default
;
36
37
38
StatusCode
LArRampAdHocPatchingAlg::initialize
()
39
{
40
ATH_MSG_INFO
(
"Initialing LArRampAdHocPatchingAlg..."
);
41
ATH_MSG_INFO
(
"HG: "
<<
m_channelsToBePatchedHG
.size()<<
" "
<<
m_patchesToBeAppliedHG
.size());
42
ATH_MSG_INFO
(
"MG: "
<<
m_channelsToBePatchedMG
.size()<<
" "
<<
m_patchesToBeAppliedMG
.size());
43
ATH_MSG_INFO
(
"LG: "
<<
m_channelsToBePatchedLG
.size()<<
" "
<<
m_patchesToBeAppliedLG
.size());
44
45
if
( !
m_channelsToBePatchedHG
.empty() && (
m_channelsToBePatchedHG
.size() !=
m_patchesToBeAppliedHG
.size() ) ) {
46
ATH_MSG_ERROR
(
"Wrong size of HIGH gain input vectors!"
);
47
return
StatusCode::FAILURE;
48
}
else
{
49
unsigned
count
= std::count (
m_patchesToBeAppliedHG
.begin(),
m_patchesToBeAppliedHG
.end(), 1 );
// 1 is to apply values
50
if
( (
count
> 0) && (
m_valuesToBeAppliedHG
.size() !=
count
)) {
51
ATH_MSG_ERROR
(
"Wrong size of HIGH gain values vector ! "
<<
count
<<
" "
<<
m_valuesToBeAppliedHG
.size());
52
return
StatusCode::FAILURE;
53
}
else
{
54
ATH_MSG_INFO
(
m_channelsToBePatchedHG
.size() <<
" ad-hoc patches to be applied in HIGH gain"
);
55
}
56
}
57
58
if
( !
m_channelsToBePatchedMG
.empty() && (
m_channelsToBePatchedMG
.size() !=
m_patchesToBeAppliedMG
.size() ) ) {
59
ATH_MSG_ERROR
(
"Wrong size of MEDIUM gain input vectors!"
);
60
return
StatusCode::FAILURE;
61
}
else
{
62
unsigned
count
= std::count (
m_patchesToBeAppliedMG
.begin(),
m_patchesToBeAppliedMG
.end(), 1 );
// 1 is to apply values
63
if
( (
count
> 0) && (
m_valuesToBeAppliedMG
.size() !=
count
)) {
64
ATH_MSG_ERROR
(
"Wrong size of MEDIUM gain values vector !"
);
65
return
StatusCode::FAILURE;
66
}
else
{
67
ATH_MSG_INFO
(
m_channelsToBePatchedMG
.size() <<
" ad-hoc patches to be applied in MEDIUM gain"
);
68
}
69
}
70
71
if
( !
m_channelsToBePatchedLG
.empty() && (
m_channelsToBePatchedLG
.size() !=
m_patchesToBeAppliedLG
.size() ) ) {
72
ATH_MSG_ERROR
(
"Wrong size of LOW gain input vectors!"
);
73
return
StatusCode::FAILURE;
74
}
else
{
75
unsigned
count
= std::count (
m_patchesToBeAppliedLG
.begin(),
m_patchesToBeAppliedLG
.end(), 1 );
// 1 is to apply values
76
if
( (
count
> 0) && (
m_valuesToBeAppliedLG
.size() !=
count
)) {
77
ATH_MSG_ERROR
(
"Wrong size of LOW gain values vector !"
);
78
return
StatusCode::FAILURE;
79
}
else
{
80
ATH_MSG_INFO
(
m_channelsToBePatchedLG
.size() <<
" ad-hoc patches to be applied in LOW gain"
);
81
}
82
}
83
84
return
StatusCode::SUCCESS;
85
}
86
87
88
StatusCode
LArRampAdHocPatchingAlg::stop
()
89
{
90
ATH_MSG_INFO
(
"Entering LArRampAdHocPatchingAlg"
);
91
92
if
(!
m_newContainerKey
.empty()) {
//New container key give -> different containers for reading and writing
93
ATH_CHECK
(
detStore
()->retrieve(
m_contIn
,
m_containerKey
) );
//const-retrieve
94
m_contOut
=
new
LArRampComplete
();
95
m_contOut
->setGroupingType((
LArConditionsContainerBase::GroupingType
)
m_contIn
->groupingType());
96
ATH_CHECK
(
m_contOut
->initialize() );
97
ATH_CHECK
(
detStore
()->record(
m_contOut
,
m_newContainerKey
) );
98
ATH_MSG_INFO
(
"Loaded input container "
<<
m_containerKey
99
<<
", write to new container "
<<
m_newContainerKey
);
100
}
101
else
{
//Same container for reading and writing (must not be locked)
102
ATH_CHECK
(
detStore
()->retrieve(
m_contOut
,
m_containerKey
) );
//non-const retrieve
103
m_contIn
=
m_contOut
;
104
ATH_MSG_INFO
(
"Work on container '"
<<
m_containerKey
<<
"'"
);
105
}
106
107
if
(!
m_channelsToBePatchedHG
.empty()) {
108
ATH_MSG_INFO
(
"Going to apply ad-hoc patches to HIGH gain ramps."
);
109
ATH_CHECK
(
ApplyAdHocPatches
(
m_channelsToBePatchedHG
,
m_patchesToBeAppliedHG
,
m_valuesToBeAppliedHG
, 0) );
110
}
111
112
if
(!
m_channelsToBePatchedMG
.empty()) {
113
ATH_MSG_INFO
(
"Going to apply ad-hoc patches to MEDIUM gain ramps."
);
114
ATH_CHECK
(
ApplyAdHocPatches
(
m_channelsToBePatchedMG
,
m_patchesToBeAppliedMG
,
m_valuesToBeAppliedMG
,1) );
115
}
116
117
if
(!
m_channelsToBePatchedLG
.empty()) {
118
ATH_MSG_INFO
(
"Going to apply ad-hoc patches to LOW gain ramps."
);
119
ATH_CHECK
(
ApplyAdHocPatches
(
m_channelsToBePatchedLG
,
m_patchesToBeAppliedLG
,
m_valuesToBeAppliedLG
,2) );
120
}
121
122
ATH_MSG_INFO
(
"Done with LArRampAdHocPatchingAlg"
);
123
return
StatusCode::SUCCESS;
124
}
125
126
127
128
StatusCode
LArRampAdHocPatchingAlg::ApplyAdHocPatches
(std::vector<unsigned>& channelsToBePatched , std::vector<unsigned>& patchesToBeApplied, std::vector<std::vector<double> >& valuesToBeApplied,
unsigned
gain)
129
{
130
if
(channelsToBePatched.size() != patchesToBeApplied.size())
131
return
StatusCode::FAILURE;
132
unsigned
putcount=0;
133
for
(
unsigned
ich=0;ich<channelsToBePatched.size();++ich ) {
134
const
HWIdentifier
chid = (
HWIdentifier
)channelsToBePatched[ich];
135
// ... if so, proceed with ad-hoc patching(s)
136
const
unsigned
patchMethod
= patchesToBeApplied[ich];
137
//bool status = false;
138
switch
(
patchMethod
) {
139
case
ZeroIntercept
: {
140
// check if the channel to be patched is there...
141
if
(
m_contIn
->get(chid,gain).isEmpty())
continue
;
142
ZeroTheIntercept
(chid,gain);
143
break
;
144
}
145
case
PutValues
: {
146
if
( valuesToBeApplied[putcount].
empty
() )
return
StatusCode::FAILURE;
147
PutTheValues
(chid,valuesToBeApplied[putcount],gain);
148
++putcount;
149
break
;
150
}
151
}
152
/*
153
if (status) {
154
(*m_log) << MSG::INFO << "Sucessfully patched channel 0x" << MSG::hex << chid.get_compact() << MSG::dec <<" Gain:" << gain << endmsg;
155
} else {
156
(*m_log) << MSG::WARNING << "Failed to patch channel 0x" << MSG::hex << chid.get_compact() << MSG::dec <<" Gain:" << gain << endmsg;
157
}
158
*/
159
}
160
return
StatusCode::SUCCESS;
161
}
162
163
164
bool
LArRampAdHocPatchingAlg::ZeroTheIntercept
(
HWIdentifier
chid,
unsigned
gain)
165
{
166
unsigned
s =
m_contIn
->get(chid,gain).m_vRamp.size();
167
LArRampObj
patch;
168
patch.
m_vRamp
.clear();
169
patch.
m_vRamp
.resize(s);
170
ATH_MSG_INFO
(
"Size of the patched object: "
<<s);
171
if
(s==0)
return
false
;
172
patch.
m_vRamp
[0] = 0.;
// zeroes the intercept
173
for
(
unsigned
i=1;i<s;++i){
// copy the other coefficients
174
patch.
m_vRamp
[i] =
m_contIn
->get(chid,gain).m_vRamp[i];
175
}
176
StatusCode
sc
=
m_contOut
->insertCorrection(chid,patch,gain,
m_useCorrChannel
);
177
if
(
sc
.isFailure()) {
178
ATH_MSG_ERROR
(
"Failed to zero the ramp intercept channel 0x"
179
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
180
return
false
;
181
}
else
{
182
ATH_MSG_INFO
(
"Successfully zeroed the ramp intercept channel 0x"
183
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
184
return
true
;
185
}
186
}
187
188
bool
LArRampAdHocPatchingAlg::PutTheValues
(
HWIdentifier
chid, std::vector<double>& rvalues,
unsigned
gain)
189
{
190
unsigned
s = rvalues.size();
191
LArRampObj
patch;
192
patch.
m_vRamp
.clear();
193
patch.
m_vRamp
.resize(s);
194
ATH_MSG_INFO
(
"Size of the patched object: "
<<s);
195
if
(s==0)
return
false
;
196
for
(
unsigned
i=0;i<s;++i){
// copy the values
197
patch.
m_vRamp
[i] = rvalues[i];
198
}
199
StatusCode
sc
;
200
try
{
sc
=
m_contOut
->insertCorrection(chid,patch,gain,
m_useCorrChannel
);}
201
catch
(...) {
ATH_MSG_INFO
(
"Skipping insert of corrections, maybe it's not about this partition"
);}
202
if
(
sc
.isFailure()) {
203
ATH_MSG_ERROR
(
"Failed to put the values for channel 0x"
204
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
205
return
false
;
206
}
else
{
207
ATH_MSG_INFO
(
"Successfully put the values for channel 0x"
208
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
209
return
true
;
210
}
211
}
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:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
LArRampAdHocPatchingAlg.h
Algorithm implementing ad-hoc Ramp patches.
empty
static const Attributes_t empty
Definition
XmlStreamer.cxx:16
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
HWIdentifier
Definition
HWIdentifier.h:13
Identifier::get_compact
value_type get_compact() const
Get the compact id.
LArConditionsContainerBase::GroupingType
GroupingType
Grouping type.
Definition
LArConditionsContainerBase.h:44
LArRampAdHocPatchingAlg::m_patchesToBeAppliedMG
std::vector< unsigned > m_patchesToBeAppliedMG
Definition
LArRampAdHocPatchingAlg.h:78
LArRampAdHocPatchingAlg::m_valuesToBeAppliedHG
std::vector< std::vector< double > > m_valuesToBeAppliedHG
Definition
LArRampAdHocPatchingAlg.h:81
LArRampAdHocPatchingAlg::~LArRampAdHocPatchingAlg
~LArRampAdHocPatchingAlg()
Destructor.
LArRampAdHocPatchingAlg::m_channelsToBePatchedLG
std::vector< unsigned > m_channelsToBePatchedLG
Definition
LArRampAdHocPatchingAlg.h:75
LArRampAdHocPatchingAlg::m_channelsToBePatchedMG
std::vector< unsigned > m_channelsToBePatchedMG
Definition
LArRampAdHocPatchingAlg.h:74
LArRampAdHocPatchingAlg::m_useCorrChannel
bool m_useCorrChannel
Definition
LArRampAdHocPatchingAlg.h:95
LArRampAdHocPatchingAlg::stop
StatusCode stop()
Finalize method.
Definition
LArRampAdHocPatchingAlg.cxx:88
LArRampAdHocPatchingAlg::LArRampObj
LArRampComplete::LArCondObj LArRampObj
Definition
LArRampAdHocPatchingAlg.h:59
LArRampAdHocPatchingAlg::m_channelsToBePatchedHG
std::vector< unsigned > m_channelsToBePatchedHG
Definition
LArRampAdHocPatchingAlg.h:73
LArRampAdHocPatchingAlg::m_patchesToBeAppliedHG
std::vector< unsigned > m_patchesToBeAppliedHG
Definition
LArRampAdHocPatchingAlg.h:77
LArRampAdHocPatchingAlg::m_contIn
const LArRampComplete * m_contIn
Definition
LArRampAdHocPatchingAlg.h:61
LArRampAdHocPatchingAlg::patchMethod
patchMethod
Definition
LArRampAdHocPatchingAlg.h:85
LArRampAdHocPatchingAlg::ZeroIntercept
@ ZeroIntercept
Definition
LArRampAdHocPatchingAlg.h:86
LArRampAdHocPatchingAlg::PutValues
@ PutValues
Definition
LArRampAdHocPatchingAlg.h:87
LArRampAdHocPatchingAlg::m_valuesToBeAppliedMG
std::vector< std::vector< double > > m_valuesToBeAppliedMG
Definition
LArRampAdHocPatchingAlg.h:82
LArRampAdHocPatchingAlg::m_containerKey
std::string m_containerKey
Definition
LArRampAdHocPatchingAlg.h:64
LArRampAdHocPatchingAlg::m_valuesToBeAppliedLG
std::vector< std::vector< double > > m_valuesToBeAppliedLG
Definition
LArRampAdHocPatchingAlg.h:83
LArRampAdHocPatchingAlg::m_contOut
LArRampComplete * m_contOut
Definition
LArRampAdHocPatchingAlg.h:62
LArRampAdHocPatchingAlg::ApplyAdHocPatches
StatusCode ApplyAdHocPatches(std::vector< unsigned > &channelsToBePatched, std::vector< unsigned > &patchesTobeApplied, std::vector< std::vector< double > > &valuesToBeApplied, unsigned gain)
Definition
LArRampAdHocPatchingAlg.cxx:128
LArRampAdHocPatchingAlg::ZeroTheIntercept
bool ZeroTheIntercept(HWIdentifier chid, unsigned gain)
Definition
LArRampAdHocPatchingAlg.cxx:164
LArRampAdHocPatchingAlg::m_newContainerKey
std::string m_newContainerKey
Definition
LArRampAdHocPatchingAlg.h:65
LArRampAdHocPatchingAlg::LArRampAdHocPatchingAlg
LArRampAdHocPatchingAlg(const std::string &name, ISvcLocator *pSvcLocator)
regular Algorithm constructor
Definition
LArRampAdHocPatchingAlg.cxx:9
LArRampAdHocPatchingAlg::PutTheValues
bool PutTheValues(HWIdentifier chid, std::vector< double > &rvalues, unsigned gain)
Definition
LArRampAdHocPatchingAlg.cxx:188
LArRampAdHocPatchingAlg::m_patchesToBeAppliedLG
std::vector< unsigned > m_patchesToBeAppliedLG
Definition
LArRampAdHocPatchingAlg.h:79
LArRampAdHocPatchingAlg::initialize
StatusCode initialize()
Initialize method.
Definition
LArRampAdHocPatchingAlg.cxx:38
LArRampComplete
Definition
LArRampComplete.h:50
LArRampP1::m_vRamp
std::vector< float > m_vRamp
Definition
LArRampP1.h:30
count
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Definition
hcg.cxx:148
Generated on
for ATLAS Offline Software by
1.17.0