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-2025 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_CHECK
(
detStore
()->symLink(
m_contOut
,
static_cast<
ILArRamp
*
>
(
m_contOut
)) );
99
ATH_MSG_INFO
(
"Loaded input container "
<<
m_containerKey
100
<<
", write to new container "
<<
m_newContainerKey
);
101
}
102
else
{
//Same container for reading and writing (must not be locked)
103
ATH_CHECK
(
detStore
()->retrieve(
m_contOut
,
m_containerKey
) );
//non-const retrieve
104
m_contIn
=
m_contOut
;
105
ATH_MSG_INFO
(
"Work on container '"
<<
m_containerKey
<<
"'"
);
106
}
107
108
if
(!
m_channelsToBePatchedHG
.empty()) {
109
ATH_MSG_INFO
(
"Going to apply ad-hoc patches to HIGH gain ramps."
);
110
ATH_CHECK
(
ApplyAdHocPatches
(
m_channelsToBePatchedHG
,
m_patchesToBeAppliedHG
,
m_valuesToBeAppliedHG
, 0) );
111
}
112
113
if
(!
m_channelsToBePatchedMG
.empty()) {
114
ATH_MSG_INFO
(
"Going to apply ad-hoc patches to MEDIUM gain ramps."
);
115
ATH_CHECK
(
ApplyAdHocPatches
(
m_channelsToBePatchedMG
,
m_patchesToBeAppliedMG
,
m_valuesToBeAppliedMG
,1) );
116
}
117
118
if
(!
m_channelsToBePatchedLG
.empty()) {
119
ATH_MSG_INFO
(
"Going to apply ad-hoc patches to LOW gain ramps."
);
120
ATH_CHECK
(
ApplyAdHocPatches
(
m_channelsToBePatchedLG
,
m_patchesToBeAppliedLG
,
m_valuesToBeAppliedLG
,2) );
121
}
122
123
ATH_MSG_INFO
(
"Done with LArRampAdHocPatchingAlg"
);
124
return
StatusCode::SUCCESS;
125
}
126
127
128
129
StatusCode
LArRampAdHocPatchingAlg::ApplyAdHocPatches
(std::vector<unsigned>& channelsToBePatched , std::vector<unsigned>& patchesToBeApplied, std::vector<std::vector<double> >& valuesToBeApplied,
unsigned
gain)
130
{
131
if
(channelsToBePatched.size() != patchesToBeApplied.size())
132
return
StatusCode::FAILURE;
133
unsigned
putcount=0;
134
for
(
unsigned
ich=0;ich<channelsToBePatched.size();++ich ) {
135
const
HWIdentifier
chid = (
HWIdentifier
)channelsToBePatched[ich];
136
// ... if so, proceed with ad-hoc patching(s)
137
const
unsigned
patchMethod
= patchesToBeApplied[ich];
138
//bool status = false;
139
switch
(
patchMethod
) {
140
case
ZeroIntercept
: {
141
// check if the channel to be patched is there...
142
if
(
m_contIn
->get(chid,gain).isEmpty())
continue
;
143
ZeroTheIntercept
(chid,gain);
144
break
;
145
}
146
case
PutValues
: {
147
if
( valuesToBeApplied[putcount].
empty
() )
return
StatusCode::FAILURE;
148
PutTheValues
(chid,valuesToBeApplied[putcount],gain);
149
++putcount;
150
break
;
151
}
152
}
153
/*
154
if (status) {
155
(*m_log) << MSG::INFO << "Sucessfully patched channel 0x" << MSG::hex << chid.get_compact() << MSG::dec <<" Gain:" << gain << endmsg;
156
} else {
157
(*m_log) << MSG::WARNING << "Failed to patch channel 0x" << MSG::hex << chid.get_compact() << MSG::dec <<" Gain:" << gain << endmsg;
158
}
159
*/
160
}
161
return
StatusCode::SUCCESS;
162
}
163
164
165
bool
LArRampAdHocPatchingAlg::ZeroTheIntercept
(
HWIdentifier
chid,
unsigned
gain)
166
{
167
unsigned
s =
m_contIn
->get(chid,gain).m_vRamp.size();
168
LArRampObj
patch;
169
patch.
m_vRamp
.clear();
170
patch.
m_vRamp
.resize(s);
171
ATH_MSG_INFO
(
"Size of the patched object: "
<<s);
172
if
(s==0)
return
false
;
173
patch.
m_vRamp
[0] = 0.;
// zeroes the intercept
174
for
(
unsigned
i=1;i<s;++i){
// copy the other coefficients
175
patch.
m_vRamp
[i] =
m_contIn
->get(chid,gain).m_vRamp[i];
176
}
177
StatusCode
sc
=
m_contOut
->insertCorrection(chid,patch,gain,
m_useCorrChannel
);
178
if
(
sc
.isFailure()) {
179
ATH_MSG_ERROR
(
"Failed to zero the ramp intercept channel 0x"
180
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
181
return
false
;
182
}
else
{
183
ATH_MSG_INFO
(
"Successfully zeroed the ramp intercept channel 0x"
184
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
185
return
true
;
186
}
187
}
188
189
bool
LArRampAdHocPatchingAlg::PutTheValues
(
HWIdentifier
chid, std::vector<double>& rvalues,
unsigned
gain)
190
{
191
unsigned
s = rvalues.size();
192
LArRampObj
patch;
193
patch.
m_vRamp
.clear();
194
patch.
m_vRamp
.resize(s);
195
ATH_MSG_INFO
(
"Size of the patched object: "
<<s);
196
if
(s==0)
return
false
;
197
for
(
unsigned
i=0;i<s;++i){
// copy the values
198
patch.
m_vRamp
[i] = rvalues[i];
199
}
200
StatusCode
sc
;
201
try
{
sc
=
m_contOut
->insertCorrection(chid,patch,gain,
m_useCorrChannel
);}
202
catch
(...) {
ATH_MSG_INFO
(
"Skipping insert of corrections, maybe it's not about this partition"
);}
203
if
(
sc
.isFailure()) {
204
ATH_MSG_ERROR
(
"Failed to put the values for channel 0x"
205
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
206
return
false
;
207
}
else
{
208
ATH_MSG_INFO
(
"Successfully put the values for channel 0x"
209
<< MSG::hex << chid.
get_compact
() << MSG::dec <<
", gain "
<< gain <<
"."
);
210
return
true
;
211
}
212
}
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_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
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
ILArRamp
Definition
ILArRamp.h:12
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:129
LArRampAdHocPatchingAlg::ZeroTheIntercept
bool ZeroTheIntercept(HWIdentifier chid, unsigned gain)
Definition
LArRampAdHocPatchingAlg.cxx:165
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:189
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