]>
Commit | Line | Data |
---|---|---|
62bb3cd4 | 1 | //-*- Mode: C++ -*- |
2 | // @(#) $Id$ | |
3 | ||
4 | #ifndef ALIHLTOUT_H | |
5 | #define ALIHLTOUT_H | |
5db0e774 | 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 * | |
62bb3cd4 | 9 | |
10 | /** @file AliHLTOUT.h | |
11 | @author Matthias Richter | |
12 | @date | |
13 | @brief The control class for HLTOUT data. | |
5db0e774 | 14 | */ |
62bb3cd4 | 15 | |
4de7334f | 16 | #include <vector> |
62bb3cd4 | 17 | #include "AliHLTLogging.h" |
5db0e774 | 18 | #include "AliHLTModuleAgent.h" |
19 | ||
20 | class AliHLTOUTHandler; | |
04058ee9 | 21 | class AliHLTOUTHandlerDesc; // AliHLTModuleAgent.h |
c5123824 | 22 | class AliESDEvent; |
23 | class AliHLTReconstructor; | |
c1292031 | 24 | class AliRawReader; |
25 | class TTree; | |
5db0e774 | 26 | |
27 | #define AliHLTOUTInvalidIndex (~(AliHLTUInt32_t)0) | |
28 | ||
29 | typedef vector<AliHLTUInt32_t> AliHLTOUTIndexList; | |
62bb3cd4 | 30 | |
31 | /** | |
32 | * @class AliHLTOUT | |
33 | * The control class for HLTOUT data. | |
34 | * The output of the HLT, either from the HLTOUT nodes or simulated output, | |
35 | * is transferred and stored in the HOMER format. The AliHLTOUT class | |
36 | * implements scanning of the HOMER data for all HLTOUT DDL links and | |
37 | * abstracts access to the complete HLTOUT data. | |
38 | * | |
39 | */ | |
b005ef92 | 40 | class AliHLTOUT { |
62bb3cd4 | 41 | public: |
42 | /** standard constructor */ | |
43 | AliHLTOUT(); | |
44 | /** standard destructor */ | |
45 | virtual ~AliHLTOUT(); | |
46 | ||
c1292031 | 47 | /** |
48 | * Create an AliHLTOUTRawReader instance. | |
49 | * Helper function to transparently access classes from the | |
50 | * libHLTrec library. | |
51 | */ | |
52 | static AliHLTOUT* New(AliRawReader* pRawReader); | |
53 | ||
54 | /** | |
55 | * Create an AliHLTOUTDigitReader instance | |
56 | * Helper function to transparently access classes from the | |
57 | * libHLTrec library. | |
58 | */ | |
59 | static AliHLTOUT* New(TTree* pDigitTree, int event=-1); | |
60 | ||
b005ef92 | 61 | /** |
62 | * Get the global instance. | |
63 | * The global instance is set temporarily by the AliHLTOUTGlobalInstanceGuard | |
64 | * mainly for the sake of data input to an analysis chain. The | |
65 | * AliHLTOUTPublisherComponent objects can access the global instance. | |
66 | */ | |
67 | static AliHLTOUT* GetGlobalInstance() {return fgGlobalInstance;} | |
68 | ||
c1292031 | 69 | /** |
70 | * Delete an instance of the HLTOUT. | |
71 | * Helper function to transparently access classes from the | |
72 | * libHLTrec library. Before deleting, the availability of the | |
73 | * library is checked. | |
74 | */ | |
75 | static void Delete(AliHLTOUT* pInstance); | |
76 | ||
4de7334f | 77 | /** |
78 | * Locking guard for the AliHLTOUT object. | |
79 | * If the object is locked, the selection of data blocks can not be changed. | |
80 | */ | |
81 | class AliHLTOUTLockGuard { | |
82 | public: | |
83 | /** constructor */ | |
84 | AliHLTOUTLockGuard(AliHLTOUT* pInstance) : fpInstance(pInstance) | |
049b43b2 | 85 | {if (fpInstance) fpInstance->SetStatusFlag(kLocked);} |
4de7334f | 86 | /** destructor */ |
87 | ~AliHLTOUTLockGuard() | |
049b43b2 | 88 | {if (fpInstance) fpInstance->ClearStatusFlag(kLocked);} |
4de7334f | 89 | |
90 | private: | |
91 | /** standard constructor prohibited */ | |
92 | AliHLTOUTLockGuard(); | |
93 | /** copy constructor prohibited */ | |
94 | AliHLTOUTLockGuard(const AliHLTOUTLockGuard&); | |
95 | /** assignment operator prohibited */ | |
96 | AliHLTOUTLockGuard& operator=(const AliHLTOUTLockGuard&); | |
97 | ||
98 | /** the AliHLTOUT instance the guard is locking */ | |
99 | AliHLTOUT* fpInstance; //!transient | |
100 | }; | |
101 | ||
b005ef92 | 102 | /** |
103 | * Guard for handling of global AliHLTOUT instance. | |
104 | * The global HLTOUT instance can be set for certain steps of the | |
105 | * processing. The initial objective is to support input to the | |
106 | * AliHLTOUTPublisherComponent running in a kChain handler. | |
107 | * | |
108 | * The Guard restores the original instance when closed. | |
109 | */ | |
110 | class AliHLTOUTGlobalInstanceGuard { | |
111 | public: | |
112 | /** constructor */ | |
113 | AliHLTOUTGlobalInstanceGuard(AliHLTOUT* pInstance) : fpLastInstance(AliHLTOUT::fgGlobalInstance) | |
114 | {AliHLTOUT::fgGlobalInstance=pInstance;} | |
115 | /** destructor */ | |
116 | ~AliHLTOUTGlobalInstanceGuard() | |
117 | {AliHLTOUT::fgGlobalInstance=fpLastInstance;} | |
118 | ||
119 | private: | |
120 | /** standard constructor prohibited */ | |
121 | AliHLTOUTGlobalInstanceGuard(); | |
122 | /** copy constructor prohibited */ | |
123 | AliHLTOUTGlobalInstanceGuard(const AliHLTOUTGlobalInstanceGuard&); | |
124 | /** assignment operator prohibited */ | |
125 | AliHLTOUTGlobalInstanceGuard& operator=(const AliHLTOUTGlobalInstanceGuard&); | |
126 | ||
127 | /** the AliHLTOUT instance the guard is locking */ | |
128 | AliHLTOUT* fpLastInstance; //!transient | |
129 | }; | |
130 | ||
4b113031 | 131 | /** |
132 | * The HLT OUT Event Header. | |
133 | * Defined between HLT and DAQ. | |
134 | */ | |
135 | struct AliHLTOUTEventHeader { | |
136 | /**Total length of the data in bytes, including HLT event header, excluding CDH. */ | |
137 | AliHLTUInt32_t fLength; //! see above | |
138 | /** version of the header */ | |
139 | AliHLTUInt32_t fVersion; //! see above | |
c2b283d6 | 140 | /** High 32 bit word of event id */ |
141 | AliHLTUInt32_t fEventIDHigh; //! see above | |
142 | /** Low 32 bit word of event id */ | |
143 | AliHLTUInt32_t fEventIDLow; //! see above | |
4b113031 | 144 | }; |
145 | ||
44dc7683 | 146 | enum { |
147 | /// versions 1 of the HLT header | |
148 | kVersion1 = 1, | |
149 | /// versions 2 of the HLT header | |
150 | kVersion2 = 2 | |
151 | }; | |
152 | ||
153 | enum { | |
154 | /// size of HLT decision in data format version 1: 29x4 | |
155 | kSizeDecisionVersion1 = 116, | |
156 | /// size of HLT decision in data format version 2: 30x4 | |
157 | kSizeDecisionVersion2 = 120 | |
158 | }; | |
159 | ||
4b113031 | 160 | // definitions from ALICE internal notes ALICE-INT-2002-010 and |
161 | // ALICE-INT-2006-XXX | |
13398559 | 162 | enum { |
163 | /** the 32bit word in the CDH containing the status flags */ | |
164 | kCDHStatusWord=4, //! see above | |
165 | /** start of the flags in word fgkCDHStatusWord */ | |
166 | kCDHStatusFlagsOffset=12, //! see above | |
167 | /** bit indicating HLT decision in the HLTOUT*/ | |
168 | kCDHFlagsHLTDecision=6, //! see above | |
169 | /** bit indicating HLT payload in the HLTOUT*/ | |
170 | kCDHFlagsHLTPayload=7 //! see above | |
171 | }; | |
4b113031 | 172 | |
f3c1d403 | 173 | class AliHLTOUTHandlerListEntry; |
4de7334f | 174 | /** |
175 | * Block descriptor. | |
176 | */ | |
177 | class AliHLTOUTBlockDescriptor { | |
178 | public: | |
0f1882a7 | 179 | AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index, AliHLTOUT* pCollection) |
180 | : fDataType(dt), fSpecification(spec), fIndex(index), fSelected(false), fProcessed(false), fpCollection(pCollection) {}; | |
181 | AliHLTOUTBlockDescriptor(const AliHLTOUTBlockDescriptor& src) | |
182 | : fDataType(src.fDataType), fSpecification(src.fSpecification), fIndex(src.fIndex), fSelected(false), fProcessed(false), fpCollection(src.fpCollection) {} | |
183 | AliHLTOUTBlockDescriptor& operator=(const AliHLTOUTBlockDescriptor& src) | |
184 | { fDataType=src.fDataType; fSpecification=src.fSpecification; fIndex=src.fIndex; fSelected=false; fProcessed=false; fpCollection=src.fpCollection; return *this; } | |
4de7334f | 185 | ~AliHLTOUTBlockDescriptor() {} |
186 | ||
187 | operator AliHLTComponentDataType() const {return fDataType;} | |
188 | operator AliHLTUInt32_t() const {return fSpecification;} | |
189 | int operator==(AliHLTComponentDataType dt) const {return dt==fDataType;} | |
190 | int operator==(AliHLTUInt32_t spec) const {return spec==fSpecification;} | |
0f1882a7 | 191 | int operator==(AliHLTOUT* collection) const {return collection==fpCollection;} |
4de7334f | 192 | |
193 | AliHLTUInt32_t GetIndex() const {return fIndex;} | |
b005ef92 | 194 | AliHLTOUT* GetCollection() const {return fpCollection;} |
0f1882a7 | 195 | |
196 | bool IsSelected() const {return fSelected;} | |
197 | void Select(bool selected=true) {fSelected=selected;} | |
d4a18597 | 198 | bool IsProcessed() const {return fProcessed;} |
0f1882a7 | 199 | void MarkProcessed() {fProcessed=true;} |
200 | ||
201 | /** | |
202 | * Get the data buffer | |
203 | * @param pBuffer [out] buffer of the selected data block | |
204 | * @param size [out] size of the selected data block | |
205 | */ | |
206 | int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size) { | |
207 | if (fpCollection) return fpCollection->GetDataBuffer(GetIndex(), pBuffer, size); | |
208 | return -ENODEV; | |
209 | } | |
210 | ||
f3c1d403 | 211 | /** |
212 | * Get the handler descriptor | |
213 | */ | |
214 | const AliHLTOUTHandlerListEntry& GetHandlerDesc(); | |
215 | ||
0f1882a7 | 216 | private: |
4de7334f | 217 | /** data type of the block */ |
218 | AliHLTComponentDataType fDataType; //!transient | |
219 | /** data specification of the block */ | |
220 | AliHLTUInt32_t fSpecification; //!transient | |
221 | /** index in the data stream */ | |
222 | AliHLTUInt32_t fIndex; //!transient | |
0f1882a7 | 223 | /** selection flag */ |
224 | bool fSelected; //!transient | |
225 | /** processed flag */ | |
226 | bool fProcessed; //!transient | |
227 | /** the collection */ | |
228 | AliHLTOUT* fpCollection; //!transient | |
4de7334f | 229 | }; |
230 | ||
c5123824 | 231 | class AliHLTOUTHandlerListEntry { |
232 | public: | |
233 | AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler, | |
234 | AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc, | |
235 | AliHLTModuleAgent* pAgent, | |
236 | AliHLTUInt32_t index); | |
237 | ||
238 | /** copy constructor for vector handling */ | |
239 | AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src); | |
240 | ||
241 | /** assignment operator for vector handling */ | |
242 | AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src); | |
243 | ||
244 | ~AliHLTOUTHandlerListEntry(); | |
245 | ||
246 | static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry; //! initializer | |
247 | ||
248 | operator AliHLTOUTHandler*() const {return fpHandler;} | |
249 | ||
250 | // please note that fpHandlerDesc is really a pointer and is created | |
251 | // in the constructor. Thats why it is dereferenced here. The pointer | |
252 | // type is on purpose, even though it is a bit confusing with the | |
253 | // argument by reference in the AliHLTOUTHandlerListEntry constructor. | |
254 | operator const AliHLTModuleAgent::AliHLTOUTHandlerDesc&() const | |
255 | {return fpHandlerDesc?*fpHandlerDesc:AliHLTModuleAgent::fgkVoidHandlerDesc;} | |
256 | operator AliHLTModuleAgent*() const {return fpAgent;} | |
257 | ||
258 | /** | |
259 | * Two list entries are considered to be equal if the handlers | |
260 | * are equal. | |
261 | */ | |
262 | bool operator==(const AliHLTOUTHandlerListEntry& entry) const; | |
263 | ||
264 | bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const; | |
265 | ||
b005ef92 | 266 | /** |
267 | * Compare the handler descriptor of this list entry with another | |
268 | * descriptor. | |
f3c1d403 | 269 | * @return true if both handler and agent match |
b005ef92 | 270 | */ |
271 | bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc) const; | |
272 | ||
c5123824 | 273 | AliHLTUInt32_t operator[](int i) const; |
274 | ||
275 | /** | |
276 | * Add a block index to this descriptor. | |
277 | * One descriptor can serve multiple blocks if the agent returns the | |
278 | * same handler for all of the blocks. Instead of creating a new entry | |
279 | * the block index ist just added | |
280 | */ | |
281 | void AddIndex(AliHLTUInt32_t index); | |
282 | ||
283 | /** | |
b005ef92 | 284 | * Add all indices of the descriptor. |
c5123824 | 285 | */ |
286 | void AddIndex(AliHLTOUTHandlerListEntry &desc); | |
287 | ||
288 | /** | |
289 | * Check if an index is served by this descriptor. | |
290 | * @return true if the index is in the table | |
291 | */ | |
0f1882a7 | 292 | bool HasIndex(AliHLTUInt32_t index) const; |
c5123824 | 293 | |
b005ef92 | 294 | /** |
295 | * Invalidate all block indices | |
296 | */ | |
297 | void InvalidateBlocks() {fBlocks.clear();} | |
298 | ||
299 | /** | |
300 | * Check whether the entry has valid blocks. | |
301 | */ | |
302 | bool IsEmpty() {return fBlocks.size()==0;} | |
303 | ||
c5123824 | 304 | private: |
305 | /** standard constructor prohibited */ | |
306 | AliHLTOUTHandlerListEntry(); | |
307 | ||
308 | /** pointer to the handler */ | |
309 | AliHLTOUTHandler* fpHandler; //! transient | |
310 | ||
311 | /** pointer to handler description */ | |
312 | AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient | |
313 | ||
314 | /** pointer to module agent */ | |
315 | AliHLTModuleAgent* fpAgent; //! transient | |
316 | ||
b005ef92 | 317 | /** list of block indices */ |
c5123824 | 318 | AliHLTOUTIndexList fBlocks; //!transient |
319 | }; | |
320 | ||
321 | typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector; | |
322 | typedef vector<AliHLTOUTBlockDescriptor> AliHLTOUTBlockDescriptorVector; | |
0f1882a7 | 323 | typedef vector<AliHLTOUT*> AliHLTOUTPVector; |
324 | ||
325 | /** | |
326 | * Selection guard for the AliHLTOUT object. | |
327 | * If the object is locked, the selection of data blocks can not be changed. | |
328 | */ | |
329 | class AliHLTOUTSelectionGuard { | |
330 | public: | |
331 | /** constructor */ | |
332 | AliHLTOUTSelectionGuard(AliHLTOUT* pInstance) : fpInstance(pInstance) | |
333 | {if (fpInstance) fpInstance->SelectDataBlock();} | |
334 | /** constructor */ | |
335 | AliHLTOUTSelectionGuard(AliHLTOUT* pInstance, const AliHLTOUTHandlerListEntry* pHandlerDesc) : fpInstance(pInstance) | |
336 | {if (fpInstance) fpInstance->SelectDataBlocks(pHandlerDesc);} | |
337 | /** destructor */ | |
338 | ~AliHLTOUTSelectionGuard() | |
339 | {if (fpInstance) fpInstance->DisableBlockSelection();} | |
340 | ||
341 | private: | |
342 | /** standard constructor prohibited */ | |
343 | AliHLTOUTSelectionGuard(); | |
344 | /** copy constructor prohibited */ | |
345 | AliHLTOUTSelectionGuard(const AliHLTOUTSelectionGuard&); | |
346 | /** assignment operator prohibited */ | |
347 | AliHLTOUTSelectionGuard& operator=(const AliHLTOUTSelectionGuard&); | |
348 | ||
349 | /** the AliHLTOUT instance the guard is locking */ | |
350 | AliHLTOUT* fpInstance; //!transient | |
351 | }; | |
c5123824 | 352 | |
353 | /** | |
354 | * Init for processing. | |
355 | * The HLTOUT is scanned for all available data blocks and the | |
356 | * AliHLTOUTHandler objects for the data blocks are created according | |
357 | * to the module agents (see AliHLTModuleAgent). | |
358 | */ | |
359 | int Init(); | |
360 | ||
b005ef92 | 361 | /** |
362 | * Reset and clear all data block descriptors. | |
363 | * @note Since sub-collections are only referred via the block | |
364 | * descriptors, all information on sub-collections is also lost. | |
365 | * Child classes should implement ResetInput in order to cleanup | |
366 | * the input devices. | |
367 | */ | |
368 | int Reset(); | |
369 | ||
c63e8be4 | 370 | /** |
371 | * Get the current event id | |
372 | */ | |
373 | AliHLTUInt64_t EventId() {return fCurrentEventId;} | |
374 | ||
c5123824 | 375 | /** |
376 | * Get number of data blocks in the HLTOUT data | |
377 | */ | |
378 | int GetNofDataBlocks(); | |
379 | ||
380 | /** | |
381 | * Select the first data block of a certain data type and specification. | |
382 | * The selection criteria can be of kAliHLTAnyDataType and/or | |
383 | * kAliHLTVoidDataSpec in order to be ignored and just match any data block. | |
384 | * | |
385 | * The search criteria can be combined with a handler type (e.g. kRawReader) | |
386 | * @param dt [in] data type to match <br> | |
387 | * @param spec [in] data specification to match <br> | |
388 | * @param handlerType [in] type of the handler | |
b005ef92 | 389 | * @param skipProcessed [in] skip all block marked processed |
c1292031 | 390 | * @return block index: >= 0 if success, -ENOENT if no block found <br> |
c5123824 | 391 | * neg. error code if failed <br> |
392 | * -EPERM if access denied (object locked) | |
393 | */ | |
394 | int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType, | |
395 | AliHLTUInt32_t spec=kAliHLTVoidDataSpec, | |
0f1882a7 | 396 | AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput, |
397 | bool skipProcessed=true); | |
c5123824 | 398 | |
399 | /** | |
400 | * Select the next data block of data type and specification of the previous | |
401 | * call to @ref SelectFirstDataBlock. | |
c1292031 | 402 | * @return block index: >= 0 if success, -ENOENT if no block found <br> |
c5123824 | 403 | * neg. error code if failed <br> |
404 | * -EPERM if access denied (object locked) | |
405 | */ | |
406 | int SelectNextDataBlock(); | |
407 | ||
408 | /** | |
409 | * Get properties of the selected data block. | |
410 | * @param dt [out] data type of the selected block | |
411 | * @param spec [out] data specification of the selected block | |
412 | */ | |
413 | int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec); | |
414 | ||
415 | /** | |
416 | * Get handler description of the current data block. | |
417 | */ | |
418 | const AliHLTOUTHandlerListEntry& GetDataBlockHandlerDesc(); | |
419 | ||
420 | /** | |
421 | * Get handler type of the selected data block. | |
422 | * @return handler type for the selected data block | |
423 | */ | |
424 | AliHLTModuleAgent::AliHLTOUTHandlerType GetDataBlockHandlerType(); | |
425 | ||
426 | /** | |
427 | * Get the index of the current data block. | |
428 | * @return index, AliHLTOUTInvalidIndex if no block selected | |
429 | */ | |
430 | AliHLTUInt32_t GetDataBlockIndex(); | |
431 | ||
432 | /** | |
433 | * Get buffer of the selected data block. | |
434 | * @param pBuffer [out] buffer of the selected data block | |
435 | * @param size [out] size of the selected data block | |
436 | */ | |
437 | int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size); | |
438 | ||
439 | /** | |
440 | * Release buffer after use. | |
441 | * @param pBuffer [in] buffer of the selected data block | |
442 | */ | |
443 | int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer); | |
444 | ||
e5701dcf | 445 | /** |
446 | * Get a TObject from the data buffer | |
447 | * @return TObject pointer if data block is a streamed object | |
448 | */ | |
449 | TObject* GetDataObject(); | |
450 | ||
451 | /** | |
452 | * Release data object | |
453 | */ | |
454 | int ReleaseDataObject(TObject* pObject); | |
455 | ||
0f1882a7 | 456 | /** |
457 | * Add the current data block to the selection. | |
458 | * Note: enables also the block selection | |
459 | */ | |
460 | int SelectDataBlock(); | |
461 | ||
462 | /** | |
463 | * Add the all data blocks of a certain handler to the selection. | |
464 | * Note: enables also the block selection | |
465 | */ | |
466 | int SelectDataBlocks(const AliHLTOUTHandlerListEntry* pHandlerDesc); | |
467 | ||
468 | /** | |
469 | * Enable the selection of data blocks. | |
470 | */ | |
471 | int EnableBlockSelection(); | |
472 | ||
473 | /** | |
474 | * Disable the selection of data blocks. | |
475 | */ | |
476 | int DisableBlockSelection(); | |
477 | ||
478 | /** | |
479 | * Reset the data block selection. | |
480 | * Resets the selection list, none of the blocks is selected. | |
481 | */ | |
482 | int ResetBlockSelection(); | |
483 | ||
484 | /** | |
485 | * Mark the current block as processed. | |
486 | */ | |
487 | int MarkDataBlockProcessed(); | |
488 | ||
489 | /** | |
490 | * Mark all data blocks of a certain handler processed. | |
491 | */ | |
492 | int MarkDataBlocksProcessed(const AliHLTOUTHandlerListEntry* pHandlerDesc); | |
493 | ||
494 | /** | |
495 | * Add a sub collection to the HLTOUT. | |
496 | */ | |
497 | int AddSubCollection(AliHLTOUT* pCollection); | |
498 | ||
499 | /** | |
500 | * Release a previously added sub collection. | |
501 | */ | |
502 | int ReleaseSubCollection(AliHLTOUT* pCollection); | |
503 | ||
c5123824 | 504 | /** |
505 | * Get module agent for the selected data block. | |
506 | */ | |
507 | AliHLTModuleAgent* GetAgent(); | |
508 | ||
509 | /** | |
510 | * Get handler for the selected data block. | |
511 | */ | |
512 | AliHLTOUTHandler* GetHandler(); | |
513 | ||
514 | /** | |
515 | * Convert data buffer to ESD. | |
516 | * The buffer is supposed to describe a streamed AliESDEvent object. | |
517 | * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root, | |
518 | * where 'det' is derived from the data type origin. Each time the function is invoked | |
519 | * a new event is created. Dummy events are added if the previous events did not contain | |
520 | * | |
521 | * The function needs AliRoot and might not be implemented by all AliHLTOUT | |
522 | * implementations. | |
523 | * a data block of this specification. | |
524 | * @param pBuffer [in] the data buffer | |
525 | * @param size [in] data buffer size | |
526 | * @param dt [in] data type of the block | |
527 | * @param tgtesd [out] optional target | |
528 | */ | |
529 | virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL) const; | |
530 | ||
13398559 | 531 | enum AliHLTOUTByteOrder { |
049b43b2 | 532 | /** no data block selected */ |
533 | kInvalidByteOrder=-1, | |
534 | kUnknownByteOrder=0, | |
535 | kLittleEndian, | |
536 | kBigEndian | |
537 | }; | |
538 | ||
13398559 | 539 | enum AliHLTOUTDataType { |
049b43b2 | 540 | kUint64 = 0, |
541 | kUint32 = 1, | |
542 | kUint16 = 2, | |
543 | kUint8 = 3, | |
544 | kDouble = 4, | |
545 | kFloat = 5 | |
546 | }; | |
547 | ||
548 | /** | |
549 | * Check byte order of selected block | |
550 | */ | |
13398559 | 551 | AliHLTOUTByteOrder CheckByteOrder(); |
049b43b2 | 552 | |
553 | /** | |
554 | * Check alignment of selected block | |
555 | */ | |
13398559 | 556 | int CheckAlignment(AliHLTOUT::AliHLTOUTDataType type); |
049b43b2 | 557 | |
44dc7683 | 558 | /** |
559 | * Helper function to byte swap a 64 bit value. | |
560 | */ | |
ff3b6fed | 561 | static AliHLTUInt64_t ByteSwap64(AliHLTUInt64_t src); |
44dc7683 | 562 | |
563 | /** | |
564 | * Helper function to byte swap a 32 bit value. | |
565 | */ | |
ff3b6fed | 566 | static AliHLTUInt32_t ByteSwap32(AliHLTUInt32_t src); |
44dc7683 | 567 | |
c5123824 | 568 | /** |
569 | * Insert a handler item. | |
570 | * The current list entries are checked if the handler is already in | |
571 | * the list. It is added if not in the list, otherwise the block index | |
572 | * is added to the existing entry. | |
62ff1e23 | 573 | * @param list the handler list |
c5123824 | 574 | * @param entry handler list entry |
575 | * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br> | |
576 | * neg. error code if failed | |
577 | */ | |
578 | static int InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry); | |
579 | ||
b005ef92 | 580 | /** |
581 | * Insert all handlers of the specified type to the list. | |
582 | */ | |
583 | int FillHandlerList(AliHLTOUTHandlerListEntryVector& list, AliHLTModuleAgent::AliHLTOUTHandlerType handlerType); | |
584 | ||
585 | /** | |
586 | * Remove empty items which have a duplicate in the list. | |
587 | */ | |
588 | static int RemoveEmptyDuplicateHandlers(AliHLTOUTHandlerListEntryVector& list); | |
589 | ||
590 | /** | |
591 | * Find an entry of a certain description in the list. | |
592 | * @return index of the entry if found, -ENOENT if not found | |
593 | */ | |
594 | static int FindHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTModuleAgent::AliHLTOUTHandlerDesc desc); | |
595 | ||
596 | /** | |
597 | * Invalidate all blocks of the handlers in the list | |
598 | */ | |
599 | static int InvalidateBlocks(AliHLTOUTHandlerListEntryVector& list); | |
600 | ||
62bb3cd4 | 601 | protected: |
4de7334f | 602 | /** |
603 | * Add a block descriptor. | |
604 | * This is done by the child classes generating the index. The AliHLTOUT | |
605 | * object must be locked for index generation. | |
606 | * @param desc the block descriptor | |
607 | * @return 0 if success, -EPERM if access denied | |
608 | */ | |
609 | int AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc); | |
62bb3cd4 | 610 | |
c63e8be4 | 611 | /** |
612 | * Set the event id, only for child classes | |
613 | */ | |
614 | void SetEventId(AliHLTUInt64_t id); | |
615 | ||
44dc7683 | 616 | /** |
617 | * Print output or suppress. | |
618 | */ | |
619 | bool BeVerbose() {return fbVerbose;} | |
620 | ||
621 | /** | |
622 | * Switch output. | |
623 | */ | |
624 | void SwitchVerbosity(bool verbose) {fbVerbose=verbose;} | |
625 | ||
62bb3cd4 | 626 | private: |
627 | /** copy constructor prohibited */ | |
628 | AliHLTOUT(const AliHLTOUT&); | |
629 | /** assignment operator prohibited */ | |
630 | AliHLTOUT& operator=(const AliHLTOUT&); | |
631 | ||
049b43b2 | 632 | /** |
633 | * Internal status flags | |
634 | */ | |
635 | enum { | |
0f1882a7 | 636 | /** the HLTOUT object is locked with the current data block selection */ |
049b43b2 | 637 | kLocked = 0x1, |
638 | /** childs can add block descriptors */ | |
639 | kCollecting = 0x2, | |
640 | /** user of the data block has checked the byte order */ | |
641 | kByteOrderChecked = 0x4, | |
642 | /** warning on byte order missmatch has been printed */ | |
643 | kByteOrderWarning = 0x8, | |
644 | /** user of the data block has checked the alignment */ | |
645 | kAlignmentChecked = 0x10, | |
646 | /** warning on alignment missmatch has been printed */ | |
0f1882a7 | 647 | kAlignmentWarning = 0x20, |
648 | /** enable block selection list */ | |
649 | kBlockSelection = 0x40, | |
650 | /** skip processed data blocks */ | |
651 | kSkipProcessed = 0x80, | |
652 | /** marked as sub collection */ | |
653 | kIsSubCollection = 0x100 | |
049b43b2 | 654 | }; |
655 | ||
4de7334f | 656 | /** |
657 | * Generate the index of the HLTOUT data. | |
658 | * Must be implemented by the child classes. | |
659 | */ | |
660 | virtual int GenerateIndex()=0; | |
661 | ||
5db0e774 | 662 | /** |
663 | * Find AliHLTOUTHandler objects for the data blocks. | |
664 | * The available AliHLTModuleAgents are probed whether they provide | |
665 | * handlers for data processing. | |
666 | */ | |
667 | int InitHandlers(); | |
668 | ||
b005ef92 | 669 | /** |
670 | * Cleanup and reset the data input. | |
671 | */ | |
672 | virtual int ResetInput(); | |
673 | ||
4de7334f | 674 | /** |
675 | * Get the data buffer | |
676 | * @param index [in] index of the block | |
677 | * @param pBuffer [out] buffer of the selected data block | |
678 | * @param size [out] size of the selected data block | |
679 | */ | |
680 | virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer, | |
681 | AliHLTUInt32_t& size)=0; | |
682 | ||
049b43b2 | 683 | /** |
684 | * Check byte order of data block | |
685 | */ | |
13398559 | 686 | virtual AliHLTOUTByteOrder CheckBlockByteOrder(AliHLTUInt32_t index)=0; |
049b43b2 | 687 | |
688 | /** | |
689 | * Check alignment of data block | |
690 | */ | |
13398559 | 691 | virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)=0; |
049b43b2 | 692 | |
693 | /** | |
694 | * Select the data block of data type and specification of the previous | |
695 | * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock | |
696 | * and @ref SelectNextDataBlock, starts to find a block at the current list | |
0f1882a7 | 697 | * position. |
698 | * | |
699 | * The data block is searched from the conditions of fSearchDataType, | |
700 | * fSearchSpecification, fSearchHandlerType and the selection list. | |
701 | * | |
049b43b2 | 702 | * @return identifier >=0 if success, neg. error code if failed <br> |
703 | * -ENOENT if no block found <br> | |
704 | * -EPERM if access denied (object locked) | |
705 | */ | |
706 | int FindAndSelectDataBlock(); | |
707 | ||
708 | /** | |
709 | * Set status flag. | |
710 | * @param flag flag to set | |
711 | * @return current status flags | |
712 | */ | |
713 | unsigned int SetStatusFlag(unsigned int flag) {return fFlags|=flag;} | |
714 | ||
715 | /** | |
716 | * Clear status flag. | |
717 | * @param flag flag to clear | |
718 | * @return current status flags | |
719 | */ | |
720 | unsigned int ClearStatusFlag(unsigned int flag) {return fFlags&=~flag;} | |
721 | ||
722 | /** | |
723 | * Check status flag. | |
724 | * @param flag flag to check | |
725 | * @return 1 if flag is set | |
726 | */ | |
727 | int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;} | |
728 | ||
626bfcc1 | 729 | /** |
730 | * Find handler description for a certain block index. | |
731 | */ | |
44dc7683 | 732 | const AliHLTOUTHandlerListEntry& FindHandlerDesc(AliHLTUInt32_t blockIndex); |
626bfcc1 | 733 | |
c1292031 | 734 | /** |
735 | * Internal New function for the external HLTOUT instances. | |
736 | * Currently supported classes are AliHLTOUTRawReader and | |
737 | * AliHLTOUTDigitReader, both implemented in libHLTrec.so. | |
738 | */ | |
739 | static AliHLTOUT* New(const char* classname); | |
740 | ||
741 | /** | |
742 | * Set the RawReader as parameter. | |
743 | * The function is for internal use only in conjunction with the | |
744 | * New() functions. | |
745 | */ | |
746 | virtual void SetParam(AliRawReader* pRawReader); | |
747 | ||
748 | /** | |
749 | * Set the RunLoader as parameter | |
750 | * The function is for internal use only in conjunction with the | |
751 | * New() functions. | |
752 | */ | |
753 | virtual void SetParam(TTree* pDigitTree, int event=-1); | |
754 | ||
4de7334f | 755 | /** data type for the current block search, set from @ref SelectFirstDataBlock */ |
756 | AliHLTComponentDataType fSearchDataType; //!transient | |
757 | ||
758 | /** data specification for the current block search */ | |
759 | AliHLTUInt32_t fSearchSpecification; //!transient | |
760 | ||
44dc7683 | 761 | /** handler type for the current block search */ |
762 | AliHLTModuleAgent::AliHLTOUTHandlerType fSearchHandlerType; // !transient | |
763 | ||
049b43b2 | 764 | /** instance flags: locked, collecting, ... */ |
765 | unsigned int fFlags; //!transient | |
4de7334f | 766 | |
767 | /** list of block descriptors */ | |
13398559 | 768 | AliHLTOUTBlockDescriptorVector fBlockDescList; //!transient |
4de7334f | 769 | |
770 | /** current position in the list */ | |
0f1882a7 | 771 | unsigned int fCurrent; //!transient |
4de7334f | 772 | |
773 | /** data buffer under processing */ | |
774 | const AliHLTUInt8_t* fpBuffer; //!transient | |
775 | ||
5db0e774 | 776 | /** list of AliHLTOUTHandlers */ |
13398559 | 777 | AliHLTOUTHandlerListEntryVector fDataHandlers; // !transient |
5db0e774 | 778 | |
44dc7683 | 779 | /** verbose or silent output */ |
780 | bool fbVerbose; //!transient | |
781 | ||
b005ef92 | 782 | /** gobal instance set for certain steps of the analysis */ |
783 | static AliHLTOUT* fgGlobalInstance; //! transient | |
784 | ||
785 | /** logging methods */ | |
786 | AliHLTLogging fLog; //! transient | |
787 | ||
e5701dcf | 788 | /** current buffer converted to a TObject */ |
789 | TObject* fpDataObject; //! | |
790 | const AliHLTUInt8_t* fpObjectBuffer; //! | |
791 | AliHLTUInt32_t fObjectBufferSize; //! | |
792 | ||
c63e8be4 | 793 | /** current event id */ |
794 | AliHLTUInt64_t fCurrentEventId; //! | |
795 | ||
796 | ClassDef(AliHLTOUT, 6) | |
62bb3cd4 | 797 | }; |
798 | #endif |