Line data Source code
1 : //-*- Mode: C++ -*-
2 : // $Id$
3 :
4 : #ifndef ALIHLTDATABUFFER_H
5 : #define ALIHLTDATABUFFER_H
6 : //* This file is property of and copyright by the *
7 : //* ALICE Experiment at CERN, All rights reserved. *
8 : //* See cxx source for full Copyright notice *
9 :
10 : // @file AliHLTDataBuffer.h
11 : // @author Matthias Richter
12 : // @date
13 : // @brief Handling of Data Buffers for HLT components.
14 : // @note The class is used in Offline (AliRoot) context
15 :
16 : #include <vector>
17 : #include "TObject.h"
18 : #include "AliHLTLogging.h"
19 : #include "AliHLTDataTypes.h"
20 : #include "AliHLTComponent.h"
21 :
22 : using std::vector;
23 :
24 : class AliHLTConsumerDescriptor;
25 : class AliHLTTask;
26 :
27 : /** list of AliHLTConsumerDescriptor pointers */
28 : typedef vector<AliHLTConsumerDescriptor*> AliHLTConsumerDescriptorPList;
29 :
30 : typedef AliHLTUInt8_t* AliHLTUInt8Pointer_t;
31 :
32 : /**
33 : * @class AliHLTDataBuffer
34 : * @brief Handling of data buffers for the HLT.
35 : *
36 : * The class provides handling of data buffers for HLT tasks. Each task gets
37 : * its own Data Buffer instance. The buffer is grouped into different data
38 : * segments according to the output of the component.<br>
39 : * The Data Buffer keeps control over the data requests of the 'child'
40 : * components. Each component can subscribe to a certain segment of the data
41 : * buffer. It's state is then changed from 'reserved' to 'active'. After the
42 : * data processing, the component has to release the segment and it's state is
43 : * set to 'processed'. If all components have requested and released their data,
44 : * the Raw Buffer is released and pushed back in the list of available buffers.
45 : *
46 : * @note This class is only used for the @ref alihlt_system.
47 : *
48 : * @ingroup alihlt_system
49 : */
50 : class AliHLTDataBuffer : public TObject, public AliHLTLogging
51 : {
52 : public:
53 : //////////////////////////////////////////////////////////////////////////////
54 : // constructors and destructors
55 :
56 : /* standard constructor
57 : */
58 : AliHLTDataBuffer();
59 : /** destructor */
60 : virtual ~AliHLTDataBuffer();
61 :
62 : //////////////////////////////////////////////////////////////////////////////
63 : // initialization
64 :
65 : /**
66 : * Add component to the list of consumers
67 : * @param pConsumer - a consumer of type AliHLTComponent
68 : */
69 : int SetConsumer(AliHLTComponent* pConsumer);
70 :
71 : //////////////////////////////////////////////////////////////////////////////
72 : // component to component communication
73 :
74 : /**
75 : * Determine the number of matching data blocks for the component and a
76 : * consumer component. <br>
77 : * The first approach will support only one output data type for processing
78 : * components.
79 : * @param pConsumer the component which subscribes to the buffer
80 : * @param tgtList (optional) the list to receive the data types
81 : * @return: number of data blocks which match the input data types
82 : * of the consumer, neg. error code if failed <br>
83 : * -EINVAL invalid parameter <br>
84 : */
85 : int FindMatchingDataBlocks(const AliHLTComponent* pConsumer,
86 : AliHLTComponentDataTypeList* tgtList=NULL);
87 :
88 : /**
89 : * Subscribe to a segment of the data buffer.
90 : * The function prepares the block descriptor for subsequent use with the
91 : * AliHLTComponent::ProcessEvent method, the method can prepare several block
92 : * descriptors up to the array size specified by iArraySize. The return value
93 : * is independent from the array size the number of block descriptors which
94 : * would have been prepared if there was enough space in the array<br>
95 : * The method is used by the consumer component.
96 : * @param pConsumer the component which subscribes to the buffer
97 : * @param blockDescList block descriptor vector to be filled
98 : * @return: number of matching data blocks, neg. error code if failed<br>
99 : * -EACCESS the consumer state can't be changed (activated)
100 : * -EBADF unresolved data segments <br>
101 : * -ENOENT consumer component not found <br>
102 : * -ENODATA data buffer does not have raw data <br>
103 : * -EINVAL invalid parameter <br>
104 : */
105 : int Subscribe(const AliHLTComponent* pConsumer,
106 : AliHLTComponentBlockDataList& blockDescList);
107 :
108 : /**
109 : * Release an instance of the data buffer.
110 : * Resets the variables of the block descriptor.
111 : * If all buffer segments are released, the Data Buffer is reseted
112 : * and the Raw Buffer released.<br>
113 : * The method is used by the consumer component.
114 : * @param pBlockDesc descriptor of the data segment
115 : * @param pConsumer the component which subscribes to the buffer
116 : * @param pOwnerTask task owning this buffer
117 : * @return: >0 if success, negative error code if failed <br>
118 : * -EACCESS the consumer state can not be changed (de-activated)
119 : * -ENOENT consumer has not subscribed to the buffer <br>
120 : * -EINVAL invalid parameter <br>
121 : */
122 : int Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTComponent* pConsumer,
123 : const AliHLTTask* pOwnerTask);
124 :
125 : /**
126 : * Release a forwarded data block.
127 : */
128 : int ReleaseForwardedBlock(AliHLTComponentBlockData* pBlockDesc,
129 : const AliHLTTask* pOwnerTask);
130 :
131 : /**
132 : * Register an input data block for forwarding.
133 : * Consumer of this data buffer subscribe to forwarded data blocks in te same way.
134 : * Forwarded data blocks are released when the last consumer has released the
135 : * blocks.
136 : * @param pSrcTask original source task of the data block
137 : * @param pBlockDesc descriptor of the data segment
138 : */
139 : int Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc);
140 :
141 : /**
142 : * Get a target buffer of minimum size iMinSize.
143 : * The method is used by the component which owns the Data Buffer to
144 : * allocate a buffer for the data it is going to produce.
145 : * @param iMinSize minumum size of the requested buffer
146 : * @return: pointer to target buffer if
147 : */
148 : AliHLTUInt8_t* GetTargetBuffer(int iMinSize);
149 : static unsigned int GetMaxBufferSize();
150 :
151 : /**
152 : * Set the segments for the data buffer.
153 : * This is usually done after the component has written the data to the buffer,
154 : * which was requested by the @ref GetTargetBuffer method. The component might
155 : * produce different types of data, for each type a segment has to be defined
156 : * which describes the data inside the buffer.<br>
157 : * The @ref AliHLTComponentBlockData segment descriptor comes directly from
158 : * the @ref AliHLTComponent::ProcessEvent method.
159 : * @param pTgt the target buffer which the segments refer to
160 : * @param arraySegments the output block descriptors of the component
161 : * @param iSize size of the array
162 : */
163 : int SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arraySegments, int iSize);
164 :
165 : /**
166 : * Check if the data buffer is empty.
167 : * @return 1 if empty, 0 if not
168 : */
169 : int IsEmpty();
170 :
171 : /**
172 : * Get the total and maximum size of the buffer.
173 : * Lets see if this is needed later
174 : */
175 : //int GetTotalSize();
176 :
177 : /**
178 : * Get the number of segments including the forwarded data blocks.
179 : * @return number of segments
180 : */
181 : int GetNofSegments() const;
182 :
183 : /**
184 : * Get the total number of consumers.
185 : * This gives the number of consumers regardless of their state.
186 : * @return number of consumers
187 : */
188 : int GetNofConsumers() const;
189 :
190 : /**
191 : * Get the number of consumers which still need to be processed during
192 : * the current event.
193 : * @return number of consumers
194 : */
195 : int GetNofPendingConsumers() const;
196 :
197 : /**
198 : * Get the number of consumers currently under processing.
199 : * @return number of active consumers
200 : */
201 : int GetNofActiveConsumers() const;
202 :
203 : /**
204 : * Check if a consumer is already in the list
205 : * @param pConsumer pointer to consumer component
206 : * @param bAllLists search in all lists if 1
207 : * search only in fConsumer list if 0
208 : * @return 1 if found, 0 if not
209 : */
210 : int FindConsumer(const AliHLTComponent* pConsumer, int bAllLists=1);
211 :
212 : /**
213 : * Public method to reset the buffer.
214 : * Eventually with some additional checks. In normal operation,
215 : * an external reset should not be necessary.
216 : */
217 : int Reset();
218 :
219 : /**
220 : * Print info about the buffer
221 : */
222 : virtual void Print(const char* option) const;
223 :
224 : /**
225 : * Set local logging level
226 : * logging filter for individual object
227 : */
228 0 : void SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
229 0 : {fgLogging.SetLocalLoggingLevel(level); AliHLTLogging::SetLocalLoggingLevel(level);}
230 :
231 : /**
232 : * Print summary of the global buffer management.
233 : */
234 : static int PrintStatistics();
235 :
236 : /**
237 : * Set the global event count.
238 : * The event count is deployed to find buffers which have not been used
239 : * for a while. In such a case to policy to find an appropriate buffer is
240 : * adjusted.
241 : */
242 0 : static int SetGlobalEventCount(AliHLTUInt32_t eventCount) {fgEventCount=eventCount; return 0;}
243 :
244 : /**
245 : * @class AliHLTDataSegment
246 : * @brief Descriptor of a data segment within the buffer.
247 : */
248 : class AliHLTDataSegment {
249 : friend class AliHLTDataBuffer; // TODO: implement some getters/setters
250 : public:
251 : AliHLTDataSegment()
252 : :
253 0 : fDataType(kAliHLTVoidDataType),
254 0 : fPtr(NULL),
255 0 : fSegmentOffset(0),
256 0 : fSegmentSize(0),
257 0 : fSpecification(0)
258 0 : {
259 0 : }
260 :
261 : AliHLTDataSegment(AliHLTUInt8_t* ptr, AliHLTUInt32_t offset, AliHLTUInt32_t size)
262 : :
263 : fDataType(kAliHLTVoidDataType),
264 : fPtr(ptr),
265 : fSegmentOffset(offset),
266 : fSegmentSize(size),
267 : fSpecification(0)
268 : {
269 : }
270 :
271 : AliHLTDataSegment(void* ptr, AliHLTUInt32_t offset, AliHLTUInt32_t size)
272 : :
273 0 : fDataType(kAliHLTVoidDataType),
274 0 : fPtr(reinterpret_cast<AliHLTUInt8_t*>(ptr)),
275 0 : fSegmentOffset(offset),
276 0 : fSegmentSize(size),
277 0 : fSpecification(0)
278 0 : {
279 0 : }
280 :
281 : AliHLTDataSegment(void* ptr, AliHLTUInt32_t offset, AliHLTUInt32_t size, AliHLTComponentDataType dt, AliHLTUInt32_t spec)
282 : :
283 0 : fDataType(dt),
284 0 : fPtr(reinterpret_cast<AliHLTUInt8_t*>(ptr)),
285 0 : fSegmentOffset(offset),
286 0 : fSegmentSize(size),
287 0 : fSpecification(spec)
288 0 : {
289 0 : }
290 :
291 : AliHLTDataSegment(const AliHLTDataSegment& src)
292 : :
293 0 : fDataType(src.fDataType),
294 0 : fPtr(src.fPtr),
295 0 : fSegmentOffset(src.fSegmentOffset),
296 0 : fSegmentSize(src.fSegmentSize),
297 0 : fSpecification(src.fSpecification)
298 0 : {
299 : // AliHLTDataSegment just stores external pointers and properties
300 0 : }
301 :
302 : AliHLTDataSegment& operator=(const AliHLTDataSegment& src)
303 : {
304 : // AliHLTDataSegment just stores external pointers and properties
305 0 : if (this==&src) return *this;
306 0 : fDataType=src.fDataType;
307 0 : fPtr=src.fPtr;
308 0 : fSegmentOffset=src.fSegmentOffset;
309 0 : fSegmentSize=src.fSegmentSize;
310 0 : fSpecification=src.fSpecification;
311 0 : return *this;
312 0 : }
313 :
314 0 : virtual ~AliHLTDataSegment() {}
315 :
316 0 : AliHLTUInt8_t* GetPtr() const {return (AliHLTUInt8_t*)*this;}
317 :
318 0 : AliHLTUInt32_t GetSize() const {return fSegmentSize;}
319 :
320 : int operator==(const AliHLTDataSegment& seg) const
321 : {
322 0 : return (fPtr+fSegmentOffset==seg.fPtr+seg.fSegmentOffset) && (fSegmentSize==seg.fSegmentSize);
323 : }
324 0 : operator AliHLTUInt8_t*() const {return fPtr+fSegmentOffset;}
325 :
326 : virtual void Print(const char* option) const;
327 :
328 : private:
329 : /** the data type of this segment */
330 : AliHLTComponentDataType fDataType; // see above
331 : /** pointer to the buffer */
332 : AliHLTUInt8Pointer_t fPtr; //!transient
333 : /** offset in byte within the data buffer */
334 : AliHLTUInt32_t fSegmentOffset; // see above
335 : /** size of the actual content */
336 : AliHLTUInt32_t fSegmentSize; // see above
337 : /** data specification */
338 : AliHLTUInt32_t fSpecification; // see above
339 :
340 : };
341 :
342 : /**
343 : * @class AliHLTForwardedDataSegment
344 : * @brief Descriptor of a forwarded data segment.
345 : * Contains in addition information about the parent of this forwarded
346 : * block and the original data type and specification
347 : */
348 : class AliHLTForwardedDataSegment : public AliHLTDataSegment {
349 : friend class AliHLTDataBuffer; // TODO: implement some getters/setters
350 : public:
351 : AliHLTForwardedDataSegment()
352 : : AliHLTDataSegment()
353 : , fParentSegment()
354 : , fParentTask(NULL)
355 : {
356 : }
357 :
358 : AliHLTForwardedDataSegment(AliHLTDataSegment& mySegment, AliHLTDataSegment& parentSegment, AliHLTTask* parentTask)
359 : : AliHLTDataSegment(mySegment)
360 : , fParentSegment(parentSegment)
361 : , fParentTask(parentTask)
362 : {
363 : }
364 :
365 : AliHLTForwardedDataSegment(const AliHLTForwardedDataSegment& src)
366 : : AliHLTDataSegment(src),
367 : fParentSegment(src.fParentSegment),
368 : fParentTask(src.fParentTask)
369 : {
370 : // AliHLTForwardedDataSegment just stores external pointers and properties
371 : }
372 :
373 : AliHLTForwardedDataSegment& operator=(const AliHLTForwardedDataSegment& src)
374 : {
375 : // AliHLTForwardedDataSegment just stores external pointers and properties
376 : AliHLTDataSegment::operator=(src);
377 : fParentSegment=src.fParentSegment;
378 : fParentTask=src.fParentTask;
379 : return *this;
380 : }
381 :
382 0 : virtual ~AliHLTForwardedDataSegment() {}
383 :
384 : virtual void Print(const char* option) const;
385 :
386 : private:
387 : /// description of the original segment
388 : AliHLTDataSegment fParentSegment; // see above
389 : /// the parent task
390 : AliHLTTask* fParentTask; //!transient
391 : };
392 :
393 : typedef vector<AliHLTDataBuffer::AliHLTDataSegment> AliHLTDataSegmentList;
394 :
395 : class AliHLTRawBuffer;
396 : typedef vector<AliHLTRawBuffer*> AliHLTRawBufferPList;
397 :
398 : /**
399 : * @class AliHLTRawPage
400 : * Memory allocation is organized in pages of a fixed size. Within a
401 : * page, AliHLTRawBuffer chunks are created.
402 : */
403 : class AliHLTRawPage : public AliHLTLogging {
404 : public:
405 : /** standard constructor */
406 0 : AliHLTRawPage() : fSize(0), fPtr(NULL), fFreeBuffers(), fUsedBuffers() {}
407 : /** constructor */
408 : AliHLTRawPage(AliHLTUInt32_t pagesize);
409 : /** destructor */
410 : virtual ~AliHLTRawPage();
411 :
412 : /** alloc a buffer of specified size from the global pages*/
413 : static AliHLTRawBuffer* GlobalAlloc(AliHLTUInt32_t size, int verbosity=0);
414 : /** find buffer in the global pages */
415 : static AliHLTRawPage* FindPage(AliHLTRawBuffer* buffer);
416 : /** cleanup the global pages */
417 : static int GlobalClean();
418 : /** adjust global page size */
419 0 : static void SetGlobalPageSize(AliHLTUInt32_t size) {fgGlobalPageSize=size;}
420 0 : static AliHLTUInt32_t GetGlobalPageSize() {return fgGlobalPageSize;}
421 : /** find next page after prev, or first page */
422 : static AliHLTRawPage* NextPage(const AliHLTRawPage* prev=NULL);
423 :
424 : /** alloc a buffer of specified size */
425 : AliHLTRawBuffer* Alloc(AliHLTUInt32_t size);
426 : /** free a buffer and merge consecutive free buffers */
427 : int Free(AliHLTRawBuffer* pBuffer);
428 : /** set the size of a raw buffer and release the remaining part */
429 : int SetSize(const AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size);
430 : /// check if the buffer is in this page
431 : bool HasBuffer(const AliHLTRawBuffer* pBuffer);
432 :
433 0 : AliHLTUInt32_t Size() const {return fSize;}
434 : AliHLTUInt32_t Capacity() const;
435 0 : bool IsUsed() const {return fUsedBuffers.size()>0;}
436 0 : bool IsFragmented() const {return (fFreeBuffers.size()+fUsedBuffers.size())>1;}
437 :
438 : /**
439 : * Print page information
440 : */
441 : virtual void Print(const char* option);
442 :
443 : private:
444 : /** copy constructor prohibited */
445 : AliHLTRawPage(const AliHLTRawPage&);
446 : /** assignment operator prohibited */
447 : AliHLTRawPage& operator=(const AliHLTRawPage&);
448 :
449 : /// list of global pages
450 : static vector<AliHLTDataBuffer::AliHLTRawPage*> fgGlobalPages; //! transient
451 : /// pages size of global pages
452 : static AliHLTUInt32_t fgGlobalPageSize; //! transient
453 :
454 : /** page size */
455 : AliHLTUInt32_t fSize; // see above
456 : /** the memory segment */
457 : AliHLTUInt8_t* fPtr; //! transient
458 :
459 : /** list of free buffers */
460 : AliHLTRawBufferPList fFreeBuffers; //! transient
461 : /** list of used buffers */
462 : AliHLTRawBufferPList fUsedBuffers; //! transient
463 : };
464 :
465 : /**
466 : * @class AliHLTRawBuffer
467 : * @brief Descriptor of the raw data buffer which can host several segments.
468 : */
469 : class AliHLTRawBuffer {
470 : public:
471 : /** standard constructor */
472 0 : AliHLTRawBuffer() : fSize(0), fTotalSize(0), fExternalPtr(NULL), fPtr(NULL), fLastEventCount(0) {}
473 : /** constructor */
474 : AliHLTRawBuffer(AliHLTUInt32_t size);
475 : /** constructor */
476 : AliHLTRawBuffer(AliHLTUInt32_t size, AliHLTUInt8_t* buffer);
477 : /** destructor */
478 : virtual ~AliHLTRawBuffer();
479 :
480 : /**
481 : * Use a fraction of the buffer.
482 : * @param size size in bytes to be used
483 : * @return pointer to buffer
484 : */
485 : AliHLTUInt8_t* UseBuffer(AliHLTUInt32_t size);
486 :
487 : /**
488 : * split a buffer at specified size
489 : * only possible for buffers with external memory
490 : */
491 : AliHLTRawBuffer* Split(AliHLTUInt32_t size);
492 :
493 : /**
494 : * Check whether buffer fits for a request.
495 : * A buffer fits if it is at least of the requested size and at most
496 : * the requested size plus a margin. The margin increases with the
497 : * number of events the buffer has not been used.
498 : * @param size size of the request in bytes
499 : * @return 1 if buffer is big enough, 0 if not
500 : */
501 : int CheckSize(AliHLTUInt32_t size) const;
502 :
503 : /**
504 : * Get used size of the buffer
505 : */
506 0 : AliHLTUInt32_t GetUsedSize() const {return fSize;}
507 :
508 : /**
509 : * Get total size of the buffer
510 : */
511 0 : AliHLTUInt32_t GetTotalSize() const {return fTotalSize;}
512 :
513 : /**
514 : * Get pointer of data buffer
515 : */
516 0 : AliHLTUInt8_t* GetPointer() const {return fPtr;}
517 :
518 : /**
519 : * Write check pattern
520 : */
521 : int WritePattern(const char* pattern, int size);
522 :
523 : /**
524 : * Check pattern
525 : */
526 : int CheckPattern(const char* pattern, int size) const;
527 :
528 : /**
529 : * Reset buffer.
530 : * Data buffer remains allocated, used size set to 0
531 : */
532 : int Reset();
533 :
534 : /*
535 : * Merge buffer with succeeding buffer.
536 : * Only possible if the buffers are consecutive with out any gap.
537 : */
538 : int Merge(const AliHLTRawBuffer& succ);
539 :
540 : /**
541 : * Print buffer information
542 : */
543 : virtual void Print(const char* option) const;
544 :
545 : int operator==(void* ptr) const;
546 0 : int operator==(AliHLTUInt8_t* ptr) const {return fPtr==ptr;}
547 : int operator<(void* ptr) const;
548 : int operator<=(void* ptr) const;
549 : int operator>(void* ptr) const;
550 : int operator-(void* ptr) const;
551 : int operator<(const AliHLTRawBuffer& op) const;
552 : int operator<=(const AliHLTRawBuffer& op) const;
553 : int operator>(const AliHLTRawBuffer& op) const;
554 :
555 0 : operator void*() const {return fPtr;}
556 0 : operator AliHLTUInt8_t*() const {return fPtr;}
557 :
558 : private:
559 : /** copy constructor prohibited */
560 : AliHLTRawBuffer(const AliHLTRawBuffer&);
561 : /** assignment operator prohibited */
562 : AliHLTRawBuffer& operator=(const AliHLTRawBuffer&);
563 :
564 : /** size of the currently occupied partition of the buffer */
565 : AliHLTUInt32_t fSize; // see above
566 : /** total size of the buffer, including safety margin */
567 : AliHLTUInt32_t fTotalSize; // see above
568 : /** optional external buffer */
569 : AliHLTUInt8_t* fExternalPtr; //! transient
570 : /** the buffer, external or allocated */
571 : AliHLTUInt8_t* fPtr; //! transient
572 : /** last event count where the buffer has been used */
573 : AliHLTUInt32_t fLastEventCount; //! transient
574 : };
575 :
576 : private:
577 : /** copy constructor prohibited */
578 : AliHLTDataBuffer(const AliHLTDataBuffer&);
579 : /** assignment operator prohibited */
580 : AliHLTDataBuffer& operator=(const AliHLTDataBuffer&);
581 :
582 : /* lets see if this is needed
583 : AliHLTDataSegment* FindDataSegment(AliHLTComponentDataType datatype);
584 : */
585 :
586 : /**
587 : * Find those data segments which match the input types of a component.
588 : * @param pConsumer the component which subscribes to the buffer
589 : * @param tgtList the list to receive the data segment descriptors
590 : * @return: number of data blocks which match the input data types
591 : * of the consumer, neg. error code if failed <br>
592 : * -EINVAL invalid parameter <br>
593 : */
594 : int FindMatchingDataSegments(const AliHLTComponent* pConsumer,
595 : AliHLTDataSegmentList& tgtList);
596 :
597 : protected:
598 : // 2010-02-01 make function protected in order to be used from unit test
599 : /**
600 : * Reset the data buffer.
601 : * Removes all consumers back to the @ref fConsumers list, deletes
602 : * segments and releases the Raw Buffer.
603 : */
604 : int ResetDataBuffer();
605 : private:
606 :
607 : //////////////////////////////////////////////////////////////////////////////
608 :
609 : // the data description
610 :
611 : // the data segments within this buffer
612 : vector<AliHLTDataSegment> fSegments; // see above
613 :
614 : // the list of all consumers which are going to subscribe to the buffer
615 : AliHLTConsumerDescriptorPList fConsumers; // see above
616 : // the list of all consumers which are currently subscribed to the buffer
617 : AliHLTConsumerDescriptorPList fActiveConsumers; // see above
618 : // the list of all consumers which are already released for the current event
619 : AliHLTConsumerDescriptorPList fReleasedConsumers; // see above
620 :
621 : // the buffer instance
622 : AliHLTRawBuffer* fpBuffer; //! transient
623 :
624 : // flags indicating the state of the buffer
625 : AliHLTUInt32_t fFlags; // see above
626 :
627 : /** list of tasks with forwarded data blocks */
628 : vector<AliHLTTask*> fForwardedSegmentSources; //! transient
629 :
630 : /** list of forwarded block descriptors */
631 : vector<AliHLTDataSegment> fForwardedSegments; //! transient
632 :
633 : //////////////////////////////////////////////////////////////////////////////
634 : // global buffer handling, internal use only
635 :
636 : /**
637 : * Create a raw buffer of a certain size.
638 : * The function tries to find a buffer of the given size (or a bit bigger by a
639 : * certain margin @ref fgMargin) from the list of free buffers.
640 : * If no buffer is available, a new one is created and added to the buffer handling.
641 : * @param size min. size of the requested buffer
642 : * @return pointer to raw buffer
643 : */
644 : static AliHLTRawBuffer* CreateRawBuffer(AliHLTUInt32_t size);
645 :
646 : /**
647 : * Set the data size of a raw buffer after it has been filled by
648 : * the component.
649 : */
650 : int SetRawBufferDataSize(AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size) const;
651 :
652 : /**
653 : * Mark a buffer as free.
654 : * After the Data Buffer has finnished using the raw buffer, it is released
655 : * and added to the list of available buffers.
656 : * @param pBuffer the raw buffer to release
657 : * @return >=0 if succeeded, neg. error code if failed
658 : */
659 : static int ReleaseRawBuffer(AliHLTRawBuffer* pBuffer);
660 :
661 : /**
662 : * Deletes all the raw buffers.
663 : * When the last Data Buffer object is destructed, all raw data buffers are
664 : * relesed.
665 : */
666 : static int DeleteRawBuffers();
667 :
668 : /**
669 : * Number of instances of AliHLTDataBuffer.
670 : * The statice variable is incremented and decremented in the constructor/
671 : * destructor. All internal data structures are cleaned up when the last
672 : * instance is exiting.
673 : */
674 : static int fgNofInstances; // see above
675 : /** global list of free raw buffers */
676 : static vector<AliHLTRawBuffer*> fgFreeBuffers; // see above
677 : /** global list of currently active raw buffers */
678 : static vector<AliHLTRawBuffer*> fgActiveBuffers; // see above
679 : /** determines the raw buffer size margin at buffer requests */
680 : static AliHLTUInt32_t fgMargin; // see above
681 :
682 : /** global instance to HLT logging class for static methods */
683 : static AliHLTLogging fgLogging; // see above
684 :
685 : /** size of the safety pattern */
686 : static const Int_t fgkSafetyPatternSize; // see above
687 :
688 : /** the safety pattern */
689 : static const char fgkSafetyPattern[]; //!transient
690 :
691 : static AliHLTUInt32_t fgEventCount; //!transient
692 :
693 : //////////////////////////////////////////////////////////////////////////////
694 : // internal helper functions
695 :
696 : /**
697 : * Find the consumer descriptor for a certain component and data type in
698 : * a list of consumers.<br>
699 : * <b>Note:</b> There are three lists which contain the consumers in the
700 : * different states.
701 : * @param pConsumer pointer to consumer component
702 : * @param list list where to search for the consumer
703 : */
704 : AliHLTConsumerDescriptor* FindConsumer(const AliHLTComponent* pConsumer,
705 : AliHLTConsumerDescriptorPList &list) const;
706 :
707 : /**
708 : * Change the state of a consumer.
709 : * The state of a consumer is determined by the list it is strored in, the
710 : * method moves a consumer from the source to the target list.
711 : * @param pDesc pointer to consumer descriptor
712 : * @param srcList list where the consumer is currently to be found
713 : * @param tgtList list where to move the consumer
714 : */
715 : int ChangeConsumerState(AliHLTConsumerDescriptor* pDesc,
716 : AliHLTConsumerDescriptorPList &srcList,
717 : AliHLTConsumerDescriptorPList &tgtList);
718 :
719 : /**
720 : * Cleanup a consumer list.
721 : * Release all allocated data structures. <b>Note:</b> Not the component itself!
722 : */
723 : int CleanupConsumerList();
724 :
725 126 : ClassDef(AliHLTDataBuffer, 1)
726 : };
727 :
728 : #endif // ALIHLTDATABUFFER_H
|