]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerCounters.cxx
added AliFlatExternalTrackParam to HLT global library
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerCounters.cxx
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   AliHLTTriggerCounters.cxx
19 ///  @author Artur Szostak <artursz@iafrica.com>
20 ///  @date   4 Sep 2010
21 ///  @brief  Implementation of the HLT global trigger counters.
22 ///
23 /// This implements the trigger counters for the global HLT.
24 /// These contain the total number of fired triggers by class and their current
25 /// estimated rate.
26
27 #include "AliHLTTriggerCounters.h"
28 #include "TString.h"
29 #include "AliLog.h"
30 #include "TIterator.h"
31 #include "Riostream.h"
32 #include <cassert>
33
34 using std::cout;
35 using std::endl;
36 using std::setw;
37 ClassImp(AliHLTTriggerCounters);
38 ClassImp(AliHLTTriggerCounters::AliCounter);
39
40
41 AliHLTTriggerCounters::AliHLTTriggerCounters() :
42         AliHLTScalars(AliHLTTriggerCounters::AliCounter::Class(), 128),
43         fTimeStamp()
44 {
45         // Default constructor.
46 }
47
48
49 AliHLTTriggerCounters::AliHLTTriggerCounters(const AliHLTTriggerCounters& obj) :
50         AliHLTScalars(obj),
51         fTimeStamp(obj.fTimeStamp)
52 {
53         // Copy constructor performs a deep copy.
54 }
55
56
57 AliHLTTriggerCounters::~AliHLTTriggerCounters()
58 {
59         // Default destructor.
60 }
61
62 AliHLTScalars::AliScalar* AliHLTTriggerCounters::NewScalar(UInt_t i, const char* name, const char* description, Double_t value)
63 {
64         // Creates a new scalar object.
65         
66         return new (ScalarForConstructor(i)) AliCounter(name, description, 0, value);
67 }
68
69
70 const AliHLTScalars::AliScalar& AliHLTTriggerCounters::Sentinel() const
71 {
72         // Returns an empty sentinel object.
73         
74         static AliHLTTriggerCounters::AliCounter sentinel;
75         return sentinel;
76 }
77
78
79 bool AliHLTTriggerCounters::Add(const char* name, const char* description, Double_t rate, ULong64_t value)
80 {
81         // Adds a new counter.
82
83         AliScalar* scalar = NULL;
84         bool exists = AliHLTScalars::Add(scalar, name, description, rate);
85         assert(scalar != NULL);
86         static_cast<AliCounter*>(scalar)->Counter(value);
87         return exists;
88 }
89
90 void AliHLTTriggerCounters::Reset()
91 {
92         // Sets all the counter values and rates to zero.
93         
94         for (UInt_t i = 0; i < NumberOfCounters(); ++i)
95         {
96                 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
97                 counter->Counter(0);
98                 counter->Rate(0);
99         }
100 }
101
102
103 void AliHLTTriggerCounters::Copy(TObject& object) const
104 {
105         // Performs a deep copy.
106         
107         if (object.IsA() != AliHLTTriggerCounters::Class())
108         {
109                 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
110                 return;
111         }
112         AliHLTTriggerCounters* obj = static_cast<AliHLTTriggerCounters*>(&object);
113         obj->operator = (*this);
114 }
115
116
117 void AliHLTTriggerCounters::Print(Option_t* option) const
118 {
119         // Prints the HLT trigger counters.
120
121         TString opt = option;
122         if (opt == "compact")
123         {
124                 if (NumberOfCounters() > 0)
125                 {
126                         AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(0) );
127                         cout << counter->Counter();
128                 }
129                 for (UInt_t i = 1; i < NumberOfCounters(); ++i)
130                 {
131                         AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
132                         cout << ", " << counter->Counter();
133                 }
134                 cout << endl;
135                 return;
136         }
137         
138         // Calculate the maximum field width required to keep things aligned.
139         int fieldwidth = 0;
140         for (UInt_t i = 0; i < NumberOfCounters(); ++i)
141         {
142                 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
143                 int length = strlen(counter->Name()) + strlen(counter->Description()) + 3;
144                 if (length > fieldwidth) fieldwidth = length;
145         }
146         if (fieldwidth > 80) fieldwidth = 80;
147         
148         cout << "HLT trigger counters (" << fTimeStamp.AsString() << "):" << endl;
149         for (UInt_t i = 0; i < NumberOfCounters(); ++i)
150         {
151                 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
152                 TString str = counter->Description();
153                 str += " (";
154                 str += counter->Name();
155                 str += ")";
156                 cout << setw(fieldwidth) << str.Data() << setw(0)
157                      << " = " << counter->Counter() << setw(0)
158                      << " (" << counter->Rate() << " Hz)"
159                      << endl;
160         }
161         if (NumberOfCounters() == 0) cout << "(none)" << endl;
162 }
163
164
165 AliHLTTriggerCounters& AliHLTTriggerCounters::operator = (const AliHLTTriggerCounters& obj)
166 {
167         // Performs a deep copy.
168         
169         if (this == &obj) return *this;
170         Clear();  // Remove existing counters.
171         TObject::operator = (obj);
172         fTimeStamp = obj.fTimeStamp;
173         for (UInt_t i = 0; i < obj.NumberOfCounters(); ++i)
174         {
175                 AliCounter* counter = static_cast<AliCounter*>( obj.ScalarUncheckedAt(i) );
176                 Add(counter->Name(), counter->Description(), counter->Rate(), counter->Counter());
177         }
178         return *this;
179 }
180
181
182 bool AliHLTTriggerCounters::operator == (const AliHLTTriggerCounters& obj) const
183 {
184         // Compares two counter lists to see that they have the same counter values.
185
186         if (NumberOfCounters() != obj.NumberOfCounters()) return false;
187         if (fTimeStamp != obj.fTimeStamp) return false;
188         
189         for (UInt_t i = 0; i < NumberOfCounters(); ++i)
190         {
191                 const AliCounter* a = static_cast<const AliCounter*>( ScalarUncheckedAt(i) );
192                 const AliCounter* b = static_cast<const AliCounter*>( obj.FindObject(a->Name()) );
193                 if (b == NULL) return false;
194                 if (a->Value() != b->Value() or a->Rate() != b->Rate()) return false;
195         }
196         return true;
197 }
198
199
200 void AliHLTTriggerCounters::AliCounter::Copy(TObject& object) const
201 {
202         // Performs a deep copy.
203         
204         if (object.IsA() != AliHLTTriggerCounters::AliCounter::Class())
205         {
206                 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
207                 return;
208         }
209         AliHLTTriggerCounters::AliCounter* obj = static_cast<AliHLTTriggerCounters::AliCounter*>(&object);
210         *obj = *this;
211 }