ATLAS Offline Software
LArCaliWaveSubsetCnv_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 
5 
8 
9 
10 void
12  LArCWTransType* transObj,
13  MsgStream & log) const
14 {
15  log<<MSG::DEBUG<<" LArCaliWaveSubsetCNV_p1 begin persToTrans"<<endmsg;
16 
17  transObj->initialize (persObj->m_subset.m_febIds, persObj->m_subset.m_gain);
18 
19  unsigned int nfebids = persObj->m_subset.m_febIds.size();
20  const unsigned int nChannelsPerFeb = persObj->m_subset.subsetSize();
21  log<<MSG::DEBUG<<"Total febs:"<<nfebids<<endmsg;
22 
23  unsigned int waveIndex = 0;
24  unsigned int chIndex = 0;
25 
26  unsigned int ifebWithData = 0; // counter for febs with data
27 
28  auto subsetIt = transObj->subsetBegin();
29  for (unsigned int i = 0; i < nfebids; ++i, ++subsetIt){
30  //std::cout<<"\nfeb index:"<<i;
31 
32  unsigned int febid = subsetIt->first;
33  //std::cout<<"\tfebID: "<<febid<<std::endl;
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<<" Feb 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)))) {
53  copyChannel = false;// Channel is missing data - skip
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]; // what is this for?
68  double time =persObj->m_dt[chIndex];
69  unsigned int f =persObj->m_flag[chIndex];
70  int dac =(persObj->m_DAC[chIndex])&0xFFFF;
71  int pulsed =(persObj->m_DAC[chIndex])>>16;
72  chIndex++;
73  std::vector<double> val;
74  std::vector<double> err;
75  std::vector<int> tri;
76  for (unsigned int k = 0; k < persObj->m_samples; ++k){
77  val.push_back(persObj->m_vAmplitudes[waveIndex]);
78  err.push_back(persObj->m_vErrors[waveIndex]);
79  tri.push_back(persObj->m_vTriggers[waveIndex]);
80  waveIndex++;
81  }
82 
83  LArCaliWave cv(val,err,tri, time,dac, pulsed, f);
84  val.clear();
85  err.clear();
86  tri.clear();
87 
88  CWV.push_back(cv);
89  }
90  } // loop on channels
91  //std::cout<<std::endl;
92  } // loop on FEBs
93 
94  unsigned int ncorrs = persObj->m_subset.m_corrChannels.size();
95  //log<<MSG::DEBUG << "entering corr reading, ncorr=" << ncorrs << " waveIndex=" << waveIndex << " size=" << persObj->m_vAmplitudes.size() << endmsg;
97  corrs.resize(ncorrs);
98 
99  // Loop over corrections
100  for (unsigned int i = 0; i < ncorrs; ++i){
101  // check indexes
102  if (chIndex >= persObj->m_dt.size()) {
103  log << MSG::ERROR
104  << "LArCaliWaveSubsetCnv_p1::persToTrans - CaliWave index too large: WaveIndex/sizeInFile "
105  << chIndex << " " << persObj->m_dt.size() << " "
106  << endmsg;
107  return;
108  }
109 
110  corrs[i].first = persObj->m_subset.m_corrChannels[i];
111 
112  LArCaliWaveVec& CWV = corrs[i].second;
113 
114  double time = persObj->m_dt[chIndex];
115  unsigned int f = persObj->m_flag[chIndex];
116  int dac = (persObj->m_DAC[chIndex])&0xFFFF;
117  int pulsed =(persObj->m_DAC[chIndex])>>16;
118  chIndex++;
119  std::vector<double> val;
120  std::vector<double> err;
121  std::vector<int> tri;
122  for (unsigned int k = 0; k < persObj->m_samples; ++k){
123  if (waveIndex>=persObj->m_vAmplitudes.size())
124  log << MSG::ERROR << "Persistent LArCaliWave object is inconsistent. i=" << i << " WaveIndes="
125  << waveIndex << " size=" << persObj->m_vAmplitudes.size() << "samples=" << persObj->m_samples <<endmsg;
126  val.push_back(persObj->m_vAmplitudes[waveIndex]);
127  err.push_back(persObj->m_vErrors[waveIndex]);
128  tri.push_back(persObj->m_vTriggers[waveIndex]);
129  waveIndex++;
130  }
131 
132  LArCaliWave cv(val,err,tri, time,dac, pulsed, f);
133  val.clear();
134  err.clear();
135  tri.clear();
136 
137  CWV.push_back(cv);
138  }
139  transObj->insertCorrections (std::move (corrs));
140 
141  // Copy the rest
142  transObj->setChannel (persObj->m_subset.m_channel);
143  transObj->setGroupingType (persObj->m_subset.m_groupingType);
144  log<< MSG::DEBUG <<"CaliWave p1 done reading"<<endmsg;
145 }
146 
147 
148 void
149 LArCaliWaveSubsetCnv_p1::transToPers(const LArCWTransType* transObj, LArCWPersType* persObj, MsgStream & log) const
150 {
151  log<<MSG::DEBUG<<"LArCaliWaveSubsetCNV_p1 begin transToPers"<<endmsg;
152 
153  // Copy conditions
154 // log<<MSG::DEBUG<<"total febs:"<<nfebs<<endmsg;
155  unsigned int ncorrs = transObj->correctionVecSize();
156  // log<<MSG::DEBUG<<"total corrections: "<<ncorrs<<endmsg;
157 
158  unsigned int nsubsetsNotEmpty = 0;
159  unsigned int nchans = 0;
160  const unsigned int nChannelsPerFeb = transObj->channelVectorSize();
161 
162  persObj->m_samples=0; //for now
163 
164  std::vector<unsigned int> febsWithSparseData; // collects IDs of febs with sparse data
165 
166  const auto subsetEnd = transObj->subsetEnd();
167  for (auto subsetIt = transObj->subsetBegin();
168  subsetIt != subsetEnd;
169  ++subsetIt)
170  {
171  unsigned int nfebChans = subsetIt->second.size();
172  // std::cout<<"feb index: "<<i<<" has "<<nfebChans<<" channels. "<<std::endl;
173 
174  if (nfebChans != 0 && nfebChans != nChannelsPerFeb) {
175  log << MSG::ERROR << "LArCaliWaveSubsetCnv_p1::transToPers - found incorrect number of channels per feb: " << nfebChans<< endmsg;
176  return;
177  }
178 
179  if (nfebChans) ++nsubsetsNotEmpty; // count number of non-empty FEBS
180 
181  bool isSparse = false;
182  for (unsigned int j = 0; j < nfebChans; ++j) { // Loop over channels and check if this subset has sparse data
183  const LArCaliWaveVec& CWV = subsetIt->second[j];
184 
185  if (!isSparse && CWV.size() == 0) {
186  isSparse = true;
187  febsWithSparseData.push_back(subsetIt->first);// save febids for sparse subsets
188  // std::cout<<"febID: "<<transObj->m_subset[i].first<<" is sparse"<<std::endl;
189  }
190  if (CWV.size()){ // should be like this no?
191  //else {
192  nchans++; // count number of channels
193  //std::cout<<":"<<CWV[0].getSize()<<std::endl; always 768
194  persObj->m_samples=CWV[0].getSize(); // completely ineficient but fast to fix :-(
195  }
196  }
197 
198 // std::cout<<"\nFeb: "<<i<<" nonemptychannels till now: "<<nchans<<std::endl;
199 
200  } // loop over febs
201 
202 // std::cout<<"total nonempty febs = "<<nsubsetsNotEmpty<<std::endl;
203 
204  persObj->m_subset.m_febIds.reserve(nsubsetsNotEmpty);
205 
206  persObj->m_subset.m_corrChannels.reserve(ncorrs);
207 
208  if (febsWithSparseData.size())
209  persObj->m_subset.m_febsWithSparseData.reserve(febsWithSparseData.size()*5); // this stores FEBID + 128 bitmask of existing channels
210 
211  persObj->m_dt.reserve(nchans);
212  persObj->m_vAmplitudes.reserve(nchans*persObj->m_samples);
213  persObj->m_vErrors.reserve(nchans*persObj->m_samples);
214  persObj->m_vTriggers.reserve(nchans*persObj->m_samples);
215  persObj->m_flag.reserve(nchans);
216 
217 
218  int counterSparse=0;
219  for (auto subsetIt = transObj->subsetBegin();
220  subsetIt != subsetEnd;
221  ++subsetIt)
222  {
223  unsigned int nfebChans = subsetIt->second.size();
224 
225  if (nfebChans == 0) continue; // skip subsets without any channels
226 
227  unsigned int febid = subsetIt->first;
228  persObj->m_subset.m_febIds.push_back(febid); // stores FEBID's of nonempty FEBs
229 
230  bool isSparse=false; // this is just to avoid search loop
231  if (counterSparse < (int)febsWithSparseData.size() && febid == febsWithSparseData[counterSparse]){
232  counterSparse++;
233  isSparse=true;
234  persObj->m_subset.m_febsWithSparseData.push_back(febid);
235  }
236 
237  unsigned int chansSet = 0;
238  unsigned int chansOffset = 0;
239  for (unsigned int j = 0; j < nfebChans; ++j){
240 
241  bool saveAmplitudes=true;
242  if (isSparse) { // subset with sparse data
243 
244  if (subsetIt->second[j].size() > 0) { // channel exists
245 
246  assert (j >= chansOffset && (j - chansOffset) <= 31);
247  chansSet |= (1 << (j - chansOffset)); //store the channel number in the bit map
248 
249  //std::cout<<"1";
250  }
251  else { // channel does not exist
252  saveAmplitudes = false;
253  //std::cout<<"0";
254  }
255 
256  // Save chansSet
257  if (j == (chansOffset + 31)) {
258  persObj->m_subset.m_febsWithSparseData.push_back(chansSet);
259  chansSet = 0;
260  chansOffset += 32;
261  //std::cout<<" ";
262  }
263  } // if sparse
264 
265  if (saveAmplitudes) {// save amplitudes, errors and triggers
266  const LArCaliWaveVec& CWV = subsetIt->second[j];
267  const std::vector<double>& w=CWV[0].getWave();
268  const std::vector<double>& e=CWV[0].getErrors();
269  const std::vector<int>& t=CWV[0].getTriggers();
270  persObj->m_dt.push_back(CWV[0].getDt());
271  persObj->m_flag.push_back(CWV[0].getFlag());
272  persObj->m_DAC.push_back(CWV[0].getDAC() | (CWV[0].getIsPulsedInt()<<16));
273  for (unsigned int k = 0; k< w.size(); ++k){
274  persObj->m_vAmplitudes.push_back(w[k]);
275  persObj->m_vErrors.push_back(e[k]);
276  persObj->m_vTriggers.push_back(t[k]);
277  }
278  }
279 
280  } // over channels
281  //std::cout<<std::endl;
282  }// over febs
283 
284  // Copy corrections
285  const auto corrEnd = transObj->correctionVecEnd();
286  for (auto corrIt = transObj->correctionVecBegin();
287  corrIt != corrEnd;
288  ++corrIt)
289  {
290  // log<<MSG::DEBUG<<"WRITING CORRECTION : "<<i<<endmsg;
291  // Save channel id in febid vector
292  const LArCaliWaveVec& CWV = corrIt->second;
293  if (CWV.empty()) continue;
294  persObj->m_subset.m_corrChannels.push_back(corrIt->first);
295  // Waves
296  const std::vector<double>& w=CWV[0].getWave();
297  const std::vector<double>& e=CWV[0].getErrors();
298  const std::vector<int>& t=CWV[0].getTriggers();
299  persObj->m_dt.push_back(CWV[0].getDt());
300  persObj->m_flag.push_back(CWV[0].getFlag());
301  persObj->m_DAC.push_back(CWV[0].getDAC() | (CWV[0].getIsPulsedInt()<<16));
302  persObj->m_samples=w.size();
303  for (unsigned int k = 0; k< w.size(); ++k){
304  persObj->m_vAmplitudes.push_back(w[k]);
305  persObj->m_vErrors.push_back(e[k]);
306  persObj->m_vTriggers.push_back(t[k]);
307  }
308  }
309 
310  // Copy the rest
311  persObj->m_subset.m_gain = transObj->gain();
312  persObj->m_subset.m_channel = transObj->channel();
313  persObj->m_subset.m_groupingType = transObj->groupingType();
314  log<< MSG::DEBUG <<"CaliWave p1 written down."<<endmsg;
315 }
316 
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_p1::m_DAC
std::vector< int > m_DAC
Definition: LArCaliWaveSubset_p1.h:39
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
LArCaliWaveSubsetCnv_p1::persToTrans
virtual void persToTrans(const LArCWPersType *persObj, LArCWTransType *transObj, MsgStream &log) const override
Definition: LArCaliWaveSubsetCnv_p1.cxx:11
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
LArConditionsSubset::correctionVecEnd
ConstCorrectionVecIt correctionVecEnd() const
Definition: LArConditionsSubset.h:472
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
LArCaliWaveSubset_p1::m_vTriggers
std::vector< int > m_vTriggers
Definition: LArCaliWaveSubset_p1.h:37
LArCaliWaveSubset_p1::m_subset
LArConditionsSubset_p1 m_subset
Definition: LArCaliWaveSubset_p1.h:33
LArCaliWaveSubset_p1::m_vAmplitudes
std::vector< float > m_vAmplitudes
Definition: LArCaliWaveSubset_p1.h:35
LArCaliWaveSubset_p1::m_dt
std::vector< float > m_dt
Definition: LArCaliWaveSubset_p1.h:34
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:182
LArConditionsSubset::CorrectionVec
std::vector< CorrectionPair > CorrectionVec
Definition: LArConditionsSubset.h:144
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCaliWaveSubsetCnv_p1::transToPers
virtual void transToPers(const LArCWTransType *transObj, LArCWPersType *persObj, MsgStream &log) const override
Definition: LArCaliWaveSubsetCnv_p1.cxx:149
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_p1::m_vErrors
std::vector< float > m_vErrors
Definition: LArCaliWaveSubset_p1.h:36
LArCaliWaveSubset_p1::m_samples
unsigned int m_samples
Definition: LArCaliWaveSubset_p1.h:40
LArConditionsSubset::setChannel
void setChannel(unsigned int channel)
set the COOL channel number
Definition: LArConditionsSubset.h:567
LArCaliWaveSubset_p1::m_flag
std::vector< unsigned > m_flag
Definition: LArCaliWaveSubset_p1.h:38
integrator_ascii2db.dac
dac
Definition: integrator_ascii2db.py:126
LArConditionsSubset
template class for use for I/O of conditions data
Definition: LArConditionsSubset.h:122
LArCaliWaveSubset_p1
persistent class container of LArCaliWave data.
Definition: LArCaliWaveSubset_p1.h:28
LArConditionsSubset.h
This file defines the template class used for I/O of conditions data.
LArCaliWaveSubsetCnv_p1.h
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
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