3 #ifndef ALIHLTTRIGGERCOUNTERCOMPONENT_H
4 #define ALIHLTTRIGGERCOUNTERCOMPONENT_H
5 /* This file is property of and copyright by the ALICE HLT Project *
6 * ALICE Experiment at CERN, All rights reserved. *
7 * See cxx source for full Copyright notice */
9 /// \file AliHLTTriggerCounterComponent.h
10 /// \author Artur Szostak <artursz@iafrica.com>
12 /// \brief Declaration of the AliHLTTriggerCounterComponent component class.
14 #include "AliHLTProcessor.h"
15 #include "AliHLTTriggerCounters.h"
16 #include "THashTable.h"
17 #include "TTimeStamp.h"
21 * \class AliHLTTriggerCounterComponent
22 * This component is used to calculate online the trigger counters and rates for
23 * output HLT and input CTP / HLT triggers. The component should be connected to
24 * all the global trigger component instances in the chain and there should be
25 * only one instance of AliHLTTriggerCounterComponent in the chain. If more instances
26 * of AliHLTTriggerCounterComponent exist in the chain then the statistics will not
27 * be calculated correctly.
29 * <h2>General properties:</h2>
31 * Component ID: \b HLTTriggerCounter <br>
32 * Library: \b libAliHLTTrigger.so <br>
33 * Input Data Types: kAliHLTDataTypeGlobalTrigger | kAliHLTDataTypeTriggerDecision <br>
34 * Output Data Types: kAliHLTDataTypeInputTriggerCounters | kAliHLTDataTypeOutputTriggerCounters <br>
36 * <h2>Mandatory arguments:</h2>
39 * <h2>Optional arguments:</h2>
40 * \li -config <i>filename</i> <br>
41 * Indicates the configuration macro file to use for the initial trigger counter lists.
42 * \li -publishperiod <i>period</i> <br>
43 * Sets the period between publishing of the trigger counters in seconds.
44 * The default is to publish for every event.
46 * If specified then the initial counter configuration is not loaded from the CDB.
47 * \li -countfalseinputs <br>
48 * Indicates that input triggers which have false decision results should also be counted.
49 * \li -countfalseoutputs <br>
50 * Indicates that output triggers which have false decision results should also be counted.
51 * \li -integrationtime <i>period</i> <br>
52 * Sets the default maximum integration time in seconds to use for measuring the counter rates.
54 * <h2>Configuration:</h2>
55 * Can only be configured with the command line arguments.
57 * <h2>Default CDB entries:</h2>
58 * HLT/ConfigHLT/HLTTriggerCounter - Contains the initial counter configuration.
60 * <h2>Performance:</h2>
61 * Can run up to 1.8kHz in the HLT online system.
63 * <h2>Memory consumption:</h2>
66 * <h2>Output size:</h2>
67 * Same order of magnitude as the input data size.
69 * \ingroup alihlt_tpc_components
71 class AliHLTTriggerCounterComponent : public AliHLTProcessor
75 AliHLTTriggerCounterComponent();
76 virtual ~AliHLTTriggerCounterComponent();
78 // Methods inherited from AliHLTComponent:
79 virtual const char* GetComponentID();
80 virtual void GetInputDataTypes(AliHLTComponentDataTypeList& list);
81 virtual AliHLTComponentDataType GetOutputDataType();
82 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& list);
83 virtual void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);
84 virtual AliHLTComponent* Spawn();
85 virtual Int_t DoInit(int argc, const char** argv);
86 virtual Int_t DoDeinit();
89 * Returns a reference to the initial counter configuration to use.
90 * This should be used in the configuration file passed to the component with
91 * the -config option to setup the initial counter configuration. The following
92 * is an example of such a config file.
94 * void SetupConfig() {
95 * TMap& counters = AliHLTTriggerCounterComponent::InitialCounterConfig();
96 * counters.Add(new TObjString("TRIGGER-A"), new TObjString("Some input trigger"));
97 * TObjString* outname = new TObjString("TRIGGER-B");
98 * outname->SetBit(1<<14);
99 * counters.Add(outname, new TObjString("Some output trigger"));
103 static TMap& InitialCounterConfig()
105 fgInitialCounterConfig.SetOwner(kTRUE); // Make sure its the owner of all objects.
106 return fgInitialCounterConfig;
111 // Method inherited from AliHLTProcessor:
112 virtual int DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData);
113 using AliHLTProcessor::DoEvent;
117 /// Implements a ring buffer for old counter and time stamp values.
118 class AliRingBuffer : public TObject
123 /// The maximum number of time stamp entries held in the ring buffers for rate calculations.
124 /// The uncertainty in the rate should be ~ rate/sqrt(kTimeStampEntries)
125 kTimeStampEntries = 100
128 /// Constructor initialises the buffer
129 AliRingBuffer(const char* counterName, Double_t startTime, Double_t maxIntegTime = 1.) :
130 TObject(), fCounterName(counterName), fMaxIntegrationTime(maxIntegTime), fPos(0)
132 for (size_t i = 0; i < kTimeStampEntries; ++i) {
133 fCounterBuffer[i] = 0; fTimeBuffer[i] = startTime;
137 /// Overloaded new operator to catch and log memory allocation failures.
138 void* operator new (std::size_t size) throw (std::bad_alloc);
140 /// Symmetric delete operator for overloaded new.
141 void operator delete (void* mem) throw ();
143 /// Inherited form TObject. Returns the counter name this buffer is associated to.
144 virtual const char* GetName() const { return fCounterName.Data(); }
146 /// Inherited from TObject. Returns a hash value calculated from the counter name.
147 virtual ULong_t Hash() const { return fCounterName.Hash(); }
149 /// Returns the maximum integration time for this counter to compute the rate.
150 Double_t MaxIntegrationTime() const { return fMaxIntegrationTime; }
152 /// Returns the oldest counter value.
153 ULong64_t OldestCounter() const { return fCounterBuffer[fPos]; }
155 /// Returns the oldest time value.
156 Double_t OldestTime() const { return fTimeBuffer[fPos]; }
159 * Increments the buffer. The new time and counter values are put into the
160 * current location to replace the existing values, then the current position
161 * is incremented (and wrapped around if necessary).
162 * \note All values that are older than the fMaxIntegrationTime are also replaced.
163 * \param newCounter The new counter value to put into the buffer.
164 * \param newTime The new time value to put into the buffer.
166 void Increment(ULong64_t newCounter, Double_t newTime);
169 * Replaces all values that are older than the fMaxIntegrationTime.
170 * \param currentCounter The current counter's value.
171 * \param newTime The new time value to put into the buffer.
173 void Update(ULong64_t currentCounter, Double_t newTime);
177 TString fCounterName; // The name of the counter.
178 Double_t fMaxIntegrationTime; // The maximum integration time in seconds to calculate the rate.
179 UInt_t fPos; // Current position in the buffers.
180 ULong64_t fCounterBuffer[kTimeStampEntries]; // The counter elements of the buffer.
181 Double_t fTimeBuffer[kTimeStampEntries]; // The time elements of the buffer.
184 // Do not allow copying of this class.
185 AliHLTTriggerCounterComponent(const AliHLTTriggerCounterComponent& obj);
186 AliHLTTriggerCounterComponent& operator = (const AliHLTTriggerCounterComponent& obj);
188 /// Updates the counter rate value.
189 void UpdateCounterRate(AliHLTTriggerCounters::AliCounter* counter, AliRingBuffer* timeBuf, Double_t newTime);
191 /// Updates the counter rate value when the counter was not incremented.
192 void UpdateCounterRate2(AliHLTTriggerCounters::AliCounter* counter, AliRingBuffer* timeBuf, Double_t newTime);
194 /// Loads the initial configuration of counters from the given CDB path.
195 int LoadConfigFromCDB(const char* cdbPath);
197 /// Loads the initial configuration of counters from the given configuration file.
198 int LoadConfigFromFile(const char* configFile);
201 * Sets the initial counter values from a TMap object containing name description pairs.
202 * \param counters The list of counters to initialise. This TMap should contain TObjString
203 * pairs where the key is the name of the counter and the TMap value is the description.
204 * If the 14th bit is set in the key TObjString then the counter is considered an
205 * output counter and an input counter otherwise.
207 void SetInitialCounters(const TMap* counters);
209 double fOutputMultiplier; //! Multiplier value for the output size estimate.
210 AliHLTTriggerCounters fInputCounters; //! Input trigger counters.
211 AliHLTTriggerCounters fOutputCounters; //! Output trigger counters.
212 THashTable fInputTimes; //! Cyclic buffer storing the time stamps when the input counters were received.
213 THashTable fOutputTimes; //! Cyclic buffer storing the time stamps when the output counters were received.
214 Double_t fLastPublishTime; //! The last time the counters were pushed back to the output.
215 Double_t fPublishPeriod; //! The time between calls to push back the counters to output.
216 Double_t fDefaultMaxIntegrationTime; //! The maximum integration time to use for calculating the rates.
217 bool fCountFalseInputs; //! Indicates if the false input trigger decisions should also be counted.
218 bool fCountFalseOutputs; //! Indicates if the false output trigger decisions should also be counted.
220 static const char* fgkConfigCDBPath; //! CDB configuration path.
221 static TMap fgInitialCounterConfig; //! Initial configuration information for the counters.
223 ClassDef(AliHLTTriggerCounterComponent, 0) // Component for counting HLT triggers.
226 #endif // ALIHLTTRIGGERCOUNTERCOMPONENT_H