ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTMuonSpectroScalars.cxx
CommitLineData
c1550d2c 1// $Id: $
2/**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
5 * *
6 * Primary Authors: *
7 * Artur Szostak <artursz@iafrica.com> *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
18/// @file AliHLTMuonSpectroScalars.cxx
19/// @author Artur Szostak <artursz@iafrica.com>
20/// @date 9 Nov 2009
21/// @brief Implementation of the muon spectrometer trigger scalars.
22///
23/// This implements the trigger scalars for the muon spectrometer that can be used
1ee1ac03 24/// in the HLT global trigger and/or added to the AliESDEvent.
c1550d2c 25
26#include "AliHLTMuonSpectroScalars.h"
27#include "AliLog.h"
28#include "TObjArray.h"
29#include "TObjString.h"
30#include "TString.h"
31#include "Riostream.h"
32
3a7af7bd 33using std::cout;
34using std::endl;
35using std::setw;
c1550d2c 36ClassImp(AliHLTMuonSpectroScalars);
37ClassImp(AliHLTMuonSpectroScalars::AliScalar);
38
39
40AliHLTMuonSpectroScalars::AliHLTMuonSpectroScalars() :
41 TObject(),
42 fScalars(AliHLTMuonSpectroScalars::AliScalar::Class(), 128),
43 fIndex(128),
44 fIndexValid(false)
45{
46 // Default constructor.
47
48 fIndex.SetOwner(kFALSE);
49}
50
51
52AliHLTMuonSpectroScalars::AliHLTMuonSpectroScalars(const AliHLTMuonSpectroScalars& obj) :
53 TObject(obj),
54 fScalars(obj.fScalars),
55 fIndex(obj.fIndex),
56 fIndexValid(obj.fIndexValid)
57{
58 // Copy constructor performs a deep copy.
59
60 fIndex.SetOwner(kFALSE);
61}
62
63
64AliHLTMuonSpectroScalars::~AliHLTMuonSpectroScalars()
65{
66 // Default destructor.
67
68 Clear();
69}
70
71
72void AliHLTMuonSpectroScalars::Add(const char* name, const char* description, Double_t value)
73{
74 // Adds a new scalar.
75
76 new (fScalars[fScalars.GetEntriesFast()]) AliScalar(value, name, description);
77 fIndexValid = false; // Invalidate the index.
78}
79
80
81bool AliHLTMuonSpectroScalars::Exists(const char* name) const
82{
83 // Checks if the scalar exists or not.
84
85 if (not fIndexValid) MakeIndex();
86 AliScalar tmpobj(0, name, "");
87 Int_t n = fIndex.BinarySearch(&tmpobj);
88 if (n == -1) return false;
89 return true;
90}
91
92
93AliHLTMuonSpectroScalars::AliScalar* AliHLTMuonSpectroScalars::GetScalarN(UInt_t n)
94{
95 // Fetch the n'th scalar object.
96
97 if (n >= NumberOfScalars())
98 {
99 AliError(Form("Value 'n' is out of bounds. Should be in the range [0..%d].", NumberOfScalars()-1));
100 return NULL;
101 }
102 return static_cast<AliScalar*>( fScalars.UncheckedAt(Int_t(n)) );
103}
104
105
106const AliHLTMuonSpectroScalars::AliScalar* AliHLTMuonSpectroScalars::GetScalarN(UInt_t n) const
107{
108 // Fetch the n'th scalar object.
109
110 if (n >= NumberOfScalars())
111 {
112 AliError(Form("Value 'n' is out of bounds. Should be in the range [0..%d].", NumberOfScalars()-1));
113 return NULL;
114 }
115 return static_cast<const AliScalar*>( fScalars.UncheckedAt(Int_t(n)) );
116}
117
118
119AliHLTMuonSpectroScalars::AliScalar* AliHLTMuonSpectroScalars::GetScalar(const char* name)
120{
121 // Fetch the named scalar object.
122
123 if (not fIndexValid) MakeIndex();
124 AliScalar tmpobj(0, name, "");
125 Int_t n = fIndex.BinarySearch(&tmpobj);
126 if (n == -1)
127 {
128 AliError(Form("Scalar '%s' could not be found.", name));
129 return NULL;
130 }
131 return static_cast<AliScalar*>( fIndex.UncheckedAt(n) );
132}
133
134
135const AliHLTMuonSpectroScalars::AliScalar* AliHLTMuonSpectroScalars::GetScalar(const char* name) const
136{
137 // Fetch the named scalar object.
138
139 if (not fIndexValid) MakeIndex();
140 AliScalar tmpobj(0, name, "");
141 Int_t n = fIndex.BinarySearch(&tmpobj);
142 if (n == -1)
143 {
144 AliError(Form("Scalar '%s' could not be found.", name));
145 return NULL;
146 }
147 return static_cast<const AliScalar*>( fIndex.UncheckedAt(n) );
148}
149
150
151Double_t AliHLTMuonSpectroScalars::GetN(UInt_t n) const
152{
153 // Fetches the n'th scalar value.
154
155 const AliScalar* scalar = GetScalarN(n);
156 if (scalar == NULL) return 0;
157 return scalar->Value();
158}
159
160
161Double_t AliHLTMuonSpectroScalars::Get(const char* name) const
162{
163 // Fetches the n'th scalar value.
164
165 const AliScalar* scalar = GetScalar(name);
166 if (scalar == NULL) return 0;
167 return scalar->Value();
168}
169
170
171bool AliHLTMuonSpectroScalars::SetN(UInt_t n, Double_t value)
172{
173 // Sets the n'th scalar value.
174
175 AliScalar* scalar = GetScalarN(n);
176 if (scalar == NULL) return false;
177 scalar->Value(value);
178 return true;
179}
180
181
182bool AliHLTMuonSpectroScalars::Set(const char* name, Double_t value)
183{
184 // Sets the named scalar value.
185
186 AliScalar* scalar = GetScalar(name);
187 if (scalar == NULL) return false;
188 scalar->Value(value);
189 return true;
190}
191
192
193bool AliHLTMuonSpectroScalars::IncrementN(UInt_t n, UInt_t count)
194{
195 // Increments the n'th scalar by a value of 'count'.
196
197 AliScalar* scalar = GetScalarN(n);
198 if (scalar == NULL) return false;
199 scalar->Increment(count);
200 return true;
201}
202
203
204bool AliHLTMuonSpectroScalars::Increment(const char* name, UInt_t count)
205{
206 // Increments the named scalar by a value of 'count'.
207
208 AliScalar* scalar = GetScalar(name);
209 if (scalar == NULL) return false;
210 scalar->Increment(count);
211 return true;
212}
213
214
215const char* AliHLTMuonSpectroScalars::Name(UInt_t n) const
216{
217 // Fetches the n'th scalar's name.
218
219 const AliScalar* scalar = GetScalarN(n);
220 if (scalar == NULL) return NULL;
221 return scalar->Name();
222}
223
224
225const char* AliHLTMuonSpectroScalars::Description(UInt_t n) const
226{
227 // Fetches the n'th scalar's description.
228
229 const AliScalar* scalar = GetScalarN(n);
230 if (scalar == NULL) return NULL;
231 return scalar->Description();
232}
233
234
235void AliHLTMuonSpectroScalars::Reset()
236{
237 // Sets all the scalar values to zero.
238
239 for (Int_t i = 0; i < fScalars.GetEntriesFast(); ++i)
240 {
241 AliScalar* scalar = static_cast<AliScalar*>( fScalars.UncheckedAt(i) );
242 scalar->Value(0);
243 }
244}
245
246
247void AliHLTMuonSpectroScalars::Clear(Option_t* option)
248{
249 // Clears the array of scalars.
250
251 fScalars.Delete(option);
252 fIndex.Clear();
253}
254
255
256void AliHLTMuonSpectroScalars::Copy(TObject& object) const
257{
258 // Performs a deep copy.
259
260 if (object.IsA() != AliHLTMuonSpectroScalars::Class())
261 {
262 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
263 return;
264 }
265 AliHLTMuonSpectroScalars* obj = static_cast<AliHLTMuonSpectroScalars*>(&object);
266 *obj = *this;
267}
268
269
270TObject* AliHLTMuonSpectroScalars::FindObject(const char* name) const
271{
272 // Finds the scalar object by name.
273
274 if (fIndexValid)
275 {
276 AliScalar tmpobj(0, name, "");
277 Int_t n = fIndex.BinarySearch(&tmpobj);
278 if (n != -1) return fIndex.UncheckedAt(n);
279 }
280 else
281 {
282 return fScalars.FindObject(name);
283 }
284 return NULL;
285}
286
287
288TObject* AliHLTMuonSpectroScalars::FindObject(const TObject* obj) const
289{
290 // Finds the scalar object with the same name as obj->GetName().
291
292 return FindObject(obj->GetName());
293}
294
295
296void AliHLTMuonSpectroScalars::Print(Option_t* option) const
297{
298 // Prints the muon spectrometer's HLT trigger scalars.
299
300 TString opt = option;
301 if (opt == "compact")
302 {
303 if (NumberOfScalars() > 0)
304 cout << GetN(0);
305 for (UInt_t i = 1; i < NumberOfScalars(); ++i) cout << ", " << GetN(i);
306 cout << endl;
307 return;
308 }
309
310 // Calculate the maximum field width required to keep things aligned.
311 int fieldwidth = 0;
312 for (Int_t i = 0; i < fScalars.GetEntriesFast(); ++i)
313 {
314 AliScalar* scalar = static_cast<AliScalar*>( fScalars.UncheckedAt(i) );
315 int length = strlen(scalar->Description());
316 if (length > fieldwidth) fieldwidth = length;
317 }
318 if (fieldwidth > 80) fieldwidth = 80;
319
320 cout << "HLT muon spectrometer trigger scalars:" << endl;
321 for (Int_t i = 0; i < fScalars.GetEntriesFast(); ++i)
322 {
323 AliScalar* scalar = static_cast<AliScalar*>( fScalars.UncheckedAt(i) );
324 cout << setw(fieldwidth) << scalar->Description() << setw(0)
325 << " = " << scalar->Value() << endl;
326 }
327 if (fScalars.GetEntriesFast() == 0) cout << "(none)" << endl;
328}
329
330
331AliHLTMuonSpectroScalars& AliHLTMuonSpectroScalars::operator = (const AliHLTMuonSpectroScalars& obj)
332{
333 // Performs a deep copy.
334
335 if (this == &obj) return *this;
336 fScalars.Delete();
337 for (Int_t i = 0; i < obj.fScalars.GetEntriesFast(); ++i)
338 {
339 AliScalar* scalar = static_cast<AliScalar*>( obj.fScalars.UncheckedAt(i) );
340 Add(scalar->Name(), scalar->Description(), scalar->Value());
341 }
342 MakeIndex();
343 return *this;
344}
345
346
347bool AliHLTMuonSpectroScalars::operator == (const AliHLTMuonSpectroScalars& obj) const
348{
349 // Compares two scalar objects.
350
351 if (not fIndexValid) MakeIndex();
352 if (fScalars.GetEntriesFast() != obj.fScalars.GetEntriesFast()) return false;
353 for (Int_t i = 0; i < obj.fScalars.GetEntriesFast(); ++i)
354 {
355 AliScalar* scalar1 = static_cast<AliScalar*>( obj.fScalars.UncheckedAt(i) );
356 Int_t n = fIndex.BinarySearch(scalar1);
357 if (n == -1) return false;
358 AliScalar* scalar2 = static_cast<AliScalar*>( fIndex.UncheckedAt(n) );
359 if (scalar1->Value() != scalar2->Value()) return false;
360 }
361 return true;
362}
363
364
365void AliHLTMuonSpectroScalars::MakeIndex() const
366{
367 // Makes the index fIndex required for faster searching in fScalars.
368
369 fIndex.Clear();
370 for (Int_t i = 0; i < fScalars.GetEntriesFast(); ++i)
371 {
372 fIndex.Add(fScalars.UncheckedAt(i));
373 }
374 fIndex.Sort();
375 fIndexValid = true;
376}
377
378
379void AliHLTMuonSpectroScalars::AliScalar::Copy(TObject& object) const
380{
381 // Performs a deep copy.
382
383 if (object.IsA() != AliHLTMuonSpectroScalars::AliScalar::Class())
384 {
385 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
386 return;
387 }
388 AliHLTMuonSpectroScalars::AliScalar* obj = static_cast<AliHLTMuonSpectroScalars::AliScalar*>(&object);
389 *obj = *this;
390}