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