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 */
9 /// @file AliHLTTriggerCounters.h
10 /// @author Artur Szostak <artursz@iafrica.com>
12 /// @brief Declares the global trigger counters class for the HLT.
14 #include "AliHLTScalars.h"
16 #include "TTimeStamp.h"
17 #include "TClonesArray.h"
18 #include "THashTable.h"
21 * @class AliHLTTriggerCounters
22 * @brief HLT global trigger counters.
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.
29 * \ingroup alihlt_trigger_components
31 class AliHLTTriggerCounters : public AliHLTScalars
35 * This class stores all the required information for a HLT global trigger counter.
37 class AliCounter : public AliHLTScalars::AliScalar
40 /// Default constructor
41 AliCounter() : AliHLTScalars::AliScalar(), fCounter(0) {}
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)
48 /// Default destructor
49 virtual ~AliCounter() {}
51 /// Resets the counter value.
52 virtual void Clear(Option_t* /*option*/ = "") { fCounter = 0; Rate(0); }
54 /// Inherited from TObject. Performs a deep copy.
55 virtual void Copy(TObject& object) const;
57 /// Returns the value of the counter.
58 ULong64_t Counter() const { return fCounter; }
60 /// Sets a new value for the counter.
61 void Counter(ULong64_t value) { fCounter = value; }
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.
68 void Increment(UInt_t count = 1) { fCounter += count; }
70 /// Returns the rate of the counter (Hz).
71 Double_t Rate() const { return Value(); }
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.
77 void Rate(Double_t value) { Value(value >= 0 ? value : 0); }
79 /// Checks if two counter objects are identical.
80 bool operator == (const AliCounter& x) const
82 return AliHLTScalars::AliScalar::operator == (x)
83 and fCounter == x.fCounter;
86 /// Checks if two counter objects are not identical.
87 bool operator != (const AliCounter& x) const
89 return not (this->operator == (x));
93 ULong64_t fCounter; // The counter's value.
95 ClassDef(AliCounter, 1); // HLT trigger counter value.
98 /// Default constructor.
99 AliHLTTriggerCounters();
101 /// The copy constructor performs a deep copy.
102 AliHLTTriggerCounters(const AliHLTTriggerCounters& obj);
104 /// Default destructor.
105 virtual ~AliHLTTriggerCounters();
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.
116 bool Add(const char* name, const char* description, Double_t rate, ULong64_t value);
118 using AliHLTScalars::Add;
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.
126 const AliCounter& GetCounter(const char* name) const { return static_cast<const AliCounter&>(GetScalar(name)); }
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.
134 AliCounter& GetCounter(const char* name) { return static_cast<AliCounter&>(GetScalar(name)); }
136 /// Returns the number of counter values.
137 UInt_t NumberOfCounters() const { return NumberOfScalars(); }
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.
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.
149 const AliCounter& GetCounterN(UInt_t n) const { return static_cast<const AliCounter&>(GetScalarN(n)); }
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.
157 AliCounter& GetCounterN(UInt_t n) { return static_cast<AliCounter&>(GetScalarN(n)); }
159 /// Returns the timestamp for the counters.
160 const TTimeStamp& TimeStamp() const { return fTimeStamp; }
162 /// Updates the timestamp to the current time.
163 void UpdateTimeStamp() { fTimeStamp = TTimeStamp(); }
165 /// Resets all counter values and rates to zero.
166 virtual void Reset();
168 /// Inherited form TObject. Performs a deep copy.
169 virtual void Copy(TObject& object) const;
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.
175 virtual void Print(Option_t* option = "") const;
178 * The assignment operator performs a deep copy.
180 AliHLTTriggerCounters& operator = (const AliHLTTriggerCounters& obj);
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); }
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); }
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); }
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); }
195 * Comparison operator to check if two sets of counters have the same values
197 * \note The description strings are not checked so they could be different
198 * and the order of the counters does not matter either.
200 bool operator == (const AliHLTTriggerCounters& obj) const;
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.
207 bool operator != (const AliHLTTriggerCounters& obj) const
209 return not (this->operator == (obj));
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;
220 TTimeStamp fTimeStamp; // The time stamp for the counters.
222 ClassDef(AliHLTTriggerCounters, 1); // Set of HLT global trigger counters.
225 #endif // AliHLTTRIGGERCOUNTERS_H