]>
Commit | Line | Data |
---|---|---|
30338a30 | 1 | //-*- Mode: C++ -*- |
242bb794 | 2 | // @(#) $Id$ |
3 | ||
4 | #ifndef ALIHLTMODULEAGENT_H | |
5 | #define ALIHLTMODULEAGENT_H | |
79c114b5 | 6 | /* This file is property of and copyright by the ALICE HLT Project * |
7 | * ALICE Experiment at CERN, All rights reserved. * | |
242bb794 | 8 | * See cxx source for full Copyright notice */ |
9 | ||
10 | /** @file AliHLTModuleAgent.h | |
11 | @author Matthias Richter | |
12 | @date | |
13 | @brief Agent helper class for component libraries. | |
14 | @note The class is used in Offline (AliRoot) context | |
15 | */ | |
16 | ||
30338a30 | 17 | // see below for class documentation |
18 | // or | |
19 | // refer to README to build package | |
20 | // or | |
21 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
22 | ||
242bb794 | 23 | #include <TObject.h> |
24 | #include <TList.h> | |
164de2ba | 25 | #include <TString.h> |
242bb794 | 26 | #include "AliHLTLogging.h" |
27 | #include "AliHLTConfiguration.h" | |
28 | #include "AliHLTConfigurationHandler.h" | |
f3506ea2 | 29 | #include "AliHLTComponentHandler.h" |
242bb794 | 30 | |
31 | class AliRunLoader; | |
dee38f1b | 32 | class AliRawReader; |
62bb3cd4 | 33 | class AliRawStream; |
34 | class AliHLTOUTHandler; | |
35 | class AliHLTOUT; | |
12ec5482 | 36 | class AliHLTModulePreprocessor; |
242bb794 | 37 | |
38 | /** | |
39 | * @class AliHLTModuleAgent | |
40 | * @brief Agent helper class for HLT sub modules, e.g. PHOS, TPC, Trigger | |
41 | * | |
c215072c | 42 | * This class implements the agent base class for the HLT sub modules. |
90ebac25 | 43 | * The agent of a library gives information on the features of the library/ |
44 | * components, like the configurations to run and other component libraries | |
45 | * it depends on. | |
46 | * @note There must not be more than one agent per module/library. | |
47 | * | |
dee38f1b | 48 | * If a run loader is available, reconstruction is performed on simulated |
a55f626d | 49 | * data as part of <tt>AliSimulation</tt>, if only the raw reader is present, |
50 | * on raw data as part of <tt>AliReconstruction</tt>. The configurations | |
dee38f1b | 51 | * can adapt to the two cases. |
52 | * | |
c215072c | 53 | * All HLT component libraries are loaded on demand through the HLT steering |
54 | * instance (@ref AliHLTSystem). A library can implement an agent derived | |
55 | * from this base class, and has to define one global object of this agent | |
56 | * in the code. The agent will be registered automatically, and the features | |
57 | * can be queried when required. | |
58 | * | |
90ebac25 | 59 | * This is usually done during running the AliRoot reconstruction (see AliRoot |
3294f81a | 60 | * documentation on <tt> AliSimulation </tt> and <tt> AliReconstruction </tt>). |
dee38f1b | 61 | * The HLT implemets the @ref AliHLTSimulation and @ref |
62 | * AliHLTReconstructor which hold the HLT steering object. Several flags can | |
63 | * be specified as options via the <tt>SetRunHLT</tt> method of | |
64 | * <tt>AliSimulation</tt> and the <tt>SetOption</tt> method of | |
90ebac25 | 65 | * <tt>AliReconstruction</tt>, including the component libraries to be loaded. |
66 | * | |
67 | * @section alihltmoduleagent_interface Agent interface | |
68 | * The child can implement the following functions: | |
69 | * - @ref CreateConfigurations <br> | |
dee38f1b | 70 | * Create HLT configuration forming an HLT analysis chain. <br> |
71 | * Reconstruction of raw data or simulated data from digits needs | |
72 | * usually different configurations. If a run loader is available, | |
a55f626d | 73 | * reconstruction is performed on simulated data, on raw data if Run |
74 | * loader is NULL and only the raw reader present. | |
90ebac25 | 75 | * |
dee38f1b | 76 | * - @ref GetReconstructionChains <br> |
77 | * Configurations run during event reconstruction. <br> | |
78 | * Define chains to be run during the recunstruction step, | |
79 | * Depending on the availability of AliRoot run loader or raw reader | |
90ebac25 | 80 | * <br> |
dee38f1b | 81 | * |
90ebac25 | 82 | * - @ref GetRequiredComponentLibraries <br> |
83 | * can indicate further libraries which are required for running the | |
84 | * chains (e.g. if components of another library are used). | |
242bb794 | 85 | * |
90ebac25 | 86 | * - @ref RegisterComponents <br> |
87 | * register componens, this can be used to avoid the component | |
88 | * registration via global objects | |
89 | * @see @ref alihltcomponent-handling | |
90 | * <br> | |
62bb3cd4 | 91 | * - @ref GetHandlerDescription <br> |
92 | * the agent can announce which part of the HLTOUT data can be treated | |
93 | * by the library and through which method. Different types of handlers | |
94 | * are defined to fit the various formats of the HLTOUT data. | |
95 | * @see AliHLTOUTHandlerType | |
96 | * | |
97 | * - @ref GetOutputHandler <br> | |
98 | * Return AliHLTOUTHandler for a given data type and specification. | |
99 | * This is mainly intended to treat detector proprietary data. | |
100 | * | |
90ebac25 | 101 | * @section alihltmoduleagent_references References |
102 | * @see @ref AliHLTReconstructor interface to the AliRoot reconstruction | |
103 | * @see @ref AliHLTAgentSample agent for the libAliHLTSample library | |
242bb794 | 104 | * |
105 | * @ingroup alihlt_system | |
106 | */ | |
107 | class AliHLTModuleAgent : public TObject, public AliHLTLogging { | |
108 | public: | |
109 | /** | |
110 | * standard constructor. The agent is automatically registered in the | |
111 | * global agent manager | |
112 | */ | |
626bfcc1 | 113 | AliHLTModuleAgent(const char* id); |
242bb794 | 114 | /** destructor */ |
115 | virtual ~AliHLTModuleAgent(); | |
116 | ||
626bfcc1 | 117 | /** |
118 | * Get module id. | |
119 | * The module id is a string specifying the detector, or module. The | |
af2ed151 | 120 | * library must follow the naming scheme \em libAliHLTModule.so, e.g. |
121 | * \em libAliHLTTPC.so if the module is 'TPC' | |
626bfcc1 | 122 | */ |
123 | const char* GetModuleId() const; | |
124 | ||
242bb794 | 125 | /** |
126 | * Print status info. | |
90ebac25 | 127 | * Short summary on registered agents. This function acts globally on the |
128 | * list of agents if no specific agent is specified. | |
242bb794 | 129 | */ |
130 | static void PrintStatus(const char* agent=NULL); | |
131 | ||
132 | /** | |
133 | * Get the first agent in the list | |
134 | * @return pointer to first agent in the list, NULL if empty | |
135 | */ | |
136 | static AliHLTModuleAgent* GetFirstAgent(); | |
137 | ||
138 | /** | |
139 | * Get the next agent in the list | |
140 | * @return pointer to next agent in the list, NULL if end of list | |
141 | */ | |
142 | static AliHLTModuleAgent* GetNextAgent(); | |
143 | ||
f3506ea2 | 144 | /** |
145 | * Activate a component handler for this agent. | |
146 | * The @ref RegisterComponents method will be called in order to allow | |
147 | * the agent to register components. Once activated, the function can | |
148 | * be called repeatedly with the same handler and gently ignores the | |
149 | * invocation. In the current stage of development, only one handler | |
150 | * can be activated per agent. This is sufficient for the current | |
151 | * operation, but can be extended. | |
152 | * @param pHandler [in] the component handler instance | |
153 | */ | |
154 | int ActivateComponentHandler(AliHLTComponentHandler* pHandler); | |
155 | ||
242bb794 | 156 | /** |
157 | * Register all configurations belonging to this module with the | |
158 | * AliHLTConfigurationHandler. The agent can adapt the configurations | |
159 | * to be registered to the current AliRoot setup by checking the | |
dee38f1b | 160 | * runloader and the raw reader. <br> |
a55f626d | 161 | * The presence of Run loader and raw reader determines the mode of the |
162 | * HLT reconstruction. If a run loader is available, reconstruction is | |
163 | * performed on simulated data, a raw reader might be available in that | |
164 | * case also. When running embedded into AliReconstruction, the Run loader | |
165 | * is always NULL and the raw gives access to data. The configurations | |
dee38f1b | 166 | * can adapt to the two cases. |
167 | * | |
96bda103 | 168 | * @param handler [in] the configuration handler |
dee38f1b | 169 | * @param rawReader [in] AliRoot RawReader instance |
96bda103 | 170 | * @param runloader [in] AliRoot runloader |
242bb794 | 171 | * @return neg. error code if failed |
172 | */ | |
173 | virtual int CreateConfigurations(AliHLTConfigurationHandler* handler, | |
dee38f1b | 174 | AliRawReader* rawReader=NULL, |
242bb794 | 175 | AliRunLoader* runloader=NULL) const; |
176 | ||
177 | /** | |
dee38f1b | 178 | * Get the top configurations for event reconstruction. |
242bb794 | 179 | * A top configuration describes a processing chain. It can simply be |
180 | * described by the last configuration(s) in the chain. | |
181 | * The agent can adapt the configurations to be registered to the current | |
dee38f1b | 182 | * AliRoot setup by checking the run loader and the raw reader. |
183 | * @param rawReader [in] AliRoot RawReader instance | |
184 | * @param runloader [in] AliRoot runloader | |
90ebac25 | 185 | * @return string containing the top configurations separated by blanks |
186 | */ | |
dee38f1b | 187 | virtual const char* GetReconstructionChains(AliRawReader* rawReader=NULL, |
188 | AliRunLoader* runloader=NULL) const; | |
242bb794 | 189 | |
190 | /** | |
dee38f1b | 191 | * Component libraries which the configurations of this agent depend on. <br> |
192 | * @note This is not the right place to specify libraries which this component | |
193 | * library depends. Dependencies must be linked or loaded before. | |
242bb794 | 194 | * @return list of component libraries as a blank-separated string. |
195 | */ | |
196 | virtual const char* GetRequiredComponentLibraries() const; | |
197 | ||
198 | /** | |
f3506ea2 | 199 | * Register components. |
242bb794 | 200 | * This method can be used to register components for the module instead |
f3506ea2 | 201 | * of the 'static object approach'. Registration is done by passing a |
202 | * sample object to the AliHLTComponentHandler via | |
203 | * - @ref AliHLTComponentHandler::RegisterComponent <br> | |
204 | * The sample object is owned by the agent, make sure to delete it. | |
205 | * - @ref AliHLTComponentHandler::AddComponent <br> | |
206 | * Same functionality but handler deletes the object at the end. | |
207 | * | |
208 | * @param pHandler [in] instance of the component handler | |
242bb794 | 209 | */ |
f3506ea2 | 210 | virtual int RegisterComponents(AliHLTComponentHandler* pHandler) const; |
242bb794 | 211 | |
62bb3cd4 | 212 | /** |
213 | * IDs for output handlers. | |
214 | * The agent can provide output handlers in order to treat the output | |
215 | * data coming from the HLTOUT nodes. | |
216 | */ | |
217 | enum AliHLTOUTHandlerType { | |
218 | kUnknownOutput =0, | |
164de2ba | 219 | |
62bb3cd4 | 220 | /** output is in ESD format */ |
221 | kEsd, | |
164de2ba | 222 | |
223 | /** agent provides data for a RawReader | |
224 | * From the data block one or more output blocks can be | |
225 | * created idenditcal to the ddl format. The blocks are | |
226 | * provided to subsequent analysis by a RawReader instance. | |
227 | * The data block can be processed in order to provide the | |
228 | * raw data, e.g. in case of lossless compression. | |
229 | */ | |
230 | kRawReader, | |
231 | ||
232 | /** agent can create a raw stream | |
233 | * The agent directly generates a detector specific RawStream | |
234 | * object. This is used for pre-analyzed data which will not | |
235 | * be converted back to the raw format. | |
236 | */ | |
237 | kRawStream, | |
238 | ||
239 | /** agent provides a chain | |
d1d1bbd7 | 240 | * The data block is fed into an analysis chain, the treatment |
164de2ba | 241 | * depends on the components in the chain. |
242 | */ | |
62bb3cd4 | 243 | kChain, |
164de2ba | 244 | |
62bb3cd4 | 245 | /** agent provides detector specific handler */ |
246 | kProprietary, | |
247 | kLastOutputHandler | |
248 | }; | |
249 | ||
250 | /** | |
251 | * Output handler description. | |
252 | * \em fModule: module name specific for the handler type | |
164de2ba | 253 | * - kRawReader: DDL no printed in ascii format |
254 | * - kRawStream: class name of the RawStream class | |
62bb3cd4 | 255 | * - kChain: blank separated list of chains |
256 | * - kProprietary: name of the handler class | |
257 | */ | |
164de2ba | 258 | class AliHLTOUTHandlerDesc { |
259 | public: | |
260 | AliHLTOUTHandlerDesc() : fHType(kUnknownOutput), fDt(kAliHLTVoidDataType), fModule() {} | |
261 | ||
262 | AliHLTOUTHandlerDesc(AliHLTOUTHandlerType handlerType, AliHLTComponentDataType dt, const char* module) | |
263 | : fHType(handlerType), fDt(dt), fModule(module) {} | |
264 | ||
626bfcc1 | 265 | AliHLTOUTHandlerDesc(const AliHLTOUTHandlerDesc& src) |
266 | : fHType(src.fHType), fDt(src.fDt), fModule(src.fModule) {} | |
267 | ||
268 | const AliHLTOUTHandlerDesc& operator=(const AliHLTOUTHandlerDesc& src) { | |
b0914d2e | 269 | fHType=src.fHType; fDt=src.fDt; fModule=src.fModule; return *this; |
626bfcc1 | 270 | } |
271 | ||
71af1abf | 272 | ~AliHLTOUTHandlerDesc() {} |
164de2ba | 273 | |
44dc7683 | 274 | bool operator==(const AliHLTOUTHandlerType handlerType) const { |
275 | return fHType==handlerType; | |
276 | } | |
b005ef92 | 277 | /** |
278 | * Two descriptors are equal if all members match. | |
279 | */ | |
280 | bool operator==(const AliHLTOUTHandlerDesc& desc) const { | |
281 | return fDt==desc.fDt && fHType==desc.fHType && fModule==desc.fModule; | |
282 | } | |
283 | ||
c5123824 | 284 | operator AliHLTOUTHandlerType() {return fHType;} |
285 | operator AliHLTComponentDataType() {return fDt;} | |
44dc7683 | 286 | |
164de2ba | 287 | private: |
62bb3cd4 | 288 | /** type of the handler */ |
13398559 | 289 | AliHLTOUTHandlerType fHType; //!transient |
62bb3cd4 | 290 | /** data type treated by the handler */ |
13398559 | 291 | AliHLTComponentDataType fDt; //!transient |
62bb3cd4 | 292 | /** class or chain name */ |
13398559 | 293 | TString fModule; //!transient |
62bb3cd4 | 294 | }; |
295 | ||
c5123824 | 296 | static const AliHLTOUTHandlerDesc fgkVoidHandlerDesc; //! initializer |
297 | ||
62bb3cd4 | 298 | /** |
299 | * Get handler description for a data block. | |
9d4cf2ab | 300 | * Depending on the data type and data specification the handler must |
301 | * provide information | |
302 | * - if it can handle the data block, and | |
303 | * - details how it will handle it, mainly the type of the handler | |
304 | * @ref AliHLTOUTHandlerType | |
305 | * | |
62bb3cd4 | 306 | * @param dt [in] data type of the block |
307 | * @param spec [in] specification of the block | |
626bfcc1 | 308 | * @param desc [out] handler description |
62bb3cd4 | 309 | * @return 1 if the agent can provide a handler, 0 if not |
310 | */ | |
311 | virtual int GetHandlerDescription(AliHLTComponentDataType dt, | |
312 | AliHLTUInt32_t spec, | |
af2ed151 | 313 | AliHLTOUTHandlerDesc& desc) const; |
164de2ba | 314 | |
62bb3cd4 | 315 | /** |
316 | * Get handler for a data block of the HLTOUT data. | |
164de2ba | 317 | * The agent can also provide an overloaded @ref DeleteOutputHandler |
318 | * function to implement customized clean up. It is also possible to | |
319 | * return the same instance of a handler for different data blocks.<br> | |
320 | * | |
321 | * The framework first collects the handlers for all data blocks, and | |
322 | * calls the @ref AliHLTOUTHandler::ProcessData method afterwords for | |
323 | * each handler. | |
62bb3cd4 | 324 | * @param dt [in] data type of the block |
325 | * @param spec [in] specification of the block | |
164de2ba | 326 | * @return pointer to handler |
62bb3cd4 | 327 | */ |
328 | virtual AliHLTOUTHandler* GetOutputHandler(AliHLTComponentDataType dt, | |
164de2ba | 329 | AliHLTUInt32_t spec); |
330 | ||
331 | /** | |
332 | * Delete an HLTOUT handler. | |
d4a18597 | 333 | * This is the final cleanup. The framwork makes sure that the handler is |
334 | * not used any further outside the agent. Even if the agent returned the | |
335 | * same handler several times, cleanup is invoked only once. The default | |
336 | * implementation just deletes the object. | |
164de2ba | 337 | * @param pInstance pointer to handler |
338 | */ | |
339 | virtual int DeleteOutputHandler(AliHLTOUTHandler* pInstance); | |
62bb3cd4 | 340 | |
341 | /** | |
342 | * Get raw stream for a data block. | |
343 | * @param dt [in] data type of the block | |
344 | * @param spec [in] specification of the block | |
345 | * @param pData [in] data control object | |
346 | * @return Rawstream object, NULL if no Rawstream available for data type/spec | |
347 | */ | |
164de2ba | 348 | // this method is likely to be moved to a specific implementation |
349 | // of AliHLTOUTHandler | |
350 | // virtual AliRawStream* GetRawStream(AliHLTComponentDataType dt, | |
351 | // AliHLTUInt32_t spec, | |
352 | // const AliHLTOUT* pData); | |
62bb3cd4 | 353 | |
12ec5482 | 354 | /** |
355 | * Get the preprocessor for this component library. | |
356 | * Create an instance of the preprocessor for this component library. | |
357 | * The caller will delete it after useage. | |
358 | * @return pointer to AliHLTModulePreprocessor object. | |
359 | */ | |
360 | virtual AliHLTModulePreprocessor* GetPreprocessor(); | |
361 | ||
90ebac25 | 362 | /** |
363 | * Old method kept for backward compatibility, redirected to @ref | |
dee38f1b | 364 | * GetReconstructionChains. |
90ebac25 | 365 | */ |
366 | const char* GetTopConfigurations(AliRunLoader* runloader=NULL) const { | |
dee38f1b | 367 | return GetReconstructionChains(NULL,runloader); |
90ebac25 | 368 | } |
369 | ||
242bb794 | 370 | protected: |
371 | ||
372 | private: | |
626bfcc1 | 373 | /** standard constructor prohibited */ |
374 | AliHLTModuleAgent(); | |
dee38f1b | 375 | /** copy constructor prohibited */ |
376 | AliHLTModuleAgent(const AliHLTModuleAgent&); | |
377 | /** assignment operator prohibited */ | |
378 | AliHLTModuleAgent& operator=(const AliHLTModuleAgent&); | |
379 | ||
242bb794 | 380 | /** |
381 | * Register agent in the global list. | |
382 | * @return neg. error code if failed | |
383 | */ | |
384 | static int Register(AliHLTModuleAgent* pAgent); | |
385 | ||
386 | /** | |
387 | * Unregister agent in the global list. | |
388 | * @return neg. error code if failed | |
389 | */ | |
390 | static int Unregister(AliHLTModuleAgent* pAgent); | |
391 | ||
392 | /** the list of active agents */ | |
13398559 | 393 | static AliHLTModuleAgent* fgAnchor; //! transient |
7617ca1e | 394 | |
395 | /** next element in the list */ | |
396 | AliHLTModuleAgent* fpNext; //! transient | |
242bb794 | 397 | |
398 | /** the current object link (list position) */ | |
13398559 | 399 | static AliHLTModuleAgent* fgCurrent; //! transient |
7617ca1e | 400 | |
401 | /** number of agents */ | |
13398559 | 402 | static int fgCount; //! transient |
242bb794 | 403 | |
626bfcc1 | 404 | /** instance of the active component handler */ |
f3506ea2 | 405 | AliHLTComponentHandler* fpComponentHandler; //! transient |
406 | ||
626bfcc1 | 407 | /** id of the module */ |
408 | TString fModuleId; //! transient | |
409 | ||
410 | ClassDef(AliHLTModuleAgent, 3); | |
242bb794 | 411 | }; |
412 | ||
413 | #endif |