3 #ifndef AliHLTMUONSPECTROSCALARS_H
4 #define AliHLTMUONSPECTROSCALARS_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 AliHLTMuonSpectroScalars.h
10 /// @author Artur Szostak <artursz@iafrica.com>
12 /// @brief Declares the scalars class for the muon spectrometer.
15 #include "TObjArray.h"
16 #include "TClonesArray.h"
19 * @class AliHLTMuonSpectroScalars
20 * @brief Muon spectrometer HLT trigger summary scalars.
22 * This scalars class contains summary information such as the number of tracks found,
23 * number of pairs found and so on, all within the muon spectrometer.
24 * Objects of this class are generated by the AliHLTMuonSpectroTriggerComponent to
25 * be used in the HLT global trigger and/or added to the AliESDEvent object.
27 * \ingroup alihlt_trigger_components
29 class AliHLTMuonSpectroScalars : public TObject
33 * Scalar class to store all the required information for a muon spectrometer scalar.
35 class AliScalar : public TObject
38 /// Default constructor
39 AliScalar() : TObject(), fValue(0), fName(), fDescription() {}
41 /// Constructor to set some initial values.
42 AliScalar(Double_t value, const char* name, const char* description) :
43 TObject(), fValue(value), fName(name), fDescription(description)
46 /// Default destructor
47 virtual ~AliScalar() {}
49 /// Inherited from TObject. Returns the name of the scalar.
50 virtual const char* GetName() const { return fName; }
52 /// Inherited from TObject. Returns the description of the scalar.
53 virtual const char* GetTitle() const {return fDescription; }
55 /// Inherited from TObject. Compares two scalar names.
56 virtual Int_t Compare(const TObject *obj) const
58 return fName.CompareTo(obj->GetName());
61 /// Inherited from TObject. Returns true.
62 virtual Bool_t IsSortable() const { return kTRUE; }
65 * Inherited from TObject.
66 * Returns true if the names of the scalars are the same.
68 virtual Bool_t IsEqual(const TObject *obj) const
70 return fName == obj->GetName();
73 /// Resets the scalar value.
74 virtual void Clear(Option_t* /*option*/ = "") { fValue = 0; }
76 /// Inherited form TObject. Performs a deep copy.
77 virtual void Copy(TObject& object) const;
79 /// Returns the value of the scalar.
80 Double_t Value() const { return fValue; }
83 * Sets a new value for the scalar.
84 * \param value The new value to use. If negative then 0 is used instead.
86 void Value(Double_t value) { fValue = value >= 0 ? value : 0; }
88 /// Increments the scalar value by 'count'.
89 void Increment(UInt_t count = 1) { fValue += count; }
91 /// Returns the name of the scalar.
92 const char* Name() const { return fName.Data(); }
94 /// Returns the description string for the scalar.
95 const char* Description() const { return fDescription.Data(); }
97 /// Checks if two scalar objects are equal.
98 bool operator == (const AliScalar& x) const
100 return fValue == x.fValue and fName == x.fName
101 and fDescription == x.fDescription;
104 /// Checks if two scalar objects are not equal.
105 bool operator != (const AliScalar& x) const
107 return not (this->operator == (x));
111 Double_t fValue; /// The scalar value.
112 TString fName; /// The name of the scalar.
113 TString fDescription; /// A description of what the scalar represents.
115 ClassDef(AliScalar, 1); // A scalar value for the muon spectrometer.
118 /// Default constructor.
119 AliHLTMuonSpectroScalars();
121 /// The copy constructor performs a deep copy.
122 AliHLTMuonSpectroScalars(const AliHLTMuonSpectroScalars& obj);
124 /// Default destructor.
125 virtual ~AliHLTMuonSpectroScalars();
128 * Adds a new scalar to the end of the scalars list.
129 * \param name The name of the scalar value.
130 * \param description A short description of the scalar value.
131 * \param value The value of the new scalar.
133 void Add(const char* name, const char* description, Double_t value = 0);
135 /// Returns the number of scalar values.
136 UInt_t NumberOfScalars() const { return UInt_t(fScalars.GetEntriesFast()); }
138 /// Checks to see if the named scalar exists.
139 bool Exists(const char* name) const;
142 * Fetches the n'th scalar object.
143 * \param n The scalar object to fetch.
144 * \returns the n'th scalar object, otherwise NULL if <i>n</i> was out of range.
146 AliScalar* GetScalarN(UInt_t n);
147 const AliScalar* GetScalarN(UInt_t n) const;
150 * Fetches the named scalar object. Will apply a binary search for the object.
151 * This means rebuilding the internal index if necessary.
152 * \param name The name of the scalar object.
153 * \returns the found scalar object, otherwise NULL if it was not found.
155 AliScalar* GetScalar(const char* name);
156 const AliScalar* GetScalar(const char* name) const;
159 * Fetches the n'th scalar value.
160 * \param n The scalar number to fetch.
161 * \returns the n'th scalar, otherwise 0 if <i>n</i> was out of range.
163 Double_t GetN(UInt_t n) const;
166 * Fetches the a scalar value by name.
167 * \param name The name of the scalar.
168 * \returns the scalar's value, otherwise 0 if it could not be found.
170 Double_t Get(const char* name) const;
173 * Sets the n'th scalar value.
174 * \param n The scalar number to set.
175 * \param value The new value for the scalar.
176 * \returns true if the scalar could be set, otherwise false which means
177 * that <i>n</i> was out of range.
179 bool SetN(UInt_t n, Double_t value);
182 * Sets the named scalar's value.
183 * \param name The name of the scalar to set.
184 * \param value The new value for the scalar.
185 * \returns true if the scalar could be set, otherwise false which means
186 * that it was not found.
188 bool Set(const char* name, Double_t value);
191 * Increments the n'th scalar by a value of 'count'.
192 * \param n The scalar number to increment.
193 * \param count The number to increment the scalar by. The default is 1.
194 * \returns true if the scalar could be incremented, otherwise false
195 * which means that <i>n</i> was out of range.
197 bool IncrementN(UInt_t n, UInt_t count = 1);
200 * Increments the n'th scalar by a value of 'count'.
201 * \param name The name of the scalar to set.
202 * \param count The number to increment the scalar by. The default is 1.
203 * \returns true if the scalar could be incremented, otherwise false
204 * which means that it could not be found.
206 bool Increment(const char* name, UInt_t count = 1);
209 * Returns the name of the n'th scalar.
210 * \param n The scalar number for which to return the name.
211 * \returns the n'th scalar's name, otherwise NULL if <i>n</i> was out of range.
213 const char* Name(UInt_t n) const;
216 * Returns the description string for the n'th scalar.
217 * \param n The scalar number for which to return the description.
218 * \returns the n'th scalar's description, otherwise NULL if <i>n</i> was out of range.
220 const char* Description(UInt_t n) const;
222 /// Resets all scalar values to zero.
226 * Removes all the scalars from the internal array.
227 * \param option This is passed onto the internal Delete method.
229 virtual void Clear(Option_t* option = "");
231 /// Inherited form TObject. Performs a deep copy.
232 virtual void Copy(TObject& object) const;
234 /// Finds the scalar object by name. Will not apply a binary search if fIndex
236 virtual TObject* FindObject(const char* name) const;
238 /// Finds the scalar object with the same name as obj->GetName().
239 /// Will not apply a binary search if fIndex was invalidated.
240 virtual TObject* FindObject(const TObject* obj) const;
243 * Inherited from TObject, this prints the contents of this summary object.
244 * \param option Can be "compact", which will just print all the values on one line.
246 virtual void Print(Option_t* option = "") const;
249 * The assignment operator performs a deep copy.
251 AliHLTMuonSpectroScalars& operator = (const AliHLTMuonSpectroScalars& obj);
253 /// Returns the n'th scalar value or -1 if n is out of range.
254 Double_t operator [] (UInt_t n) const { return GetN(n); }
256 /// Returns the named scalar value or -1 if not found.
257 Double_t operator [] (const TString& name) const { return Get(name.Data()); }
260 * Comparison operator to check if two scalar objects have the same values.
261 * \note The description strings are not checked so they could be different
262 * and the order of the scalars does not matter either.
264 bool operator == (const AliHLTMuonSpectroScalars& obj) const;
267 * Comparison operator to check if two scalar objects are different.
268 * \note The description strings are not checked, only the values
269 * and the order of the scalars does not matter either.
271 bool operator != (const AliHLTMuonSpectroScalars& obj) const
273 return not (this->operator == (obj));
278 /// Creates the index required for faster searches of the fScalars array.
279 void MakeIndex() const;
281 TClonesArray fScalars; /// The list of scalars. Contains AliScalar objects.
282 mutable TObjArray fIndex; //! A sorted index of the scalars for faster searches.
283 mutable bool fIndexValid; //! Indicates that the index is valid.
285 ClassDef(AliHLTMuonSpectroScalars, 1); // HLT trigger scalars for the muon spectrometer.
288 #endif // AliHLTMUONSPECTROSCALARS_H