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