ATLAS Offline Software
LArPhysWaveSubsetCnv_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  LArPWTransType* transObj,
11  MsgStream & log) const
12 {
13  log<<MSG::DEBUG<<"LArPhysWaveSubsetCNV_p1 begin persToTrans"<<endmsg;
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 
19  unsigned int nfebids = persObj->m_subset.m_febIds.size();
20  log<<MSG::DEBUG<<"\t\tTotal febs:"<<nfebids<<endmsg;
21  const unsigned int nChannelsPerFeb = persObj->m_subset.subsetSize();
22  unsigned int waveIndex = 0;
23  unsigned int 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 
31  bool hasSparseData = false;
32  unsigned int chansSet = 0;
33  unsigned int chansOffset = 0;
34 
35  if (ifebWithData < persObj->m_subset.m_febsWithSparseData.size() && febid == persObj->m_subset.m_febsWithSparseData[ifebWithData]) {
36  hasSparseData = true;// Found feb with sparse data
37  ifebWithData++;
38  chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
39  chansOffset = 0;
40  ifebWithData++;
41  }
42 
43  log<<MSG::DEBUG<<"\t\tsparse? "<< hasSparseData <<endmsg;
44 
45  for (unsigned int j = 0; j < nChannelsPerFeb; ++j){
46  bool copyChannel = true;
47  if (hasSparseData) {
48  if (!(chansSet & (1 << (j - chansOffset)))) {// Channel is missing data - skip
49  copyChannel = false; // std::cout<<"0";
50  }
51  //else std::cout<<"1";
52 
53  if (j%32 == 31 && j < nChannelsPerFeb-2) {
54  chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
55  chansOffset += 32;
56  ifebWithData++;
57  //std::cout<<" ";
58  }
59  }
60 
61  if (copyChannel) { // This channel has wave, resize vectors
62  LArPhysWave& PW = subsetIt->second[j];
63  double time = persObj->m_dt[chIndex];
64  unsigned int f = persObj->m_flag[chIndex];
65  int timeOffset = persObj->m_timeOffset[chIndex];
66  chIndex++;
67  std::vector<double> val;
68  std::vector<double> err;
69  std::vector<int> tri;
70  for (unsigned int k = 0; k < persObj->m_samples; ++k){
71  val.push_back(persObj->m_vAmplitudes[waveIndex]);
72  err.push_back(persObj->m_vErrors[waveIndex]);
73  tri.push_back(persObj->m_vTriggers[waveIndex]);
74  waveIndex++;
75  }
76 
77  LArPhysWave pw(val,err,tri, time,timeOffset, f);
78  val.clear();
79  err.clear();
80  tri.clear();
81 
82  PW=pw;
83  }
84  } // loop on channels
85  //std::cout<<std::endl;
86  } // loop on FEBs
87 
88  unsigned int ncorrs = persObj->m_subset.m_corrChannels.size();
89  log<<MSG::DEBUG<<"Total corrections:"<<ncorrs;
90  log<<MSG::DEBUG << "Corrections reading, ncorr=" << ncorrs << " waveIndex=" << waveIndex << " size=" << persObj->m_vAmplitudes.size() << endmsg;
92  corrs.resize(ncorrs);
93 
94  for (unsigned int i = 0; i < ncorrs; ++i){ // Loop over corrections
95 
96  if (chIndex >= persObj->m_dt.size()) { // check indexes
97  log << MSG::ERROR << "LArPhysWaveSubsetCnv_p1::persToTrans - PhysWave index too large: WaveIndex/sizeInFile "
98  << chIndex << " " << persObj->m_dt.size()<<" "<< endmsg;
99  return;
100  }
101 
102  corrs[i].first = persObj->m_subset.m_corrChannels[i];
103 
104  LArPhysWave& PW = corrs[i].second;
105 
106  double time = persObj->m_dt[chIndex];
107  unsigned int f = persObj->m_flag[chIndex];
108  int timeOffset = persObj->m_timeOffset[chIndex];
109  chIndex++;
110  std::vector<double> val;
111  std::vector<double> err;
112  std::vector<int> tri;
113  for (unsigned int k = 0; k < persObj->m_samples; ++k){
114  if (waveIndex>=persObj->m_vAmplitudes.size())
115  log << MSG::ERROR << "Persistent LArPhysWave object is inconsistent. i=" << i << " WaveIndes=" << waveIndex << " size=" << persObj->m_vAmplitudes.size() << "samples=" << persObj->m_samples <<endmsg;
116  val.push_back(persObj->m_vAmplitudes[waveIndex]);
117  err.push_back(persObj->m_vErrors[waveIndex]);
118  tri.push_back(persObj->m_vTriggers[waveIndex]);
119  waveIndex++;
120  }
121 
122  LArPhysWave pw(val,err,tri, time,timeOffset, f);
123  val.clear();
124  err.clear();
125  tri.clear();
126 
127  PW=pw;
128  }// over corrections
129  transObj->insertCorrections (std::move (corrs));
130 
131  log<< MSG::DEBUG <<"PhysWave successfully read."<<endmsg;
132 }
133 
134 
135 
136 
137 
138 void
140  LArPWPersType* persObj,
141  MsgStream & log) const
142 {
143  log<<MSG::DEBUG<<"LArPhysWaveSubsetCNV_p1 begin transToPers"<<endmsg;
144 
145  // Copy conditions
146  unsigned int nfebs = transObj->subsetSize();
147  log<<MSG::DEBUG<<"total febs:"<<nfebs;
148  unsigned int ncorrs = transObj->correctionVecSize();
149  log<<MSG::DEBUG<<"\t\ttotal corrections: "<<ncorrs<<endmsg;
150  const unsigned int nChannelsPerFeb = transObj->channelVectorSize();
151  unsigned int nsubsetsNotEmpty = 0;
152  unsigned int nchans = 0;
153 
154  persObj->m_samples=0; //for now
155  bool haveSampleSize=false;
156 
157  std::vector<unsigned int> febsWithSparseData; // collects IDs of febs with sparse data
158  const auto subsetEnd = transObj->subsetEnd();
159  for (auto subsetIt = transObj->subsetBegin();
160  subsetIt != subsetEnd;
161  ++subsetIt)
162  {
163  unsigned int nfebChans = subsetIt->second.size();
164 
165  if (nfebChans != 0 && nfebChans != nChannelsPerFeb) {
166  log << MSG::ERROR << "LArPhysWaveSubsetCnv_p1::transToPers - found incorrect number of channels per feb: " << nfebChans<< endmsg;
167  return;
168  }
169 
170  if (nfebChans) ++nsubsetsNotEmpty; // count number of non-empty FEBS
171 
172  bool isSparse = false;
173  for (unsigned int j = 0; j < nfebChans; ++j) { // Loop over channels and check if this subset has sparse data
174 
175  const LArPhysWave& PW = subsetIt->second[j];
176 
177  if (!isSparse && PW.isEmpty()) {
178  isSparse = true;
179  febsWithSparseData.push_back(subsetIt->first);// save febids for sparse subsets
180  log<<MSG::DEBUG<<"\t\tfebID: "<<subsetIt->first<<" is sparse"<<endmsg;
181  }
182 
183  if (!PW.isEmpty()){
184  nchans++; // count number of channels
185  if (!haveSampleSize) {
186  haveSampleSize=true;
187  persObj->m_samples=PW.getSize();
188  }
189  else
190  if (persObj->m_samples!=PW.getSize()) {
191  log << MSG::ERROR << "Waves of unequal length found in same conditions channel. Truncating to the shorter of "
192  << persObj->m_samples << " and " << PW.getSize() << endmsg;
193  persObj->m_samples=std::min(persObj->m_samples,(unsigned)PW.getSize());
194  }
195  } //else if !PS.isEmpty
196 
197  }
198 
199  //std::cout<<"\nFeb: "<<i<<" nonemptychannels till now: "<<nchans<<std::endl;
200 
201  } // loop over febs
202 
203  //std::cout<<"total nonempty febs = "<<nsubsetsNotEmpty<<std::endl;
204 
205  persObj->m_subset.m_febIds.reserve(nsubsetsNotEmpty);
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  persObj->m_timeOffset.reserve(nchans);
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].isEmpty()) { // 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) || j == nfebChans-1 ) {
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 LArPhysWave& PW = subsetIt->second[j];
267  persObj->m_dt.push_back(PW.getDt());
268  persObj->m_flag.push_back(PW.getFlag());
269  persObj->m_timeOffset.push_back(PW.getTimeOffset());
270  std::vector<double> w=PW.getWave();
271  std::vector<double> e=PW.getErrors();
272  std::vector<int> t=PW.getTriggers();
273  for (unsigned int k = 0; k< persObj->m_samples; ++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  persObj->m_subset.m_corrChannels.push_back(corrIt->first);
293 
294  const LArPhysWave& PW = corrIt->second;
295  std::vector<double> w=PW.getWave();
296  std::vector<double> e=PW.getErrors();
297  std::vector<int> t=PW.getTriggers();
298  persObj->m_dt.push_back(PW.getDt());
299  persObj->m_flag.push_back(PW.getFlag());
300  persObj->m_timeOffset.push_back(PW.getTimeOffset());
301  persObj->m_samples=w.size();
302  for (unsigned int k = 0; k< w.size(); ++k){
303  persObj->m_vAmplitudes.push_back(w[k]);
304  persObj->m_vErrors.push_back(e[k]);
305  persObj->m_vTriggers.push_back(t[k]);
306  }
307  }
308 
309  // Copy the rest
310  persObj->m_subset.m_gain = transObj->gain();
311  persObj->m_subset.m_channel = transObj->channel();
312  persObj->m_subset.m_groupingType = transObj->groupingType();
313  log<< MSG::DEBUG <<"PhysWave successfully written down."<<endmsg;
314 }
315 
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
LArPhysWaveSubset_p1
persistent class container of LArPhysWave data.
Definition: LArPhysWaveSubset_p1.h:28
LArPhysWaveSubset_p1::m_samples
unsigned int m_samples
Definition: LArPhysWaveSubset_p1.h:41
LArConditionsSubset_p1::m_corrChannels
std::vector< unsigned int > m_corrChannels
Definition: LArConditionsSubset_p1.h:76
LArWave::getSize
size_t getSize() const
number of time samples
Definition: LArWave.h:62
LArConditionsSubset_p1::m_febsWithSparseData
std::vector< unsigned int > m_febsWithSparseData
Definition: LArConditionsSubset_p1.h:77
LArWave::getFlag
unsigned getFlag() const
flag: ...
Definition: LArWave.h:178
LArWave::getWave
const std::vector< double > & getWave() const
Wave parameters.
Definition: LArWave.h:167
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
LArConditionsSubset::channelVectorSize
unsigned channelVectorSize() const
Definition: LArConditionsSubset.h:608
LArWave::getDt
const double & getDt() const
delta time
Definition: LArWave.h:50
LArConditionsSubset_p1::subsetSize
unsigned int subsetSize() const
Definition: LArConditionsSubset_p1.h:82
LArPhysWaveSubset_p1::m_timeOffset
std::vector< int > m_timeOffset
Definition: LArPhysWaveSubset_p1.h:39
LArConditionsSubset_p1::m_gain
unsigned int m_gain
Definition: LArConditionsSubset_p1.h:78
LArConditionsSubset::correctionVecEnd
ConstCorrectionVecIt correctionVecEnd() const
Definition: LArConditionsSubset.h:472
LArPhysWaveSubset_p1::m_vErrors
std::vector< float > m_vErrors
Definition: LArPhysWaveSubset_p1.h:36
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
LArPhysWave
Definition: LArPhysWave.h:14
LArPhysWaveSubset_p1::m_flag
std::vector< unsigned > m_flag
Definition: LArPhysWaveSubset_p1.h:38
LArPhysWaveSubset_p1::m_vAmplitudes
std::vector< float > m_vAmplitudes
Definition: LArPhysWaveSubset_p1.h:35
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
LArWave::isEmpty
bool isEmpty() const
is LArWave uninitialized?
Definition: LArWave.h:183
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
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
hist_file_dump.f
f
Definition: hist_file_dump.py:135
LArPhysWave::getTimeOffset
int getTimeOffset() const
Definition: LArPhysWave.h:97
LArConditionsSubset::setChannel
void setChannel(unsigned int channel)
set the COOL channel number
Definition: LArConditionsSubset.h:567
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
LArPhysWaveSubsetCnv_p1.h
LArConditionsSubset::correctionVecSize
size_type correctionVecSize() const
Size of channel set.
Definition: LArConditionsSubset.h:481
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
LArPhysWaveSubset_p1::m_subset
LArConditionsSubset_p1 m_subset
Definition: LArPhysWaveSubset_p1.h:33
LArPhysWaveSubsetCnv_p1::transToPers
virtual void transToPers(const LArPWTransType *transObj, LArPWPersType *persObj, MsgStream &log) const override
Definition: LArPhysWaveSubsetCnv_p1.cxx:139
LArConditionsSubset::subsetBegin
ConstSubsetIt subsetBegin() const
Iterators over subset.
Definition: LArConditionsSubset.h:412
LArPhysWaveSubsetCnv_p1::persToTrans
virtual void persToTrans(const LArPWPersType *persObj, LArPWTransType *transObj, MsgStream &log) const override
Definition: LArPhysWaveSubsetCnv_p1.cxx:9
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
LArConditionsSubset::subsetEnd
ConstSubsetIt subsetEnd() const
Definition: LArConditionsSubset.h:420
LArPhysWaveSubset_p1::m_vTriggers
std::vector< int > m_vTriggers
Definition: LArPhysWaveSubset_p1.h:37
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
LArWaveCumul::getErrors
const std::vector< double > & getErrors() const
error vector
Definition: LArWaveCumul.h:138
LArPhysWaveSubset_p1::m_dt
std::vector< float > m_dt
Definition: LArPhysWaveSubset_p1.h:34
fitman.k
k
Definition: fitman.py:528
LArConditionsSubset::groupingType
unsigned int groupingType() const
Type of grouping - defined in LArConditionsContainerBase.h.
Definition: LArConditionsSubset.h:507
LArWaveCumul::getTriggers
const std::vector< int > & getTriggers() const
trigger vector
Definition: LArWaveCumul.h:150