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