3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTDataBuffer.cxx
20 @author Matthias Richter
22 @brief Handling of Data Buffers for HLT components.
25 // see header file for class documentation
27 // refer to README to build package
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
35 #include "AliHLTDataBuffer.h"
36 #include "AliHLTConsumerDescriptor.h"
37 #include "AliHLTComponent.h"
38 #include "AliHLTTask.h"
42 //#include "AliHLTSystem.h"
44 typedef vector<AliHLTDataBuffer::AliHLTDataSegment> AliHLTDataSegmentList;
45 typedef vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTRawBufferPList;
47 /** ROOT macro for the implementation of ROOT specific class methods */
48 ClassImp(AliHLTDataBuffer)
50 AliHLTDataBuffer::AliHLTDataBuffer()
58 fForwardedSegmentSources(),
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 fActiveConsumers.empty();
69 fReleasedConsumers.empty();
73 int AliHLTDataBuffer::fgNofInstances=0;
74 AliHLTRawBufferPList AliHLTDataBuffer::fgFreeBuffers;
75 AliHLTRawBufferPList AliHLTDataBuffer::fgActiveBuffers;
76 AliHLTUInt32_t AliHLTDataBuffer::fgMargin=1024;
77 AliHLTLogging AliHLTDataBuffer::fgLogging;
78 const Int_t AliHLTDataBuffer::fgkSafetyPatternSize=16;
79 const char AliHLTDataBuffer::fgkSafetyPattern[]={0x28, 0x63, 0x29, 0x4d, 0x52, 0x49, 0x43, 0x48, 0x54, 0x45, 0x52, 0x20, 0x32, 0x30, 0x30, 0x37};
81 AliHLTDataBuffer::~AliHLTDataBuffer()
83 // see header file for function documentation
84 if (--fgNofInstances<=0) {
87 CleanupConsumerList();
90 int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer)
92 // see header file for function documentation
95 if (FindConsumer(pConsumer)) {
96 HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
98 AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer);
100 fConsumers.push_back(pDesc);
101 HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
103 HLTError("memory allocation failed");
107 HLTError("invalid parameter: consumer component (nil)");
113 int AliHLTDataBuffer::FindMatchingDataBlocks(const AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
115 // see header file for function documentation
118 AliHLTDataSegmentList segments;
119 if ((iResult=FindMatchingDataSegments(pConsumer, segments))>=0) {
121 AliHLTDataSegmentList::iterator segment=segments.begin();
122 while (segment!=segments.end()) {
123 tgtList->push_back((*segment).fDataType);
127 iResult=segments.size();
135 int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
137 // see header file for function documentation
140 // Matthias 26.09.2007 relax the restriction to matching data blocks
141 // all blocks are passed to the consumer, which is the policy also in
143 tgtList.assign(fSegments.begin(), fSegments.end());
145 // add all forwarded blocks
146 tgtList.insert(tgtList.begin(), fForwardedSegments.begin(), fForwardedSegments.end());
147 iResult=tgtList.size();
151 AliHLTComponentDataTypeList dtlist;
152 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
153 AliHLTDataSegmentList::iterator segment=fSegments.begin();
154 while (segment!=fSegments.end()) {
155 AliHLTComponentDataTypeList::iterator type=dtlist.begin();
156 while (type!=dtlist.end()) {
157 if ((*segment).fDataType==(*type) ||
158 (*type)==kAliHLTAnyDataType) {
159 tgtList.push_back(*segment);
173 int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockData* arrayBlockDesc, int iArraySize)
175 // see header file for function documentation
177 if (pConsumer && arrayBlockDesc) {
179 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
181 AliHLTDataSegmentList tgtList;
182 // Matthias 26.07.2007 AliHLTSystem should behave the same way as PubSub
183 // so it does not matter if there are matching data types or not, unless
184 // we implement such a check in PubSub
185 if ((iResult=FindMatchingDataSegments(pConsumer, tgtList))>=0) {
187 AliHLTDataSegmentList::iterator segment=tgtList.begin();
188 while (segment!=tgtList.end() && i<iArraySize) {
189 // fill the block data descriptor
190 arrayBlockDesc[i].fStructSize=sizeof(AliHLTComponentBlockData);
191 // the shared memory key is not used in AliRoot
192 arrayBlockDesc[i].fShmKey.fStructSize=sizeof(AliHLTComponentShmData);
193 arrayBlockDesc[i].fShmKey.fShmType=gkAliHLTComponentInvalidShmType;
194 arrayBlockDesc[i].fShmKey.fShmID=gkAliHLTComponentInvalidShmID;
195 // This models the behavior of PubSub.
196 // For incoming data blocks, fOffset must be ignored by the
197 // processing component. It is set for bookkeeping in the framework.
198 // fPtr always points to the beginning of the data.
199 arrayBlockDesc[i].fOffset=0;
200 AliHLTUInt8_t* pTgt=*segment;
201 arrayBlockDesc[i].fPtr=reinterpret_cast<void*>(pTgt);
202 arrayBlockDesc[i].fSize=(*segment).fSegmentSize;
203 arrayBlockDesc[i].fDataType=(*segment).fDataType;
204 arrayBlockDesc[i].fSpecification=(*segment).fSpecification;
205 pDesc->SetActiveDataSegment(*segment);
206 HLTDebug("component %p (%s) subscribed to segment #%d offset %d size %d data type %s %#x",
207 pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), i, arrayBlockDesc[i].fOffset,
208 arrayBlockDesc[i].fSize, (AliHLTComponent::DataType2Text(arrayBlockDesc[i].fDataType)).c_str(),
209 arrayBlockDesc[i].fSpecification);
213 // check whether there was enough space for the segments
214 if (i!=(int)tgtList.size()) {
215 HLTError("too little space in block descriptor array: required %d, available %d", tgtList.size(), iArraySize);
218 // move this consumer to the active list
220 ChangeConsumerState(pDesc, fConsumers, fReleasedConsumers);
221 HLTDebug("no input data for component %p (%s) available", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
222 } else if (ChangeConsumerState(pDesc, fConsumers, fActiveConsumers)>=0) {
223 HLTDebug("component %p (%s) subscribed to data buffer %p", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), this);
225 // TODO: cleanup the consumer descriptor correctly
226 memset(arrayBlockDesc, 0, iArraySize*sizeof(AliHLTComponentBlockData));
227 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
232 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
236 HLTError("component %p is not a data consumer of data buffer %s", pConsumer, this);
240 // Matthias 26.07.2007 until now, data had to be present for successful subscription
241 // in order to be consistent with the PubSub framework, this restiction has been
243 //HLTError("data buffer %p is empty", this);
247 HLTError("invalid parameter");
253 int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc,
254 const AliHLTComponent* pConsumer,
255 const AliHLTTask* pOwnerTask)
257 // see header file for function documentation
259 if (pBlockDesc && pConsumer) {
260 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
262 if ((iResult=pDesc->CheckActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)))!=1) {
263 HLTWarning("data segment missmatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
264 // TODO: appropriate error handling, but so far optional
267 pDesc->ReleaseActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize));
269 if (GetNofPendingConsumers()==0 && fForwardedSegments.size()>0) {
270 // last consumer, release forwarded segments
271 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
272 AliHLTDataSegmentList::iterator segment=fForwardedSegments.begin();
273 AliHLTTaskPList::iterator src=fForwardedSegmentSources.begin();
274 //HLTDebug("%p checking forwarded segments", this);
275 for (; segment!=fForwardedSegments.end(); segment++, src++) {
276 //HLTDebug("segment ptr=%p offset=%d size=%d\n"
277 // "block ptr=%p offset=%d size=%d", (*segment).fPtr, (*segment).fSegmentOffset, (*segment).fSegmentSize, pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize);
278 if ((*segment)==AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)) {
279 //HLTDebug("release segment of task %p", *src);
280 assert((*src)!=NULL);
282 if ((*src)->Release(pBlockDesc, pOwnerTask)>=0) {
283 HLTDebug("task %s (%p) released forwarded segment %p size %d of task %s (%p)",
284 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
285 (*src)->GetName(), *src);
287 HLTError("task %s (%p) failed releasing forwarded segment %p size %d of task %s (%p)",
288 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
289 (*src)->GetName(), *src);
292 fForwardedSegments.erase(segment);
293 fForwardedSegmentSources.erase(src);
298 pBlockDesc->fOffset=0;
299 pBlockDesc->fPtr=NULL;
301 if (pDesc->GetNofActiveSegments()==0) {
302 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
303 if (GetNofActiveConsumers()==0 && GetNofPendingConsumers()==0) {
304 // this is the last consumer, reset the consumer list and release the raw buffer
308 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
313 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
317 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
323 int AliHLTDataBuffer::Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc)
325 // see header file for function documentation
326 if (pSrcTask==NULL || pBlockDesc==NULL) return -EINVAL;
327 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
328 if (fForwardedSegments.size()!=fForwardedSegmentSources.size()) return -EFAULT;
329 fForwardedSegmentSources.push_back(pSrcTask);
330 fForwardedSegments.push_back(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize));
334 AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
336 // see header file for function documentation
337 AliHLTUInt8_t* pTargetBuffer=NULL;
338 if (fpBuffer!=NULL) {
339 HLTWarning("data buffer not properly reset, possible memory leak\n");
341 fpBuffer=CreateRawBuffer(iMinSize);
343 pTargetBuffer=*fpBuffer;
345 HLTError("can not create raw buffer");
347 return pTargetBuffer;
350 int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
352 // see header file for function documentation
354 if (pTgt && arrayBlockData && iSize>=0) {
356 if (*fpBuffer==pTgt) {
357 AliHLTDataBuffer::AliHLTDataSegment segment;
358 for (int i=0; i<iSize; i++) {
359 // This function has to model the behavior of PubSub
360 // For output blocks only the fOffset value is used, this must be the offset
361 // relative to the output pointer. fPtr must be either NULL or the output
362 // pointer. In either case it is 'ignored' and set to the beginning of the
364 if (arrayBlockData[i].fPtr==NULL ||
365 arrayBlockData[i].fPtr==*fpBuffer) {
366 arrayBlockData[i].fPtr=*fpBuffer;
367 if (arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->GetUsedSize()) {
368 segment.fSegmentOffset=arrayBlockData[i].fOffset;
369 segment.fPtr=(AliHLTUInt8_t*)arrayBlockData[i].fPtr;
370 segment.fSegmentSize=arrayBlockData[i].fSize;
371 segment.fDataType=arrayBlockData[i].fDataType;
372 segment.fSpecification=arrayBlockData[i].fSpecification;
373 fSegments.push_back(segment);
374 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
376 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
377 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->GetUsedSize());
381 HLTError("invalid pointer (%p) in block data specification (buffer %p size %d)."
382 "please note: for output blocks only the fOffset value is valid and must "
383 "be relative to the output buffer", arrayBlockData[i].fPtr, fpBuffer->GetPointer(), fpBuffer->GetUsedSize());
388 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->GetPointer(), fpBuffer);
392 HLTFatal("internal data structur missmatch");
396 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
402 int AliHLTDataBuffer::IsEmpty()
404 // see header file for function documentation
405 int iResult=fpBuffer==NULL || GetNofSegments()==0;
409 int AliHLTDataBuffer::GetNofSegments()
411 // see header file for function documentation
412 int iResult=fSegments.size();
416 int AliHLTDataBuffer::GetNofConsumers()
418 // see header file for function documentation
419 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
423 int AliHLTDataBuffer::GetNofPendingConsumers()
425 // see header file for function documentation
426 int iResult=fConsumers.size();
430 int AliHLTDataBuffer::GetNofActiveConsumers()
432 // see header file for function documentation
433 int iResult=fActiveConsumers.size();
437 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
439 // see header file for function documentation
440 AliHLTRawBuffer* pRawBuffer=NULL;
441 unsigned int reqSize=size+fgkSafetyPatternSize;
442 AliHLTRawBufferPList::iterator buffer=fgFreeBuffers.begin();
443 while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
444 if ((*buffer)->CheckSize(reqSize)) {
445 // assign this element
447 pRawBuffer->UseBuffer(size);
448 fgFreeBuffers.erase(buffer);
449 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "raw buffer container %p provided for request of %d bytes (total %d available in buffer %p)", pRawBuffer, size, pRawBuffer->GetTotalSize(), pRawBuffer->GetPointer());
450 fgActiveBuffers.push_back(pRawBuffer);
455 if (pRawBuffer==NULL) {
456 // no buffer found, create a new one
457 pRawBuffer=new AliHLTRawBuffer(reqSize);
459 if (pRawBuffer->GetPointer()) {
460 pRawBuffer->UseBuffer(size);
461 fgActiveBuffers.push_back(pRawBuffer);
462 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->GetPointer(), pRawBuffer->GetTotalSize(), pRawBuffer);
466 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
469 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
472 if (pRawBuffer!=NULL && fgkSafetyPatternSize>0) {
473 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "writing safety pattern to %p offset %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
474 int res=pRawBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
480 int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
482 // see header file for function documentation
485 AliHLTRawBufferPList::iterator buffer=fgActiveBuffers.begin();
486 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
489 if (buffer!=fgActiveBuffers.end()) {
490 if (fgkSafetyPatternSize>0) {
491 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", (*buffer)->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(*buffer));
492 if ((*buffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
493 fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
497 fgFreeBuffers.push_back(*buffer);
498 fgActiveBuffers.erase(buffer);
500 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
504 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
511 int AliHLTDataBuffer::DeleteRawBuffers()
513 // see header file for function documentation
516 // int iCount=fgFreeBuffers.size()+fgActiveBuffers.size();
517 AliHLTRawBufferPList::iterator buffer;;
518 while ((buffer=fgFreeBuffers.begin())!=fgFreeBuffers.end()) {
519 // iTotalSize+=(*buffer)->GetTotalSize();
521 fgFreeBuffers.erase(buffer);
523 while ((buffer=fgActiveBuffers.begin())!=fgActiveBuffers.end()) {
524 // iTotalSize+=(*buffer)->GetTotalSize();
525 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
527 fgActiveBuffers.erase(buffer);
529 // fgLogging.Logging(kHLTLogInfo, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
533 AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, AliHLTConsumerDescriptorPList &list) const
535 // see header file for function documentation
536 AliHLTConsumerDescriptor* pDesc=NULL;
537 AliHLTConsumerDescriptorPList::iterator desc=list.begin();
538 while (desc!=list.end() && pDesc==NULL) {
539 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
547 int AliHLTDataBuffer::ResetDataBuffer()
549 // see header file for function documentation
551 AliHLTRawBuffer* pBuffer=fpBuffer;
554 // cleanup forwarded segment lists
555 assert(fForwardedSegments.size()==0);
556 fForwardedSegments.clear();
557 fForwardedSegmentSources.clear();
559 // cleanup consumer states
560 AliHLTConsumerDescriptorPList::iterator desc;
561 // if (GetNofPendingConsumers()>0) {
562 // desc=fConsumers.begin();
563 // while (desc!=fConsumers.end()) {
564 // AliHLTComponent* pComp=(*desc)->GetComponent();
565 // HLTError("internal error: consumer %p (%s %p) did not get data from data buffer %p", *desc, pComp?pComp->GetComponentID():"", pComp, this);
569 desc=fReleasedConsumers.begin();
570 while (desc!=fReleasedConsumers.end()) {
571 AliHLTConsumerDescriptor* pDesc=*desc;
572 fReleasedConsumers.erase(desc);
573 desc=fReleasedConsumers.begin();
574 fConsumers.push_back(pDesc);
576 desc=fActiveConsumers.begin();
577 while (desc!=fActiveConsumers.end()) {
578 AliHLTConsumerDescriptor* pDesc=*desc;
579 HLTWarning("consumer %p was not released", pDesc);
580 fActiveConsumers.erase(desc);
581 desc=fActiveConsumers.begin();
582 fConsumers.push_back(pDesc);
586 AliHLTDataSegmentList::iterator segment=fSegments.begin();
587 while (segment!=fSegments.end()) {
588 fSegments.erase(segment);
589 segment=fSegments.begin();
592 // cleanup raw buffer
594 ReleaseRawBuffer(pBuffer);
599 int AliHLTDataBuffer::Reset()
601 // see header file for function documentation
602 return ResetDataBuffer();
605 // this is the version which works on lists of components instead of consumer descriptors
606 // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, AliHLTComponentPList &srcList, AliHLTComponentPList &tgtList)
610 // AliHLTComponentPList::iterator desc=srcList.begin();
611 // while (desc!=srcList.end()) {
612 // if ((*desc)==pConsumer) {
613 // srcList.erase(desc);
614 // tgtList.push_back(pConsumer);
619 // if (desc==srcList.end()) {
620 // HLTError("can not find consumer component %p in list", pConsumer);
624 // HLTError("invalid parameter");
630 int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, AliHLTConsumerDescriptorPList &srcList, AliHLTConsumerDescriptorPList &tgtList)
632 // see header file for function documentation
635 AliHLTConsumerDescriptorPList::iterator desc=srcList.begin();
636 while (desc!=srcList.end()) {
637 if ((*desc)==pDesc) {
639 tgtList.push_back(pDesc);
646 HLTError("can not find consumer descriptor %p in list", pDesc);
649 HLTError("invalid parameter");
655 int AliHLTDataBuffer::CleanupConsumerList()
657 // see header file for function documentation
660 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
661 while (desc!=fConsumers.end()) {
663 fConsumers.erase(desc);
664 desc=fConsumers.begin();
669 int AliHLTDataBuffer::FindConsumer(AliHLTComponent* pConsumer, int bAllLists)
671 // see header file for function documentation
672 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
673 while (desc!=fConsumers.end()) {
674 if ((*desc)->GetComponent()==pConsumer)
678 if (bAllLists==0) return 0;
680 desc=fActiveConsumers.begin();
681 while (desc!=fActiveConsumers.end()) {
682 if ((*desc)->GetComponent()==pConsumer)
686 desc=fReleasedConsumers.begin();
687 while (desc!=fReleasedConsumers.end()) {
688 if ((*desc)->GetComponent()==pConsumer)
695 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size)
699 fPtr(static_cast<AliHLTUInt8_t*>(malloc(size)))
701 // see header file for class documentation
703 // refer to README to build package
705 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
712 AliHLTDataBuffer::AliHLTRawBuffer::~AliHLTRawBuffer()
722 int AliHLTDataBuffer::AliHLTRawBuffer::operator==(void* ptr) const
724 // see header file for function documentation
725 return fPtr == static_cast<AliHLTUInt8_t*>(ptr);
728 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(void* ptr) const
730 // see header file for function documentation
731 int iResult=fPtr <= static_cast<AliHLTUInt8_t*>(ptr);
732 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
736 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(void* ptr) const
738 // see header file for function documentation
739 int iResult=fPtr+fSize > static_cast<AliHLTUInt8_t*>(ptr);
740 //printf("%p: %p + %d > %p (%d)\n", this, fPtr, fSize, ptr, iResult);
744 int AliHLTDataBuffer::AliHLTRawBuffer::operator-(void* ptr) const
746 // see header file for function documentation
747 return static_cast<int>(static_cast<AliHLTUInt8_t*>(ptr)-fPtr);
750 AliHLTUInt8_t* AliHLTDataBuffer::AliHLTRawBuffer::UseBuffer(AliHLTUInt32_t size)
752 // see header file for function documentation
753 if (size>0 && fTotalSize>=size) {
760 int AliHLTDataBuffer::AliHLTRawBuffer::CheckSize(AliHLTUInt32_t size) const
762 // see header file for function documentation
763 return fTotalSize>=size && ((fTotalSize-size)<fgMargin);
766 int AliHLTDataBuffer::AliHLTRawBuffer::Reset()
768 // see header file for function documentation
773 int AliHLTDataBuffer::AliHLTRawBuffer::WritePattern(const char* pattern, int size)
775 // see header file for function documentation
777 if (pattern!=NULL && size>0) {
778 if (fSize+size<=fTotalSize) {
779 memcpy(((char*)fPtr)+fSize, pattern, size);
788 int AliHLTDataBuffer::AliHLTRawBuffer::CheckPattern(const char* pattern, int size) const
790 // see header file for function documentation
792 if (pattern!=NULL && size>0) {
793 if (fSize+size<=fTotalSize) {
794 iResult=memcmp(((char*)fPtr)+fSize, pattern, size)!=0;