]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTConfiguration.h
Changes required to handle software triggers correctly in the global trigger component.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTConfiguration.h
1 //-*- Mode: C++ -*-
2 // $Id$
3
4 #ifndef ALIHLTCONFIGURATION_H
5 #define ALIHLTCONFIGURATION_H
6 //* This file is property of and copyright by the ALICE HLT Project        * 
7 //* ALICE Experiment at CERN, All rights reserved.                         *
8 //* See cxx source for full Copyright notice                               *
9
10 //  @file   AliHLTConfiguration.h
11 //  @author Matthias Richter
12 //  @date   
13 //  @brief  HLT configuration description for a single component.
14 //  @note   The class is used in Offline (AliRoot) context
15
16 // see below for class documentation
17 // or
18 // refer to README to build package
19 // or
20 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt   
21
22 #include <vector>
23 #include <TObject.h>
24 #include <TList.h>
25 #include "AliHLTDataTypes.h"
26 #include "AliHLTLogging.h"
27 #include "AliHLTDataBuffer.h"
28
29 class AliHLTConfigurationHandler;
30
31 /**
32  * @class AliHLTConfiguration
33  * @brief Description of HLT processing chains.
34  *
35  * This class describes a configuration for an HLT component by means of
36  * the following parameters:
37  * - configuration id:      a unique id string/name
38  * - component id:          id returned by AliHLTComponent::GetComponentID()
39  * - parent configuartions: ids of configurations it requires input from
40  * - component arguments:   passed to the component when it is initialized
41  *
42  * The definition of a configuration requires simply the creation of an object
43  * of type @ref AliHLTConfiguration. 
44  * <pre>
45  * AliHLTConfiguration myprocessor("MyProcessor", "Dummy", "publisher", "-output_percentage 80")
46  * </pre>
47  *
48  * The Configuration is automatically registered in the list of available
49  * configurations maintained by the @ref AliHLTConfigurationHandler.
50  * The list is used to resolve the dependencies on other configurations.
51  * Hierarchies can be built up by specifying the configuration id of parent
52  * configurations as input in the .
53  * A configuration entry is persistent and must be explicitly removed from
54  * the AliHLTConfigurationHandler if desired.
55  *
56  * The registration mechanism requires the HLT system to be available. The
57  * global instance of AliHLTSystem is created and retrieved by
58  * <pre>
59  * // setup the HLT system
60  * AliHLTSystem* pHLT=AliHLTPluginBase::GetInstance();
61  * </pre>
62  *
63  * A configuration is transformed into a list of AliHLTTask objects by the
64  * function AliHLTSystem::BuildTaskList().
65  *
66  * This class is only used in the HLT offline environment, see @ref alihlt_system
67  * for more details.
68  *
69  * @ingroup alihlt_system
70  */
71 class AliHLTConfiguration : public TObject, public AliHLTLogging {
72  public:
73   /**
74    * standard constructor. The configuration is automatically registered in the
75    * global configuration manager
76    */
77   AliHLTConfiguration();
78   /**
79    * constructor. The configuration is automatically registered in the
80    * global configuration manager
81    * @param id         unique id of the configuration
82    * @param component  component id
83    * @param sources    blank separated list of source configuration ids
84    * @param arguments  argument string passed to the component at initialization
85    * @param bufsize    size of the output buffer in byte, the string can contain a
86    *                   number prepended by a unit, e.g. 1M, allowed units 'k' and 'M'
87    */
88   AliHLTConfiguration(const char* id, const char* component,
89                       const char* sources, const char* arguments,
90                       const char* bufsize=NULL);
91   /** copy constructor */
92   AliHLTConfiguration(const AliHLTConfiguration& src);
93   /** assignment op */
94   AliHLTConfiguration& operator=(const AliHLTConfiguration& src);
95   /** destructor */
96   virtual ~AliHLTConfiguration();
97
98   /*****************************************************************************
99    * global initialization
100    */
101
102   /**
103    * Global initialization of the configuration handler.
104    */
105   static int GlobalInit(AliHLTConfigurationHandler* pHandler);
106
107   /**
108    * Global de-init and cleanup of the global configuration handler
109    */
110   static int GlobalDeinit(AliHLTConfigurationHandler* pHandler);
111
112   /*****************************************************************************
113    * properties of the configuration
114    */
115
116   /**
117    * Get configuration id, a unique name
118    * This is an overridden TObject function in order to return the configuration
119    * name instead of the class name. Enables use of TList standard functions.
120    * @return configuration id
121    */
122   const char *GetName() const;
123
124   /**
125    * Get id of the component.
126    * The id is a unique string.
127    * @return id of the component
128    */
129   const char* GetComponentID() const {return fComponent;}
130
131   /**
132    * Return the source string.
133    */
134   const char* GetSourceSettings() const {return fStringSources;}
135
136   /**
137    * Return the argument string.
138    */
139   const char* GetArgumentSettings() const {return fArguments;}
140
141   /**
142    * Print status info.
143    * Short summary on id, component, sources and unresolved sources.
144    */
145   void PrintStatus();
146
147   /**
148    * Get a certain source.
149    * @param  id of the source configuration
150    * @result pointer to the corresponding configuration descriptor
151    */
152   AliHLTConfiguration* GetSource(const char* id);
153
154   /**
155    * Try to find a dependency recursively in the list of sources.
156    * @param id       the source to search for
157    * @param pTgtList (optional) target list to receive the dependency tree
158    * @return
159    *   0 if not found
160    *   n found in the n-th level
161    *   dependency list in the target list  
162    */
163   int FollowDependency(const char* id, TList* pTgtList=NULL);
164
165   /**
166    * Get the number of resolved sources.
167    * @return number of resolved sources
168    */
169   int GetNofSources() {return fListSources.size();}
170
171   /**
172    * Check resolving status.
173    * @param bAuto resolve if ==1 
174    * @return 1 if all sources resolved
175    */
176   int SourcesResolved(int bAuto=0);
177
178   /**
179    * Start iteration and get the first source.
180    * @result pointer to the first configuration descriptor
181    */
182   AliHLTConfiguration* GetFirstSource();
183
184   /**
185    * Continue iteration and get the next source.
186    * @result pointer to the next configuration descriptor in the list
187    */
188   AliHLTConfiguration* GetNextSource();
189
190   /**
191    * Invalidate a dependency and mark the configuration to be re-evaluted. 
192    * @param pConf pointer to configuration descriptor
193    */
194   int InvalidateSource(AliHLTConfiguration* pConf);
195
196   /**
197    * Mark the configuration to be re-evaluted.
198    */
199   int InvalidateSources() {fNofSources=-1; return 0;}
200
201   /**
202    * Get the arguments array.
203    * @param pArgv   pointer to receive argument array pointer
204    * @return argc if succeeded, neg. error code if failed
205    */
206   int GetArguments(const char*** pArgv) const;
207
208   /**
209    * Get output buffer size.
210    * @return size in byte or -1 if not specified
211    */
212   int GetOutputBufferSize() const {return fBufferSize;}
213
214   /**
215    * Two configurations are considered equal if all properties match
216    */
217   bool operator==(const AliHLTConfiguration& c) const {
218     return (fID==c.fID) && (fComponent==c.fComponent) && (fStringSources==c.fStringSources) && (fArguments==c.fArguments);
219   }
220   bool operator!=(const AliHLTConfiguration& c) const {
221     return !(*this==c);
222   }
223
224   /**
225    * Helper function to build a vector from an argument string.
226    * The function allocates memory for each token. The caller is responsible
227    * for cleaning the strings recursively.
228    * @param arg       pointer to argument string
229    * @param argList   target to receive the argument list
230    */
231   static int InterpreteString(const char* arg, vector<char*>& argList);
232
233  protected:
234   
235
236  private:
237   /* extract the source configurations from the sources string
238    */
239   int ExtractSources();
240
241   /* extract arguments from the argument string
242    */
243   int ExtractArguments();
244
245   /**
246    * Convert buffer size string to number
247    */
248   int ConvertSizeString(const char* strSize) const;
249
250   /** id of this configuration */
251   TString fID;                                                     // see above
252   /** component id of this configuration */
253   TString fComponent;                                              // see above
254
255   /** the <i>sources</i> string as passed to the constructor */
256   TString fStringSources;                                          // see above
257   /** number of resolved sources, -1 indicates re-evaluation */
258   int fNofSources;                                                 // see above
259   /** list of sources */
260   vector<AliHLTConfiguration*> fListSources;                       // see above
261   /** iterator for the above list */
262   vector<AliHLTConfiguration*>::iterator fListSrcElement;          // see above
263
264   /**
265    * The argument string as passed to the constructor.
266    * Specifies the arguments for the Analysys component. The string will
267    * be parsed and the separated arguments stored in the @ref fArgv array
268    * and @ref fArgc member.
269    */
270   TString fArguments;                                              // see above
271   /** number of arguments */
272   int fArgc;                                                       // see above
273   /** argument array */
274   char** fArgv;                                                    // see above
275
276   /** size of the output buffer */
277   int fBufferSize;                                                 // see above
278
279   /** the instance of the global configuration handler */
280   static AliHLTConfigurationHandler* fgConfigurationHandler;       //! transient
281
282   ClassDef(AliHLTConfiguration, 0);
283 };
284
285 #endif