ATLAS Offline Software
Loading...
Searching...
No Matches
LArPhysWaveSubsetCnv_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
7
8void
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+1 < 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 // coverity[bad_shift]
49 // coverity[integer_overflow]
50 if (!(chansSet & (1 << (j - chansOffset)))) {// Channel is missing data - skip
51 copyChannel = false; // std::cout<<"0";
52 }
53 //else std::cout<<"1";
54
55 if (j%32 == 31 && j < nChannelsPerFeb-2) {
56 chansSet = persObj->m_subset.m_febsWithSparseData[ifebWithData];
57 chansOffset += 32;
58 ifebWithData++;
59 //std::cout<<" ";
60 }
61 }
62
63 if (copyChannel) { // This channel has wave, resize vectors
64 LArPhysWave& PW = subsetIt->second[j];
65 double time = persObj->m_dt[chIndex];
66 unsigned int f = persObj->m_flag[chIndex];
67 int timeOffset = persObj->m_timeOffset[chIndex];
68 chIndex++;
69 std::vector<double> val;
70 std::vector<double> err;
71 std::vector<int> tri;
72 for (unsigned int k = 0; k < persObj->m_samples; ++k){
73 val.push_back(persObj->m_vAmplitudes[waveIndex]);
74 err.push_back(persObj->m_vErrors[waveIndex]);
75 tri.push_back(persObj->m_vTriggers[waveIndex]);
76 waveIndex++;
77 }
78
79 LArPhysWave pw(val,err,tri, time,timeOffset, f);
80 val.clear();
81 err.clear();
82 tri.clear();
83
84 PW=pw;
85 }
86 } // loop on channels
87 //std::cout<<std::endl;
88 } // loop on FEBs
89
90 unsigned int ncorrs = persObj->m_subset.m_corrChannels.size();
91 log<<MSG::DEBUG<<"Total corrections:"<<ncorrs;
92 log<<MSG::DEBUG << "Corrections reading, ncorr=" << ncorrs << " waveIndex=" << waveIndex << " size=" << persObj->m_vAmplitudes.size() << endmsg;
94 corrs.resize(ncorrs);
95
96 for (unsigned int i = 0; i < ncorrs; ++i){ // Loop over corrections
97
98 if (chIndex >= persObj->m_dt.size()) { // check indexes
99 log << MSG::ERROR << "LArPhysWaveSubsetCnv_p1::persToTrans - PhysWave index too large: WaveIndex/sizeInFile "
100 << chIndex << " " << persObj->m_dt.size()<<" "<< endmsg;
101 return;
102 }
103
104 corrs[i].first = persObj->m_subset.m_corrChannels[i];
105
106 LArPhysWave& PW = corrs[i].second;
107
108 double time = persObj->m_dt[chIndex];
109 unsigned int f = persObj->m_flag[chIndex];
110 int timeOffset = persObj->m_timeOffset[chIndex];
111 chIndex++;
112 std::vector<double> val;
113 std::vector<double> err;
114 std::vector<int> tri;
115 for (unsigned int k = 0; k < persObj->m_samples; ++k){
116 if (waveIndex>=persObj->m_vAmplitudes.size())
117 log << MSG::ERROR << "Persistent LArPhysWave object is inconsistent. i=" << i << " WaveIndes=" << waveIndex << " size=" << persObj->m_vAmplitudes.size() << "samples=" << persObj->m_samples <<endmsg;
118 val.push_back(persObj->m_vAmplitudes[waveIndex]);
119 err.push_back(persObj->m_vErrors[waveIndex]);
120 tri.push_back(persObj->m_vTriggers[waveIndex]);
121 waveIndex++;
122 }
123
124 LArPhysWave pw(val,err,tri, time,timeOffset, f);
125 val.clear();
126 err.clear();
127 tri.clear();
128
129 PW=pw;
130 }// over corrections
131 transObj->insertCorrections (std::move (corrs));
132
133 log<< MSG::DEBUG <<"PhysWave successfully read."<<endmsg;
134}
135
136
137
138
139
140void
142 LArPWPersType* persObj,
143 MsgStream & log) const
144{
145 log<<MSG::DEBUG<<"LArPhysWaveSubsetCNV_p1 begin transToPers"<<endmsg;
146
147 // Copy conditions
148 unsigned int nfebs = transObj->subsetSize();
149 log<<MSG::DEBUG<<"total febs:"<<nfebs;
150 unsigned int ncorrs = transObj->correctionVecSize();
151 log<<MSG::DEBUG<<"\t\ttotal corrections: "<<ncorrs<<endmsg;
152 const unsigned int nChannelsPerFeb = transObj->channelVectorSize();
153 unsigned int nsubsetsNotEmpty = 0;
154 unsigned int nchans = 0;
155
156 persObj->m_samples=0; //for now
157 bool haveSampleSize=false;
158
159 std::vector<unsigned int> febsWithSparseData; // collects IDs of febs with sparse data
160 const auto subsetEnd = transObj->subsetEnd();
161 for (auto subsetIt = transObj->subsetBegin();
162 subsetIt != subsetEnd;
163 ++subsetIt)
164 {
165 unsigned int nfebChans = subsetIt->second.size();
166
167 if (nfebChans != 0 && nfebChans != nChannelsPerFeb) {
168 log << MSG::ERROR << "LArPhysWaveSubsetCnv_p1::transToPers - found incorrect number of channels per feb: " << nfebChans<< endmsg;
169 return;
170 }
171
172 if (nfebChans) ++nsubsetsNotEmpty; // count number of non-empty FEBS
173
174 bool isSparse = false;
175 for (unsigned int j = 0; j < nfebChans; ++j) { // Loop over channels and check if this subset has sparse data
176
177 const LArPhysWave& PW = subsetIt->second[j];
178
179 if (!isSparse && PW.isEmpty()) {
180 isSparse = true;
181 febsWithSparseData.push_back(subsetIt->first);// save febids for sparse subsets
182 log<<MSG::DEBUG<<"\t\tfebID: "<<subsetIt->first<<" is sparse"<<endmsg;
183 }
184
185 if (!PW.isEmpty()){
186 nchans++; // count number of channels
187 if (!haveSampleSize) {
188 haveSampleSize=true;
189 persObj->m_samples=PW.getSize();
190 }
191 else
192 if (persObj->m_samples!=PW.getSize()) {
193 log << MSG::ERROR << "Waves of unequal length found in same conditions channel. Truncating to the shorter of "
194 << persObj->m_samples << " and " << PW.getSize() << endmsg;
195 persObj->m_samples=std::min(persObj->m_samples,(unsigned)PW.getSize());
196 }
197 } //else if !PS.isEmpty
198
199 }
200
201 //std::cout<<"\nFeb: "<<i<<" nonemptychannels till now: "<<nchans<<std::endl;
202
203 } // loop over febs
204
205 //std::cout<<"total nonempty febs = "<<nsubsetsNotEmpty<<std::endl;
206
207 persObj->m_subset.m_febIds.reserve(nsubsetsNotEmpty);
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 persObj->m_timeOffset.reserve(nchans);
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].isEmpty()) { // channel exists
247
248 assert (j >= chansOffset && (j - chansOffset) <= 31);
249 // coverity[integer_overflow]
250 chansSet |= (1 << (j - chansOffset)); //store the channel number in the bit map
251
252 //std::cout<<"1";
253 }
254 else { // channel does not exist
255 saveAmplitudes = false;
256 //std::cout<<"0";
257 }
258
259 // Save chansSet
260 if (j == (chansOffset + 31) || j == nfebChans-1 ) {
261 persObj->m_subset.m_febsWithSparseData.push_back(chansSet);
262 chansSet = 0;
263 chansOffset += 32;
264 //std::cout<<" ";
265 }
266 } // if sparse
267
268 if (saveAmplitudes) {// save amplitudes, errors and triggers
269 const LArPhysWave& PW = subsetIt->second[j];
270 persObj->m_dt.push_back(PW.getDt());
271 persObj->m_flag.push_back(PW.getFlag());
272 persObj->m_timeOffset.push_back(PW.getTimeOffset());
273 std::vector<double> w=PW.getWave();
274 std::vector<double> e=PW.getErrors();
275 std::vector<int> t=PW.getTriggers();
276 for (unsigned int k = 0; k< persObj->m_samples; ++k){
277 persObj->m_vAmplitudes.push_back(w[k]);
278 persObj->m_vErrors.push_back(e[k]);
279 persObj->m_vTriggers.push_back(t[k]);
280 }
281 }
282
283 } // over channels
284 //std::cout<<std::endl;
285 }// over febs
286
287 // Copy corrections
288 const auto corrEnd = transObj->correctionVecEnd();
289 for (auto corrIt = transObj->correctionVecBegin();
290 corrIt != corrEnd;
291 ++corrIt)
292 {
293 // log<<MSG::DEBUG<<"WRITING CORRECTION : "<<i<<endmsg;
294 // Save channel id in febid vector
295 persObj->m_subset.m_corrChannels.push_back(corrIt->first);
296
297 const LArPhysWave& PW = corrIt->second;
298 std::vector<double> w=PW.getWave();
299 std::vector<double> e=PW.getErrors();
300 std::vector<int> t=PW.getTriggers();
301 persObj->m_dt.push_back(PW.getDt());
302 persObj->m_flag.push_back(PW.getFlag());
303 persObj->m_timeOffset.push_back(PW.getTimeOffset());
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 <<"PhysWave successfully written down."<<endmsg;
317}
318
#define endmsg
This file defines the template class used for I/O of conditions data.
LArPhysWaveSubset_p1 LArPWPersType
LArConditionsSubset< LArPhysWave > LArPWTransType
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
virtual void transToPers(const LArPWTransType *transObj, LArPWPersType *persObj, MsgStream &log) const override
virtual void persToTrans(const LArPWPersType *persObj, LArPWTransType *transObj, MsgStream &log) const override
std::vector< int > m_timeOffset
std::vector< float > m_vAmplitudes
LArConditionsSubset_p1 m_subset
std::vector< unsigned > m_flag
std::vector< float > m_dt
std::vector< float > m_vErrors
std::vector< int > m_vTriggers
int getTimeOffset() const
Definition LArPhysWave.h:97
const std::vector< int > & getTriggers() const
trigger vector
const std::vector< double > & getErrors() const
error vector
size_t getSize() const
number of time samples
Definition LArWave.h:62
bool isEmpty() const
is LArWave uninitialized?
Definition LArWave.h:183
const std::vector< double > & getWave() const
Wave parameters.
Definition LArWave.h:167
const double & getDt() const
delta time
Definition LArWave.h:50
unsigned getFlag() const
flag: ...
Definition LArWave.h:178