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