ATLAS Offline Software
Loading...
Searching...
No Matches
LArDuplicateConstants.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5//Dear emacs, this is -*-c++-*-
6
8
14
20
21LArDuplicateConstants::LArDuplicateConstants (const std::string& name, ISvcLocator* pSvcLocator)
22 : AthAlgorithm(name,pSvcLocator),
23 m_onlineHelper(nullptr)
24{
25 declareProperty("SourceGain" , m_gainIN = 1);
26 declareProperty("TargetGain" , m_gainOUT = 2);
27 declareProperty("KeyPedestal" , m_keyPed = "" ); //"LArPedestal");
28 declareProperty("KeyRamp" , m_keyRamp = "" ); //"LArRamp");
29 declareProperty("KeyMphysMcali" , m_keyMPMC = "" ); //"LArMphysOverMcal");
30 declareProperty("KeyOFC" , m_keyOFC = "" ); //"LArOFC");
31 declareProperty("KeyShape" , m_keyShape = "" ); //"LArShape");
32}
33
34
36= default;
37
38
40{
41 ATH_MSG_INFO ( "Initialing " << name() );
42 ATH_MSG_INFO ( "INPUT gain = " << m_gainIN );
43 ATH_MSG_INFO ( "OUTPUT gain = " << m_gainOUT );
44 return StatusCode::SUCCESS;
45}
46
47
49{
50 ATH_MSG_INFO ( "Entering LArDuplicateConstants" );
51
52 ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
53
54 // PEDESTAL
55
56 if (!m_keyPed.empty()) {
57
58 const LArPedestalComplete* PedestalIN;
59 LArPedestalComplete* PedestalOUT;
60 ATH_CHECK( detStore()->retrieve(PedestalIN,m_keyPed) );
61 PedestalOUT=const_cast<LArPedestalComplete*>(PedestalIN); // cast to non-const the same container
62
63 unsigned int n_tot_ped = 0;
64 unsigned int n_dup_ped = 0;
65
66 PedestalIt ped_it = PedestalIN->begin(m_gainIN);
67 PedestalIt ped_it_e = PedestalIN->end(m_gainIN);
68 if ( ped_it == ped_it_e ) {
69 ATH_MSG_WARNING ( "LArPedestalComplete (key = " << m_keyPed << ") has no pedestals with gain = " << m_gainIN );
70 }
71 for ( ; ped_it!=ped_it_e; ped_it++) {
72 const HWIdentifier chid = ped_it.channelId();
73 if (m_onlineHelper->isEMBPS(chid)) { // duplicate constants for EMB PS only
74 n_tot_ped++;
75 const LArPedestalP1& ped_t = PedestalOUT->get(chid,m_gainOUT);
76 if (ped_t.isEmpty()) {
77 n_dup_ped++;
78 const LArPedestalP1& ped = PedestalIN->get(chid,m_gainIN);
79 PedestalOUT->setPdata(chid,ped,m_gainOUT);
80 ATH_MSG_VERBOSE ( "Pedestal for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
81 << " duplicated from gain " << m_gainIN << " to gain " << m_gainOUT );
82 } else {
83 ATH_MSG_VERBOSE ( "Pedestal for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
84 << " in gain " << m_gainOUT << " exists! Not duplicating..." );
85 }
86 }
87 }
88 ATH_MSG_INFO ( "LArPedestalComplete (key = " << m_keyPed << ") content duplicated from gain "
89 << m_gainIN << " to gain " << m_gainOUT
90 << " (" << n_dup_ped << "/" << n_tot_ped << " PS channels)" );
91 }
92
93 // RAMP
94
95 if (!m_keyRamp.empty()) {
96
97 const LArRampComplete* RampIN = nullptr;
98 LArRampComplete* RampOUT = nullptr;
99 ATH_CHECK( detStore()->retrieve(RampIN,m_keyRamp) );
100 RampOUT=const_cast<LArRampComplete*>(RampIN); // cast to non-const the same container
101
102 bool undoCorr=false;
103
104 if (!RampOUT->correctionsApplied()) {
105 ATH_CHECK( RampOUT->applyCorrections() );
106 undoCorr=true;
107 ATH_MSG_INFO ( "Applied corrections for Ramp" );
108 }
109 unsigned deltaGain = (m_gainOUT-m_gainIN); // Ex: 2-1 = 1
110 float scaleRamp = pow(10.,deltaGain); // Ex: 10^1 = 10
111 ATH_MSG_INFO ( "Ramp scale factor = " << scaleRamp );
112
113 unsigned int n_tot_ramp = 0;
114 unsigned int n_dup_ramp = 0;
115 unsigned nCorrChans=0;
116
117 RampIt ramp_it = RampIN->begin(m_gainIN);
118 RampIt ramp_it_e = RampIN->end(m_gainIN);
119 if ( ramp_it == ramp_it_e ) {
120 ATH_MSG_WARNING ( "LArRampComplete (key = " << m_keyRamp << ") has no ramps with gain = " << m_gainIN );
121 }
122 for ( ; ramp_it!=ramp_it_e; ramp_it++) {
123 const HWIdentifier chid = ramp_it.channelId();
124 if (m_onlineHelper->isEMBPS(chid)) { // duplicate constants for EMB PS only
125 n_tot_ramp++;
126 const LArRampP1& ramp_t = RampOUT->get(chid,m_gainOUT);
127 if (ramp_t.isEmpty()) {
128 n_dup_ramp++;
129 const LArRampP1& ramp = RampIN->get(chid,m_gainIN);
130 // scale ramp according to gain difference
131 unsigned s = ramp.m_vRamp.size();
132 LArRampP1 newramp;
133 newramp.m_vRamp.clear();
134 newramp.m_vRamp.resize(s);
135 for (unsigned i=0;i<s;i++) {
136 newramp.m_vRamp[i] = ramp.m_vRamp[i] * scaleRamp;
137 }
138 RampOUT->setPdata(chid,newramp,m_gainOUT);
139 ATH_MSG_VERBOSE ( "Ramp for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
140 << " duplicated from gain " << m_gainIN << " to gain " << m_gainOUT );
141 } else {
142 ATH_MSG_VERBOSE ( "Ramp for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
143 << " in gain " << m_gainOUT << " exists! Not duplicating..." );
144 }
145 }
146 }
147 if (undoCorr) {
148 ATH_CHECK( RampOUT->undoCorrections() );
149 ATH_MSG_INFO ( "Undo corrections for Ramp" );
150 }
151 else {
152 //Now work on correction channels
155 for (;cit!=cit_e;cit++) {
156 const HWIdentifier chid(cit->first);
157 if (m_onlineHelper->isEMBPS(chid)) { // duplicate constants for EMB PS only
158 const LArRampP1& ramp=cit->second;
159 const unsigned s = ramp.m_vRamp.size();
160 LArRampP1 newramp;
161 newramp.m_vRamp.clear();
162 newramp.m_vRamp.resize(s);
163 for (unsigned i=0;i<s;i++) {
164 newramp.m_vRamp[i] = ramp.m_vRamp[i] * scaleRamp;
165 }
166 ATH_CHECK( RampOUT->insertCorrection(chid,newramp,m_gainOUT,false) );
167 ++nCorrChans;
168 }//end if isEMBPS
169 } // end loop over correction channels
170 }
171 ATH_MSG_INFO ( "LArRampComplete (key = " << m_keyRamp << ") content duplicated from gain "
172 << m_gainIN << " to gain " << m_gainOUT
173 << " (" << n_dup_ramp << "/" << n_tot_ramp << " + " << nCorrChans << " PS channels)" );
174 }
175
176 // MPHYSOVERMCALI
177
178 if (!m_keyMPMC.empty()) {
179
180 const LArMphysOverMcalComplete* MphysMcaliIN = nullptr;
181 LArMphysOverMcalComplete* MphysMcaliOUT = nullptr;
182 ATH_CHECK( detStore()->retrieve(MphysMcaliIN,m_keyMPMC) );
183 MphysMcaliOUT=const_cast<LArMphysOverMcalComplete*>(MphysMcaliIN); // cast to non-const the same container
184
185 unsigned int n_tot_mpmc = 0;
186 unsigned int n_dup_mpmc = 0;
187
188 MpMcIt mpmc_it = MphysMcaliIN->begin(m_gainIN);
189 MpMcIt mpmc_it_e = MphysMcaliIN->end(m_gainIN);
190 if ( mpmc_it == mpmc_it_e ) {
191 ATH_MSG_WARNING ( "LArMphysOverMcaliComplete (key = " << m_keyMPMC << ") has no Mphys/Mcali with gain = " << m_gainIN );
192 }
193 for ( ; mpmc_it!=mpmc_it_e; mpmc_it++) {
194 const HWIdentifier chid = mpmc_it.channelId();
195 if (m_onlineHelper->isEMBPS(chid)) { // duplicate constants for EMB PS only
196 n_tot_mpmc++;
197 const LArSingleFloatP& mpmc_t = MphysMcaliOUT->get(chid,m_gainOUT);
198 if (mpmc_t.isEmpty()) {
199 n_dup_mpmc++;
200 const LArSingleFloatP& mpmc = MphysMcaliIN->get(chid,m_gainIN);
201 MphysMcaliOUT->setPdata(chid,mpmc,m_gainOUT);
202 ATH_MSG_VERBOSE ( "MpMc for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
203 << " duplicated from gain " << m_gainIN << " to gain " << m_gainOUT );
204 } else {
205 ATH_MSG_VERBOSE ( "MpMc for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
206 << " in gain " << m_gainOUT << " exists! Not duplicating..." );
207 }
208 }
209 }
210 ATH_MSG_INFO ( "LArMphysOverMcaliComplete (key = " << m_keyMPMC << ") content duplicated from gain "
211 << m_gainIN << " to gain " << m_gainOUT
212 << " (" << n_dup_mpmc << "/" << n_tot_mpmc << " PS channels)" );
213 }
214
215 // OFC
216
217 if (!m_keyOFC.empty()) {
218
219 const LArOFCComplete* OFCIN = nullptr;
220 LArOFCComplete* OFCOUT = nullptr;
221 ATH_CHECK( detStore()->retrieve(OFCIN,m_keyOFC) );
222 OFCOUT=const_cast<LArOFCComplete*>(OFCIN); // cast to non-const the same container
223
224 unsigned int n_tot_ofc = 0;
225 unsigned int n_dup_ofc = 0;
226
227 OFCIt ofc_it = OFCIN->begin(m_gainIN);
228 OFCIt ofc_it_e = OFCIN->end(m_gainIN);
229 if ( ofc_it == ofc_it_e ) {
230 ATH_MSG_WARNING ( "LArOFCComplete (key = " << m_keyOFC << ") has no OFCs with gain = " << m_gainIN );
231 }
232 for ( ; ofc_it!=ofc_it_e; ofc_it++) {
233 const HWIdentifier chid = ofc_it.channelId();
234 if (m_onlineHelper->isEMBPS(chid)) { // duplicate constants for EMB PS only
235 n_tot_ofc++;
236
237 //const LArOFCP1& ofc_t = OFCOUT->get(chid,m_gainOUT); // gives a segmentation fault from LAr2DWaveBase::LAr2DWaveBase(LArCompactSubsetChannelProxy const&) ()
238 // LArOFCP1 ofc_t = OFCOUT->get(chid,m_gainOUT); // make a copy instead? Nope, still segfaulting.
239 // if (ofc_t.isEmpty()) { } // cannot use this :-(
240
241 // directly get one data member :-(
242 ILArOFC::OFCRef_t vOFCa_t = OFCOUT->OFC_a(chid,m_gainOUT);
243 if (!vOFCa_t.size()) { // emulate isEmpty() behavior
244
245 n_dup_ofc++;
246 const LArOFCP1& ofc = OFCIN->get(chid,m_gainIN); // why is this working here? Because it;s not empty?
247 OFCOUT->setPdata(chid,ofc,m_gainOUT);
248 ATH_MSG_VERBOSE ( "OFC for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
249 << " duplicated from gain " << m_gainIN << " to gain " << m_gainOUT );
250 } else {
251 ATH_MSG_VERBOSE ( "OFC for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
252 << " in gain " << m_gainOUT << " exists! Not duplicating..." );
253
254 }
255 }
256 }
257 ATH_MSG_INFO ( "LArOFCComplete (key = " << m_keyOFC << ") content duplicated from gain "
258 << m_gainIN << " to gain " << m_gainOUT
259 << " (" << n_dup_ofc << "/" << n_tot_ofc << " PS channels)" );
260 }
261
262 // SHAPE
263
264 if (!m_keyShape.empty()) {
265
266 const LArShapeComplete* ShapeIN = nullptr;
267 LArShapeComplete* ShapeOUT = nullptr;
268 ATH_CHECK( detStore()->retrieve(ShapeIN,m_keyShape) );
269 ShapeOUT=const_cast<LArShapeComplete*>(ShapeIN); // cast to non-const the same container
270
271 unsigned int n_tot_shape = 0;
272 unsigned int n_dup_shape = 0;
273
274 ShapeIt shape_it = ShapeIN->begin(m_gainIN);
275 ShapeIt shape_it_e = ShapeIN->end(m_gainIN);
276 if ( shape_it == shape_it_e ) {
277 ATH_MSG_WARNING ( "LArShapeComplete (key = " << m_keyShape << ") has no Shapes with gain = " << m_gainIN );
278 }
279 for ( ; shape_it!=shape_it_e; shape_it++) {
280 const HWIdentifier chid = shape_it.channelId();
281 if (m_onlineHelper->isEMBPS(chid)) { // duplicate constants for EMB PS only
282 n_tot_shape++;
283
284 //const LArShapeP2& shape_t = ShapeOUT->get(chid,m_gainOUT);
285 //if (shape_t.isEmpty()) {
286
287 ILArShape::ShapeRef_t vShape_t = ShapeOUT->Shape(chid,m_gainOUT);
288 if (!vShape_t.size()) {
289
290 n_dup_shape++;
291 const LArShapeP2& shape = ShapeIN->get(chid,m_gainIN);
292 ShapeOUT->setPdata(chid,shape,m_gainOUT);
293 ATH_MSG_VERBOSE ( "Shape for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
294 << " duplicated from gain " << m_gainIN << " to gain " << m_gainOUT );
295 } else {
296 ATH_MSG_VERBOSE ( "Shape for channel 0x" << MSG::hex << chid.get_compact() << MSG::dec
297 << " in gain " << m_gainOUT << " exists! Not duplicating..." );
298 }
299 }
300 }
301 ATH_MSG_INFO ( "LArShapeComplete (key = " << m_keyShape << ") content duplicated from gain "
302 << m_gainIN << " to gain " << m_gainOUT
303 << " (" << n_dup_shape << "/" << n_tot_shape << " PS channels)" );
304
305 }
306
307 ATH_MSG_INFO ( "Done with LArDuplicateConstants" );
308 return StatusCode::SUCCESS;
309}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
LArPedestalComplete::ConstConditionsMapIterator PedestalIt
LArMphysOverMcalComplete::ConstConditionsMapIterator MpMcIt
LArShapeComplete::ConstConditionsMapIterator ShapeIt
LArRampComplete::ConstConditionsMapIterator RampIt
LArOFCComplete::ConstConditionsMapIterator OFCIt
Algorithm implementing ad-hoc duplication ofconstants.
constexpr int pow(int base, int exp) noexcept
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
LArVectorProxy OFCRef_t
This class defines the interface for accessing Optimal Filtering coefficients for each channel provid...
Definition ILArOFC.h:26
LArVectorProxy ShapeRef_t
This class defines the interface for accessing Shape (Nsample variable, Dt = 25 ns fixed) @stereotype...
Definition ILArShape.h:26
value_type get_compact() const
Get the compact id.
StatusCode insertCorrection(HWIdentifier id, const T &cond, unsigned int gain, bool corrChannel=true)
access to corrections -
bool correctionsApplied() const
Have corrections been applied?
void setPdata(const HWIdentifier id, const T &payload, unsigned int gain=0)
put payload in persistent data
ConditionsMap::const_iterator ConstConditionsMapIterator
StatusCode applyCorrections()
apply correction set
StatusCode undoCorrections()
undo corrections that have been already applied
ConstCorrectionIt undoCorrBegin(unsigned int gain) const
get iterator over the Undo-Vector for a certain gain
ConstCorrectionIt undoCorrEnd(unsigned int gain) const
ConstReference get(const HWIdentifier id, unsigned int gain=0) const
get data with online identifier
ConstConditionsMapIterator begin(unsigned int gain) const
get iterator for all channels for a gain
ConstConditionsMapIterator end(unsigned int gain) const
end of all channels for this gain
Subset::ConstCorrectionVecIt ConstCorrectionIt
const LArOnlineID * m_onlineHelper
LArDuplicateConstants(const std::string &name, ISvcLocator *pSvcLocator)
This class implements the ILArMphysOverMcal interface.
This class implements the ILArOFC interface.
virtual OFCRef_t OFC_a(const HWIdentifier &CellID, int gain, int tbin=0) const override
access to OFCs by online ID, gain, and tbin (!=0 for testbeam)
c-struct reproducing the structure of the persistent data
Definition LArOFCP1.h:22
This class implements the ILArPedestal interface.
bool isEmpty() const
Persistent data for LArRamp Copied from LAr.
Definition LArRampP1.h:24
std::vector< float > m_vRamp
Definition LArRampP1.h:30
bool isEmpty() const
Definition LArRampP1.h:29
This class implements the ILArShape interface.
virtual ShapeRef_t Shape(const HWIdentifier &CellID, int gain, int tbin=0, int mode=0) const override
c-struct reproducing the structure of the persistent data
Definition LArShapeP2.h:21
bool isEmpty() const