2 /**************************************************************************
3 * This file is property of and copyright by the ALICE HLT Project *
4 * All rights reserved. *
7 * Artur Szostak <artursz@iafrica.com> *
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 **************************************************************************/
18 /// @file AliHLTTriggerCounters.cxx
19 /// @author Artur Szostak <artursz@iafrica.com>
21 /// @brief Implementation of the HLT global trigger counters.
23 /// This implements the trigger counters for the global HLT.
24 /// These contain the total number of fired triggers by class and their current
27 #include "AliHLTTriggerCounters.h"
30 #include "TIterator.h"
31 #include "Riostream.h"
37 ClassImp(AliHLTTriggerCounters);
38 ClassImp(AliHLTTriggerCounters::AliCounter);
41 AliHLTTriggerCounters::AliHLTTriggerCounters() :
42 AliHLTScalars(AliHLTTriggerCounters::AliCounter::Class(), 128),
45 // Default constructor.
49 AliHLTTriggerCounters::AliHLTTriggerCounters(const AliHLTTriggerCounters& obj) :
51 fTimeStamp(obj.fTimeStamp)
53 // Copy constructor performs a deep copy.
57 AliHLTTriggerCounters::~AliHLTTriggerCounters()
59 // Default destructor.
62 AliHLTScalars::AliScalar* AliHLTTriggerCounters::NewScalar(UInt_t i, const char* name, const char* description, Double_t value)
64 // Creates a new scalar object.
66 return new (ScalarForConstructor(i)) AliCounter(name, description, 0, value);
70 const AliHLTScalars::AliScalar& AliHLTTriggerCounters::Sentinel() const
72 // Returns an empty sentinel object.
74 static AliHLTTriggerCounters::AliCounter sentinel;
79 bool AliHLTTriggerCounters::Add(const char* name, const char* description, Double_t rate, ULong64_t value)
81 // Adds a new counter.
83 AliScalar* scalar = NULL;
84 bool exists = AliHLTScalars::Add(scalar, name, description, rate);
85 assert(scalar != NULL);
86 static_cast<AliCounter*>(scalar)->Counter(value);
90 void AliHLTTriggerCounters::Reset()
92 // Sets all the counter values and rates to zero.
94 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
96 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
103 void AliHLTTriggerCounters::Copy(TObject& object) const
105 // Performs a deep copy.
107 if (object.IsA() != AliHLTTriggerCounters::Class())
109 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
112 AliHLTTriggerCounters* obj = static_cast<AliHLTTriggerCounters*>(&object);
113 obj->operator = (*this);
117 void AliHLTTriggerCounters::Print(Option_t* option) const
119 // Prints the HLT trigger counters.
121 TString opt = option;
122 if (opt == "compact")
124 if (NumberOfCounters() > 0)
126 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(0) );
127 cout << counter->Counter();
129 for (UInt_t i = 1; i < NumberOfCounters(); ++i)
131 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
132 cout << ", " << counter->Counter();
138 // Calculate the maximum field width required to keep things aligned.
140 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
142 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
143 int length = strlen(counter->Name()) + strlen(counter->Description()) + 3;
144 if (length > fieldwidth) fieldwidth = length;
146 if (fieldwidth > 80) fieldwidth = 80;
148 cout << "HLT trigger counters (" << fTimeStamp.AsString() << "):" << endl;
149 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
151 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
152 TString str = counter->Description();
154 str += counter->Name();
156 cout << setw(fieldwidth) << str.Data() << setw(0)
157 << " = " << counter->Counter() << setw(0)
158 << " (" << counter->Rate() << " Hz)"
161 if (NumberOfCounters() == 0) cout << "(none)" << endl;
165 AliHLTTriggerCounters& AliHLTTriggerCounters::operator = (const AliHLTTriggerCounters& obj)
167 // Performs a deep copy.
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)
175 AliCounter* counter = static_cast<AliCounter*>( obj.ScalarUncheckedAt(i) );
176 Add(counter->Name(), counter->Description(), counter->Rate(), counter->Counter());
182 bool AliHLTTriggerCounters::operator == (const AliHLTTriggerCounters& obj) const
184 // Compares two counter lists to see that they have the same counter values.
186 if (NumberOfCounters() != obj.NumberOfCounters()) return false;
187 if (fTimeStamp != obj.fTimeStamp) return false;
189 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
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;
200 void AliHLTTriggerCounters::AliCounter::Copy(TObject& object) const
202 // Performs a deep copy.
204 if (object.IsA() != AliHLTTriggerCounters::AliCounter::Class())
206 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
209 AliHLTTriggerCounters::AliCounter* obj = static_cast<AliHLTTriggerCounters::AliCounter*>(&object);