ATLAS Offline Software
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 
16 #ifndef LARRAWCONDITIONS_LARCONDITIONSSUBSET_H
17 #define LARRAWCONDITIONS_LARCONDITIONSSUBSET_H
18 
51 #include <vector>
52 #include <map>
53 #include <algorithm>
55 
63 template <class T>
65 {
66 public:
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,
98  COPIER copier);
99 };
100 
101 
102 template <class T>
103 template <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 
120 template<class T>
122 {
123 public:
124 
127  typedef typename Traits::FebId FebId;
130  typedef typename Traits::FebPair FebPair;
133  typedef typename SubsetVector::const_iterator ConstSubsetIt;
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;
147  typedef typename CorrectionVec::size_type size_type;
148 
151 
153  LArConditionsSubset(unsigned int gain);
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 
168  virtual ~LArConditionsSubset();
169 
170 
173 
176 
178  ConstSubsetIt subsetBegin() const;
179  ConstSubsetIt subsetEnd() const;
182 
184  size_type subsetSize() const;
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 
216  void shrink_to_fit();
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 
234  void insertCorrections (CorrectionVec&& corrs);
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 
245 private:
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 
268 template<class T>
269 inline
270 void
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 
290 template<class T>
291 inline
293  :
294  m_gain(0),
295  m_channel(0),
296  m_groupingType(0)
297 {}
298 
299 template<class T>
300 inline
302  :
303  m_gain(gain),
304  m_channel(0),
305  m_groupingType(0)
306 {}
307 
308 template<class T>
309 inline
311  unsigned int gain)
312  :
313  m_subset(ids.size()),
314  m_gain(gain),
315  m_channel(0),
316  m_groupingType(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 
337 template<class T>
338 template <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 
361 template<class T>
362 inline
364 {}
365 
366 
367 template<class T>
368 inline
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 
393 template<class T>
394 inline
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 
409 template<class T>
410 inline
413 {
414  return (m_subset.begin());
415 }
416 
417 template<class T>
418 inline
421 {
422  return (m_subset.end());
423 }
424 
425 template<class T>
426 inline
429 {
430  return (m_subset.begin());
431 }
432 
433 template<class T>
434 inline
437 {
438  return (m_subset.end());
439 }
440 
441 template<class T>
442 inline
445 {
446  return (m_subset.size());
447 }
448 
449 template<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 
463 template<class T>
466 {
467  return (m_correctionVec.begin());
468 }
469 
470 template<class T>
473 {
474  return (m_correctionVec.end());
475 }
476 
477 
478 
479 template<class T>
482 {
483  return (m_correctionVec.size());
484 }
485 
486 
487 template<class T>
488 inline
489 unsigned int
491 {
492  return (m_gain);
493 }
494 
495 template<class T>
496 inline
497 unsigned int
499 {
500  return (m_channel);
501 }
502 
503 
504 template<class T>
505 inline
506 unsigned int
508 {
509  return (m_groupingType);
510 }
511 
512 template<class T>
513 inline
514 unsigned 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 
526 template<class T>
527 inline
528 void
529 LArConditionsSubset<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 
547 template<class T>
548 inline
549 void
551 {
552  m_subset.shrink_to_fit();
553 }
554 
555 
556 template<class T>
557 inline
558 void
560 {
561  m_gain = gain;
562 }
563 
564 template<class T>
565 inline
566 void
568 {
569  m_channel = channel;
570 }
571 
572 template<class T>
573 inline
574 void
576 {
577  m_groupingType = type;
578 }
579 
580 template<class T>
581 inline
582 void
584 {
585  m_correctionVec.push_back(CorrectionPair(id,cond));
586  std::sort(m_correctionVec.begin(), m_correctionVec.end(), PairSort());
587 }
588 
589 
590 template<class T>
591 inline
592 void
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());
600  std::sort(m_correctionVec.begin(), m_correctionVec.end(), PairSort());
601  }
602 }
603 
604 
605 template<class T>
606 inline
607 unsigned
609 {
610  //SuperCells have 320 channels per FEB, the regular readout has 128.
611  return m_groupingType == LArConditionsContainerBase::SuperCells ? 320 : 128;
612 }
613 
614 
615 
616 #endif // LARRAWCONDITIONS_LARCONDITIONSSUBSET_H
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
LArConditionsSubset::setGroupingType
void setGroupingType(unsigned int type)
set the type of grouping - defined in LArConditionsContainerBase.h
Definition: LArConditionsSubset.h:575
LArConditionsSubsetTraits::ChannelVector
std::vector< T > ChannelVector
Definition: LArConditionsSubset.h:73
LArConditionsContainerBase::SuperCells
@ SuperCells
Definition: LArConditionsContainerBase.h:51
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
LArConditionsSubset::CorrectionVecIt
CorrectionVec::iterator CorrectionVecIt
Definition: LArConditionsSubset.h:146
LArConditionsSubset::SubsetMap
std::map< FebId, unsigned int > SubsetMap
Definition: LArConditionsSubset.h:255
get_generator_info.result
result
Definition: get_generator_info.py:21
LArConditionsSubset::FebPairReference
Traits::FebPairReference FebPairReference
Definition: LArConditionsSubset.h:131
LArConditionsSubset::nConditions
unsigned int nConditions() const
Number of conditions objects in this subset.
Definition: LArConditionsSubset.h:515
LArConditionsSubset::SubsetVector
Traits::SubsetVector SubsetVector
Definition: LArConditionsSubset.h:132
LArConditionsSubset::m_gain
unsigned int m_gain
Definition: LArConditionsSubset.h:259
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
LArConditionsSubset::PairSort
Definition: LArConditionsSubset.h:248
LArConditionsSubset::LArConditionsSubset
LArConditionsSubset()
Default constructor.
Definition: LArConditionsSubset.h:292
index
Definition: index.py:1
LArConditionsSubset::m_channel
unsigned int m_channel
Definition: LArConditionsSubset.h:260
LArConditionsSubsetTraits::empty
static const T & empty()
Definition: LArConditionsSubset.h:80
LArConditionsSubsetTraits::ChannelVectorPointer
ChannelVector * ChannelVectorPointer
Definition: LArConditionsSubset.h:75
LArConditionsContainerBase.h
This file contain an implementation base class for LArConditionsContainer.
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArConditionsSubset::channelVectorSize
unsigned channelVectorSize() const
Definition: LArConditionsSubset.h:608
skel.it
it
Definition: skel.GENtoEVGEN.py:396
LArConditionsSubset::m_subset
SubsetVector m_subset
Definition: LArConditionsSubset.h:258
LArConditionsSubset::ConstCorrectionVecIt
CorrectionVec::const_iterator ConstCorrectionVecIt
Definition: LArConditionsSubset.h:145
LArConditionsSubsetTraits::FebPairReference
FebPair & FebPairReference
Definition: LArConditionsSubset.h:77
LArConditionsSubset::shrink_to_fit
void shrink_to_fit()
Reallocate to match size actually used.
Definition: LArConditionsSubset.h:550
LArConditionsSubset::fillMap
void fillMap()
Fill map from vector.
Definition: LArConditionsSubset.h:271
LArConditionsSubset::correctionVecEnd
ConstCorrectionVecIt correctionVecEnd() const
Definition: LArConditionsSubset.h:472
LArConditionsSubset::ConstSubsetIt
SubsetVector::const_iterator ConstSubsetIt
Definition: LArConditionsSubset.h:133
x
#define x
LArConditionsSubset::m_correctionVec
CorrectionVec m_correctionVec
Definition: LArConditionsSubset.h:262
LArConditionsSubset::Traits
LArConditionsSubsetTraits< T > Traits
Public typedefs for FEB id and channel vector - Subset.
Definition: LArConditionsSubset.h:126
LArConditionsSubset::Payload
T Payload
Public typedefs for channel id and T vector - CorrectionSet.
Definition: LArConditionsSubset.h:141
LArConditionsSubsetTraits::FebId
unsigned int FebId
Definition: LArConditionsSubset.h:67
LArConditionsSubsetTraits::SubsetVector
std::vector< FebPair > SubsetVector
Definition: LArConditionsSubset.h:78
LArConditionsSubset::ConstPointer
Traits::ConstPointer ConstPointer
Definition: LArConditionsSubset.h:138
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
LArConditionsSubset::ChannelVector
Traits::ChannelVector ChannelVector
Definition: LArConditionsSubset.h:128
LArConditionsSubset::initialize
void initialize(const std::vector< FebId > &ids, unsigned int gain)
Initialize with set of FEB ids.
Definition: LArConditionsSubset.h:529
LArConditionsSubsetTraits::Reference
T & Reference
Definition: LArConditionsSubset.h:69
LArConditionsSubset::CorrectionVec
std::vector< CorrectionPair > CorrectionVec
Definition: LArConditionsSubset.h:144
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArConditionsSubset::SubsetIt
SubsetVector::iterator SubsetIt
Definition: LArConditionsSubset.h:134
LArConditionsSubset::FebId
Traits::FebId FebId
Definition: LArConditionsSubset.h:127
LArConditionsSubset::channel
unsigned int channel() const
Access to the COOL channel number.
Definition: LArConditionsSubset.h:498
LArConditionsSubsetTraits::Pointer
T * Pointer
Definition: LArConditionsSubset.h:71
LArConditionsSubsetTraits::ConstPointer
const T * ConstPointer
Definition: LArConditionsSubset.h:72
LArConditionsSubset::m_subsetMap
SubsetMap m_subsetMap
Definition: LArConditionsSubset.h:257
LArConditionsSubsetTraits::ConstChannelVector
const std::vector< T > ConstChannelVector
Definition: LArConditionsSubset.h:74
LArConditionsSubset::setChannel
void setChannel(unsigned int channel)
set the COOL channel number
Definition: LArConditionsSubset.h:567
LArConditionsSubset::setGain
void setGain(unsigned int gain)
set gain
Definition: LArConditionsSubset.h:559
LArConditionsSubset::~LArConditionsSubset
virtual ~LArConditionsSubset()
destructor
Definition: LArConditionsSubset.h:363
LArConditionsSubsetTraits::FebPair
std::pair< FebId, ChannelVector > FebPair
Definition: LArConditionsSubset.h:76
LArConditionsSubset::ConstReference
Traits::ConstReference ConstReference
Definition: LArConditionsSubset.h:136
LArConditionsSubset
template class for use for I/O of conditions data
Definition: LArConditionsSubset.h:122
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
LArConditionsSubset::FebPair
Traits::FebPair FebPair
Definition: LArConditionsSubset.h:130
LArConditionsSubset::CorrectionPair
std::pair< ChannelId, T > CorrectionPair
Definition: LArConditionsSubset.h:143
LArConditionsSubset::subsetSize
size_type subsetSize() const
Size of subset.
Definition: LArConditionsSubset.h:444
LArConditionsSubset::findChannelVector
ConstSubsetIt findChannelVector(FebId febId) const
Access to a channel vector of a given FEB.
Definition: LArConditionsSubset.h:396
LArConditionsSubset::ConstChannelVector
Traits::ConstChannelVector ConstChannelVector
Definition: LArConditionsSubset.h:129
LArConditionsSubset::m_groupingType
unsigned int m_groupingType
Definition: LArConditionsSubset.h:261
CxxUtils::to
CONT to(RANGE &&r)
Definition: ranges.h:39
LArConditionsSubset::insertCorrection
void insertCorrection(ChannelId id, const T &cond)
Insert a new channel id / T pair correction.
Definition: LArConditionsSubset.h:583
LArConditionsSubset::gain
unsigned int gain() const
Access to gain.
Definition: LArConditionsSubset.h:490
python.PyAthena.v
v
Definition: PyAthena.py:154
LArConditionsSubset::ChannelId
unsigned int ChannelId
Definition: LArConditionsSubset.h:142
DeMoScan.index
string index
Definition: DeMoScan.py:364
LArConditionsSubset::correctionVecSize
size_type correctionVecSize() const
Size of channel set.
Definition: LArConditionsSubset.h:481
LArConditionsSubsetTraits::ConstReference
const T & ConstReference
Definition: LArConditionsSubset.h:70
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
y
#define y
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArConditionsSubset::size_type
CorrectionVec::size_type size_type
Definition: LArConditionsSubset.h:147
LArConditionsSubset::PairSort::operator()
bool operator()(const CorrectionPair &x, const CorrectionPair &y)
Definition: LArConditionsSubset.h:250
LArConditionsSubset::Reference
Traits::Reference Reference
Definition: LArConditionsSubset.h:135
LArConditionsSubset::Pointer
Traits::Pointer Pointer
Definition: LArConditionsSubset.h:137
LArConditionsSubsetTraits::copySubset
static void copySubset(OTHERIT otherBeg, OTHERIT otherEnd, SubsetVector &to, COPIER copier)
Helper used by LArConditionsSubset::assign.
Definition: LArConditionsSubset.h:104
LArConditionsSubset::subsetBegin
ConstSubsetIt subsetBegin() const
Iterators over subset.
Definition: LArConditionsSubset.h:412
LArConditionsSubset::subsetEnd
ConstSubsetIt subsetEnd() const
Definition: LArConditionsSubset.h:420
LArConditionsSubset::findConditionsObj
ConstCorrectionVecIt findConditionsObj(ChannelId id) const
Access to a conditions object for a given channel id - searches channel set ONLY.
Definition: LArConditionsSubset.h:451
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
LArConditionsSubset::correctionVecBegin
ConstCorrectionVecIt correctionVecBegin() const
Iterators over channel set.
Definition: LArConditionsSubset.h:465
LArConditionsSubset::assign
void assign(const LArConditionsSubset< U > &other, COPIER copier)
Copy from another subset object.
Definition: LArConditionsSubset.h:339
LArConditionsSubset::insertCorrections
void insertCorrections(CorrectionVec &&corrs)
Insert a group of corrections.
Definition: LArConditionsSubset.h:593
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
LArConditionsSubsetTraits
Traits class giving the types to use for the objects contained within the subset.
Definition: LArConditionsSubset.h:65
LArConditionsSubset::groupingType
unsigned int groupingType() const
Type of grouping - defined in LArConditionsContainerBase.h.
Definition: LArConditionsSubset.h:507