ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
9LArRampAdHocPatchingAlg::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
35= default;
36
37
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
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
95 m_contOut->setGroupingType((LArConditionsContainerBase::GroupingType)m_contIn->groupingType());
96 ATH_CHECK( m_contOut->initialize() );
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
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." );
110 }
111
112 if (!m_channelsToBePatchedMG.empty()) {
113 ATH_MSG_INFO ( "Going to apply ad-hoc patches to MEDIUM gain ramps." );
115 }
116
117 if (!m_channelsToBePatchedLG.empty()) {
118 ATH_MSG_INFO ( "Going to apply ad-hoc patches to LOW gain ramps." );
120 }
121
122 ATH_MSG_INFO ( "Done with LArRampAdHocPatchingAlg" );
123 return StatusCode::SUCCESS;
124}
125
126
127
128StatusCode 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
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
188bool 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
static Double_t sc
Algorithm implementing ad-hoc Ramp patches.
static const Attributes_t empty
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
value_type get_compact() const
Get the compact id.
std::vector< unsigned > m_patchesToBeAppliedMG
std::vector< std::vector< double > > m_valuesToBeAppliedHG
~LArRampAdHocPatchingAlg()
Destructor.
std::vector< unsigned > m_channelsToBePatchedLG
std::vector< unsigned > m_channelsToBePatchedMG
StatusCode stop()
Finalize method.
LArRampComplete::LArCondObj LArRampObj
std::vector< unsigned > m_channelsToBePatchedHG
std::vector< unsigned > m_patchesToBeAppliedHG
const LArRampComplete * m_contIn
std::vector< std::vector< double > > m_valuesToBeAppliedMG
std::vector< std::vector< double > > m_valuesToBeAppliedLG
StatusCode ApplyAdHocPatches(std::vector< unsigned > &channelsToBePatched, std::vector< unsigned > &patchesTobeApplied, std::vector< std::vector< double > > &valuesToBeApplied, unsigned gain)
bool ZeroTheIntercept(HWIdentifier chid, unsigned gain)
LArRampAdHocPatchingAlg(const std::string &name, ISvcLocator *pSvcLocator)
regular Algorithm constructor
bool PutTheValues(HWIdentifier chid, std::vector< double > &rvalues, unsigned gain)
std::vector< unsigned > m_patchesToBeAppliedLG
StatusCode initialize()
Initialize method.
std::vector< float > m_vRamp
Definition LArRampP1.h:30
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:148