ATLAS Offline Software
LArRampAdHocPatchingAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //Dear emacs, this is -*-c++-*-
6 
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 
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
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 
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 
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  }
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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArRampAdHocPatchingAlg::PutValues
@ PutValues
Definition: LArRampAdHocPatchingAlg.h:87
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArRampComplete
Definition: LArRampComplete.h:50
LArRampAdHocPatchingAlg::m_channelsToBePatchedMG
std::vector< unsigned > m_channelsToBePatchedMG
Definition: LArRampAdHocPatchingAlg.h:74
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArRampP1
Persistent data for LArRamp Copied from LAr.
Definition: LArRampP1.h:24
LArConditionsContainer::insertCorrection
StatusCode insertCorrection(HWIdentifier id, const T &cond, unsigned int gain, bool corrChannel=true)
access to corrections -
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArRampAdHocPatchingAlg::m_containerKey
std::string m_containerKey
Definition: LArRampAdHocPatchingAlg.h:64
LArRampAdHocPatchingAlg::ZeroTheIntercept
bool ZeroTheIntercept(HWIdentifier chid, unsigned gain)
Definition: LArRampAdHocPatchingAlg.cxx:165
LArRampAdHocPatchingAlg::m_channelsToBePatchedLG
std::vector< unsigned > m_channelsToBePatchedLG
Definition: LArRampAdHocPatchingAlg.h:75
LArRampAdHocPatchingAlg::initialize
StatusCode initialize()
Initialize method.
Definition: LArRampAdHocPatchingAlg.cxx:38
LArRampAdHocPatchingAlg::PutTheValues
bool PutTheValues(HWIdentifier chid, std::vector< double > &rvalues, unsigned gain)
Definition: LArRampAdHocPatchingAlg.cxx:189
LArRampAdHocPatchingAlg::~LArRampAdHocPatchingAlg
~LArRampAdHocPatchingAlg()
Destructor.
LArRampAdHocPatchingAlg::m_contOut
LArRampComplete * m_contOut
Definition: LArRampAdHocPatchingAlg.h:62
HWIdentifier
Definition: HWIdentifier.h:13
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
LArRampAdHocPatchingAlg::patchMethod
patchMethod
Definition: LArRampAdHocPatchingAlg.h:85
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArRampP1::m_vRamp
std::vector< float > m_vRamp
Definition: LArRampP1.h:30
LArRampAdHocPatchingAlg::ZeroIntercept
@ ZeroIntercept
Definition: LArRampAdHocPatchingAlg.h:86
LArRampAdHocPatchingAlg::m_valuesToBeAppliedHG
std::vector< std::vector< double > > m_valuesToBeAppliedHG
Definition: LArRampAdHocPatchingAlg.h:81
LArRampAdHocPatchingAlg::m_patchesToBeAppliedLG
std::vector< unsigned > m_patchesToBeAppliedLG
Definition: LArRampAdHocPatchingAlg.h:79
LArRampAdHocPatchingAlg::m_newContainerKey
std::string m_newContainerKey
Definition: LArRampAdHocPatchingAlg.h:65
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArRampAdHocPatchingAlg::m_patchesToBeAppliedMG
std::vector< unsigned > m_patchesToBeAppliedMG
Definition: LArRampAdHocPatchingAlg.h:78
LArConditionsContainerBase::GroupingType
GroupingType
Grouping type.
Definition: LArConditionsContainerBase.h:44
LArConditionsContainer::groupingType
unsigned int groupingType() const
Type of grouping - defined in LArConditionContainerBase.h.
lumiFormat.i
int i
Definition: lumiFormat.py:92
LArRampAdHocPatchingAlg::m_valuesToBeAppliedLG
std::vector< std::vector< double > > m_valuesToBeAppliedLG
Definition: LArRampAdHocPatchingAlg.h:83
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArConditionsContainer::get
ConstReference get(const HWIdentifier id, unsigned int gain=0) const
get data with online identifier
ILArRamp
Definition: ILArRamp.h:12
LArRampAdHocPatchingAlg::ApplyAdHocPatches
StatusCode ApplyAdHocPatches(std::vector< unsigned > &channelsToBePatched, std::vector< unsigned > &patchesTobeApplied, std::vector< std::vector< double > > &valuesToBeApplied, unsigned gain)
Definition: LArRampAdHocPatchingAlg.cxx:129
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArRampAdHocPatchingAlg::m_channelsToBePatchedHG
std::vector< unsigned > m_channelsToBePatchedHG
Definition: LArRampAdHocPatchingAlg.h:73
AthAlgorithm
Definition: AthAlgorithm.h:47
LArRampAdHocPatchingAlg::LArRampAdHocPatchingAlg
LArRampAdHocPatchingAlg(const std::string &name, ISvcLocator *pSvcLocator)
regular Algorithm constructor
Definition: LArRampAdHocPatchingAlg.cxx:9
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArRampAdHocPatchingAlg::m_valuesToBeAppliedMG
std::vector< std::vector< double > > m_valuesToBeAppliedMG
Definition: LArRampAdHocPatchingAlg.h:82
LArRampAdHocPatchingAlg::m_contIn
const LArRampComplete * m_contIn
Definition: LArRampAdHocPatchingAlg.h:61
LArRampAdHocPatchingAlg::m_useCorrChannel
bool m_useCorrChannel
Definition: LArRampAdHocPatchingAlg.h:95
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
LArConditionsContainer::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
LArRampAdHocPatchingAlg.h
Algorithm implementing ad-hoc Ramp patches.
LArRampAdHocPatchingAlg::stop
StatusCode stop()
Finalize method.
Definition: LArRampAdHocPatchingAlg.cxx:88
LArRampAdHocPatchingAlg::m_patchesToBeAppliedHG
std::vector< unsigned > m_patchesToBeAppliedHG
Definition: LArRampAdHocPatchingAlg.h:77