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