ATLAS Offline Software
Loading...
Searching...
No Matches
LArConditionsSubset.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
15
16#ifndef LARRAWCONDITIONS_LARCONDITIONSSUBSET_H
17#define LARRAWCONDITIONS_LARCONDITIONSSUBSET_H
50
51#include <vector>
52#include <map>
53#include <algorithm>
55
63template <class T>
65{
66public:
67 typedef unsigned int FebId;
68
69 typedef T& Reference;
70 typedef const T& ConstReference;
71 typedef T* Pointer;
72 typedef const T* ConstPointer;
73 typedef typename std::vector<T> ChannelVector;
74 typedef const typename std::vector<T> ConstChannelVector;
76 typedef typename std::pair<FebId, ChannelVector> FebPair;
78 typedef typename std::vector<FebPair> SubsetVector;
79
80 static const T& empty()
81 {
82 static const T dum {};
83 return dum;
84 }
85
86
94 template <class OTHERIT, class COPIER>
95 static void copySubset (OTHERIT otherBeg,
96 OTHERIT otherEnd,
97 SubsetVector& to,
98 COPIER copier);
99};
100
101
102template <class T>
103template <class OTHERIT, class COPIER>
105 OTHERIT otherEnd,
106 SubsetVector& to,
107 COPIER copier)
108{
109 to.reserve (std::distance (otherBeg, otherEnd));
110 for (; otherBeg != otherEnd; ++otherBeg) {
111 ChannelVector v (otherBeg->second.size());
112 for (size_t i = 0; i < otherBeg->second.size(); i++) {
113 copier (otherBeg->second[i], v[i]);
114 }
115 to.emplace_back (otherBeg->first, std::move (v));
116 }
117}
118
119
120template<class T>
122{
123public:
124
127 typedef typename Traits::FebId FebId;
130 typedef typename Traits::FebPair FebPair;
133 typedef typename SubsetVector::const_iterator ConstSubsetIt;
134 typedef typename SubsetVector::iterator SubsetIt;
135 typedef typename Traits::Reference Reference;
137 typedef typename Traits::Pointer Pointer;
139
141 typedef T Payload;
142 typedef unsigned int ChannelId;
143 typedef typename std::pair<ChannelId, T> CorrectionPair;
144 typedef typename std::vector<CorrectionPair> CorrectionVec;
145 typedef typename CorrectionVec::const_iterator ConstCorrectionVecIt;
146 typedef typename CorrectionVec::iterator CorrectionVecIt;
147 typedef typename CorrectionVec::size_type size_type;
148
151
154
156 LArConditionsSubset(const std::vector<FebId>& ids, unsigned int gain);
157
158
162 template <class U, class COPIER>
163 void assign (const LArConditionsSubset<U>& other,
164 COPIER copier);
165
166
169
170
173
176
182
185
186
190
194
197
198
200 unsigned int gain() const;
201
203 unsigned int channel() const;
204
206 unsigned int groupingType() const;
207
209 unsigned int nConditions() const;
210
212 void initialize (const std::vector<FebId>& ids,
213 unsigned int gain);
214
217
218
220 void setGain(unsigned int gain);
221
223 void setChannel(unsigned int channel);
224
226 void setGroupingType(unsigned int type);
227
230 void insertCorrection (ChannelId id, const T& cond);
231
235
236 //Get channelVectorSize()
237 unsigned channelVectorSize() const;
238
240 // This is also called from a ROOT read rule after an object is read.
241 // (Nominally private, but needs to be public to be callable
242 // from a ROOT read rule.)
243 void fillMap();
244
245private:
246
247 class PairSort
248 {
249 public:
251 return (x.first < y.first);
252 }
253 };
254
255 typedef typename std::map<FebId, unsigned int> SubsetMap;
256
259 unsigned int m_gain;
260 unsigned int m_channel;
261 unsigned int m_groupingType;
263};
264
265
266// INLINE FUNCTIONS
267
268template<class T>
269inline
270void
272{
273 // Fill map from subset
274 m_subsetMap.clear();
275
276// std::cout << "fillMap: subset size, map size "
277// << m_subset.size() << " " << m_subsetMap.size()
278// << std::endl;
279
280 for (unsigned int i = 0; i < m_subset.size(); ++i) {
281 m_subsetMap[m_subset[i].first] = i;
282 }
283
284// std::cout << "fillMap: subset size, map size "
285// << m_subset.size() << " " << m_subsetMap.size()
286// << std::endl;
287}
288
289
290template<class T>
291inline
298
299template<class T>
300inline
307
308template<class T>
309inline
311 unsigned int gain)
312 :
313 m_subset(ids.size()),
314 m_gain(gain),
315 m_channel(0),
317
318{
319
320// std::cout << "LArConditionsSubset: ids size, gain "
321// << ids.size() << " " << gain
322// << std::endl;
323
324 // Loop over fed id list, insert id and resize channel vector
325 for (unsigned int i = 0; i < ids.size(); ++i) {
326 m_subset[i].first = ids[i];
327 // NOTE: we move the resize of the channel vector for each feb
328 // to the non-const find method below. This allows to keep the
329 // overall subset size to a minimum for non-full subsets..
330 //m_subset[i].second.resize(channelVectorSize());
331 }
332 // Fill map for future lookups
333 fillMap();
334}
335
336
337template<class T>
338template <class U, class COPIER>
340 COPIER copier)
341{
342 m_subsetMap.clear();
343 m_gain = other.gain();
344 m_channel = other.channel();
345 m_groupingType = other.groupingType();
346
347 Traits::copySubset (other.subsetBegin(), other.subsetEnd(), m_subset, copier);
348
349 size_t corrsz = other.correctionVecSize();
350 auto otherCorr = other.correctionVecBegin();
351 m_correctionVec.resize (corrsz);
352 for (size_t i = 0; i < corrsz; i++) {
353 m_correctionVec[i].first = otherCorr[i].first;
354 copier (otherCorr[i].second, m_correctionVec[i].second);
355 }
356
357 fillMap();
358}
359
360
361template<class T>
362inline
365
366
367template<class T>
368inline
371{
372
373// std::cout << "findChannelVector: febid, size "
374// << febID << " " << m_subsetMap.size()
375// << std::endl;
376
377
378 typename SubsetMap::const_iterator it = m_subsetMap.find(febID);
379 if (it != m_subsetMap.end()) {
380 unsigned int index = (*it).second;
381 if (index < m_subset.size()) {
382 // check that channel vector has been resized already
383 if (m_subset[index].second.size() == 0) {
384 m_subset[index].second.resize(channelVectorSize());
385 }
386 return (m_subset.begin() + index);
387 }
388 }
389 return (m_subset.end());
390}
391
392
393template<class T>
394inline
397{
398 typename SubsetMap::const_iterator it = m_subsetMap.find(febID);
399 if (it != m_subsetMap.end()) {
400 unsigned int index = (*it).second;
401 if (index < m_subset.size()) {
402 return (m_subset.begin() + index);
403 }
404 }
405 return (m_subset.end());
406}
407
408
409template<class T>
410inline
413{
414 return (m_subset.begin());
415}
416
417template<class T>
418inline
421{
422 return (m_subset.end());
423}
424
425template<class T>
426inline
429{
430 return (m_subset.begin());
431}
432
433template<class T>
434inline
437{
438 return (m_subset.end());
439}
440
441template<class T>
442inline
445{
446 return (m_subset.size());
447}
448
449template<class T>
452{
453 ConstCorrectionVecIt result = (std::lower_bound(m_correctionVec.begin(),
454 m_correctionVec.end(),
455 CorrectionPair(id, T()),
456 PairSort()));
457 if ( m_correctionVec.end() != result && id != result->first ) {
458 result = m_correctionVec.end();
459 }
460 return (result);
461}
462
463template<class T>
466{
467 return (m_correctionVec.begin());
468}
469
470template<class T>
473{
474 return (m_correctionVec.end());
475}
476
477
478
479template<class T>
482{
483 return (m_correctionVec.size());
484}
485
486
487template<class T>
488inline
489unsigned int
491{
492 return (m_gain);
493}
494
495template<class T>
496inline
497unsigned int
499{
500 return (m_channel);
501}
502
503
504template<class T>
505inline
506unsigned int
511
512template<class T>
513inline
514unsigned int
516{
517 unsigned int tot = 0;
518 for (unsigned int i = 0; i < m_subset.size(); ++i) {
519 tot += m_subset[i].second.size();
520 }
521 return (tot);
522}
523
524
525
526template<class T>
527inline
528void
529LArConditionsSubset<T>::initialize (const std::vector<FebId>& ids, unsigned int gain)
530{
531 m_correctionVec.clear();
532
533 // resize the subset
534 m_subset.resize(ids.size());
535 m_gain = gain;
536
537 // Loop over fed id list, insert id and resize channel vector
538 for (unsigned int i = 0; i < ids.size(); ++i) {
539 m_subset[i].first = ids[i];
540 m_subset[i].second.resize(channelVectorSize());
541 }
542
543 // Fill map for future lookups
544 fillMap();
545}
546
547template<class T>
548inline
549void
551{
552 m_subset.shrink_to_fit();
553}
554
555
556template<class T>
557inline
558void
560{
561 m_gain = gain;
562}
563
564template<class T>
565inline
566void
571
572template<class T>
573inline
574void
579
580template<class T>
581inline
582void
584{
585 m_correctionVec.push_back(CorrectionPair(id,cond));
587}
588
589
590template<class T>
591inline
592void
594{
595 if (m_correctionVec.empty()) {
596 m_correctionVec = std::move (corrs);
597 }
598 else {
599 m_correctionVec.insert (m_correctionVec.end(), corrs.begin(), corrs.end());
601 }
602}
603
604
605template<class T>
606inline
607unsigned
609{
610 //SuperCells have 320 channels per FEB, the regular readout has 128.
612}
613
614
615
616#endif // LARRAWCONDITIONS_LARCONDITIONSSUBSET_H
This file contain an implementation base class for LArConditionsContainer.
#define y
#define x
Traits class giving the types to use for the objects contained within the subset.
std::vector< FebPair > SubsetVector
std::pair< FebId, ChannelVector > FebPair
const std::vector< T > ConstChannelVector
static void copySubset(OTHERIT otherBeg, OTHERIT otherEnd, SubsetVector &to, COPIER copier)
Helper used by LArConditionsSubset::assign.
bool operator()(const CorrectionPair &x, const CorrectionPair &y)
CorrectionVec::const_iterator ConstCorrectionVecIt
std::pair< ChannelId, LArAutoCorrP1 > CorrectionPair
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
void shrink_to_fit()
Reallocate to match size actually used.
unsigned channelVectorSize() const
unsigned int nConditions() const
Number of conditions objects in this subset.
ConstCorrectionVecIt correctionVecBegin() const
Iterators over channel set.
unsigned int groupingType() const
Type of grouping - defined in LArConditionsContainerBase.h.
void fillMap()
Fill map from vector.
void assign(const LArConditionsSubset< U > &other, COPIER copier)
Copy from another subset object.
LArConditionsSubset(unsigned int gain)
Constructor for corrections - only need gain.
ConstCorrectionVecIt correctionVecEnd() const
SubsetVector::const_iterator ConstSubsetIt
void setGroupingType(unsigned int type)
set the type of grouping - defined in LArConditionsContainerBase.h
ConstSubsetIt subsetBegin() const
Iterators over subset.
LArConditionsSubsetTraits< LArAutoCorrP1 > Traits
size_type correctionVecSize() const
Size of channel set.
std::vector< CorrectionPair > CorrectionVec
std::map< FebId, unsigned int > SubsetMap
SubsetIt findChannelVector(FebId febId)
Access to a channel vector of a given FEB.
void insertCorrection(ChannelId id, const T &cond)
Insert a new channel id / T pair correction.
void setGain(unsigned int gain)
set gain
LArConditionsSubset(const std::vector< FebId > &ids, unsigned int gain)
Constructor with initializing set of FEB ids.
unsigned int channel() const
Access to the COOL channel number.
ConstCorrectionVecIt findConditionsObj(ChannelId id) const
Access to a conditions object for a given channel id - searches channel set ONLY.
void insertCorrections(CorrectionVec &&corrs)
Insert a group of corrections.
void setChannel(unsigned int channel)
set the COOL channel number
ConstSubsetIt findChannelVector(FebId febId) const
Access to a channel vector of a given FEB.
Traits::ConstChannelVector ConstChannelVector
LArConditionsSubset()
Default constructor.
virtual ~LArConditionsSubset()
destructor
Definition index.py:1
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.