ATLAS Offline Software
Loading...
Searching...
No Matches
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
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_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
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." );
111 }
112
113 if (!m_channelsToBePatchedMG.empty()) {
114 ATH_MSG_INFO ( "Going to apply ad-hoc patches to MEDIUM gain ramps." );
116 }
117
118 if (!m_channelsToBePatchedLG.empty()) {
119 ATH_MSG_INFO ( "Going to apply ad-hoc patches to LOW gain ramps." );
121 }
122
123 ATH_MSG_INFO ( "Done with LArRampAdHocPatchingAlg" );
124 return StatusCode::SUCCESS;
125}
126
127
128
129StatusCode 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
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
189bool 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}
#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 with parameters:
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:146