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 *
11 @author Matthias Richter
13 @brief The control class for HLTOUT data.
17 #include "AliHLTLogging.h"
18 #include "AliHLTModuleAgent.h"
20 class AliHLTOUTHandler;
21 class AliHLTOUTHandlerDesc; // AliHLTModuleAgent.h
23 class AliHLTReconstructor;
25 #define AliHLTOUTInvalidIndex (~(AliHLTUInt32_t)0)
27 typedef vector<AliHLTUInt32_t> AliHLTOUTIndexList;
31 * The control class for HLTOUT data.
32 * The output of the HLT, either from the HLTOUT nodes or simulated output,
33 * is transferred and stored in the HOMER format. The AliHLTOUT class
34 * implements scanning of the HOMER data for all HLTOUT DDL links and
35 * abstracts access to the complete HLTOUT data.
38 class AliHLTOUT : public AliHLTLogging {
40 /** standard constructor */
42 /** standard destructor */
46 * Locking guard for the AliHLTOUT object.
47 * If the object is locked, the selection of data blocks can not be changed.
49 class AliHLTOUTLockGuard {
52 AliHLTOUTLockGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
53 {if (fpInstance) fpInstance->SetStatusFlag(kLocked);}
56 {if (fpInstance) fpInstance->ClearStatusFlag(kLocked);}
59 /** standard constructor prohibited */
61 /** copy constructor prohibited */
62 AliHLTOUTLockGuard(const AliHLTOUTLockGuard&);
63 /** assignment operator prohibited */
64 AliHLTOUTLockGuard& operator=(const AliHLTOUTLockGuard&);
66 /** the AliHLTOUT instance the guard is locking */
67 AliHLTOUT* fpInstance; //!transient
71 * The HLT OUT Event Header.
72 * Defined between HLT and DAQ.
74 struct AliHLTOUTEventHeader {
75 /**Total length of the data in bytes, including HLT event header, excluding CDH. */
76 AliHLTUInt32_t fLength; //! see above
77 /** version of the header */
78 AliHLTUInt32_t fVersion; //! see above
79 /** High 32 bit word of event id */
80 AliHLTUInt32_t fEventIDHigh; //! see above
81 /** Low 32 bit word of event id */
82 AliHLTUInt32_t fEventIDLow; //! see above
86 /// versions 1 of the HLT header
88 /// versions 2 of the HLT header
93 /// size of HLT decision in data format version 1: 29x4
94 kSizeDecisionVersion1 = 116,
95 /// size of HLT decision in data format version 2: 30x4
96 kSizeDecisionVersion2 = 120
99 // definitions from ALICE internal notes ALICE-INT-2002-010 and
100 // ALICE-INT-2006-XXX
102 /** the 32bit word in the CDH containing the status flags */
103 kCDHStatusWord=4, //! see above
104 /** start of the flags in word fgkCDHStatusWord */
105 kCDHStatusFlagsOffset=12, //! see above
106 /** bit indicating HLT decision in the HLTOUT*/
107 kCDHFlagsHLTDecision=6, //! see above
108 /** bit indicating HLT payload in the HLTOUT*/
109 kCDHFlagsHLTPayload=7 //! see above
115 class AliHLTOUTBlockDescriptor {
117 AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index)
118 : fDataType(dt), fSpecification(spec), fIndex(index) {};
119 ~AliHLTOUTBlockDescriptor() {}
121 operator AliHLTComponentDataType() const {return fDataType;}
122 operator AliHLTUInt32_t() const {return fSpecification;}
123 int operator==(AliHLTComponentDataType dt) const {return dt==fDataType;}
124 int operator==(AliHLTUInt32_t spec) const {return spec==fSpecification;}
126 AliHLTUInt32_t GetIndex() const {return fIndex;}
128 /** data type of the block */
129 AliHLTComponentDataType fDataType; //!transient
130 /** data specification of the block */
131 AliHLTUInt32_t fSpecification; //!transient
132 /** index in the data stream */
133 AliHLTUInt32_t fIndex; //!transient
136 class AliHLTOUTHandlerListEntry {
138 AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
139 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
140 AliHLTModuleAgent* pAgent,
141 AliHLTUInt32_t index);
143 /** copy constructor for vector handling */
144 AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src);
146 /** assignment operator for vector handling */
147 AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src);
149 ~AliHLTOUTHandlerListEntry();
151 static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry; //! initializer
153 operator AliHLTOUTHandler*() const {return fpHandler;}
155 // please note that fpHandlerDesc is really a pointer and is created
156 // in the constructor. Thats why it is dereferenced here. The pointer
157 // type is on purpose, even though it is a bit confusing with the
158 // argument by reference in the AliHLTOUTHandlerListEntry constructor.
159 operator const AliHLTModuleAgent::AliHLTOUTHandlerDesc&() const
160 {return fpHandlerDesc?*fpHandlerDesc:AliHLTModuleAgent::fgkVoidHandlerDesc;}
161 operator AliHLTModuleAgent*() const {return fpAgent;}
164 * Two list entries are considered to be equal if the handlers
167 bool operator==(const AliHLTOUTHandlerListEntry& entry) const;
169 bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const;
171 AliHLTUInt32_t operator[](int i) const;
174 * Add a block index to this descriptor.
175 * One descriptor can serve multiple blocks if the agent returns the
176 * same handler for all of the blocks. Instead of creating a new entry
177 * the block index ist just added
179 void AddIndex(AliHLTUInt32_t index);
182 * Add all indexes of the descriptor.
184 void AddIndex(AliHLTOUTHandlerListEntry &desc);
187 * Check if an index is served by this descriptor.
188 * @return true if the index is in the table
190 bool HasIndex(AliHLTUInt32_t index);
193 /** standard constructor prohibited */
194 AliHLTOUTHandlerListEntry();
196 /** pointer to the handler */
197 AliHLTOUTHandler* fpHandler; //! transient
199 /** pointer to handler description */
200 AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient
202 /** pointer to module agent */
203 AliHLTModuleAgent* fpAgent; //! transient
205 /** list of block indexes */
206 AliHLTOUTIndexList fBlocks; //!transient
209 typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
210 typedef vector<AliHLTOUTBlockDescriptor> AliHLTOUTBlockDescriptorVector;
213 * Init for processing.
214 * The HLTOUT is scanned for all available data blocks and the
215 * AliHLTOUTHandler objects for the data blocks are created according
216 * to the module agents (see AliHLTModuleAgent).
221 * Get number of data blocks in the HLTOUT data
223 int GetNofDataBlocks();
226 * Select the first data block of a certain data type and specification.
227 * The selection criteria can be of kAliHLTAnyDataType and/or
228 * kAliHLTVoidDataSpec in order to be ignored and just match any data block.
230 * The search criteria can be combined with a handler type (e.g. kRawReader)
231 * @param dt [in] data type to match <br>
232 * @param spec [in] data specification to match <br>
233 * @param handlerType [in] type of the handler
234 * @return identifier >0 if success, 0 if no block found <br>
235 * neg. error code if failed <br>
236 * -EPERM if access denied (object locked)
238 int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
239 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
240 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput);
243 * Select the next data block of data type and specification of the previous
244 * call to @ref SelectFirstDataBlock.
245 * @return identifier >0 if success, 0 if no block found <br>
246 * neg. error code if failed <br>
247 * -EPERM if access denied (object locked)
249 int SelectNextDataBlock();
252 * Get properties of the selected data block.
253 * @param dt [out] data type of the selected block
254 * @param spec [out] data specification of the selected block
256 int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
259 * Get handler description of the current data block.
261 const AliHLTOUTHandlerListEntry& GetDataBlockHandlerDesc();
264 * Get handler type of the selected data block.
265 * @return handler type for the selected data block
267 AliHLTModuleAgent::AliHLTOUTHandlerType GetDataBlockHandlerType();
270 * Get the index of the current data block.
271 * @return index, AliHLTOUTInvalidIndex if no block selected
273 AliHLTUInt32_t GetDataBlockIndex();
276 * Get buffer of the selected data block.
277 * @param pBuffer [out] buffer of the selected data block
278 * @param size [out] size of the selected data block
280 int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size);
283 * Release buffer after use.
284 * @param pBuffer [in] buffer of the selected data block
286 int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
289 * Get module agent for the selected data block.
291 AliHLTModuleAgent* GetAgent();
294 * Get handler for the selected data block.
296 AliHLTOUTHandler* GetHandler();
299 * Convert data buffer to ESD.
300 * The buffer is supposed to describe a streamed AliESDEvent object.
301 * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root,
302 * where 'det' is derived from the data type origin. Each time the function is invoked
303 * a new event is created. Dummy events are added if the previous events did not contain
305 * The function needs AliRoot and might not be implemented by all AliHLTOUT
307 * a data block of this specification.
308 * @param pBuffer [in] the data buffer
309 * @param size [in] data buffer size
310 * @param dt [in] data type of the block
311 * @param tgtesd [out] optional target
313 virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL) const;
315 enum AliHLTOUTByteOrder {
316 /** no data block selected */
317 kInvalidByteOrder=-1,
323 enum AliHLTOUTDataType {
333 * Check byte order of selected block
335 AliHLTOUTByteOrder CheckByteOrder();
338 * Check alignment of selected block
340 int CheckAlignment(AliHLTOUT::AliHLTOUTDataType type);
343 * Helper function to byte swap a 64 bit value.
345 static AliHLTUInt64_t ByteSwap64(AliHLTUInt64_t src);
348 * Helper function to byte swap a 32 bit value.
350 static AliHLTUInt32_t ByteSwap32(AliHLTUInt32_t src);
353 * Insert a handler item.
354 * The current list entries are checked if the handler is already in
355 * the list. It is added if not in the list, otherwise the block index
356 * is added to the existing entry.
357 * @param list the handler list
358 * @param entry handler list entry
359 * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
360 * neg. error code if failed
362 static int InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry);
366 * Add a block descriptor.
367 * This is done by the child classes generating the index. The AliHLTOUT
368 * object must be locked for index generation.
369 * @param desc the block descriptor
370 * @return 0 if success, -EPERM if access denied
372 int AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc);
375 * Print output or suppress.
377 bool BeVerbose() {return fbVerbose;}
382 void SwitchVerbosity(bool verbose) {fbVerbose=verbose;}
385 /** copy constructor prohibited */
386 AliHLTOUT(const AliHLTOUT&);
387 /** assignment operator prohibited */
388 AliHLTOUT& operator=(const AliHLTOUT&);
391 * Internal status flags
394 /** the HLTOUT object is locked with the current data block */
396 /** childs can add block descriptors */
398 /** user of the data block has checked the byte order */
399 kByteOrderChecked = 0x4,
400 /** warning on byte order missmatch has been printed */
401 kByteOrderWarning = 0x8,
402 /** user of the data block has checked the alignment */
403 kAlignmentChecked = 0x10,
404 /** warning on alignment missmatch has been printed */
405 kAlignmentWarning = 0x20
409 * Generate the index of the HLTOUT data.
410 * Must be implemented by the child classes.
412 virtual int GenerateIndex()=0;
415 * Find AliHLTOUTHandler objects for the data blocks.
416 * The available AliHLTModuleAgents are probed whether they provide
417 * handlers for data processing.
422 * Get the data buffer
423 * @param index [in] index of the block
424 * @param pBuffer [out] buffer of the selected data block
425 * @param size [out] size of the selected data block
427 virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
428 AliHLTUInt32_t& size)=0;
431 * Check byte order of data block
433 virtual AliHLTOUTByteOrder CheckBlockByteOrder(AliHLTUInt32_t index)=0;
436 * Check alignment of data block
438 virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)=0;
441 * Select the data block of data type and specification of the previous
442 * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock
443 * and @ref SelectNextDataBlock, starts to find a block at the current list
445 * @return identifier >=0 if success, neg. error code if failed <br>
446 * -ENOENT if no block found <br>
447 * -EPERM if access denied (object locked)
449 int FindAndSelectDataBlock();
453 * @param flag flag to set
454 * @return current status flags
456 unsigned int SetStatusFlag(unsigned int flag) {return fFlags|=flag;}
460 * @param flag flag to clear
461 * @return current status flags
463 unsigned int ClearStatusFlag(unsigned int flag) {return fFlags&=~flag;}
467 * @param flag flag to check
468 * @return 1 if flag is set
470 int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;}
473 * Find handler description for a certain block index.
475 const AliHLTOUTHandlerListEntry& FindHandlerDesc(AliHLTUInt32_t blockIndex);
477 /** data type for the current block search, set from @ref SelectFirstDataBlock */
478 AliHLTComponentDataType fSearchDataType; //!transient
480 /** data specification for the current block search */
481 AliHLTUInt32_t fSearchSpecification; //!transient
483 /** handler type for the current block search */
484 AliHLTModuleAgent::AliHLTOUTHandlerType fSearchHandlerType; // !transient
486 /** instance flags: locked, collecting, ... */
487 unsigned int fFlags; //!transient
489 /** list of block descriptors */
490 AliHLTOUTBlockDescriptorVector fBlockDescList; //!transient
492 /** current position in the list */
493 AliHLTOUTBlockDescriptorVector::iterator fCurrent; //!transient
495 /** data buffer under processing */
496 const AliHLTUInt8_t* fpBuffer; //!transient
498 /** list of AliHLTOUTHandlers */
499 AliHLTOUTHandlerListEntryVector fDataHandlers; // !transient
501 /** verbose or silent output */
502 bool fbVerbose; //!transient
504 ClassDef(AliHLTOUT, 2)