3 #ifndef ALIHLTGLOBALTRIGGERCOMPONENT_H
4 #define ALIHLTGLOBALTRIGGERCOMPONENT_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 AliHLTGlobalTriggerComponent.h
10 /// @author Artur Szostak <artursz@iafrica.com>
12 /// @brief Declaration of the AliHLTGlobalTriggerComponent component class.
14 #include "AliHLTTrigger.h"
15 #include "AliHLTTriggerDecision.h"
16 #include "TClonesArray.h"
18 class AliHLTTriggerMenu;
19 class AliHLTGlobalTrigger;
22 * \class AliHLTGlobalTriggerComponent
23 * This class applies the global HLT trigger to all trigger information produced
24 * by components deriving from AliHLTTrigger.
25 * Any information delivered by other components in data blocks that contain
26 * TObjects can also be used for the trigger algorithm. In such cases a symbol
27 * needs to be defined in the global trigger menu which can then be used inside
28 * the trigger condition expressions.
30 * <h2>General properties:</h2>
32 * Component ID: \b HLTGlobalTrigger <br>
33 * Library: \b libAliHLTTrigger.so <br>
34 * Input Data Types: ::kAliHLTAnyDataType <br>
35 * Output Data Types: kAliHLTDataTypeGlobalTrigger and kAliHLTDataTypeReadoutList <br>
37 * <h2>Mandatory arguments:</h2>
40 * <h2>Optional arguments:</h2>
41 * <!-- NOTE: ignore the \li. <i> and </i>: it's just doxygen formatting -->
42 * \li -config <i>filename</i> <br>
43 * Indicates the configuration macro file to use for the global HLT trigger menu.
44 * \li -includepath <i>path</i> <br>
45 * Indicates the include path to use if the automatically generated code that
46 * implements the global HLT trigger requires non-standard includes.
47 * \li -include <i>filename</i> <br>
48 * Indicates a file name that should be included in the automatically generated
49 * trigger implementation code.
51 * If specified the automatically generated class will contain extra debugging
52 * code and the ACLiC system will have debugging compilation turned on.
54 * Use CINT to interprete the generated global trigger instead of compiling it.
55 * This will also be the case if no compiler is available.
56 * \li -usecode <i>filename</i> <i>classname</i> <br>
57 * Used to force the component to use an existing class for the global HLT trigger
58 * class implementation, with the name of <i>classname</i> and found in the file
61 * Indicates that the CTP data should not be added to the global HLT trigger decision.
62 * \li -forward-input <br>
63 * Forward the input objects instead of adding them to the global HLT trigger decision.
64 * This will also add a short info on the input objects and decisions, like
65 * -include-input=short, to switch off -include-input=none can be placed after the
67 * \li -include-input[=none,short,objects,both] <br>
68 * Steer adding of input objects to the global HLT trigger decision.
69 * Options: none - include nothing, short - include a short TNames array,
70 * objects - include objects, by default on
71 * both - include both objects and short info
72 * \li -process-all-events <br>
73 * Indicates that all events should be processed with the global trigger logic and
74 * not just the data events. The default is not to process just the data events.
75 * \li -monitoring[=n] <br>
76 * enable monitoring trigger once every n seconds, enable for every event if
77 * parameter n is omitted
78 * \li -dont-make-software-triggers <br>
79 * This option prevents the Common Data Header from being interpreted to generate
80 * software event input triggers for the trigger menu. Normally the following default
81 * triggers are available in the trigger menu:
82 * START_OF_DATA - start of data event.
83 * END_OF_DATA - end of data event.
84 * SOFTWARE - general software trigger.
85 * CALIBRATION - calibration trigger.
86 * With this option these will not be automatically generated by the global trigger.
87 * \li -randomseed <i>number</i> <br>
88 * Specifies the random number seed to give to the internal random number generator.
89 * This is only useful for debugging to generate reproducible number sequences.
90 * The random numbers are only used if a trigger is scaled down using the scale down
91 * option in a trigger menu item. The seed is normally randomly chosen by default.
93 * <h2>Configuration:</h2>
94 * Configured from CDB but can be overridden with the -config argument.
96 * <h2>Default CDB entries:</h2>
97 * HLT/ConfigHLT/HLTGlobalTrigger - Contains the global trigger menu.
99 * <h2>Performance:</h2>
100 * This is a linear function of the number of input triggers (AliHLTTrigger) that
101 * need to be processed.
102 * For a modest trigger menu configurations the processing time per event should
103 * be on the order of a few milliseconds.
105 * <h2>Memory consumption:</h2>
106 * Memory consumption is minimal. It should be on the order of 2 or 3 MBytes.
108 * <h2>Output size:</h2>
109 * This will depend almost linearly on the number of intput triggers and summary
110 * data objects used. Thus, for every trigger (AliHLTTrigger object) specified
111 * in the trigger menu the output size will require about 1 kBytes.
112 * Then for every summary data object (i.e. TObject symbol defined in the trigger
113 * menu configuration) one will need an extra few kBytes, depending on the size
114 * of the summary objects.
115 * In total one would expect no more than a MByte output size for a large trigger
116 * configuration and typically only a few kBytes for a small or optimised one.
118 * \ingroup alihlt_trigger_components
120 class AliHLTGlobalTriggerComponent : public AliHLTTrigger
124 AliHLTGlobalTriggerComponent();
125 virtual ~AliHLTGlobalTriggerComponent();
128 * Inherited from AliHLTTrigger.
129 * @return string containing the global trigger name.
131 virtual const char* GetTriggerName() const { return "HLTGlobalTrigger"; };
134 * Inherited from AliHLTTrigger.
135 * This returns kAliHLTDataTypeGlobalTrigger by default.
136 * @param list <i>[out]</i>: The list of data types to be filled.
138 virtual void GetOutputDataTypes(AliHLTComponentDataTypeList& list) const;
141 * Get a ratio by how much the data volume is shrunk or enhanced.
142 * The method returns a size proportional to the trigger name string length
143 * for constBase, and 1 for inputMultiplier.
144 * @param constBase <i>[out]</i>: additive part, independent of the
146 * @param inputMultiplier <i>[out]</i>: multiplication ratio
148 virtual void GetOutputDataSize(unsigned long& constBase, double& inputMultiplier);
151 * Initialise the component.
152 * \param argc The number of arguments in argv.
153 * \param argv Array of component argument strings.
154 * \returns Zero on success and negative number on failure.
156 virtual Int_t DoInit(int argc, const char** argv);
159 * Cleanup the component.
160 * \returns Zero on success and negative number on failure.
162 virtual Int_t DoDeinit();
165 * Spawn function creates a new object.
166 * @return new class instance.
168 virtual AliHLTComponent* Spawn();
171 kForwardInput = BIT(14), // forward input objects instead of adding them to the decision object
172 kIncludeInput = BIT(15), // include input objects in the decision object
173 kIncludeShort = BIT(16), // include short description of input objects: name, title, decision
174 kSkipCTP = BIT(17), // skip CTP data object in the decision object
177 void SetBit(AliHLTUInt32_t f, bool set) {
181 void SetBit(AliHLTUInt32_t f) { fBits |= f; }
182 void ResetBit(AliHLTUInt32_t f) { fBits &= ~f; }
183 bool TestBit(AliHLTUInt32_t f) const { return (bool) ((fBits & f) != 0); }
188 * Applies the global HLT trigger.
189 * @return Zero is returned on success and a negative error code on failure.
191 virtual int DoTrigger();
194 * Reconfigures the component by loading the trigger menu from the given
196 * \param cdbEntry The CDB path to the trigger menu to load.
197 * \param chainId The ID of the component in the chain.
198 * \returns Zero on success and non-zero values otherwise.
200 virtual int Reconfigure(const char* cdbEntry, const char* chainId);
204 /// Not implemented. Do not allow copying of this object.
205 AliHLTGlobalTriggerComponent(const AliHLTGlobalTriggerComponent& obj);
206 /// Not implemented. Do not allow copying of this object.
207 AliHLTGlobalTriggerComponent& operator = (const AliHLTGlobalTriggerComponent& obj);
210 * Loads a trigger menu object from the CDB.
211 * \param cdbPath <i>in</i> The path in the CDB to load the trigger menu object from.
212 * \param menu <i>out</i> A pointer that gets filled with the new trigger menu object.
213 * \returns Zero if the trigger menu object was found and the pointer to it
214 * set in the <i>menu</i> variable. If a non-zero error code is returned then
215 * the <i>menu</i> variable is not changed at all.
217 int LoadTriggerMenu(const char* cdbPath, const AliHLTTriggerMenu*& menu);
220 * Generates a file name for the generated on the fly code using a GUID.
221 * \param name <i>out</i> The name of the class to use.
222 * \param filename <i>out</i> The name of the file containing the code.
224 void GenerateFileName(TString& name, TString& filename);
227 * Generates the code for the global trigger to apply the given trigger menu.
228 * The code will then be compiled on the fly and loaded. The name of the new
229 * class is returned so that a new instance of the class can be created via:
231 * AliHLTGlobalTrigger::CreateNew(name)
233 * where name is the name of the generated class as returned by this method.
235 * The name of the generated code file is stored in the variable fCodeFileName
236 * and the fDeleteCodeFile is set to true.
238 * \param menu <i>in</i> The trigger menu to create the global trigger class from.
239 * \param name <i>out</i> The name of the generated class.
240 * \param filename <i>out</i> The name of the generated file containing the code.
241 * \param includePaths <i>in</i> The list of include path strings.
242 * \param includeFiles <i>in</i> The list of include file strings.
243 * \returns The error code suitable to return in DoInit. Zero on success.
246 const AliHLTTriggerMenu* menu, TString& name, TString& filename,
247 const TClonesArray& includePaths, const TClonesArray& includeFiles
251 * Loads the code for the generated HLT global trigger class. The code is compiled
252 * on the fly if possible, otherwise the CINT interpreter is used to interpret
254 * \param filename The name of the file containing the code for the global trigger class.
255 * \param includePaths <i>in</i> The list of include path strings.
256 * \returns The error code suitable to return in DoInit. Zero on success.
258 int LoadTriggerClass(const char* filename, const TClonesArray& includePaths);
261 * Unloads the code that was previously loaded by LoadTriggerClass.
262 * \param filename The name of the file containing the global trigger class logic to be unloaded.
263 * \returns The error code suitable to return in DoInit. Zero on success.
265 int UnloadTriggerClass(const char* filename);
268 * Searches for the specified symbol name in the given list.
269 * \param name The name of the symbol to find.
270 * \param list The list to search for the symbol in.
271 * \returns The position (index) of the symbol found or -1 if it was not found.
273 int FindSymbol(const char* name, const TClonesArray& list);
276 * Builds the list of symbols to use in the custom global trigger menu
277 * implementation class.
278 * \param menu The trigger menu to create the global trigger class from.
279 * \param list The list to fill with symbols.
280 * \returns The error code suitable to return in DoInit. Zero on success.
282 int BuildSymbolList(const AliHLTTriggerMenu* menu, TClonesArray& list);
285 * Extracts the trailing operator in a C++ expression and returns the found
286 * operator in a separate output string.
287 * [in/out] \param expr The C++ expression to check. The trailing operator
288 * is removed from the expression if found.
289 * [out] \param op The output variable which will be filled with the
290 * operator found in the expression.
291 * \return true if the trailing operator was found in the expression and
294 bool ExtractedOperator(TString& expr, TString& op);
297 * Add trigger decisions according to the active CTP trigger classes
298 * An internal TClonesArray holds the trigger decisions to be added. The trigger
299 * decisions are updated according to the active CTP trigger mask.
300 * \param pTrigger The instance of the global trigger
301 * \param pCTPData Instance of the CTP data
302 * \param trigData Current trigger data, if NULL, the active trigger data from the CTP data is used
304 int AddCTPDecisions(AliHLTGlobalTrigger* pTrigger, const AliHLTCTPData* pCTPData, const AliHLTComponentTriggerData* trigData);
307 * This method handles the software trigger by checking the Common Data Header
308 * and filling fSoftwareTrigger with appropriate information for one of the
309 * following triggers: START_OF_DATA, END_OF_DATA, SOFTWARE or CALIBRATION, if
310 * it is indicated in the CDH L1 trigger message.
311 * \returns true if the trigger decision object was filled and false otherwise.
313 bool FillSoftwareTrigger();
316 * Print some statistics based on the trigger counters
318 int PrintStatistics(const AliHLTGlobalTrigger* pTrigger, AliHLTComponentLogSeverity level=kHLTLogInfo, int offset=1) const;
320 AliHLTGlobalTrigger* fTrigger; //! Trigger object which implements the global trigger menu.
321 bool fDebugMode; //! Indicates if the generated global trigger class should be in debug mode.
322 bool fRuntimeCompile; //! Indicates if the generated global trigger class should be compiled
323 bool fDeleteCodeFile; //! If true then the code file indicated by fCodeFileName should be deleted during DoDeinit.
324 bool fMakeSoftwareTriggers; //! Indicates if the software triggers should be filled automatically or not.
325 TString fCodeFileName; //! base file name of the generated code for the global trigger
326 TString fClassName; //! The generated/loaded trigger class name.
327 TClonesArray* fCTPDecisions; //! AliHLTTriggerDecision objects for the CTP classes
328 unsigned long fBufferSizeConst; //! Constant size estimate for GetOutputDataSize.
329 double fBufferSizeMultiplier; //! Buffer size multiplier estimate for GetOutputDataSize.
330 TClonesArray fIncludePaths; //! Paths specified by the -includepath command line option.
331 TClonesArray fIncludeFiles; //! Files specified by the -include command line option.
332 TString fLibStateAtLoad; //! This stores the loaded libraries just before we tell CINT to load the interpreted file.
333 AliHLTUInt32_t fBits; //! Status bits
334 bool fDataEventsOnly; //! Flag indicating if only data events are processed with trigger logic.
335 int fMonitorPeriod; //! Period of the monitoring trigger in s, -1 means monitoring trigger off
336 UInt_t fUniqueID; //! Unique ID for the decision output objects.
337 AliHLTTriggerDecision fSoftwareTrigger; //! Software or calibration trigger decision object to be added to trigger logic.
338 AliHLTUInt64_t fTotalEventCounter; //! Counts the total number of events handled.
340 static const char* fgkTriggerMenuCDBPath; //! The path string to read the trigger menu from the CDB.
342 ClassDef(AliHLTGlobalTriggerComponent, 0) // Global HLT trigger component class which produces the final trigger decision and readout list.
345 #endif // ALIHLTGLOBALTRIGGERCOMPONENT_H