ATLAS Offline Software
LArOFCSubsetCnv_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  LArOFCTransType* transObj,
11  MsgStream & log) const
12 {
13  // Copy basic metadata
14  transObj->setChannel (persObj->m_subset.m_channel);
15  transObj->setGroupingType (persObj->m_subset.m_groupingType);
16 
17  transObj->initialize (persObj->m_subset.m_febIds, persObj->m_subset.m_gain);
18 
19  // Copy conditions
20  unsigned int nfebids = persObj->m_subset.m_febIds.size();
21  const unsigned int nChannelsPerFeb = persObj->m_subset.subsetSize();
22  unsigned int nPhases = persObj->m_nPhases;
23  unsigned int nSamples = persObj->m_nSamples;
24  unsigned int dataIndex = 0;
25  unsigned int timeIndex = 0;
26 
27  // Loop over febs
28  unsigned int ifebWithData = 0; // counter for febs with data
29 
30  auto subsetIt = transObj->subsetBegin();
31  for (unsigned int i = 0; i < nfebids; ++i, ++subsetIt){
32  // Set febid
33  unsigned int febid = (*subsetIt).first;
34 
35  bool hasSparseData = false;
36  unsigned int chansSet = 0;
37  unsigned int chansOffset = 0;
38  if (ifebWithData < persObj->m_subset.m_febsWithSparseData.size() &&
39  febid == persObj->m_subset.m_febsWithSparseData[ifebWithData]) {
40  // Found feb with sparse data
41  hasSparseData = true;
42  ifebWithData++;
43  chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
44  chansOffset = 0;
45  ifebWithData++;
46  }
47 
48  // Loop over channels in feb - only some channels are filled
49  for (unsigned int j = 0; j < nChannelsPerFeb; ++j){
50 
51  bool copyChannel = true;
52  if (hasSparseData) {
53  if (!(chansSet & (1 << (j - chansOffset)))) {
54  // Channel is missing data - skip
55  copyChannel = false;
56  }
57  if (j%32 == 31 && j < nChannelsPerFeb-2) {
58  chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
59  chansOffset += 32;
60  ifebWithData++;
61  }
62  }
63  if (copyChannel) {
64 
65  // Channel has ofcs - loop over ofcs per channel and
66  // copy to the persistent object
67 
68  // check indexes
69  if (dataIndex >= persObj->m_vOFC_a.size() ||
70  dataIndex >= persObj->m_vOFC_b.size() ||
71  timeIndex >= persObj->m_timeOffset.size() ||
72  timeIndex >= persObj->m_timeBinWidth.size()) {
73  log << MSG::ERROR
74  << "LArOFCSubsetCnv_p1::persToTrans - ofc index too large: dataIndex size ofc_a, size ofc_b, timeIndex timeOffset size, timeBinWidth size "
75  << dataIndex << " " << persObj->m_vOFC_a.size() << " "
76  << persObj->m_vOFC_b.size() << " " << timeIndex << " "
77  << persObj->m_timeOffset.size() << " "
78  << persObj->m_timeBinWidth.size()
79  << endmsg;
80  return;
81  }
82 
84  (*subsetIt).second[j];
85  LArOFCP1 tmp (persObj->m_timeOffset[timeIndex],
86  persObj->m_timeBinWidth[timeIndex],
87  nPhases,
88  nSamples,
89  persObj->m_vOFC_a,
90  persObj->m_vOFC_b,
91  dataIndex);
92  ofcs.assign (tmp);
93  ++timeIndex;
94  dataIndex += nPhases * nSamples;
95  }
96  }
97  }
98 
99  // Copy corrections
100  unsigned int ncorrs = persObj->m_subset.m_corrChannels.size();
102 
103  if (ncorrs) {
104  // corrs exist - resize vector
105  std::vector<float> vSamples(nSamples, 0.0);
106  std::vector<std::vector<float> > vOFC(nPhases, vSamples);
107  LArOFCP1 larOFCP1(0.0, 0.0, vOFC, vOFC);
108 
109  corrs.resize(ncorrs, LArOFCTransType::CorrectionPair(0, larOFCP1));
110  }
111 
112  // Loop over corrections
113  for (unsigned int i = 0; i < ncorrs; ++i){
114  // check indexes
115  if (dataIndex >= persObj->m_vOFC_a.size() ||
116  dataIndex >= persObj->m_vOFC_b.size() ||
117  timeIndex >= persObj->m_timeOffset.size() ||
118  timeIndex >= persObj->m_timeBinWidth.size()) {
119  log << MSG::ERROR
120  << "LArOFCSubsetCnv_p1::persToTrans - ofc index too large: dataIndex size ofc_a, size ofc_b, timeIndex timeOffset size, timeBinWidth size "
121  << dataIndex << " " << persObj->m_vOFC_a.size() << " "
122  << persObj->m_vOFC_b.size() << " " << timeIndex << " "
123  << persObj->m_timeOffset.size() << " "
124  << persObj->m_timeBinWidth.size()
125  << endmsg;
126  return;
127  }
128 
129  // copy channel id
130  corrs[i].first = persObj->m_subset.m_corrChannels[i];
131 
132  LArOFCP1& ofcs = corrs[i].second;
133  LArOFCP1 tmp (persObj->m_timeOffset[timeIndex],
134  persObj->m_timeBinWidth[timeIndex],
135  nPhases,
136  nSamples,
137  persObj->m_vOFC_a,
138  persObj->m_vOFC_b,
139  dataIndex);
140  ofcs.setFrom (tmp);
141  ++timeIndex;
142  dataIndex += nPhases * nSamples;
143  }
144  transObj->insertCorrections (std::move (corrs));
145 
146  transObj->shrink_to_fit();
147 }
148 
149 
150 void
152  LArOFCPersType* persObj,
153  MsgStream &log) const
154 {
155  // Copy conditions
156 
157  // We copy all ofcs into a few simple vectors.
158  // For the conditions, there are two situations to treat:
159  // 1) dense data: normal conditions where each feb has 128
160  // channels and all channels have data,
161  // 2) sparse data: conditions data where some channels are
162  // missing data. This is true for MC conditions (only some
163  // channels have data, and symmetry is used to obtain
164  // conditions for the rest of the channels), as well for
165  // 'normal' conditions it may happen that some channels may
166  // be missing data.
167  //
168  // Treating 1) is straight-forward. For 2) we need to keep track
169  // of which channels are present. We do so with
170  // m_subset.m_febsWithSparseData where we store the febid followed by
171  // four unsigned ints which contain the full bit pattern of the
172  // channels set (i.e. bits 0-127).
173  //
174  // Note that one may also have a subset with all channels missing
175  // data. In this case, we do not write out the empty subset.
176  //
177  // Finally, for corrections, we save the channel ids in
178  // m_subset.m_corrChannels and the ofcs in the same vectors as the
179  // rest of the conditions data.
180  //
181  // For each channel with data, the number of ofcs is assumed
182  // constant. This is calculated at the beginning, along with
183  // whether a feb is sparse or not.
184  //
185 
186  // Get the number of channels, corrections and the size of ofc vectors
187  unsigned int nsubsetsNotEmpty = 0;
188  unsigned int ncorrs = transObj->correctionVecSize();
189  const unsigned int nChannelsPerFeb = transObj->channelVectorSize();
190  unsigned int nchans = 0;
191  unsigned int nPhases = 0;
192  unsigned int nSamples = 0;
193  bool foundOFCs = false;
194  std::vector<unsigned int> febsWithSparseData;
195 
196  // Find the number of ofcs and check for sparse conditions,
197  // e.g. MC conditions
198  const auto subsetEnd = transObj->subsetEnd();
199  for (auto subsetIt = transObj->subsetBegin();
200  subsetIt != subsetEnd;
201  ++subsetIt)
202  {
203  unsigned int nfebChans = (*subsetIt).second.size();
204 
205  if (nfebChans != 0 && nfebChans != nChannelsPerFeb) {
206  log << MSG::ERROR
207  << "LArOFCSubsetCnv_p1::transToPers - found incorrect number of channels per feb: " << nfebChans
208  << endmsg;
209  return;
210  }
211  if (nfebChans) ++nsubsetsNotEmpty; // count number of non-empty subsets
212 
213  // Loop over channels and check if this subset has sparse data
214  bool subsetIsSparse = false;
215  for (unsigned int j = 0; j < nfebChans; ++j) {
217  (*subsetIt).second[j];
218  if (ofc.OFC_aSize() == 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 (!foundOFCs) {
228  // Save the number of phases and samples for each
229  // ofc from first channels present
230  nPhases = ofc.OFC_aSize();
231  nSamples = ofc.OFC_a(0).size();
232  foundOFCs = true;
233  }
234  }
235  }
236  }
237  if (!foundOFCs && ncorrs>0) {
238  // Save the number of phases and samples for each ofc from
239  // first correction - couldn't find it from channels
240  const LArOFCP1& ofc = transObj->correctionVecBegin()->second;
241  nPhases = ofc.OFC_aSize();
242  nSamples = ofc.OFC_a(0).size();
243  }
244 
245  // Save sizes
246  persObj->m_nPhases = nPhases;
247  persObj->m_nSamples = nSamples;
248 
249  // Reserve space in vectors
250  persObj->m_subset.m_febIds.reserve(nsubsetsNotEmpty);
251  persObj->m_subset.m_corrChannels.reserve(ncorrs);
252  unsigned int ndataTot = (nchans + ncorrs)*nPhases*nSamples;
253  unsigned int nTime = (nchans + ncorrs);
254  persObj->m_vOFC_a.reserve(ndataTot);
255  persObj->m_vOFC_b.reserve(ndataTot);
256  persObj->m_timeOffset.reserve(nTime);
257  persObj->m_timeBinWidth.reserve(nTime);
258 
259  // For subsets with sparse data, reserve space for identifying
260  // channels written out:
261  // 1 - febid
262  // 4 - for 128 bits (4*32)
263  if (febsWithSparseData.size())
264  persObj->m_subset.m_febsWithSparseData.reserve(febsWithSparseData.size()*5);
265 
266  // Copy conditions in subset
267  unsigned int isparse = 0;
268  for (auto subsetIt = transObj->subsetBegin();
269  subsetIt != subsetEnd;
270  ++subsetIt)
271  {
272  unsigned int nfebChans = (*subsetIt).second.size();
273 
274  // skip subsets without any channels
275  if (nfebChans == 0) continue;
276 
277  unsigned int febid = (*subsetIt).first;
278  persObj->m_subset.m_febIds.push_back(febid);
279 
280 
281  bool isSparse = false;
282  if (isparse < febsWithSparseData.size() &&
283  febsWithSparseData[isparse] == febid) {
284  // sparse subset, save channels with data
285  isparse++;
286  isSparse = true;
287  // save febid
288  persObj->m_subset.m_febsWithSparseData.push_back(febid);
289  }
290 
291  // Now loop over channels and save ofc and times
292  unsigned int chansSet = 0;
293  unsigned int chansOffset = 0;
294  for (unsigned int j = 0; j < nfebChans; ++j){
295 
296  bool saveOFCs = true;
297  if (isSparse) {
298  // subset with sparse data
299  if ((*subsetIt).second[j].OFC_aSize() > 0) {
300  // store the channel number in bit map
301  assert (j >= chansOffset && (j - chansOffset) <= 31);
302  chansSet |= (1 << (j - chansOffset));
303  }
304  else {
305  saveOFCs = false;
306  }
307  // Save chansSet
308  if (j == (chansOffset + 31) || j == nfebChans-1) {
309  persObj->m_subset.m_febsWithSparseData.push_back(chansSet);
310  chansSet = 0;
311  chansOffset += 32;
312  }
313  }
314  if (saveOFCs) {
315  bool tooSmall=false;
316  // Loop over phases and samples per channel
317  for (unsigned int k = 0; k < nPhases; ++k) {
318  for (unsigned int l = 0; l < nSamples; ++l) {
319  //check if data object is big enough
320  if (k >= (*subsetIt).second[j].OFC_aSize() ||
321  l >= (*subsetIt).second[j].OFC_a(k).size())
322  {
323  tooSmall=true;
324  persObj->m_vOFC_a.push_back(0.);
325  persObj->m_vOFC_b.push_back(0.);
326  }
327  else {
328  persObj->m_vOFC_a.push_back((*subsetIt).second[j].OFC_a(k)[l]);
329  persObj->m_vOFC_b.push_back((*subsetIt).second[j].OFC_b(k)[l]);
330 // std::cout << "WL Data: FEB=" << std::hex << febid << std::dec << " [" << i << "] Channel="
331 // << j << " Phase="<< k<< " Sample " << l << " OFC="
332 // << (*subsetIt).second[j].m_vOFC_a[k][l] << std::endl;
333  }
334  }
335  }
336  // set time offset and binwidth
337  persObj->m_timeOffset.push_back((*subsetIt).second[j].timeOffset());
338  persObj->m_timeBinWidth.push_back((*subsetIt).second[j].timeBinWidth());
339  if (tooSmall)
340  log << MSG::ERROR << "Feb 0x" << std::hex << febid << std::dec << " channel " << j <<": OFC object too small. Expected "
341  << nPhases << " phases and " << nSamples << " samples. Padded with 0.0" << endmsg;
342 
343  }// end if saveOFC
344 
345 // static unsigned int nch = 0;
346 // ++nch;
347 // std::cout << "transToPers - i, j, save " << i << " " << j << " "
348 // << saveOFCs << " " << nch << " febid " << febid
349 // << " chansSet " << std::hex << chansSet << std::dec
350 // << " chansOffset " << chansOffset
351 // << std::endl;
352 
353  }
354  }
355 
356  // Copy corrections
357  const auto corrEnd = transObj->correctionVecEnd();
358  for (auto corrIt = transObj->correctionVecBegin();
359  corrIt != corrEnd;
360  ++corrIt)
361  {
362  persObj->m_subset.m_corrChannels.push_back(corrIt->first);
363  // OFCs
364  bool tooSmall=false;
365  // Loop over phases and samples per channel
366  for (unsigned int k = 0; k < nPhases; ++k) {
367  for (unsigned int l = 0; l < nSamples; ++l) {
368  //check if data object is big enough
369  if (k >= corrIt->second.OFC_aSize() ||
370  l >= corrIt->second.OFC_a(k).size())
371  {
372  tooSmall=true;
373  persObj->m_vOFC_a.push_back(0.);
374  persObj->m_vOFC_b.push_back(0.);
375  }
376  else {
377  persObj->m_vOFC_a.push_back(corrIt->second.OFC_a(k)[l]);
378  persObj->m_vOFC_b.push_back(corrIt->second.OFC_b(k)[l]);
379  }
380  }
381  }
382  // set time offset and binwidth
383  persObj->m_timeOffset.push_back(corrIt->second.timeOffset());
384  persObj->m_timeBinWidth.push_back(corrIt->second.timeBinWidth());
385  if (tooSmall)
386  log << MSG::ERROR << "Correction (channel 0x" << std::hex << corrIt->first << std::dec <<
387  "): OFC object too small. Expected " << nPhases << " phases and " << nSamples << " samples. Padded with 0.0" << endmsg;
388  }
389 
390  // Copy the rest
391  persObj->m_subset.m_gain = transObj->gain();
392  persObj->m_subset.m_channel = transObj->channel();
393  persObj->m_subset.m_groupingType = transObj->groupingType();
394 
395 }
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
LArOFCSubset_p1::m_timeOffset
std::vector< float > m_timeOffset
Definition: LArOFCSubset_p1.h:38
LArOFCP1
c-struct reproducing the structure of the persistent data
Definition: LArOFCP1.h:22
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
LArOFCSubset_p1::m_nPhases
unsigned int m_nPhases
Definition: LArOFCSubset_p1.h:40
LArOFCSubset_p1::m_subset
LArConditionsSubset_p1 m_subset
Definition: LArOFCSubset_p1.h:35
LArConditionsSubset::channelVectorSize
unsigned channelVectorSize() const
Definition: LArConditionsSubset.h:608
LAr2DWaveBase::setFrom
void setFrom(LAr2DWaveBase &other)
Assign from another wave object.
Definition: LAr2DWaveBase.cxx:109
LArOFCSubsetCnv_p1::persToTrans
virtual void persToTrans(const LArOFCPersType *persObj, LArOFCTransType *transObj, MsgStream &log) const override
Definition: LArOFCSubsetCnv_p1.cxx:9
LArConditionsSubset_p1::subsetSize
unsigned int subsetSize() const
Definition: LArConditionsSubset_p1.h:82
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
LArConditionsSubset::shrink_to_fit
void shrink_to_fit()
Reallocate to match size actually used.
Definition: LArConditionsSubset.h:550
LArConditionsSubset_p1::m_gain
unsigned int m_gain
Definition: LArConditionsSubset_p1.h:78
LArConditionsSubset::correctionVecEnd
ConstCorrectionVecIt correctionVecEnd() const
Definition: LArConditionsSubset.h:472
LArOFCSubset_p1::m_vOFC_b
std::vector< float > m_vOFC_b
Definition: LArOFCSubset_p1.h:37
LArOFCSubset_p1::m_timeBinWidth
std::vector< float > m_timeBinWidth
Definition: LArOFCSubset_p1.h:39
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
LArOFCSubset_p1::m_vOFC_a
std::vector< float > m_vOFC_a
Definition: LArOFCSubset_p1.h:36
LArConditionsSubset::CorrectionVec
std::vector< CorrectionPair > CorrectionVec
Definition: LArConditionsSubset.h:144
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
LArConditionsSubset::setChannel
void setChannel(unsigned int channel)
set the COOL channel number
Definition: LArConditionsSubset.h:567
LArConditionsSubset::ConstReference
Traits::ConstReference ConstReference
Definition: LArConditionsSubset.h:136
LArOFCSubsetCnv_p1::transToPers
virtual void transToPers(const LArOFCTransType *transObj, LArOFCPersType *persObj, MsgStream &log) const override
Definition: LArOFCSubsetCnv_p1.cxx:151
LArOFCSubset_p1
persistent class container of LArConditionsSubset for LArOFC data.
Definition: LArOFCSubset_p1.h:30
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
LArConditionsSubset::gain
unsigned int gain() const
Access to gain.
Definition: LArConditionsSubset.h:490
LArOFCSubsetCnv_p1.h
LArConditionsSubset::correctionVecSize
size_type correctionVecSize() const
Size of channel set.
Definition: LArConditionsSubset.h:481
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArConditionsSubset::Reference
Traits::Reference Reference
Definition: LArConditionsSubset.h:135
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
LArConditionsSubset::subsetBegin
ConstSubsetIt subsetBegin() const
Iterators over subset.
Definition: LArConditionsSubset.h:412
LArOFCSubset_p1::m_nSamples
unsigned int m_nSamples
Definition: LArOFCSubset_p1.h:41
LArConditionsSubset::subsetEnd
ConstSubsetIt subsetEnd() const
Definition: LArConditionsSubset.h:420
ReadOfcFromCool.ofc
ofc
Definition: ReadOfcFromCool.py:110
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