]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/trigger/AliHLTTriggerCounterComponent.h
code cleanup
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerCounterComponent.h
CommitLineData
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.
742ae1c4 51 *
52 * <h2>Configuration:</h2>
53 * Can only be configured with the command line arguments.
54 *
55 * <h2>Default CDB entries:</h2>
56 * HLT/ConfigHLT/HLTTriggerCounter - Contains the initial counter configuration.
57 *
58 * <h2>Performance:</h2>
247b2cad 59 * Can run up to 1.8kHz in the HLT online system.
742ae1c4 60 *
61 * <h2>Memory consumption:</h2>
62 * Negligible.
63 *
64 * <h2>Output size:</h2>
65 * Same order of magnitude as the input data size.
66 *
67 * \ingroup alihlt_tpc_components
68 */
69class AliHLTTriggerCounterComponent : public AliHLTProcessor
70{
71public:
72
73 AliHLTTriggerCounterComponent();
74 virtual ~AliHLTTriggerCounterComponent();
75
76 // Methods inherited from AliHLTComponent:
77 virtual const char* GetComponentID();
78 virtual void GetInputDataTypes(AliHLTComponentDataTypeList& list);
79 virtual AliHLTComponentDataType GetOutputDataType();
80 virtual int GetOutputDataTypes(AliHLTComponentDataTypeList& list);
81 virtual void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);
82 virtual AliHLTComponent* Spawn();
83 virtual Int_t DoInit(int argc, const char** argv);
84 virtual Int_t DoDeinit();
85
86 /**
87 * Returns a reference to the initial counter configuration to use.
88 * This should be used in the configuration file passed to the component with
89 * the -config option to setup the initial counter configuration. The following
90 * is an example of such a config file.
91 * \code
92 * void SetupConfig() {
93 * TMap& counters = AliHLTTriggerCounterComponent::InitialCounterConfig();
94 * counters.Add(new TObjString("TRIGGER-A"), new TObjString("Some input trigger"));
95 * TObjString* outname = new TObjString("TRIGGER-B");
96 * outname->SetBit(1<<14);
97 * counters.Add(outname, new TObjString("Some output trigger"));
98 * }
99 * \endcode
100 */
101 static TMap& InitialCounterConfig()
102 {
103 fgInitialCounterConfig.SetOwner(kTRUE); // Make sure its the owner of all objects.
104 return fgInitialCounterConfig;
105 }
106
107protected:
108
109 // Method inherited from AliHLTProcessor:
110 virtual int DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData);
111 using AliHLTProcessor::DoEvent;
112
113private:
114
115 /// Implements a ring buffer for old counter and time stamp values.
116 class AliRingBuffer : public TObject
117 {
118 public:
119 enum
120 {
121 /// The maximum number of time stamp entries held in the ring buffers for rate calculations.
122 /// The uncertainty in the rate should be ~ rate/sqrt(kTimeStampEntries)
123 kTimeStampEntries = 100
124 };
125
126 /// Constructor initialises the buffer
127 AliRingBuffer(const char* counterName, Double_t startTime) : TObject(), fCounterName(counterName), fPos(0)
128 {
129 for (size_t i = 0; i < kTimeStampEntries; ++i) {
130 fCounterBuffer[i] = 0; fTimeBuffer[i] = startTime;
131 }
132 }
133
134 /// Inherited form TObject. Returns the counter name this buffer is associated to.
135 virtual const char* GetName() const { return fCounterName.Data(); }
136
137 /// Inherited from TObject. Returns a hash value calculated from the counter name.
138 virtual ULong_t Hash() const { return fCounterName.Hash(); }
139
140 /// Returns the oldest counter value.
141 ULong64_t OldestCounter() const { return fCounterBuffer[fPos]; }
142
143 /// Returns the oldest time value.
144 Double_t OldestTime() const { return fTimeBuffer[fPos]; }
145
146 /**
147 * Increments the buffer. The new time and counter values are put into the
148 * current location to replace the existing values, then the current position
149 * is incremented (and wrapped around if necessary).
150 * \param newCounter The new counter value to put into the buffer.
151 * \param newTime The new time value to put into the buffer.
152 */
153 void Increment(ULong64_t newCounter, Double_t newTime)
154 {
155 fCounterBuffer[fPos] = newCounter;
156 fTimeBuffer[fPos] = newTime;
157 fPos = (fPos+1) % kTimeStampEntries;
158 }
159
160 private:
161
162 TString fCounterName; // The name of the counter.
163 UInt_t fPos; // Current position in the buffers.
164 ULong64_t fCounterBuffer[kTimeStampEntries]; // The counter elements of the buffer.
165 Double_t fTimeBuffer[kTimeStampEntries]; // The time elements of the buffer.
166 };
167
168 // Do not allow copying of this class.
169 AliHLTTriggerCounterComponent(const AliHLTTriggerCounterComponent& obj);
170 AliHLTTriggerCounterComponent& operator = (const AliHLTTriggerCounterComponent& obj);
171
172 /// Updates the counter rate value.
173 void UpdateCounterRate(AliHLTTriggerCounters::AliCounter* counter, AliRingBuffer* timeBuf, Double_t newTime);
174
175 /// Loads the initial configuration of counters from the given CDB path.
176 int LoadConfigFromCDB(const char* cdbPath);
177
178 /// Loads the initial configuration of counters from the given configuration file.
179 int LoadConfigFromFile(const char* configFile);
180
181 /**
182 * Sets the initial counter values from a TMap object containing name description pairs.
183 * \param counters The list of counters to initialise. This TMap should contain TObjString
184 * pairs where the key is the name of the counter and the TMap value is the description.
185 * If the 14th bit is set in the key TObjString then the counter is considered an
186 * output counter and an input counter otherwise.
187 */
188 void SetInitialCounters(const TMap* counters);
189
190 double fOutputMultiplier; //! Multiplier value for the output size estimate.
191 AliHLTTriggerCounters fInputCounters; //! Input trigger counters.
192 AliHLTTriggerCounters fOutputCounters; //! Output trigger counters.
193 THashTable fInputTimes; //! Cyclic buffer storing the time stamps when the input counters were received.
194 THashTable fOutputTimes; //! Cyclic buffer storing the time stamps when the output counters were received.
195 Double_t fLastPublishTime; //! The last time the counters were pushed back to the output.
196 Double_t fPublishPeriod; //! The time between calls to push back the counters to output.
247b2cad 197 bool fCountFalseInputs; //! Indicates if the false input trigger decisions should also be counted.
198 bool fCountFalseOutputs; //! Indicates if the false output trigger decisions should also be counted.
742ae1c4 199
200 static const char* fgkConfigCDBPath; //! CDB configuration path.
201 static TMap fgInitialCounterConfig; //! Initial configuration information for the counters.
202
203 ClassDef(AliHLTTriggerCounterComponent, 0) // Component for counting HLT triggers.
204};
205
206#endif // ALIHLTTRIGGERCOUNTERCOMPONENT_H