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"
34 ClassImp(AliHLTTriggerCounters);
35 ClassImp(AliHLTTriggerCounters::AliCounter);
38 AliHLTTriggerCounters::AliHLTTriggerCounters() :
39 AliHLTScalars(AliHLTTriggerCounters::AliCounter::Class(), 128),
42 // Default constructor.
46 AliHLTTriggerCounters::AliHLTTriggerCounters(const AliHLTTriggerCounters& obj) :
48 fTimeStamp(obj.fTimeStamp)
50 // Copy constructor performs a deep copy.
54 AliHLTTriggerCounters::~AliHLTTriggerCounters()
56 // Default destructor.
59 AliHLTScalars::AliScalar* AliHLTTriggerCounters::NewScalar(UInt_t i, const char* name, const char* description, Double_t value)
61 // Creates a new scalar object.
63 return new (ScalarForConstructor(i)) AliCounter(name, description, 0, value);
67 const AliHLTScalars::AliScalar& AliHLTTriggerCounters::Sentinel() const
69 // Returns an empty sentinel object.
71 static AliHLTTriggerCounters::AliCounter sentinel;
76 bool AliHLTTriggerCounters::Add(const char* name, const char* description, Double_t rate, ULong64_t value)
78 // Adds a new counter.
80 AliScalar* scalar = NULL;
81 bool exists = AliHLTScalars::Add(scalar, name, description, rate);
82 assert(scalar != NULL);
83 static_cast<AliCounter*>(scalar)->Counter(value);
87 void AliHLTTriggerCounters::Reset()
89 // Sets all the counter values and rates to zero.
91 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
93 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
100 void AliHLTTriggerCounters::Copy(TObject& object) const
102 // Performs a deep copy.
104 if (object.IsA() != AliHLTTriggerCounters::Class())
106 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
109 AliHLTTriggerCounters* obj = static_cast<AliHLTTriggerCounters*>(&object);
110 obj->operator = (*this);
114 void AliHLTTriggerCounters::Print(Option_t* option) const
116 // Prints the HLT trigger counters.
118 TString opt = option;
119 if (opt == "compact")
121 if (NumberOfCounters() > 0)
123 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(0) );
124 cout << counter->Counter();
126 for (UInt_t i = 1; i < NumberOfCounters(); ++i)
128 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
129 cout << ", " << counter->Counter();
135 // Calculate the maximum field width required to keep things aligned.
137 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
139 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
140 int length = strlen(counter->Name()) + strlen(counter->Description()) + 3;
141 if (length > fieldwidth) fieldwidth = length;
143 if (fieldwidth > 80) fieldwidth = 80;
145 cout << "HLT trigger counters (" << fTimeStamp.AsString() << "):" << endl;
146 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
148 AliCounter* counter = static_cast<AliCounter*>( ScalarUncheckedAt(i) );
149 TString str = counter->Description();
151 str += counter->Name();
153 cout << setw(fieldwidth) << str.Data() << setw(0)
154 << " = " << counter->Counter() << setw(0)
155 << " (" << counter->Rate() << " Hz)"
158 if (NumberOfCounters() == 0) cout << "(none)" << endl;
162 AliHLTTriggerCounters& AliHLTTriggerCounters::operator = (const AliHLTTriggerCounters& obj)
164 // Performs a deep copy.
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)
172 AliCounter* counter = static_cast<AliCounter*>( obj.ScalarUncheckedAt(i) );
173 Add(counter->Name(), counter->Description(), counter->Rate(), counter->Counter());
179 bool AliHLTTriggerCounters::operator == (const AliHLTTriggerCounters& obj) const
181 // Compares two counter lists to see that they have the same counter values.
183 if (NumberOfCounters() != obj.NumberOfCounters()) return false;
184 if (fTimeStamp != obj.fTimeStamp) return false;
186 for (UInt_t i = 0; i < NumberOfCounters(); ++i)
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;
197 void AliHLTTriggerCounters::AliCounter::Copy(TObject& object) const
199 // Performs a deep copy.
201 if (object.IsA() != AliHLTTriggerCounters::AliCounter::Class())
203 AliError(Form("Cannot copy to an object of type '%s'.", object.ClassName()));
206 AliHLTTriggerCounters::AliCounter* obj = static_cast<AliHLTTriggerCounters::AliCounter*>(&object);