ATLAS Offline Software
LArRampSubsetCnv_p1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
9 void
11  LArRampTransType* transObj,
12  MsgStream & log) const
13 {
14  // Copy basic metadata
15  transObj->setChannel (persObj->m_subset.m_channel);
16  transObj->setGroupingType (persObj->m_subset.m_groupingType);
17 
18  transObj->initialize (persObj->m_subset.m_febIds, persObj->m_subset.m_gain);
19 
20  // Copy conditions
21  unsigned int nfebids = persObj->m_subset.m_febIds.size();
22  unsigned int nRamps = persObj->m_vRampSize;
23  const unsigned int nChannelsPerFeb = persObj->m_subset.subsetSize();
24  unsigned int rampIndex = 0;
25 
26  // Loop over febs
27  unsigned int ifebWithData = 0; // counter for febs with data
28 
29  auto subsetIt = transObj->subsetBegin();
30  for (unsigned int i = 0; i < nfebids; ++i, ++subsetIt){
31  // Set febid
32  unsigned int febid = subsetIt->first;
33 
34  bool hasSparseData = false;
35  unsigned int chansSet = 0;
36  unsigned int chansOffset = 0;
37  if (ifebWithData+1 < persObj->m_subset.m_febsWithSparseData.size() &&
38  febid == persObj->m_subset.m_febsWithSparseData[ifebWithData]) {
39  // Found feb with sparse data
40  hasSparseData = true;
41  ifebWithData++;
42  chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
43  chansOffset = 0;
44  ifebWithData++;
45  }
46 
47  // Loop over channels in feb - only some channels are filled
48  for (unsigned int j = 0; j < nChannelsPerFeb; ++j){
49 
50  bool copyChannel = true;
51  if (hasSparseData) {
52  // coverity[bad_shift]
53  // coverity[integer_overflow]
54  if (!(chansSet & (1 << (j - chansOffset)))) {
55  // Channel is missing data - skip
56  copyChannel = false;
57  }
58  if (j%32 == 31 && j < nChannelsPerFeb-2) {
59  chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
60  chansOffset += 32;
61  ifebWithData++;
62  }
63  }
64  if (copyChannel) {
65 
66  // Channel has ramps - loop over ramps per channel
67  // and copy to the persistent object
68 
69  // check indexes
70  if (rampIndex + persObj->m_vRampSize > persObj->m_vRamp.size()) {
71  log << MSG::ERROR
72  << "LArRampSubsetCnv_p1::persToTrans - ramp index too large: ramp/size "
73  << rampIndex << " " << persObj->m_vRamp.size() << " "
74  << endmsg;
75  return;
76  }
77 
78  // This channel has ramps, resize vectors
79  subsetIt->second[j].m_vRamp.resize(nRamps);
80 
81  for (unsigned int k = 0; k < persObj->m_vRampSize; ++k){
82  subsetIt->second[j].m_vRamp[k] = persObj->m_vRamp[rampIndex];
83  rampIndex++;
84  }
85  }
86 
87 // static unsigned int nch1 = 0;
88 // ++nch1;
89 // std::cout << "persToTrans - i, j, copy " << i << " " << j << " "
90 // << copyChannel << " " << nch1
91 // << " hasSparseData " << hasSparseData
92 // << " chansSet, chansOffset, ifebWithData " << std::hex
93 // << chansSet << std::dec << " " << chansOffset << " " << ifebWithData
94 // << " febids " << febid << " "
95 // << sparseFebid
96 // << std::endl;
97 
98  }
99  }
100 
101  // Copy corrections
102  unsigned int ncorrs = persObj->m_subset.m_corrChannels.size();
104  if (ncorrs) {
105  // corrs exist - resize vector
106  std::vector<float> vRamp(nRamps,0.0);
107  LArRampP1 larRampP1(vRamp);
108 
109  corrs.resize(ncorrs, LArRampTransType::CorrectionPair(0, larRampP1));
110  }
111 
112  // Loop over corrections
113  for (unsigned int i = 0; i < ncorrs; ++i){
114  // check indexes
115  if (rampIndex + persObj->m_vRampSize > persObj->m_vRamp.size()) {
116  log << MSG::ERROR
117  << "LArRampSubsetCnv_p1::persToTrans - ramp index too large: ramp/size "
118  << rampIndex << " " << persObj->m_vRamp.size() << " "
119  << endmsg;
120  return;
121  }
122  corrs[i].first = persObj->m_subset.m_corrChannels[i];
123  // Loop over ramps per channel
124  for (unsigned int k = 0; k < persObj->m_vRampSize; ++k){
125  corrs[i].second.m_vRamp[k] = persObj->m_vRamp[rampIndex];
126  rampIndex++;
127  }
128  }
129  transObj->insertCorrections (std::move (corrs));
130 
131 }
132 
133 
134 
135 
136 void
138  LArRampPersType* persObj,
139  MsgStream &log) const
140 {
141  // Copy conditions
142 
143  // We copy all ramps into a single vector.
144  // For the conditions, there are two situations to treat:
145  // 1) dense data: normal conditions where each feb has 128
146  // channels and all channels have data,
147  // 2) sparse data: conditions data where some channels are
148  // missing data. This is true for MC conditions (only some
149  // channels have data, and symmetry is used to obtain
150  // conditions for the rest of the channels), as well for
151  // 'normal' conditions it may happen that some channels may
152  // be missing data.
153  //
154  // Treating 1) is straight-forward. For 2) we need to keep track
155  // of which channels are present. We do so with
156  // m_subset.m_febsWithSparseData where we store the febid followed by
157  // four unsigned ints which contain the full bit pattern of the
158  // channels set (i.e. bits 0-127).
159  //
160  // Note that one may also have a subset with all channels missing
161  // data. In this case, we do not write out the empty subset.
162  //
163  // Finally, for corrections, we save the channel ids in
164  // m_subset.m_corrChannels and the ramps in the same vectors as
165  // the rest of the conditions data.
166  //
167  // For each channel with data, the number of ramps is assumed
168  // constant. This is calculated at the beginning, along with
169  // whether a feb is sparse or not.
170  //
171 
172  // Get the number of channels, corrections and the size of ramp
173  unsigned int nsubsetsNotEmpty = 0;
174  unsigned int ncorrs = transObj->correctionVecSize();
175  const unsigned int nChannelsPerFeb = transObj->channelVectorSize();
176  unsigned int nchans = 0;
177  unsigned int nRamps = 0;
178  bool foundNRamps = false;
179  std::vector<unsigned int> febsWithSparseData;
180 
181  // Find the number of ramps and check for sparse conditions,
182  // e.g. MC conditions
183  const auto subsetEnd = transObj->subsetEnd();
184  for (auto subsetIt = transObj->subsetBegin();
185  subsetIt != subsetEnd;
186  ++subsetIt)
187  {
188  unsigned int nfebChans = subsetIt->second.size();
189 
190  if (nfebChans != 0 && nfebChans != nChannelsPerFeb) {
191  log << MSG::ERROR
192  << "LArRampSubsetCnv_p1::transToPers - found incorrect number of channels per feb: " << nfebChans
193  << endmsg;
194  return;
195  }
196  if (nfebChans) ++nsubsetsNotEmpty; // count number of non-empty subsets
197 
198  // Loop over channels and check if this subset has sparse data
199  bool subsetIsSparse = false;
200  for (unsigned int j = 0; j < nfebChans; ++j) {
201  const LArRampP1& ramp = subsetIt->second[j];
202  if (ramp.m_vRamp.size() == 0) {
203  if (!subsetIsSparse) {
204  // save febids for sparse subsets
205  subsetIsSparse = true;
206  febsWithSparseData.push_back(subsetIt->first);
207  }
208  }
209  else {
210  nchans++; // count number of channels
211  if (!foundNRamps) {
212  // Save the number of ramps and derivatives from first channels present
213  nRamps = ramp.m_vRamp.size();
214  foundNRamps = true;
215  }
216  }
217  }
218  }
219  if (!foundNRamps && ncorrs>0) {
220  // Save the number of ramps and derivatives from first
221  // correct - couldn't find it from channels
222  const LArRampP1& ramp = transObj->correctionVecBegin()->second;
223  nRamps = ramp.m_vRamp.size();
224  }
225 
226 
227  // Save sizes
228  persObj->m_vRampSize = nRamps;
229 
230  // Reserve space in vectors
231  persObj->m_subset.m_febIds.reserve(nsubsetsNotEmpty);
232  persObj->m_subset.m_corrChannels.reserve(ncorrs);
233  unsigned int nRampsTot = (nchans + ncorrs)*nRamps;
234  persObj->m_vRamp.reserve(nRampsTot);
235 
236  // For subsets with sparse data, reserve space for identifying
237  // channels written out:
238  // 1 - febid
239  // 4 - for 128 bits (4*32)
240  if (febsWithSparseData.size())
241  persObj->m_subset.m_febsWithSparseData.reserve(febsWithSparseData.size()*5);
242 
243  // Copy conditions in subset
244  unsigned int isparse = 0;
245  for (auto subsetIt = transObj->subsetBegin();
246  subsetIt != subsetEnd;
247  ++subsetIt)
248  {
249  unsigned int nfebChans = subsetIt->second.size();
250 
251  // skip subsets without any channels
252  if (nfebChans == 0) continue;
253 
254  unsigned int febid = subsetIt->first;
255  persObj->m_subset.m_febIds.push_back(febid);
256 
257 
258  bool isSparse = false;
259  if (isparse < febsWithSparseData.size() &&
260  febsWithSparseData[isparse] == febid) {
261  // sparse subset, save channels with data
262  isparse++;
263  isSparse = true;
264  // save febid
265  persObj->m_subset.m_febsWithSparseData.push_back(febid);
266  }
267 
268  // Now loop over channels and save ramps and channel number
269  unsigned int chansSet = 0;
270  unsigned int chansOffset = 0;
271  for (unsigned int j = 0; j < nfebChans; ++j){
272 
273  bool saveRamps = true;
274  if (isSparse) {
275  // subset with sparse data
276 
277  if (subsetIt->second[j].m_vRamp.size() > 0) {
278  // store the channel number in bit map
279  assert (j >= chansOffset && (j - chansOffset) <= 31);
280  // coverity[integer_overflow]
281  chansSet |= (1 << (j - chansOffset));
282  }
283  else {
284  saveRamps = false;
285  }
286  // Save chansSet
287  if (j == (chansOffset + 31) || j == nfebChans-1 ) {
288  persObj->m_subset.m_febsWithSparseData.push_back(chansSet);
289  chansSet = 0;
290  chansOffset += 32;
291  }
292  }
293  if (saveRamps) {
294  // save ramps
295  bool tooSmall=false;
296  for (unsigned int k = 0; k < nRamps; ++k){
297  if (k>=subsetIt->second[j].m_vRamp.size()) {
298  tooSmall=true;
299  persObj->m_vRamp.push_back(0.0);
300  }
301  else
302  persObj->m_vRamp.push_back(subsetIt->second[j].m_vRamp[k]);
303  }
304  if (tooSmall)
305  log << MSG::ERROR << "Feb 0x" << std::hex << febid << std::dec << " channel " << j <<": Ramp object too small. Expected a polynom of degree "
306  << nRamps << ". Padded with 0.0" << endmsg;
307  }
308 
309 // static unsigned int nch = 0;
310 // ++nch;
311 // std::cout << "transToPers - i, j, save " << i << " " << j << " "
312 // << saveRamps << " " << nch << " febid " << febid
313 // << " chansSet " << std::hex << chansSet << std::dec
314 // << " chansOffset " << chansOffset
315 // << std::endl;
316 
317  }
318  }
319 
320  // Copy corrections
321  const auto corrEnd = transObj->correctionVecEnd();
322  for (auto corrIt = transObj->correctionVecBegin();
323  corrIt != corrEnd;
324  ++corrIt)
325  {
326  // Save channel id in febid vector
327  bool tooSmall=false;
328  persObj->m_subset.m_corrChannels.push_back(corrIt->first);
329  // Ramps
330  for (unsigned int k = 0; k < nRamps; ++k){
331  if (k>=corrIt->second.m_vRamp.size()) {
332  tooSmall=true;
333  persObj->m_vRamp.push_back(0.0);
334  }
335  else
336  persObj->m_vRamp.push_back(corrIt->second.m_vRamp[k]);
337  }
338  if (tooSmall)
339  log << MSG::ERROR << "Correction (channel 0x" << std::hex << corrIt->first << std::dec <<
340  "): Ramp object too small. Expected a polynom of degree " << nRamps << ". Padded with 0.0" << endmsg;
341  }
342 
343  // Copy the rest
344  persObj->m_subset.m_gain = transObj->gain();
345  persObj->m_subset.m_channel = transObj->channel();
346  persObj->m_subset.m_groupingType = transObj->groupingType();
347 }
LArConditionsSubset::setGroupingType
void setGroupingType(unsigned int type)
set the type of grouping - defined in LArConditionsContainerBase.h
Definition: LArConditionsSubset.h:575
LArConditionsSubset_p1::m_channel
unsigned int m_channel
Definition: LArConditionsSubset_p1.h:79
LArConditionsSubset_p1::m_corrChannels
std::vector< unsigned int > m_corrChannels
Definition: LArConditionsSubset_p1.h:76
LArConditionsSubset_p1::m_febsWithSparseData
std::vector< unsigned int > m_febsWithSparseData
Definition: LArConditionsSubset_p1.h:77
LArRampSubsetCnv_p1::transToPers
virtual void transToPers(const LArRampTransType *transObj, LArRampPersType *persObj, MsgStream &log) const override
Definition: LArRampSubsetCnv_p1.cxx:137
LArRampP1
Persistent data for LArRamp Copied from LAr.
Definition: LArRampP1.h:24
LArRampSubset_p1::m_vRampSize
unsigned int m_vRampSize
Definition: LArRampSubset_p1.h:37
LArConditionsSubset::channelVectorSize
unsigned channelVectorSize() const
Definition: LArConditionsSubset.h:608
LArConditionsSubset_p1::subsetSize
unsigned int subsetSize() const
Definition: LArConditionsSubset_p1.h:82
LArRampSubset_p1::m_subset
LArConditionsSubset_p1 m_subset
Definition: LArRampSubset_p1.h:35
LArConditionsSubset_p1::m_gain
unsigned int m_gain
Definition: LArConditionsSubset_p1.h:78
LArRampSubset_p1::m_vRamp
std::vector< float > m_vRamp
Definition: LArRampSubset_p1.h:36
LArConditionsSubset::correctionVecEnd
ConstCorrectionVecIt correctionVecEnd() const
Definition: LArConditionsSubset.h:472
LArRampP1::m_vRamp
std::vector< float > m_vRamp
Definition: LArRampP1.h:30
LArConditionsSubset_p1::m_febIds
std::vector< unsigned int > m_febIds
Definition: LArConditionsSubset_p1.h:75
LArConditionsSubset::initialize
void initialize(const std::vector< FebId > &ids, unsigned int gain)
Initialize with set of FEB ids.
Definition: LArConditionsSubset.h:529
LArConditionsSubset::CorrectionVec
std::vector< CorrectionPair > CorrectionVec
Definition: LArConditionsSubset.h:144
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArConditionsSubset_p1::m_groupingType
unsigned int m_groupingType
Definition: LArConditionsSubset_p1.h:80
LArConditionsSubset::channel
unsigned int channel() const
Access to the COOL channel number.
Definition: LArConditionsSubset.h:498
LArConditionsSubset::setChannel
void setChannel(unsigned int channel)
set the COOL channel number
Definition: LArConditionsSubset.h:567
LArConditionsSubset
template class for use for I/O of conditions data
Definition: LArConditionsSubset.h:122
LArConditionsSubset.h
This file defines the template class used for I/O of conditions data.
LArConditionsSubset::CorrectionPair
std::pair< ChannelId, T > CorrectionPair
Definition: LArConditionsSubset.h:143
LArRampSubsetCnv_p1.h
LArRampSubset_p1
persistent class container of LArConditionsSubset for LArRamp data.
Definition: LArRampSubset_p1.h:30
LArConditionsSubset::gain
unsigned int gain() const
Access to gain.
Definition: LArConditionsSubset.h:490
LArConditionsSubset::correctionVecSize
size_type correctionVecSize() const
Size of channel set.
Definition: LArConditionsSubset.h:481
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArConditionsSubset::subsetBegin
ConstSubsetIt subsetBegin() const
Iterators over subset.
Definition: LArConditionsSubset.h:412
LArConditionsSubset::subsetEnd
ConstSubsetIt subsetEnd() const
Definition: LArConditionsSubset.h:420
LArRampSubsetCnv_p1::persToTrans
virtual void persToTrans(const LArRampPersType *persObj, LArRampTransType *transObj, MsgStream &log) const override
Definition: LArRampSubsetCnv_p1.cxx:10
LArConditionsSubset::correctionVecBegin
ConstCorrectionVecIt correctionVecBegin() const
Iterators over channel set.
Definition: LArConditionsSubset.h:465
LArConditionsSubset::insertCorrections
void insertCorrections(CorrectionVec &&corrs)
Insert a group of corrections.
Definition: LArConditionsSubset.h:593
fitman.k
k
Definition: fitman.py:528
LArConditionsSubset::groupingType
unsigned int groupingType() const
Type of grouping - defined in LArConditionsContainerBase.h.
Definition: LArConditionsSubset.h:507