]>
Commit | Line | Data |
---|---|---|
e113820f | 1 | //-*- Mode: C++ -*- |
2 | // $Id: $ | |
3 | #ifndef AliHLTTRIGGERCOUNTERS_H | |
4 | #define AliHLTTRIGGERCOUNTERS_H | |
5 | /* This file is property of and copyright by the ALICE HLT Project * | |
6 | * ALICE Experiment at CERN, All rights reserved. * | |
7 | * See cxx source for full Copyright notice */ | |
8 | ||
9 | /// @file AliHLTTriggerCounters.h | |
10 | /// @author Artur Szostak <artursz@iafrica.com> | |
11 | /// @date 4 Sep 2010 | |
12 | /// @brief Declares the global trigger counters class for the HLT. | |
13 | ||
14 | #include "AliHLTScalars.h" | |
15 | #include "TNamed.h" | |
16 | #include "TTimeStamp.h" | |
17 | #include "TClonesArray.h" | |
18 | #include "THashTable.h" | |
19 | ||
20 | /** | |
21 | * @class AliHLTTriggerCounters | |
22 | * @brief HLT global trigger counters. | |
23 | * | |
24 | * This counters class contains summary information about the number of times a | |
25 | * trigger was fired in the HLT and its current rate estimate. Objects of this | |
26 | * class are generated by the AliHLTTriggerCountersMakerComponent to be used for | |
27 | * monitoring purposes. | |
28 | * | |
29 | * \ingroup alihlt_trigger_components | |
30 | */ | |
31 | class AliHLTTriggerCounters : public AliHLTScalars | |
32 | { | |
33 | public: | |
34 | /** | |
35 | * This class stores all the required information for a HLT global trigger counter. | |
36 | */ | |
37 | class AliCounter : public AliHLTScalars::AliScalar | |
38 | { | |
39 | public: | |
40 | /// Default constructor | |
41 | AliCounter() : AliHLTScalars::AliScalar(), fCounter(0) {} | |
42 | ||
43 | /// Constructor to set some initial values. | |
44 | AliCounter(const char* name, const char* description, ULong64_t value, Double_t rate) : | |
45 | AliHLTScalars::AliScalar(name, description, rate), fCounter(value) | |
46 | {} | |
47 | ||
48 | /// Default destructor | |
49 | virtual ~AliCounter() {} | |
50 | ||
51 | /// Resets the counter value. | |
52 | virtual void Clear(Option_t* /*option*/ = "") { fCounter = 0; Rate(0); } | |
53 | ||
54 | /// Inherited from TObject. Performs a deep copy. | |
55 | virtual void Copy(TObject& object) const; | |
56 | ||
57 | /// Returns the value of the counter. | |
58 | ULong64_t Counter() const { return fCounter; } | |
59 | ||
60 | /// Sets a new value for the counter. | |
61 | void Counter(ULong64_t value) { fCounter = value; } | |
62 | ||
63 | /** | |
64 | * Increments the counter by a value of 'count'. | |
65 | * \param count The number to increment the counter by. The default is 1. | |
66 | * \note The rate is not updated. | |
67 | */ | |
68 | void Increment(UInt_t count = 1) { fCounter += count; } | |
69 | ||
70 | /// Returns the rate of the counter (Hz). | |
71 | Double_t Rate() const { return Value(); } | |
72 | ||
73 | /** | |
74 | * Sets a new value for the counter's rate. | |
75 | * \param value The new value to use (Hz). If negative then 0 is used instead. | |
76 | */ | |
77 | void Rate(Double_t value) { Value(value >= 0 ? value : 0); } | |
78 | ||
79 | /// Checks if two counter objects are identical. | |
80 | bool operator == (const AliCounter& x) const | |
81 | { | |
82 | return AliHLTScalars::AliScalar::operator == (x) | |
83 | and fCounter == x.fCounter; | |
84 | } | |
85 | ||
86 | /// Checks if two counter objects are not identical. | |
87 | bool operator != (const AliCounter& x) const | |
88 | { | |
89 | return not (this->operator == (x)); | |
90 | } | |
91 | ||
92 | private: | |
93 | ULong64_t fCounter; // The counter's value. | |
94 | ||
95 | ClassDef(AliCounter, 1); // HLT trigger counter value. | |
96 | }; | |
97 | ||
98 | /// Default constructor. | |
99 | AliHLTTriggerCounters(); | |
100 | ||
101 | /// The copy constructor performs a deep copy. | |
102 | AliHLTTriggerCounters(const AliHLTTriggerCounters& obj); | |
103 | ||
104 | /// Default destructor. | |
105 | virtual ~AliHLTTriggerCounters(); | |
106 | ||
107 | /** | |
108 | * Adds a new counter to the end of the counters list. | |
109 | * If the counter already exists then its values are updated instead. | |
110 | * \param name The name of the counter value. | |
111 | * \param description A short description of the counter value. | |
112 | * \param rate The rate of the new counter. | |
113 | * \param value The value of the new counter. | |
114 | * \returns true if the counter already exists and false otherwise. | |
115 | */ | |
116 | bool Add(const char* name, const char* description, Double_t rate, ULong64_t value); | |
117 | ||
118 | using AliHLTScalars::Add; | |
119 | ||
120 | /** | |
121 | * Fetches the specified counter object. | |
122 | * \param name The name of the counter object. | |
123 | * \returns the found counter object, otherwise an empty sentinel object with | |
124 | * zeros. One can tell it is a sentinel because the name will be empty. | |
125 | */ | |
126 | const AliCounter& GetCounter(const char* name) const { return static_cast<const AliCounter&>(GetScalar(name)); } | |
127 | ||
128 | /** | |
129 | * Fetches the specified counter object for editing. | |
130 | * \param name The name of the counter object. | |
131 | * \returns the found counter object. If the counter does not already | |
132 | * exist then a new one is created and returned. | |
133 | */ | |
134 | AliCounter& GetCounter(const char* name) { return static_cast<AliCounter&>(GetScalar(name)); } | |
135 | ||
136 | /// Returns the number of counter values. | |
137 | UInt_t NumberOfCounters() const { return NumberOfScalars(); } | |
138 | ||
139 | // Note: the following GetCounterN methods do not use the same name as | |
140 | // GetCounter above because the parameter type would unfortunately be | |
141 | // ambiguous to an ISO c++ compiler. | |
142 | ||
143 | /** | |
144 | * Fetches the n'th counter object. | |
145 | * \param n The number of the counter object. | |
146 | * \returns the found counter object, otherwise an empty sentinel object with | |
147 | * zeros. One can tell it is a sentinel because the name will be empty. | |
148 | */ | |
149 | const AliCounter& GetCounterN(UInt_t n) const { return static_cast<const AliCounter&>(GetScalarN(n)); } | |
150 | ||
151 | /** | |
152 | * Fetches the n'th counter object for editing. | |
153 | * \param n The number of the counter object. | |
154 | * \returns the found counter object. If the counter does not already | |
155 | * exist then a new one is created and returned. | |
156 | */ | |
157 | AliCounter& GetCounterN(UInt_t n) { return static_cast<AliCounter&>(GetScalarN(n)); } | |
158 | ||
159 | /// Returns the timestamp for the counters. | |
160 | const TTimeStamp& TimeStamp() const { return fTimeStamp; } | |
161 | ||
162 | /// Updates the timestamp to the current time. | |
163 | void UpdateTimeStamp() { fTimeStamp = TTimeStamp(); } | |
164 | ||
165 | /// Resets all counter values and rates to zero. | |
166 | virtual void Reset(); | |
167 | ||
168 | /// Inherited form TObject. Performs a deep copy. | |
169 | virtual void Copy(TObject& object) const; | |
170 | ||
171 | /** | |
172 | * Inherited from TObject, this prints the contents of this summary object. | |
173 | * \param option Can be "compact", which will just print all the values on one line. | |
174 | */ | |
175 | virtual void Print(Option_t* option = "") const; | |
176 | ||
177 | /** | |
178 | * The assignment operator performs a deep copy. | |
179 | */ | |
180 | AliHLTTriggerCounters& operator = (const AliHLTTriggerCounters& obj); | |
181 | ||
182 | /// Returns the n'th counter or a zero sentinel if n is out of range. | |
183 | const AliCounter& operator [] (UInt_t n) const { return GetCounterN(n); } | |
184 | ||
185 | /// Returns the n'th counter for editing. A new counter is created if n is out of range. | |
186 | AliCounter& operator [] (UInt_t n) { return GetCounterN(n); } | |
187 | ||
188 | /// Returns the named counter or a zero sentinel if no such counter is found. | |
189 | const AliCounter& operator [] (const char* name) const { return GetCounter(name); } | |
190 | ||
191 | /// Returns the named counter for editing. A new counter is created if n is out of range. | |
192 | AliCounter& operator [] (const char* name) { return GetCounter(name); } | |
193 | ||
194 | /** | |
195 | * Comparison operator to check if two sets of counters have the same values | |
196 | * and time stamp. | |
197 | * \note The description strings are not checked so they could be different | |
198 | * and the order of the counters does not matter either. | |
199 | */ | |
200 | bool operator == (const AliHLTTriggerCounters& obj) const; | |
201 | ||
202 | /** | |
203 | * Comparison operator to check if two sets of counters are different. | |
204 | * \note The description strings are not checked, only the values and rates are. | |
205 | * In addition, the order of the counters does not matter. | |
206 | */ | |
207 | bool operator != (const AliHLTTriggerCounters& obj) const | |
208 | { | |
209 | return not (this->operator == (obj)); | |
210 | } | |
211 | ||
212 | protected: | |
213 | ||
214 | // The following is inherited from AliHLTScalars: | |
215 | virtual AliScalar* NewScalar(UInt_t i, const char* name, const char* description, Double_t value); | |
216 | virtual const AliScalar& Sentinel() const; | |
217 | ||
218 | private: | |
219 | ||
220 | TTimeStamp fTimeStamp; // The time stamp for the counters. | |
221 | ||
222 | ClassDef(AliHLTTriggerCounters, 1); // Set of HLT global trigger counters. | |
223 | }; | |
224 | ||
225 | #endif // AliHLTTRIGGERCOUNTERS_H |