Adding AliTPCcalibV0 to the Makefile (Marian)
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTOUT.h
CommitLineData
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
20class AliHLTOUTHandler;
04058ee9 21class AliHLTOUTHandlerDesc; // AliHLTModuleAgent.h
5db0e774 22
23#define AliHLTOUTInvalidIndex (~(AliHLTUInt32_t)0)
24
25typedef vector<AliHLTUInt32_t> AliHLTOUTIndexList;
62bb3cd4 26
27/**
28 * @class AliHLTOUT
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.
34 *
35 */
36class AliHLTOUT : public AliHLTLogging {
37 public:
38 /** standard constructor */
39 AliHLTOUT();
40 /** standard destructor */
41 virtual ~AliHLTOUT();
42
5db0e774 43 /**
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).
48 */
49 int Init();
50
4de7334f 51 /**
52 * Get number of data blocks in the HLTOUT data
53 */
54 int GetNofDataBlocks();
55
56 /**
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.
5db0e774 60 *
61 * The search criteria can be combined with a handler type (e.g. kRawReader)
4de7334f 62 * @param dt [in] data type to match <br>
63 * @param spec [in] data specification to match <br>
5db0e774 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>
4de7334f 67 * -EPERM if access denied (object locked)
68 */
18b56222 69 int SelectFirstDataBlock(AliHLTComponentDataType dt=kAliHLTAnyDataType,
70 AliHLTUInt32_t spec=kAliHLTVoidDataSpec,
5db0e774 71 AliHLTModuleAgent::AliHLTOUTHandlerType handlerType=AliHLTModuleAgent::kUnknownOutput);
4de7334f 72
73 /**
74 * Select the next data block of data type and specification of the previous
75 * call to @ref SelectFirstDataBlock.
5db0e774 76 * @return identifier >0 if success, 0 if no block found <br>
77 * neg. error code if failed <br>
4de7334f 78 * -EPERM if access denied (object locked)
79 */
80 int SelectNextDataBlock();
81
82 /**
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
86 */
87 int GetDataBlockDescription(AliHLTComponentDataType& dt, AliHLTUInt32_t& spec);
88
5db0e774 89 /**
90 * Get the index of the current data block.
91 * @return index, AliHLTOUTInvalidIndex if no block selected
92 */
93 AliHLTUInt32_t GetDataBlockIndex();
94
4de7334f 95 /**
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
99 */
100 int GetDataBuffer(const AliHLTUInt8_t* &pBuffer, AliHLTUInt32_t& size);
101
102 /**
103 * Release buffer after use.
104 * @param pBuffer [in] buffer of the selected data block
105 */
106 int ReleaseDataBuffer(const AliHLTUInt8_t* pBuffer);
107
626bfcc1 108 /**
109 * Get handler for the selected data block.
110 */
111 AliHLTOUTHandler* GetHandler();
112
4de7334f 113 /**
114 * Locking guard for the AliHLTOUT object.
115 * If the object is locked, the selection of data blocks can not be changed.
116 */
117 class AliHLTOUTLockGuard {
118 public:
119 /** constructor */
120 AliHLTOUTLockGuard(AliHLTOUT* pInstance) : fpInstance(pInstance)
049b43b2 121 {if (fpInstance) fpInstance->SetStatusFlag(kLocked);}
4de7334f 122 /** destructor */
123 ~AliHLTOUTLockGuard()
049b43b2 124 {if (fpInstance) fpInstance->ClearStatusFlag(kLocked);}
4de7334f 125
126 private:
127 /** standard constructor prohibited */
128 AliHLTOUTLockGuard();
129 /** copy constructor prohibited */
130 AliHLTOUTLockGuard(const AliHLTOUTLockGuard&);
131 /** assignment operator prohibited */
132 AliHLTOUTLockGuard& operator=(const AliHLTOUTLockGuard&);
133
134 /** the AliHLTOUT instance the guard is locking */
135 AliHLTOUT* fpInstance; //!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
147 /** event id */
148 AliHLTUInt64_t fEventID; //! see above
149 };
150
151 // definitions from ALICE internal notes ALICE-INT-2002-010 and
152 // ALICE-INT-2006-XXX
13398559 153 enum {
154 /** the 32bit word in the CDH containing the status flags */
155 kCDHStatusWord=4, //! see above
156 /** start of the flags in word fgkCDHStatusWord */
157 kCDHStatusFlagsOffset=12, //! see above
158 /** bit indicating HLT decision in the HLTOUT*/
159 kCDHFlagsHLTDecision=6, //! see above
160 /** bit indicating HLT payload in the HLTOUT*/
161 kCDHFlagsHLTPayload=7 //! see above
162 };
4b113031 163
4de7334f 164 /**
165 * Block descriptor.
166 */
167 class AliHLTOUTBlockDescriptor {
168 public:
169 AliHLTOUTBlockDescriptor(AliHLTComponentDataType dt, AliHLTUInt32_t spec, AliHLTUInt32_t index)
170 : fDataType(dt), fSpecification(spec), fIndex(index) {};
171 ~AliHLTOUTBlockDescriptor() {}
172
173 operator AliHLTComponentDataType() const {return fDataType;}
174 operator AliHLTUInt32_t() const {return fSpecification;}
175 int operator==(AliHLTComponentDataType dt) const {return dt==fDataType;}
176 int operator==(AliHLTUInt32_t spec) const {return spec==fSpecification;}
177
178 AliHLTUInt32_t GetIndex() const {return fIndex;}
179 private:
180 /** data type of the block */
181 AliHLTComponentDataType fDataType; //!transient
182 /** data specification of the block */
183 AliHLTUInt32_t fSpecification; //!transient
184 /** index in the data stream */
185 AliHLTUInt32_t fIndex; //!transient
186 };
187
13398559 188 enum AliHLTOUTByteOrder {
049b43b2 189 /** no data block selected */
190 kInvalidByteOrder=-1,
191 kUnknownByteOrder=0,
192 kLittleEndian,
193 kBigEndian
194 };
195
13398559 196 enum AliHLTOUTDataType {
049b43b2 197 kUint64 = 0,
198 kUint32 = 1,
199 kUint16 = 2,
200 kUint8 = 3,
201 kDouble = 4,
202 kFloat = 5
203 };
204
205 /**
206 * Check byte order of selected block
207 */
13398559 208 AliHLTOUTByteOrder CheckByteOrder();
049b43b2 209
210 /**
211 * Check alignment of selected block
212 */
13398559 213 int CheckAlignment(AliHLTOUT::AliHLTOUTDataType type);
049b43b2 214
62bb3cd4 215 protected:
4de7334f 216 /**
217 * Add a block descriptor.
218 * This is done by the child classes generating the index. The AliHLTOUT
219 * object must be locked for index generation.
220 * @param desc the block descriptor
221 * @return 0 if success, -EPERM if access denied
222 */
223 int AddBlockDescriptor(const AliHLTOUTBlockDescriptor desc);
62bb3cd4 224
225 private:
226 /** copy constructor prohibited */
227 AliHLTOUT(const AliHLTOUT&);
228 /** assignment operator prohibited */
229 AliHLTOUT& operator=(const AliHLTOUT&);
230
049b43b2 231 /**
232 * Internal status flags
233 */
234 enum {
235 /** the HLTOUT object is locked with the current data block */
236 kLocked = 0x1,
237 /** childs can add block descriptors */
238 kCollecting = 0x2,
239 /** user of the data block has checked the byte order */
240 kByteOrderChecked = 0x4,
241 /** warning on byte order missmatch has been printed */
242 kByteOrderWarning = 0x8,
243 /** user of the data block has checked the alignment */
244 kAlignmentChecked = 0x10,
245 /** warning on alignment missmatch has been printed */
246 kAlignmentWarning = 0x20
247 };
248
5db0e774 249 class AliHLTOUTHandlerListEntry {
250 public:
251 AliHLTOUTHandlerListEntry(AliHLTOUTHandler* pHandler,
252 AliHLTModuleAgent::AliHLTOUTHandlerDesc& handlerDesc,
253 AliHLTModuleAgent* pAgent,
254 AliHLTUInt32_t index);
255
256 /** copy constructor for vector handling */
257 AliHLTOUTHandlerListEntry(const AliHLTOUTHandlerListEntry& src);
258
259 /** assignment operator for vector handling */
260 AliHLTOUTHandlerListEntry& operator=(const AliHLTOUTHandlerListEntry& src);
261
262 ~AliHLTOUTHandlerListEntry();
263
13398559 264 static const AliHLTOUTHandlerListEntry fgkVoidHandlerListEntry; //! initializer
626bfcc1 265
5db0e774 266 operator AliHLTOUTHandler*() const {return fpHandler;}
13398559 267 operator AliHLTModuleAgent::AliHLTOUTHandlerDesc&() const {return *fpHandlerDesc;}
5db0e774 268 operator AliHLTModuleAgent*() const {return fpAgent;}
269
a3ef3c1d 270 /**
271 * Two list entries are considered to be equal if the handlers
272 * are equal.
273 */
5db0e774 274 bool operator==(const AliHLTOUTHandlerListEntry& entry) const;
275
276 AliHLTUInt32_t operator[](int i) const;
277
a3ef3c1d 278 /**
279 * Add a block index to this descriptor.
280 * One descriptor can serve multiple blocks if the agent returns the
281 * same handler for all of the blocks. Instead of creating a new entry
282 * the block index ist just added
283 */
5db0e774 284 void AddIndex(AliHLTUInt32_t index);
285
a3ef3c1d 286 /**
287 * Add all indexes of the descriptor.
288 */
289 void AddIndex(AliHLTOUTHandlerListEntry &desc);
290
291 /**
292 * Check if an index is served by this descriptor.
293 * @return true if the index is in the table
294 */
626bfcc1 295 bool HasIndex(AliHLTUInt32_t index);
296
5db0e774 297 private:
298 /** standard constructor prohibited */
299 AliHLTOUTHandlerListEntry();
300
301 /** pointer to the handler */
302 AliHLTOUTHandler* fpHandler; //! transient
303
304 /** pointer to handler description */
626bfcc1 305 AliHLTModuleAgent::AliHLTOUTHandlerDesc* fpHandlerDesc; //! transient
5db0e774 306
307 /** pointer to module agent */
308 AliHLTModuleAgent* fpAgent; //! transient
309
310 /** list of block indexes */
311 AliHLTOUTIndexList fBlocks; //!transient
312 };
626bfcc1 313
4de7334f 314 /**
315 * Generate the index of the HLTOUT data.
316 * Must be implemented by the child classes.
317 */
318 virtual int GenerateIndex()=0;
319
5db0e774 320 /**
321 * Find AliHLTOUTHandler objects for the data blocks.
322 * The available AliHLTModuleAgents are probed whether they provide
323 * handlers for data processing.
324 */
325 int InitHandlers();
326
4de7334f 327 /**
328 * Get the data buffer
329 * @param index [in] index of the block
330 * @param pBuffer [out] buffer of the selected data block
331 * @param size [out] size of the selected data block
332 */
333 virtual int GetDataBuffer(AliHLTUInt32_t index, const AliHLTUInt8_t* &pBuffer,
334 AliHLTUInt32_t& size)=0;
335
049b43b2 336 /**
337 * Check byte order of data block
338 */
13398559 339 virtual AliHLTOUTByteOrder CheckBlockByteOrder(AliHLTUInt32_t index)=0;
049b43b2 340
341 /**
342 * Check alignment of data block
343 */
13398559 344 virtual int CheckBlockAlignment(AliHLTUInt32_t index, AliHLTOUT::AliHLTOUTDataType type)=0;
049b43b2 345
346 /**
347 * Select the data block of data type and specification of the previous
348 * call to @ref SelectFirstDataBlock. Core function of @ref SelectFirstDataBlock
349 * and @ref SelectNextDataBlock, starts to find a block at the current list
350 * position.
351 * @return identifier >=0 if success, neg. error code if failed <br>
352 * -ENOENT if no block found <br>
353 * -EPERM if access denied (object locked)
354 */
355 int FindAndSelectDataBlock();
356
357 /**
358 * Set status flag.
359 * @param flag flag to set
360 * @return current status flags
361 */
362 unsigned int SetStatusFlag(unsigned int flag) {return fFlags|=flag;}
363
364 /**
365 * Clear status flag.
366 * @param flag flag to clear
367 * @return current status flags
368 */
369 unsigned int ClearStatusFlag(unsigned int flag) {return fFlags&=~flag;}
370
371 /**
372 * Check status flag.
373 * @param flag flag to check
374 * @return 1 if flag is set
375 */
376 int CheckStatusFlag(unsigned int flag) const {return (fFlags&flag)==flag;}
377
5db0e774 378 /**
379 * Insert a handler item.
380 * The current list entries are checked if the handler is already in
381 * the list. It is added if not in the list, otherwise the block index
382 * is added to the existing entry.
383 * @param entry handler list entry
384 * @return 0 if added, EEXIST (non negative!) if merged with existing entry <br>
385 * neg. error code if failed
386 */
387 int InsertHandler(const AliHLTOUTHandlerListEntry &entry);
388
626bfcc1 389 /**
390 * Find handler description for a certain block index.
391 */
392 AliHLTOUTHandlerListEntry FindHandlerDesc(AliHLTUInt32_t blockIndex);
393
4de7334f 394 /** data type for the current block search, set from @ref SelectFirstDataBlock */
395 AliHLTComponentDataType fSearchDataType; //!transient
396
397 /** data specification for the current block search */
398 AliHLTUInt32_t fSearchSpecification; //!transient
399
049b43b2 400 /** instance flags: locked, collecting, ... */
401 unsigned int fFlags; //!transient
4de7334f 402
13398559 403 typedef vector<AliHLTOUTHandlerListEntry> AliHLTOUTHandlerListEntryVector;
404 typedef vector<AliHLTOUTBlockDescriptor> AliHLTOUTBlockDescriptorVector;
405
4de7334f 406 /** list of block descriptors */
13398559 407 AliHLTOUTBlockDescriptorVector fBlockDescList; //!transient
4de7334f 408
409 /** current position in the list */
13398559 410 AliHLTOUTBlockDescriptorVector::iterator fCurrent; //!transient
4de7334f 411
412 /** data buffer under processing */
413 const AliHLTUInt8_t* fpBuffer; //!transient
414
5db0e774 415 /** list of AliHLTOUTHandlers */
13398559 416 AliHLTOUTHandlerListEntryVector fDataHandlers; // !transient
5db0e774 417
418 ClassDef(AliHLTOUT, 1)
62bb3cd4 419};
420#endif