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