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