ATLAS Offline Software
LArCaliWaveSubsetCnv_p3.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 
9 void
10 LArCaliWaveSubsetCnv_p3::persToTrans(const LArCaliWaveSubset_p3* persObj, LArCWTransType* transObj, MsgStream & log) const
11 {
12  log<<MSG::DEBUG<<"LArCaliWaveSubsetCNV_p3 begin persToTrans"<<endmsg;
13 
14  // Copy basic metadata
15  transObj->setChannel (persObj->m_subset.m_channel);
16  transObj->setGroupingType (persObj->m_subset.m_groupingType);
17  transObj->initialize (persObj->m_subset.m_febIds, persObj->m_subset.m_gain);
18  unsigned int nfebids = persObj->m_subset.m_febIds.size();
19  log<<MSG::DEBUG<<"Total febs:"<<nfebids;
20  unsigned int ncorrs = persObj->m_subset.m_corrChannels.size();
21  log<<MSG::DEBUG<<"\tCorrections:"<<ncorrs<<endmsg;
22  const unsigned int nChannelsPerFeb = persObj->m_subset.subsetSize();
23  unsigned int cwvIndex=0, waveIndex=0, chIndex = 0;
24 
25  unsigned int ifebWithData = 0; // counter for febs with data
26 
27  auto subsetIt = transObj->subsetBegin();
28  for (unsigned int i = 0; i < nfebids; ++i, ++subsetIt){
29  unsigned int febid = subsetIt->first;
30  log<<MSG::DEBUG<<"feb index: "<<i<<"\tfebID: "<<febid;
31 
32  bool hasSparseData = false;
33  unsigned int chansSet = 0;
34  unsigned int chansOffset = 0;
35 
36  if (ifebWithData < persObj->m_subset.m_febsWithSparseData.size() && febid == persObj->m_subset.m_febsWithSparseData[ifebWithData]) {
37  hasSparseData = true;// Found feb with sparse data
38  ifebWithData++;
39  chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
40  chansOffset = 0;
41  ifebWithData++;
42  }
43 
44  log<<MSG::DEBUG<<"\tFeb sparse? "<< hasSparseData <<endmsg;
45 
46  for (unsigned int j = 0; j < nChannelsPerFeb; ++j){
47  bool copyChannel = true;
48  if (hasSparseData) {
49  if (!(chansSet & (1 << (j - chansOffset)))) { // 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 
59  if (copyChannel) { // This channel has wave, resize vectors
60  LArCaliWaveVec& CWV = subsetIt->second[j];
61 
62  unsigned int nDAC=persObj->m_vDAC[cwvIndex];
63  cwvIndex++;
64  for (unsigned int nD=0;nD<nDAC;nD++){
65  double time =persObj->m_dt[chIndex];
66  unsigned int f =persObj->m_flag[chIndex];
67  int dac =persObj->m_DAC[chIndex];
68  int pulsed =persObj->m_isPulsed[chIndex];
69  chIndex++;
70 
71  std::vector<double> val, err;
72  std::vector<int> tri;
73 
74  for (unsigned int k = 0; k < persObj->m_samples; ++k){
75  val.push_back(persObj->m_vAmplitudes[waveIndex]);
76  err.push_back(persObj->m_vErrors[waveIndex]);
77  tri.push_back(persObj->m_vTriggers[waveIndex]);
78  waveIndex++;
79  }
80 
81  LArCaliWave cv(val,err,tri, time,dac, pulsed, f);
82  val.clear();
83  err.clear();
84  tri.clear();
85 
86  CWV.push_back(cv);
87  }
88  }
89  } // loop on channels
90  } // loop on FEBs
91 
92 
93  log<<MSG::DEBUG << "Correction reading, ncorr:" << ncorrs << "\twaveIndex=" << waveIndex << "\tsize:" << persObj->m_vAmplitudes.size()<<endmsg;
95  corrs.resize(ncorrs);
96 
97  // Loop over corrections
98  for (unsigned int i = 0; i < ncorrs; ++i){
99  if (cwvIndex >= persObj->m_vDAC.size()) {// check indexes
100  log << MSG::ERROR
101  << "LArCaliWaveSubsetCnv_p3::persToTrans - CaliWave index too large: cwvIndex/sizeInFile "
102  << cwvIndex << " " << persObj->m_vDAC.size() << " " << endmsg;
103  return;
104  }
105 
106 
107  corrs[i].first = persObj->m_subset.m_corrChannels[i];
108 
109  LArCaliWaveVec& CWV = corrs[i].second;
110 
111  unsigned int nDAC=persObj->m_vDAC[cwvIndex];
112  cwvIndex++;
113  for (unsigned int nD=0;nD<nDAC;nD++){
114  if (chIndex >= persObj->m_dt.size()) {// check indexes
115  log << MSG::ERROR
116  << "LArCaliWaveSubsetCnv_p3::persToTrans - CaliWave index too large: WaveIndex/sizeInFile "
117  << chIndex << " " << persObj->m_dt.size() << " " << endmsg;
118  return;
119  }
120 
121  double time = persObj->m_dt[chIndex];
122  unsigned int f = persObj->m_flag[chIndex];
123  int dac = persObj->m_DAC[chIndex];
124  int pulsed = persObj->m_isPulsed[chIndex];
125  chIndex++;
126  std::vector<double> val, err;
127  std::vector<int> tri;
128  for (unsigned int k = 0; k < persObj->m_samples; ++k){
129 
130  if (waveIndex>=persObj->m_vAmplitudes.size())
131  log << MSG::ERROR << "Persistent LArCaliWave object is inconsistent. i=" << i << " WaveIndes="
132  << waveIndex << " size=" << persObj->m_vAmplitudes.size() << "samples=" << persObj->m_samples <<endmsg;
133 
134  val.push_back(persObj->m_vAmplitudes[waveIndex]);
135  err.push_back(persObj->m_vErrors[waveIndex]);
136  tri.push_back(persObj->m_vTriggers[waveIndex]);
137  waveIndex++;
138  }
139 
140  LArCaliWave cv(val,err,tri, time,dac, pulsed, f);
141  val.clear();
142  err.clear();
143  tri.clear();
144 
145  CWV.push_back(cv);
146 
147  }// over DAC values
148  }//over corrections
149  transObj->insertCorrections (std::move (corrs));
150 
151 
152  log<< MSG::DEBUG <<"CaliWave ver p2 successfully read in."<<endmsg;
153 }
154 
155 
156 
157 
158 
159 
160 void
162 {
163  log<<MSG::DEBUG<<" LArCaliWaveSubsetCNV_p3 begin Writing"<<endmsg;
164 
165  unsigned int nfebs = transObj->subsetSize();
166  log<<MSG::DEBUG<<"total febs:"<<nfebs;
167  unsigned int ncorrs = transObj->correctionVecSize();
168  log<<MSG::DEBUG<<"\tCorrections: "<<ncorrs<<endmsg;
169  const unsigned int nChannelsPerFeb = transObj->channelVectorSize();
170 
171  unsigned int nsubsetsNotEmpty = 0;
172  unsigned int nchans = 0;
173 
174  persObj->m_samples=0;
175 
176  std::vector<unsigned int> febsWithSparseData; // collects IDs of febs with sparse data
177 
178  const auto subsetEnd = transObj->subsetEnd();
179  for (auto subsetIt = transObj->subsetBegin();
180  subsetIt != subsetEnd;
181  ++subsetIt)
182  {
183  unsigned int nfebChans = subsetIt->second.size();
184 
185  if (nfebChans != 0 && nfebChans != nChannelsPerFeb) {
186  log << MSG::ERROR << "LArCaliWaveSubsetCnv_p3::transToPers - found incorrect number of channels per feb: " << nfebChans<< endmsg;
187  return;
188  }
189 
190  if (nfebChans) ++nsubsetsNotEmpty; // count number of non-empty FEBS
191 
192  bool isSparse = false;
193  for (unsigned int j = 0; j < nfebChans; ++j) { // Loop over channels and check if this subset has sparse data
194 
195  const LArCaliWaveVec& CWV = subsetIt->second[j];
196 
197  if (!isSparse && CWV.size() == 0) {
198  isSparse = true;
199  febsWithSparseData.push_back(subsetIt->first);// save febids for sparse subsets
200  }
201 
202  if (CWV.size()){ // should be like this no?
203  //else {
204  nchans++; // count number of channels
205  persObj->m_samples=CWV[0].getSize(); // completely ineficient but fast to fix :-(
206  }
207 
208  }
209 
210  } // loop over febs
211 
212  persObj->m_subset.m_febIds.reserve(nsubsetsNotEmpty);
213 
214  persObj->m_subset.m_corrChannels.reserve(ncorrs);
215 
216  if (febsWithSparseData.size())
217  persObj->m_subset.m_febsWithSparseData.reserve(febsWithSparseData.size()*5); // this stores FEBID + 128 bitmask of existing channels
218 
219  persObj->m_dt.reserve(nchans);
220  persObj->m_vAmplitudes.reserve(nchans*persObj->m_samples);
221  persObj->m_vErrors.reserve(nchans*persObj->m_samples);
222  persObj->m_vTriggers.reserve(nchans*persObj->m_samples);
223  persObj->m_flag.reserve(nchans);
224 
225  int counterSparse=0;
226  for (auto subsetIt = transObj->subsetBegin();
227  subsetIt != subsetEnd;
228  ++subsetIt)
229  {
230  unsigned int nfebChans = subsetIt->second.size();
231 
232  if (nfebChans == 0) continue; // skip subsets without any channels
233 
234  unsigned int febid = subsetIt->first;
235  persObj->m_subset.m_febIds.push_back(febid); // stores FEBID's of nonempty FEBs
236 
237  bool isSparse=false; // this is just to avoid search loop
238  if (counterSparse < (int)febsWithSparseData.size() && febid == febsWithSparseData[counterSparse]){
239  counterSparse++;
240  isSparse=true;
241  persObj->m_subset.m_febsWithSparseData.push_back(febid);
242  }
243 
244  unsigned int chansSet = 0;
245  unsigned int chansOffset = 0;
246  for (unsigned int j = 0; j < nfebChans; ++j){
247 
248  bool saveAmplitudes=true;
249  if (isSparse) { // subset with sparse data
250 
251  if (subsetIt->second[j].size() > 0) { // channel exists
252 
253  assert (j >= chansOffset && (j - chansOffset) <= 31);
254  chansSet |= (1 << (j - chansOffset)); //store the channel number in the bit map
255 
256  }
257  else { // channel does not exist
258  saveAmplitudes = false;
259  }
260 
261  // Save chansSet
262  if (j == (chansOffset + 31) || j == nfebChans-1 ) {
263  persObj->m_subset.m_febsWithSparseData.push_back(chansSet);
264  chansSet = 0;
265  chansOffset += 32;
266  }
267  } // if sparse
268 
269  if (saveAmplitudes) { // save amplitudes, errors and triggers
270  const LArCaliWaveVec& CWV = subsetIt->second[j];
271  int dacValues=CWV.size();
272  persObj->m_vDAC.push_back(dacValues);
273 
274  for(int dv=0;dv<dacValues;dv++){
275  persObj->m_dt.push_back(CWV[dv].getDt());
276  persObj->m_flag.push_back(CWV[dv].getFlag());
277  persObj->m_DAC.push_back(CWV[dv].getDAC());
278  persObj->m_isPulsed.push_back(CWV[dv].getIsPulsedInt());
279  const std::vector<double>& w=CWV[dv].getWave();
280  const std::vector<double>& e=CWV[dv].getErrors();
281  const std::vector<int>& t=CWV[dv].getTriggers();
282  for (unsigned int k = 0; k< w.size(); ++k){
283  persObj->m_vAmplitudes.push_back(w[k]);
284  persObj->m_vErrors.push_back(e[k]);
285  persObj->m_vTriggers.push_back(t[k]);
286  } // over samples
287  }// over DAC values
288  }
289 
290  } // over channels
291  }// over febs
292 
293  // Copy corrections
294  const auto corrEnd = transObj->correctionVecEnd();
295  for (auto corrIt = transObj->correctionVecBegin();
296  corrIt != corrEnd;
297  ++corrIt)
298  {
299  persObj->m_subset.m_corrChannels.push_back(corrIt->first);// Save channel id in febid vector
300 
301  const LArCaliWaveVec& CWV = corrIt->second;
302 
303  int dacValues=CWV.size();
304  persObj->m_vDAC.push_back(dacValues);
305  log<<MSG::DEBUG<<"\t CWV size: "<<dacValues;
306 
307  for(int dv=0;dv<dacValues;dv++){
308  persObj->m_dt.push_back(CWV[dv].getDt());
309  persObj->m_flag.push_back(CWV[dv].getFlag());
310  persObj->m_DAC.push_back(CWV[dv].getDAC());
311  persObj->m_isPulsed.push_back(CWV[dv].getIsPulsedInt());
312  const std::vector<double>& w=CWV[dv].getWave();
313  const std::vector<double>& e=CWV[dv].getErrors();
314  const std::vector<int>& t=CWV[dv].getTriggers();
315  persObj->m_samples=w.size();
316  for (unsigned int k = 0; k< w.size(); ++k){
317  persObj->m_vAmplitudes.push_back(w[k]);
318  persObj->m_vErrors.push_back(e[k]);
319  persObj->m_vTriggers.push_back(t[k]);
320  }// over samples
321  }// over dac values
322  }// over corrections
323 
324  // Copy the rest
325  persObj->m_subset.m_gain = transObj->gain();
326  persObj->m_subset.m_channel = transObj->channel();
327  persObj->m_subset.m_groupingType = transObj->groupingType();
328  log<< MSG::DEBUG <<" Cali Wave p2 successfully written down."<<endmsg;
329 }
330 
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
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
LArConditionsSubset_p1::m_corrChannels
std::vector< unsigned int > m_corrChannels
Definition: LArConditionsSubset_p1.h:76
PlotCalibFromCool.dv
dv
Definition: PlotCalibFromCool.py:762
LArConditionsSubset_p1::m_febsWithSparseData
std::vector< unsigned int > m_febsWithSparseData
Definition: LArConditionsSubset_p1.h:77
LArCaliWaveSubset_p3::m_vDAC
std::vector< unsigned short > m_vDAC
Definition: LArCaliWaveSubset_p3.h:37
LArCaliWaveSubset_p3::m_vTriggers
std::vector< int > m_vTriggers
Definition: LArCaliWaveSubset_p3.h:36
LArCaliWaveSubset_p3::m_dt
std::vector< float > m_dt
Definition: LArCaliWaveSubset_p3.h:33
LArConditionsSubset::channelVectorSize
unsigned channelVectorSize() const
Definition: LArConditionsSubset.h:608
LArCaliWaveSubset_p3::m_isPulsed
std::vector< int > m_isPulsed
Definition: LArCaliWaveSubset_p3.h:40
LArConditionsSubset_p1::subsetSize
unsigned int subsetSize() const
Definition: LArConditionsSubset_p1.h:82
LArCaliWaveSubset_p3::m_vErrors
std::vector< float > m_vErrors
Definition: LArCaliWaveSubset_p3.h:35
LArConditionsSubset_p1::m_gain
unsigned int m_gain
Definition: LArConditionsSubset_p1.h:78
LArConditionsSubset::correctionVecEnd
ConstCorrectionVecIt correctionVecEnd() const
Definition: LArConditionsSubset.h:472
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
LArCaliWaveSubsetCnv_p3::transToPers
virtual void transToPers(const LArCWTransType *transObj, LArCaliWaveSubset_p3 *persObj, MsgStream &log) const override
Definition: LArCaliWaveSubsetCnv_p3.cxx:161
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
LArCaliWave
Definition: LArCaliWave.h:44
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
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
LArCaliWaveSubset_p3
persistent class container of LArCaliWave data.
Definition: LArCaliWaveSubset_p3.h:27
LArConditionsSubset::channel
unsigned int channel() const
Access to the COOL channel number.
Definition: LArConditionsSubset.h:498
LArCaliWaveVec
Definition: LArCaliWave.h:91
LArCaliWaveSubset_p3::m_vAmplitudes
std::vector< float > m_vAmplitudes
Definition: LArCaliWaveSubset_p3.h:34
LArConditionsSubset::setChannel
void setChannel(unsigned int channel)
set the COOL channel number
Definition: LArConditionsSubset.h:567
integrator_ascii2db.dac
dac
Definition: integrator_ascii2db.py:126
LArCaliWaveSubsetCnv_p3::persToTrans
virtual void persToTrans(const LArCaliWaveSubset_p3 *persObj, LArCWTransType *transObj, MsgStream &log) const override
Definition: LArCaliWaveSubsetCnv_p3.cxx:10
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.
LArCaliWaveSubset_p3::m_flag
std::vector< unsigned > m_flag
Definition: LArCaliWaveSubset_p3.h:38
LArConditionsSubset::subsetSize
size_type subsetSize() const
Size of subset.
Definition: LArConditionsSubset.h:444
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
HLT::getFlag
const std::vector< bool > & getFlag(const TrigPassFlags *flags, const T *obj, const CONTAINER *container, const size_t position)
Returns the flag at index position.
Definition: TrigPassFlags.h:145
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArCaliWaveSubset_p3::m_DAC
std::vector< int > m_DAC
Definition: LArCaliWaveSubset_p3.h:39
LArCaliWaveSubsetCnv_p3.h
LArConditionsSubset::subsetBegin
ConstSubsetIt subsetBegin() const
Iterators over subset.
Definition: LArConditionsSubset.h:412
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
LArConditionsSubset::subsetEnd
ConstSubsetIt subsetEnd() const
Definition: LArConditionsSubset.h:420
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
LArCaliWaveSubset_p3::m_subset
LArConditionsSubset_p1 m_subset
Definition: LArCaliWaveSubset_p3.h:32
LArCaliWaveSubset_p3::m_samples
unsigned int m_samples
Definition: LArCaliWaveSubset_p3.h:41
fitman.k
k
Definition: fitman.py:528
LArConditionsSubset::groupingType
unsigned int groupingType() const
Type of grouping - defined in LArConditionsContainerBase.h.
Definition: LArConditionsSubset.h:507