ATLAS Offline Software
SubDetHitStatistics.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Dear emacs, this is -*-c++-*-
6 
26 #ifndef SUBDETHITSTATISTICS_H
27 #define SUBDETHITSTATISTICS_H
28 
29 #include "AthenaKernel/CLASS_DEF.h"
30 
32 
33 
35 public:
36 
44  unsigned char *m_p;
45  public:
46  static const unsigned int OVERFLOW_VALUE = 255;
47 
49  OverflowControlledRef(unsigned char& c) : m_p(&c) {}
50 
52  operator unsigned int () const { return *m_p; }
53  unsigned int value() const { return *m_p; }
54 
56  OverflowControlledRef operator=(unsigned int rhs) { *m_p = (rhs > OVERFLOW_VALUE) ? OVERFLOW_VALUE : rhs; return *this; }
57 
59  OverflowControlledRef operator++() { unsigned int tmp = 1 + *m_p; *m_p = (tmp > OVERFLOW_VALUE) ? OVERFLOW_VALUE : tmp; return *this; }
60 
62  OverflowControlledRef operator+=(unsigned int rhs) {
63  unsigned int tmp = *m_p + rhs;
64  *m_p = ((tmp > OVERFLOW_VALUE)
65  ||(tmp < rhs)/*protection agains overflowing tmp */
66  ) ? OVERFLOW_VALUE : tmp;
67  return *this;
68  }
69  }; // end of class OverflowControlledRef
70 
71  //----------------------------------------------------------------
72  // SubDetHitStatistics non-class members
73 
76 
78 
80  unsigned int operator[](SubDetType i) const { return m_numPRDs[i]; }
81 
84 
85 private:
90  unsigned char m_numPRDs[NUM_SUBDETECTORS];
91 
92  friend class TrackTruthCollectionAccessor; // in TrackTruthTPCnv
93 
94 public:
95 };
96 
97 template<class Ostream> Ostream& operator<<(Ostream& os, const SubDetHitStatistics& m) {
98  os<<"SubDetStat(";
99  for(unsigned i=0; i<SubDetHitStatistics::NUM_SUBDETECTORS; i++) {
102  }
103  return os<<")";
104 }
105 
106 // That method would be the *only* one in a .so file.
107 // So inline it and get rid of the library.
108 // Also note that memset()-ing 7 bytes can be inlined by gcc.
109 #include <cstring>
111  memset(m_numPRDs, 0, NUM_SUBDETECTORS);
112 }
113 
114 CLASS_DEF(SubDetHitStatistics, 73400190, 1)
115 
116 #endif/*SUBDETHITSTATISTICS_H*/
SubDetHitStatistics::SubDetType
SubDetType
Definition: SubDetHitStatistics.h:74
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
SubDetHitStatistics::SCT
@ SCT
Definition: SubDetHitStatistics.h:74
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Pixel
Definition: PixelFEUtils.h:16
SubDetHitStatistics::OverflowControlledRef::OverflowControlledRef
OverflowControlledRef(unsigned char &c)
constructor from a ref to the storage we control
Definition: SubDetHitStatistics.h:49
SubDetHitStatistics::NUM_SUBDETECTORS
@ NUM_SUBDETECTORS
Definition: SubDetHitStatistics.h:74
SubDetHitStatistics
Definition: SubDetHitStatistics.h:34
SubDetHitStatistics::OVERFLOW_VALUE
static const unsigned int OVERFLOW_VALUE
Definition: SubDetHitStatistics.h:75
operator<<
Ostream & operator<<(Ostream &os, const SubDetHitStatistics &m)
Definition: SubDetHitStatistics.h:97
SubDetHitStatistics::MM
@ MM
Definition: SubDetHitStatistics.h:74
SubDetHitStatistics::OverflowControlledRef::operator=
OverflowControlledRef operator=(unsigned int rhs)
protected assignment
Definition: SubDetHitStatistics.h:56
SubDetHitStatistics::CSC
@ CSC
Definition: SubDetHitStatistics.h:74
xAOD::unsigned
unsigned
Definition: RingSetConf_v1.cxx:662
SubDetHitStatistics::operator[]
OverflowControlledRef operator[](SubDetType i)
Write access protected agains overflows.
Definition: SubDetHitStatistics.h:83
SubDetHitStatistics::OverflowControlledRef::OVERFLOW_VALUE
static const unsigned int OVERFLOW_VALUE
Definition: SubDetHitStatistics.h:46
SubDetHitStatistics::m_numPRDs
unsigned char m_numPRDs[NUM_SUBDETECTORS]
For InDet, the largest typical number of measurements per track is 36 in the TRT.
Definition: SubDetHitStatistics.h:90
lumiFormat.i
int i
Definition: lumiFormat.py:85
SubDetHitStatistics::MDT
@ MDT
Definition: SubDetHitStatistics.h:74
SubDetHitStatistics::SubDetHitStatistics
SubDetHitStatistics()
Definition: SubDetHitStatistics.h:110
SubDetHitStatistics::OverflowControlledRef::m_p
unsigned char * m_p
Definition: SubDetHitStatistics.h:44
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
SubDetHitStatistics::OverflowControlledRef::value
unsigned int value() const
Definition: SubDetHitStatistics.h:53
SubDetHitStatistics::TGC
@ TGC
Definition: SubDetHitStatistics.h:74
SubDetHitStatistics::OverflowControlledRef::operator+=
OverflowControlledRef operator+=(unsigned int rhs)
protected add-to
Definition: SubDetHitStatistics.h:62
SubDetHitStatistics::operator[]
unsigned int operator[](SubDetType i) const
Counts of up to (OVERFLOW_VALUE-1) hits.
Definition: SubDetHitStatistics.h:80
SubDetHitStatistics::RPC
@ RPC
Definition: SubDetHitStatistics.h:74
SubDetHitStatistics::TRT
@ TRT
Definition: SubDetHitStatistics.h:74
TrackTruthCollectionAccessor
Definition: TrackTruthCollectionAccessor.h:16
CLASS_DEF
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Definition: Control/AthenaKernel/AthenaKernel/CLASS_DEF.h:64
SubDetHitStatistics::OverflowControlledRef::operator++
OverflowControlledRef operator++()
protected (prefix) increment
Definition: SubDetHitStatistics.h:59
SubDetHitStatistics::STGC
@ STGC
Definition: SubDetHitStatistics.h:74
python.compressB64.c
def c
Definition: compressB64.py:93
SubDetHitStatistics::OverflowControlledRef
A simple class to retrofit overflow protection into the existing code.
Definition: SubDetHitStatistics.h:43
CLASS_DEF.h
macros to associate a CLID to a type