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