ATLAS Offline Software
Loading...
Searching...
No Matches
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
25
26#ifndef SUBDETHITSTATISTICS_H
27#define SUBDETHITSTATISTICS_H
28
30
32
33
35public:
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
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
85private:
91
92 friend class TrackTruthCollectionAccessor; // in TrackTruthTPCnv
93
94public:
95};
96
97template<class Ostream> Ostream& operator<<(Ostream& os, const SubDetHitStatistics& m) {
98 os<<"SubDetStat(";
99 for(unsigned i=0; i<SubDetHitStatistics::NUM_SUBDETECTORS; i++) {
100 os<<unsigned(m[SubDetHitStatistics::SubDetType(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>
113
114CLASS_DEF(SubDetHitStatistics, 73400190, 1)
115
116#endif/*SUBDETHITSTATISTICS_H*/
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
Ostream & operator<<(Ostream &os, const SubDetHitStatistics &m)
A simple class to retrofit overflow protection into the existing code.
OverflowControlledRef operator++()
protected (prefix) increment
OverflowControlledRef operator=(unsigned int rhs)
protected assignment
OverflowControlledRef(unsigned char &c)
constructor from a ref to the storage we control
OverflowControlledRef operator+=(unsigned int rhs)
protected add-to
OverflowControlledRef operator[](SubDetType i)
Write access protected agains overflows.
unsigned char m_numPRDs[NUM_SUBDETECTORS]
For InDet, the largest typical number of measurements per track is 36 in the TRT.
unsigned int operator[](SubDetType i) const
Counts of up to (OVERFLOW_VALUE-1) hits.
friend class TrackTruthCollectionAccessor
static const unsigned int OVERFLOW_VALUE
Definition TgcBase.h:6
Definition HitInfo.h:33