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