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