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;
27 #define AliHLTOUTInvalidIndex (~(AliHLTUInt32_t)0)
29 typedef vector<AliHLTUInt32_t> AliHLTOUTIndexList;
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.
40 class AliHLTOUT : public AliHLTLogging {
42 /** standard constructor */
44 /** standard destructor */
48 * Create an AliHLTOUTRawReader instance.
49 * Helper function to transparently access classes from the
52 static AliHLTOUT* New(AliRawReader* pRawReader);
55 * Create an AliHLTOUTDigitReader instance
56 * Helper function to transparently access classes from the
59 static AliHLTOUT* New(TTree* pDigitTree, int event=-1);
62 * Delete an instance of the HLTOUT.
63 * Helper function to transparently access classes from the
64 * libHLTrec library. Before deleting, the availability of the
67 static void Delete(AliHLTOUT* pInstance);
70 * Locking guard for the AliHLTOUT object.
71 * If the object is locked, the selection of data blocks can not be changed.
73 class AliHLTOUTLockGuard {
76 AliHLTOUTLockGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
77 {if (fpInstance) fpInstance->SetStatusFlag(kLocked);}
80 {if (fpInstance) fpInstance->ClearStatusFlag(kLocked);}
83 /** standard constructor prohibited */
85 /** copy constructor prohibited */
86 AliHLTOUTLockGuard(const AliHLTOUTLockGuard&);
87 /** assignment operator prohibited */
88 AliHLTOUTLockGuard& operator=(const AliHLTOUTLockGuard&);
90 /** the AliHLTOUT instance the guard is locking */
91 AliHLTOUT* fpInstance; //!transient
95 * The HLT OUT Event Header.
96 * Defined between HLT and DAQ.
98 struct AliHLTOUTEventHeader {
99 /**Total length of the data in bytes, including HLT event header, excluding CDH. */
100 AliHLTUInt32_t fLength; //! see above
101 /** version of the header */
102 AliHLTUInt32_t fVersion; //! see above
103 /** High 32 bit word of event id */
104 AliHLTUInt32_t fEventIDHigh; //! see above
105 /** Low 32 bit word of event id */
106 AliHLTUInt32_t fEventIDLow; //! see above
110 /// versions 1 of the HLT header
112 /// versions 2 of the HLT header
117 /// size of HLT decision in data format version 1: 29x4
118 kSizeDecisionVersion1 = 116,
119 /// size of HLT decision in data format version 2: 30x4
120 kSizeDecisionVersion2 = 120
123 // definitions from ALICE internal notes ALICE-INT-2002-010 and
124 // ALICE-INT-2006-XXX
126 /** the 32bit word in the CDH containing the status flags */
127 kCDHStatusWord=4, //! see above
128 /** start of the flags in word fgkCDHStatusWord */
129 kCDHStatusFlagsOffset=12, //! see above
130 /** bit indicating HLT decision in the HLTOUT*/
131 kCDHFlagsHLTDecision=6, //! see above
132 /** bit indicating HLT payload in the HLTOUT*/
133 kCDHFlagsHLTPayload=7 //! see above
139 class AliHLTOUTBlockDescriptor {
141 AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index)
142 : fDataType(dt), fSpecification(spec), fIndex(index) {};
143 ~AliHLTOUTBlockDescriptor() {}
145 operator AliHLTComponentDataType() const {return fDataType;}
146 operator AliHLTUInt32_t() const {return fSpecification;}
147 int operator==(AliHLTComponentDataType dt) const {return dt==fDataType;}
148 int operator==(AliHLTUInt32_t spec) const {return spec==fSpecification;}
150 AliHLTUInt32_t GetIndex() const {return fIndex;}
152 /** data type of the block */
153 AliHLTComponentDataType fDataType; //!transient
154 /** data specification of the block */
155 AliHLTUInt32_t fSpecification; //!transient
156 /** index in the data stream */
157 AliHLTUInt32_t fIndex; //!transient
160 class AliHLTOUTHandlerListEntry {
162 AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
163 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
164 AliHLTModuleAgent* pAgent,
165 AliHLTUInt32_t index);
167 /** copy constructor for vector handling */
168 AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src);
170 /** assignment operator for vector handling */
171 AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src);
173 ~AliHLTOUTHandlerListEntry();
175 static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry; //! initializer
177 operator AliHLTOUTHandler*() const {return fpHandler;}
179 // please note that fpHandlerDesc is really a pointer and is created
180 // in the constructor. Thats why it is dereferenced here. The pointer
181 // type is on purpose, even though it is a bit confusing with the
182 // argument by reference in the AliHLTOUTHandlerListEntry constructor.
183 operator const AliHLTModuleAgent::AliHLTOUTHandlerDesc&() const
184 {return fpHandlerDesc?*fpHandlerDesc:AliHLTModuleAgent::fgkVoidHandlerDesc;}
185 operator AliHLTModuleAgent*() const {return fpAgent;}
188 * Two list entries are considered to be equal if the handlers
191 bool operator==(const AliHLTOUTHandlerListEntry& entry) const;
193 bool operator==(const AliHLTModuleAgent::AliHLTOUTHandlerType handlerType) const;
195 AliHLTUInt32_t operator[](int i) const;
198 * Add a block index to this descriptor.
199 * One descriptor can serve multiple blocks if the agent returns the
200 * same handler for all of the blocks. Instead of creating a new entry
201 * the block index ist just added
203 void AddIndex(AliHLTUInt32_t index);
206 * Add all indexes of the descriptor.
208 void AddIndex(AliHLTOUTHandlerListEntry &desc);
211 * Check if an index is served by this descriptor.
212 * @return true if the index is in the table
214 bool HasIndex(AliHLTUInt32_t index);
217 /** standard constructor prohibited */
218 AliHLTOUTHandlerListEntry();
220 /** pointer to the handler */
221 AliHLTOUTHandler* fpHandler; //! transient
223 /** pointer to handler description */
224 AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient
226 /** pointer to module agent */
227 AliHLTModuleAgent* fpAgent; //! transient
229 /** list of block indexes */
230 AliHLTOUTIndexList fBlocks; //!transient
233 typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
234 typedef vector<AliHLTOUTBlockDescriptor> AliHLTOUTBlockDescriptorVector;
237 * Init for processing.
238 * The HLTOUT is scanned for all available data blocks and the
239 * AliHLTOUTHandler objects for the data blocks are created according
240 * to the module agents (see AliHLTModuleAgent).
245 * Get number of data blocks in the HLTOUT data
247 int GetNofDataBlocks();
250 * Select the first data block of a certain data type and specification.
251 * The selection criteria can be of kAliHLTAnyDataType and/or
252 * kAliHLTVoidDataSpec in order to be ignored and just match any data block.
254 * The search criteria can be combined with a handler type (e.g. kRawReader)
255 * @param dt [in] data type to match <br>
256 * @param spec [in] data specification to match <br>
257 * @param handlerType [in] type of the handler
258 * @return block index: >= 0 if success, -ENOENT if no block found <br>
259 * neg. error code if failed <br>
260 * -EPERM if access denied (object locked)
262 int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
263 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
264 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput);
267 * Select the next data block of data type and specification of the previous
268 * call to @ref SelectFirstDataBlock.
269 * @return block index: >= 0 if success, -ENOENT if no block found <br>
270 * neg. error code if failed <br>
271 * -EPERM if access denied (object locked)
273 int SelectNextDataBlock();
276 * Get properties of the selected data block.
277 * @param dt [out] data type of the selected block
278 * @param spec [out] data specification of the selected block
280 int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
283 * Get handler description of the current data block.
285 const AliHLTOUTHandlerListEntry& GetDataBlockHandlerDesc();
288 * Get handler type of the selected data block.
289 * @return handler type for the selected data block
291 AliHLTModuleAgent::AliHLTOUTHandlerType GetDataBlockHandlerType();
294 * Get the index of the current data block.
295 * @return index, AliHLTOUTInvalidIndex if no block selected
297 AliHLTUInt32_t GetDataBlockIndex();
300 * Get buffer of the selected data block.
301 * @param pBuffer [out] buffer of the selected data block
302 * @param size [out] size of the selected data block
304 int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size);
307 * Release buffer after use.
308 * @param pBuffer [in] buffer of the selected data block
310 int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
313 * Get module agent for the selected data block.
315 AliHLTModuleAgent* GetAgent();
318 * Get handler for the selected data block.
320 AliHLTOUTHandler* GetHandler();
323 * Convert data buffer to ESD.
324 * The buffer is supposed to describe a streamed AliESDEvent object.
325 * If no target object is specified, the ESD is written to a file AliHLTdetESDs.root,
326 * where 'det' is derived from the data type origin. Each time the function is invoked
327 * a new event is created. Dummy events are added if the previous events did not contain
329 * The function needs AliRoot and might not be implemented by all AliHLTOUT
331 * a data block of this specification.
332 * @param pBuffer [in] the data buffer
333 * @param size [in] data buffer size
334 * @param dt [in] data type of the block
335 * @param tgtesd [out] optional target
337 virtual int WriteESD(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliESDEvent* tgtesd=NULL) const;
339 enum AliHLTOUTByteOrder {
340 /** no data block selected */
341 kInvalidByteOrder=-1,
347 enum AliHLTOUTDataType {
357 * Check byte order of selected block
359 AliHLTOUTByteOrder CheckByteOrder();
362 * Check alignment of selected block
364 int CheckAlignment(AliHLTOUT::AliHLTOUTDataType type);
367 * Helper function to byte swap a 64 bit value.
369 static AliHLTUInt64_t ByteSwap64(AliHLTUInt64_t src);
372 * Helper function to byte swap a 32 bit value.
374 static AliHLTUInt32_t ByteSwap32(AliHLTUInt32_t src);
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 list the handler list
382 * @param entry handler list entry
383 * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
384 * neg. error code if failed
386 static int InsertHandler(AliHLTOUTHandlerListEntryVector& list, const AliHLTOUTHandlerListEntry &entry);
390 * Add a block descriptor.
391 * This is done by the child classes generating the index. The AliHLTOUT
392 * object must be locked for index generation.
393 * @param desc the block descriptor
394 * @return 0 if success, -EPERM if access denied
396 int AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc);
399 * Print output or suppress.
401 bool BeVerbose() {return fbVerbose;}
406 void SwitchVerbosity(bool verbose) {fbVerbose=verbose;}
409 /** copy constructor prohibited */
410 AliHLTOUT(const AliHLTOUT&);
411 /** assignment operator prohibited */
412 AliHLTOUT& operator=(const AliHLTOUT&);
415 * Internal status flags
418 /** the HLTOUT object is locked with the current data block */
420 /** childs can add block descriptors */
422 /** user of the data block has checked the byte order */
423 kByteOrderChecked = 0x4,
424 /** warning on byte order missmatch has been printed */
425 kByteOrderWarning = 0x8,
426 /** user of the data block has checked the alignment */
427 kAlignmentChecked = 0x10,
428 /** warning on alignment missmatch has been printed */
429 kAlignmentWarning = 0x20
433 * Generate the index of the HLTOUT data.
434 * Must be implemented by the child classes.
436 virtual int GenerateIndex()=0;
439 * Find AliHLTOUTHandler objects for the data blocks.
440 * The available AliHLTModuleAgents are probed whether they provide
441 * handlers for data processing.
446 * Get the data buffer
447 * @param index [in] index of the block
448 * @param pBuffer [out] buffer of the selected data block
449 * @param size [out] size of the selected data block
451 virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
452 AliHLTUInt32_t& size)=0;
455 * Check byte order of data block
457 virtual AliHLTOUTByteOrder CheckBlockByteOrder(AliHLTUInt32_t index)=0;
460 * Check alignment of data block
462 virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)=0;
465 * Select the data block of data type and specification of the previous
466 * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock
467 * and @ref SelectNextDataBlock, starts to find a block at the current list
469 * @return identifier >=0 if success, neg. error code if failed <br>
470 * -ENOENT if no block found <br>
471 * -EPERM if access denied (object locked)
473 int FindAndSelectDataBlock();
477 * @param flag flag to set
478 * @return current status flags
480 unsigned int SetStatusFlag(unsigned int flag) {return fFlags|=flag;}
484 * @param flag flag to clear
485 * @return current status flags
487 unsigned int ClearStatusFlag(unsigned int flag) {return fFlags&=~flag;}
491 * @param flag flag to check
492 * @return 1 if flag is set
494 int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;}
497 * Find handler description for a certain block index.
499 const AliHLTOUTHandlerListEntry& FindHandlerDesc(AliHLTUInt32_t blockIndex);
502 * Internal New function for the external HLTOUT instances.
503 * Currently supported classes are AliHLTOUTRawReader and
504 * AliHLTOUTDigitReader, both implemented in libHLTrec.so.
506 static AliHLTOUT* New(const char* classname);
509 * Set the RawReader as parameter.
510 * The function is for internal use only in conjunction with the
513 virtual void SetParam(AliRawReader* pRawReader);
516 * Set the RunLoader as parameter
517 * The function is for internal use only in conjunction with the
520 virtual void SetParam(TTree* pDigitTree, int event=-1);
522 /** data type for the current block search, set from @ref SelectFirstDataBlock */
523 AliHLTComponentDataType fSearchDataType; //!transient
525 /** data specification for the current block search */
526 AliHLTUInt32_t fSearchSpecification; //!transient
528 /** handler type for the current block search */
529 AliHLTModuleAgent::AliHLTOUTHandlerType fSearchHandlerType; // !transient
531 /** instance flags: locked, collecting, ... */
532 unsigned int fFlags; //!transient
534 /** list of block descriptors */
535 AliHLTOUTBlockDescriptorVector fBlockDescList; //!transient
537 /** current position in the list */
538 AliHLTOUTBlockDescriptorVector::iterator fCurrent; //!transient
540 /** data buffer under processing */
541 const AliHLTUInt8_t* fpBuffer; //!transient
543 /** list of AliHLTOUTHandlers */
544 AliHLTOUTHandlerListEntryVector fDataHandlers; // !transient
546 /** verbose or silent output */
547 bool fbVerbose; //!transient
549 ClassDef(AliHLTOUT, 2)