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