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.
48 * <h2>Configuration:</h2>
49 * Can only be configured with the command line arguments.
51 * <h2>Default CDB entries:</h2>
52 * HLT/ConfigHLT/HLTTriggerCounter - Contains the initial counter configuration.
54 * <h2>Performance:</h2>
55 * Can run over 2kHz in HLT online system.
57 * <h2>Memory consumption:</h2>
60 * <h2>Output size:</h2>
61 * Same order of magnitude as the input data size.
63 * \ingroup alihlt_tpc_components
65 class AliHLTTriggerCounterComponent : public AliHLTProcessor
69 AliHLTTriggerCounterComponent();
70 virtual ~AliHLTTriggerCounterComponent();
72 // Methods inherited from AliHLTComponent:
73 virtual const char* GetComponentID();
74 virtual void GetInputDataTypes(AliHLTComponentDataTypeList& list);
75 virtual AliHLTComponentDataType GetOutputDataType();
76 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& list);
77 virtual void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);
78 virtual AliHLTComponent* Spawn();
79 virtual Int_t DoInit(int argc, const char** argv);
80 virtual Int_t DoDeinit();
83 * Returns a reference to the initial counter configuration to use.
84 * This should be used in the configuration file passed to the component with
85 * the -config option to setup the initial counter configuration. The following
86 * is an example of such a config file.
88 * void SetupConfig() {
89 * TMap& counters = AliHLTTriggerCounterComponent::InitialCounterConfig();
90 * counters.Add(new TObjString("TRIGGER-A"), new TObjString("Some input trigger"));
91 * TObjString* outname = new TObjString("TRIGGER-B");
92 * outname->SetBit(1<<14);
93 * counters.Add(outname, new TObjString("Some output trigger"));
97 static TMap& InitialCounterConfig()
99 fgInitialCounterConfig.SetOwner(kTRUE); // Make sure its the owner of all objects.
100 return fgInitialCounterConfig;
105 // Method inherited from AliHLTProcessor:
106 virtual int DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData);
107 using AliHLTProcessor::DoEvent;
111 /// Implements a ring buffer for old counter and time stamp values.
112 class AliRingBuffer : public TObject
117 /// The maximum number of time stamp entries held in the ring buffers for rate calculations.
118 /// The uncertainty in the rate should be ~ rate/sqrt(kTimeStampEntries)
119 kTimeStampEntries = 100
122 /// Constructor initialises the buffer
123 AliRingBuffer(const char* counterName, Double_t startTime) : TObject(), fCounterName(counterName), fPos(0)
125 for (size_t i = 0; i < kTimeStampEntries; ++i) {
126 fCounterBuffer[i] = 0; fTimeBuffer[i] = startTime;
130 /// Inherited form TObject. Returns the counter name this buffer is associated to.
131 virtual const char* GetName() const { return fCounterName.Data(); }
133 /// Inherited from TObject. Returns a hash value calculated from the counter name.
134 virtual ULong_t Hash() const { return fCounterName.Hash(); }
136 /// Returns the oldest counter value.
137 ULong64_t OldestCounter() const { return fCounterBuffer[fPos]; }
139 /// Returns the oldest time value.
140 Double_t OldestTime() const { return fTimeBuffer[fPos]; }
143 * Increments the buffer. The new time and counter values are put into the
144 * current location to replace the existing values, then the current position
145 * is incremented (and wrapped around if necessary).
146 * \param newCounter The new counter value to put into the buffer.
147 * \param newTime The new time value to put into the buffer.
149 void Increment(ULong64_t newCounter, Double_t newTime)
151 fCounterBuffer[fPos] = newCounter;
152 fTimeBuffer[fPos] = newTime;
153 fPos = (fPos+1) % kTimeStampEntries;
158 TString fCounterName; // The name of the counter.
159 UInt_t fPos; // Current position in the buffers.
160 ULong64_t fCounterBuffer[kTimeStampEntries]; // The counter elements of the buffer.
161 Double_t fTimeBuffer[kTimeStampEntries]; // The time elements of the buffer.
164 // Do not allow copying of this class.
165 AliHLTTriggerCounterComponent(const AliHLTTriggerCounterComponent& obj);
166 AliHLTTriggerCounterComponent& operator = (const AliHLTTriggerCounterComponent& obj);
168 /// Updates the counter rate value.
169 void UpdateCounterRate(AliHLTTriggerCounters::AliCounter* counter, AliRingBuffer* timeBuf, Double_t newTime);
171 /// Loads the initial configuration of counters from the given CDB path.
172 int LoadConfigFromCDB(const char* cdbPath);
174 /// Loads the initial configuration of counters from the given configuration file.
175 int LoadConfigFromFile(const char* configFile);
178 * Sets the initial counter values from a TMap object containing name description pairs.
179 * \param counters The list of counters to initialise. This TMap should contain TObjString
180 * pairs where the key is the name of the counter and the TMap value is the description.
181 * If the 14th bit is set in the key TObjString then the counter is considered an
182 * output counter and an input counter otherwise.
184 void SetInitialCounters(const TMap* counters);
186 double fOutputMultiplier; //! Multiplier value for the output size estimate.
187 AliHLTTriggerCounters fInputCounters; //! Input trigger counters.
188 AliHLTTriggerCounters fOutputCounters; //! Output trigger counters.
189 THashTable fInputTimes; //! Cyclic buffer storing the time stamps when the input counters were received.
190 THashTable fOutputTimes; //! Cyclic buffer storing the time stamps when the output counters were received.
191 Double_t fLastPublishTime; //! The last time the counters were pushed back to the output.
192 Double_t fPublishPeriod; //! The time between calls to push back the counters to output.
194 static const char* fgkConfigCDBPath; //! CDB configuration path.
195 static TMap fgInitialCounterConfig; //! Initial configuration information for the counters.
197 ClassDef(AliHLTTriggerCounterComponent, 0) // Component for counting HLT triggers.
200 #endif // ALIHLTTRIGGERCOUNTERCOMPONENT_H