]>
Commit | Line | Data |
---|---|---|
742ae1c4 | 1 | //-*- Mode: C++ -*- |
2 | // $Id: $ | |
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 */ | |
8 | ||
9 | /// \file AliHLTTriggerCounterComponent.h | |
10 | /// \author Artur Szostak <artursz@iafrica.com> | |
11 | /// \date 3 Nov 2010 | |
12 | /// \brief Declaration of the AliHLTTriggerCounterComponent component class. | |
13 | ||
14 | #include "AliHLTProcessor.h" | |
15 | #include "AliHLTTriggerCounters.h" | |
16 | #include "THashTable.h" | |
17 | #include "TTimeStamp.h" | |
18 | #include "TMap.h" | |
19 | ||
20 | /** | |
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. | |
28 | * | |
29 | * <h2>General properties:</h2> | |
30 | * | |
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> | |
35 | * | |
36 | * <h2>Mandatory arguments:</h2> | |
37 | * None. | |
38 | * | |
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. | |
45 | * \li -skipcdb <br> | |
46 | * If specified then the initial counter configuration is not loaded from the CDB. | |
247b2cad | 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. | |
660469d3 | 51 | * \li -integrationtime <i>period</i> <br> |
52 | * Sets the default maximum integration time in seconds to use for measuring the counter rates. | |
742ae1c4 | 53 | * |
54 | * <h2>Configuration:</h2> | |
55 | * Can only be configured with the command line arguments. | |
56 | * | |
57 | * <h2>Default CDB entries:</h2> | |
58 | * HLT/ConfigHLT/HLTTriggerCounter - Contains the initial counter configuration. | |
59 | * | |
60 | * <h2>Performance:</h2> | |
247b2cad | 61 | * Can run up to 1.8kHz in the HLT online system. |
742ae1c4 | 62 | * |
63 | * <h2>Memory consumption:</h2> | |
64 | * Negligible. | |
65 | * | |
66 | * <h2>Output size:</h2> | |
67 | * Same order of magnitude as the input data size. | |
68 | * | |
69 | * \ingroup alihlt_tpc_components | |
70 | */ | |
71 | class AliHLTTriggerCounterComponent : public AliHLTProcessor | |
72 | { | |
73 | public: | |
74 | ||
75 | AliHLTTriggerCounterComponent(); | |
76 | virtual ~AliHLTTriggerCounterComponent(); | |
77 | ||
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(); | |
87 | ||
88 | /** | |
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. | |
93 | * \code | |
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")); | |
100 | * } | |
101 | * \endcode | |
102 | */ | |
103 | static TMap& InitialCounterConfig() | |
104 | { | |
105 | fgInitialCounterConfig.SetOwner(kTRUE); // Make sure its the owner of all objects. | |
106 | return fgInitialCounterConfig; | |
107 | } | |
108 | ||
109 | protected: | |
110 | ||
111 | // Method inherited from AliHLTProcessor: | |
112 | virtual int DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData); | |
113 | using AliHLTProcessor::DoEvent; | |
114 | ||
115 | private: | |
116 | ||
117 | /// Implements a ring buffer for old counter and time stamp values. | |
118 | class AliRingBuffer : public TObject | |
119 | { | |
120 | public: | |
121 | enum | |
122 | { | |
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 | |
126 | }; | |
127 | ||
128 | /// Constructor initialises the buffer | |
660469d3 | 129 | AliRingBuffer(const char* counterName, Double_t startTime, Double_t maxIntegTime = 1.) : |
130 | TObject(), fCounterName(counterName), fMaxIntegrationTime(maxIntegTime), fPos(0) | |
742ae1c4 | 131 | { |
132 | for (size_t i = 0; i < kTimeStampEntries; ++i) { | |
133 | fCounterBuffer[i] = 0; fTimeBuffer[i] = startTime; | |
134 | } | |
135 | } | |
136 | ||
660469d3 | 137 | /// Overloaded new operator to catch and log memory allocation failures. |
138 | void* operator new (std::size_t size) throw (std::bad_alloc); | |
139 | ||
140 | /// Symmetric delete operator for overloaded new. | |
141 | void operator delete (void* mem) throw (); | |
142 | ||
742ae1c4 | 143 | /// Inherited form TObject. Returns the counter name this buffer is associated to. |
144 | virtual const char* GetName() const { return fCounterName.Data(); } | |
145 | ||
146 | /// Inherited from TObject. Returns a hash value calculated from the counter name. | |
147 | virtual ULong_t Hash() const { return fCounterName.Hash(); } | |
148 | ||
660469d3 | 149 | /// Returns the maximum integration time for this counter to compute the rate. |
150 | Double_t MaxIntegrationTime() const { return fMaxIntegrationTime; } | |
151 | ||
742ae1c4 | 152 | /// Returns the oldest counter value. |
153 | ULong64_t OldestCounter() const { return fCounterBuffer[fPos]; } | |
154 | ||
155 | /// Returns the oldest time value. | |
156 | Double_t OldestTime() const { return fTimeBuffer[fPos]; } | |
157 | ||
158 | /** | |
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). | |
660469d3 | 162 | * \note All values that are older than the fMaxIntegrationTime are also replaced. |
742ae1c4 | 163 | * \param newCounter The new counter value to put into the buffer. |
164 | * \param newTime The new time value to put into the buffer. | |
165 | */ | |
660469d3 | 166 | void Increment(ULong64_t newCounter, Double_t newTime); |
167 | ||
168 | /** | |
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. | |
172 | */ | |
173 | void Update(ULong64_t currentCounter, Double_t newTime); | |
742ae1c4 | 174 | |
175 | private: | |
176 | ||
177 | TString fCounterName; // The name of the counter. | |
660469d3 | 178 | Double_t fMaxIntegrationTime; // The maximum integration time in seconds to calculate the rate. |
742ae1c4 | 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. | |
182 | }; | |
183 | ||
184 | // Do not allow copying of this class. | |
185 | AliHLTTriggerCounterComponent(const AliHLTTriggerCounterComponent& obj); | |
186 | AliHLTTriggerCounterComponent& operator = (const AliHLTTriggerCounterComponent& obj); | |
187 | ||
188 | /// Updates the counter rate value. | |
189 | void UpdateCounterRate(AliHLTTriggerCounters::AliCounter* counter, AliRingBuffer* timeBuf, Double_t newTime); | |
190 | ||
660469d3 | 191 | /// Updates the counter rate value when the counter was not incremented. |
192 | void UpdateCounterRate2(AliHLTTriggerCounters::AliCounter* counter, AliRingBuffer* timeBuf, Double_t newTime); | |
193 | ||
742ae1c4 | 194 | /// Loads the initial configuration of counters from the given CDB path. |
195 | int LoadConfigFromCDB(const char* cdbPath); | |
196 | ||
197 | /// Loads the initial configuration of counters from the given configuration file. | |
198 | int LoadConfigFromFile(const char* configFile); | |
199 | ||
200 | /** | |
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. | |
206 | */ | |
207 | void SetInitialCounters(const TMap* counters); | |
208 | ||
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. | |
660469d3 | 216 | Double_t fDefaultMaxIntegrationTime; //! The maximum integration time to use for calculating the rates. |
247b2cad | 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. | |
742ae1c4 | 219 | |
220 | static const char* fgkConfigCDBPath; //! CDB configuration path. | |
221 | static TMap fgInitialCounterConfig; //! Initial configuration information for the counters. | |
222 | ||
223 | ClassDef(AliHLTTriggerCounterComponent, 0) // Component for counting HLT triggers. | |
224 | }; | |
225 | ||
226 | #endif // ALIHLTTRIGGERCOUNTERCOMPONENT_H |