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 #define AliHLTOUTInvalidIndex (~(AliHLTUInt32_t)0)
25 typedef vector<AliHLTUInt32_t> AliHLTOUTIndexList;
29 * The control class for HLTOUT data.
30 * The output of the HLT, either from the HLTOUT nodes or simulated output,
31 * is transferred and stored in the HOMER format. The AliHLTOUT class
32 * implements scanning of the HOMER data for all HLTOUT DDL links and
33 * abstracts access to the complete HLTOUT data.
36 class AliHLTOUT : public AliHLTLogging {
38 /** standard constructor */
40 /** standard destructor */
44 * Init for processing.
45 * The HLTOUT is scanned for all available data blocks and the
46 * AliHLTOUTHandler objects for the data blocks are created according
47 * to the module agents (see AliHLTModuleAgent).
52 * Get number of data blocks in the HLTOUT data
54 int GetNofDataBlocks();
57 * Select the first data block of a certain data type and specification.
58 * The selection criteria can be of kAliHLTAnyDataType and/or
59 * kAliHLTVoidDataSpec in order to be ignored and just match any data block.
61 * The search criteria can be combined with a handler type (e.g. kRawReader)
62 * @param dt [in] data type to match <br>
63 * @param spec [in] data specification to match <br>
64 * @param handlerType [in] type of the handler
65 * @return identifier >0 if success, 0 if no block found <br>
66 * neg. error code if failed <br>
67 * -EPERM if access denied (object locked)
69 int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
70 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
71 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput);
74 * Select the next data block of data type and specification of the previous
75 * call to @ref SelectFirstDataBlock.
76 * @return identifier >0 if success, 0 if no block found <br>
77 * neg. error code if failed <br>
78 * -EPERM if access denied (object locked)
80 int SelectNextDataBlock();
83 * Get properties of the selected data block.
84 * @param dt [out] data type of the selected block
85 * @param spec [out] data specification of the selected block
87 int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
90 * Get the index of the current data block.
91 * @return index, AliHLTOUTInvalidIndex if no block selected
93 AliHLTUInt32_t GetDataBlockIndex();
96 * Get buffer of the selected data block.
97 * @param pBuffer [out] buffer of the selected data block
98 * @param size [out] size of the selected data block
100 int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size);
103 * Release buffer after use.
104 * @param pBuffer [in] buffer of the selected data block
106 int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
109 * Get handler for the selected data block.
111 AliHLTOUTHandler* GetHandler();
114 * Locking guard for the AliHLTOUT object.
115 * If the object is locked, the selection of data blocks can not be changed.
117 class AliHLTOUTLockGuard {
120 AliHLTOUTLockGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
121 {if (fpInstance) fpInstance->SetStatusFlag(kLocked);}
123 ~AliHLTOUTLockGuard()
124 {if (fpInstance) fpInstance->ClearStatusFlag(kLocked);}
127 /** standard constructor prohibited */
128 AliHLTOUTLockGuard();
129 /** copy constructor prohibited */
130 AliHLTOUTLockGuard(const AliHLTOUTLockGuard&);
131 /** assignment operator prohibited */
132 AliHLTOUTLockGuard& operator=(const AliHLTOUTLockGuard&);
134 /** the AliHLTOUT instance the guard is locking */
135 AliHLTOUT* fpInstance; //!transient
139 * The HLT OUT Event Header.
140 * Defined between HLT and DAQ.
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
148 AliHLTUInt64_t fEventID; //! see above
151 // definitions from ALICE internal notes ALICE-INT-2002-010 and
152 // ALICE-INT-2006-XXX
153 /** the 32bit word in the CDH containing the status flags */
154 static const unsigned char fgkCDHStatusWord; //! see above
155 /** start of the flags in word fgkCDHStatusWord */
156 static const unsigned char fgkCDHStatusFlagsOffset; //! see above
157 /** bit indicating HLT decision in the HLTOUT*/
158 static const unsigned char fgkCDHFlagsHLTDecision; //! see above
159 /** bit indicating HLT payload in the HLTOUT*/
160 static const unsigned char fgkCDHFlagsHLTPayload; //! see above
165 class AliHLTOUTBlockDescriptor {
167 AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index)
168 : fDataType(dt), fSpecification(spec), fIndex(index) {};
169 ~AliHLTOUTBlockDescriptor() {}
171 operator AliHLTComponentDataType() const {return fDataType;}
172 operator AliHLTUInt32_t() const {return fSpecification;}
173 int operator==(AliHLTComponentDataType dt) const {return dt==fDataType;}
174 int operator==(AliHLTUInt32_t spec) const {return spec==fSpecification;}
176 AliHLTUInt32_t GetIndex() const {return fIndex;}
178 /** data type of the block */
179 AliHLTComponentDataType fDataType; //!transient
180 /** data specification of the block */
181 AliHLTUInt32_t fSpecification; //!transient
182 /** index in the data stream */
183 AliHLTUInt32_t fIndex; //!transient
186 enum AliHLTOUTByteOrder_t {
187 /** no data block selected */
188 kInvalidByteOrder=-1,
194 enum AliHLTOUTDataType_t {
204 * Check byte order of selected block
206 AliHLTOUTByteOrder_t CheckByteOrder();
209 * Check alignment of selected block
211 int CheckAlignment(AliHLTOUT::AliHLTOUTDataType_t type);
215 * Add a block descriptor.
216 * This is done by the child classes generating the index. The AliHLTOUT
217 * object must be locked for index generation.
218 * @param desc the block descriptor
219 * @return 0 if success, -EPERM if access denied
221 int AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc);
224 /** copy constructor prohibited */
225 AliHLTOUT(const AliHLTOUT&);
226 /** assignment operator prohibited */
227 AliHLTOUT& operator=(const AliHLTOUT&);
230 * Internal status flags
233 /** the HLTOUT object is locked with the current data block */
235 /** childs can add block descriptors */
237 /** user of the data block has checked the byte order */
238 kByteOrderChecked = 0x4,
239 /** warning on byte order missmatch has been printed */
240 kByteOrderWarning = 0x8,
241 /** user of the data block has checked the alignment */
242 kAlignmentChecked = 0x10,
243 /** warning on alignment missmatch has been printed */
244 kAlignmentWarning = 0x20
247 class AliHLTOUTHandlerListEntry {
249 AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
250 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
251 AliHLTModuleAgent* pAgent,
252 AliHLTUInt32_t index);
254 /** copy constructor for vector handling */
255 AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src);
257 /** assignment operator for vector handling */
258 AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src);
260 ~AliHLTOUTHandlerListEntry();
262 static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry;
264 operator AliHLTOUTHandler*() const {return fpHandler;}
265 operator AliHLTModuleAgent::AliHLTOUTHandlerDesc&() {return *fpHandlerDesc;}
266 operator AliHLTModuleAgent*() const {return fpAgent;}
269 * Two list entries are considered to be equal if the handlers
272 bool operator==(const AliHLTOUTHandlerListEntry& entry) const;
274 AliHLTUInt32_t operator[](int i) const;
277 * Add a block index to this descriptor.
278 * One descriptor can serve multiple blocks if the agent returns the
279 * same handler for all of the blocks. Instead of creating a new entry
280 * the block index ist just added
282 void AddIndex(AliHLTUInt32_t index);
285 * Add all indexes of the descriptor.
287 void AddIndex(AliHLTOUTHandlerListEntry &desc);
290 * Check if an index is served by this descriptor.
291 * @return true if the index is in the table
293 bool HasIndex(AliHLTUInt32_t index);
296 /** standard constructor prohibited */
297 AliHLTOUTHandlerListEntry();
299 /** pointer to the handler */
300 AliHLTOUTHandler* fpHandler; //! transient
302 /** pointer to handler description */
303 AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient
305 /** pointer to module agent */
306 AliHLTModuleAgent* fpAgent; //! transient
308 /** list of block indexes */
309 AliHLTOUTIndexList fBlocks; //!transient
313 * Generate the index of the HLTOUT data.
314 * Must be implemented by the child classes.
316 virtual int GenerateIndex()=0;
319 * Find AliHLTOUTHandler objects for the data blocks.
320 * The available AliHLTModuleAgents are probed whether they provide
321 * handlers for data processing.
326 * Get the data buffer
327 * @param index [in] index of the block
328 * @param pBuffer [out] buffer of the selected data block
329 * @param size [out] size of the selected data block
331 virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
332 AliHLTUInt32_t& size)=0;
335 * Check byte order of data block
337 virtual AliHLTOUTByteOrder_t CheckBlockByteOrder(AliHLTUInt32_t index)=0;
340 * Check alignment of data block
342 virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType_t type)=0;
345 * Select the data block of data type and specification of the previous
346 * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock
347 * and @ref SelectNextDataBlock, starts to find a block at the current list
349 * @return identifier >=0 if success, neg. error code if failed <br>
350 * -ENOENT if no block found <br>
351 * -EPERM if access denied (object locked)
353 int FindAndSelectDataBlock();
357 * @param flag flag to set
358 * @return current status flags
360 unsigned int SetStatusFlag(unsigned int flag) {return fFlags|=flag;}
364 * @param flag flag to clear
365 * @return current status flags
367 unsigned int ClearStatusFlag(unsigned int flag) {return fFlags&=~flag;}
371 * @param flag flag to check
372 * @return 1 if flag is set
374 int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;}
377 * Insert a handler item.
378 * The current list entries are checked if the handler is already in
379 * the list. It is added if not in the list, otherwise the block index
380 * is added to the existing entry.
381 * @param entry handler list entry
382 * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
383 * neg. error code if failed
385 int InsertHandler(const AliHLTOUTHandlerListEntry &entry);
388 * Find handler description for a certain block index.
390 AliHLTOUTHandlerListEntry FindHandlerDesc(AliHLTUInt32_t blockIndex);
392 /** data type for the current block search, set from @ref SelectFirstDataBlock */
393 AliHLTComponentDataType fSearchDataType; //!transient
395 /** data specification for the current block search */
396 AliHLTUInt32_t fSearchSpecification; //!transient
398 /** instance flags: locked, collecting, ... */
399 unsigned int fFlags; //!transient
401 /** list of block descriptors */
402 vector<AliHLTOUTBlockDescriptor> fBlockDescList; //!transient
404 /** current position in the list */
405 vector<AliHLTOUTBlockDescriptor>::iterator fCurrent; //!transient
407 /** data buffer under processing */
408 const AliHLTUInt8_t* fpBuffer; //!transient
410 /** list of AliHLTOUTHandlers */
411 vector<AliHLTOUTHandlerListEntry> fDataHandlers; // !transient
413 ClassDef(AliHLTOUT, 1)