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.
29 #include "AliHLTDataBuffer.h"
30 #include "AliHLTConsumerDescriptor.h"
31 #include "AliHLTComponent.h"
32 #include "AliHLTTask.h"
36 //#include "AliHLTSystem.h"
38 typedef vector<AliHLTDataBuffer::AliHLTDataSegment> AliHLTDataSegmentList;
39 typedef vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTRawBufferPList;
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTDataBuffer)
44 AliHLTDataBuffer::AliHLTDataBuffer()
52 fForwardedSegmentSources(),
55 // see header file for class documentation
57 // refer to README to build package
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 fActiveConsumers.empty();
63 fReleasedConsumers.empty();
67 int AliHLTDataBuffer::fgNofInstances=0;
68 AliHLTRawBufferPList AliHLTDataBuffer::fgFreeBuffers;
69 AliHLTRawBufferPList AliHLTDataBuffer::fgActiveBuffers;
70 AliHLTUInt32_t AliHLTDataBuffer::fgMargin=1024;
71 AliHLTLogging AliHLTDataBuffer::fgLogging;
72 const Int_t AliHLTDataBuffer::fgkSafetyPatternSize=16;
73 const char AliHLTDataBuffer::fgkSafetyPattern[]={0x28, 0x63, 0x29, 0x4d, 0x52, 0x49, 0x43, 0x48, 0x54, 0x45, 0x52, 0x20, 0x32, 0x30, 0x30, 0x37};
74 AliHLTUInt32_t AliHLTDataBuffer::fgEventCount=0;
76 AliHLTDataBuffer::~AliHLTDataBuffer()
78 // see header file for function documentation
79 if (--fgNofInstances<=0) {
82 CleanupConsumerList();
85 int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer)
87 // see header file for function documentation
90 if (FindConsumer(pConsumer)) {
91 HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
93 AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer);
95 fConsumers.push_back(pDesc);
96 HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
98 HLTError("memory allocation failed");
102 HLTError("invalid parameter: consumer component (nil)");
108 int AliHLTDataBuffer::FindMatchingDataBlocks(const AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
110 // see header file for function documentation
113 AliHLTDataSegmentList segments;
114 if ((iResult=FindMatchingDataSegments(pConsumer, segments))>=0) {
116 AliHLTDataSegmentList::iterator segment=segments.begin();
117 while (segment!=segments.end()) {
118 tgtList->push_back((*segment).fDataType);
122 iResult=segments.size();
130 int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
132 // see header file for function documentation
135 // Matthias 26.09.2007 relax the restriction to matching data blocks
136 // all blocks are passed to the consumer, which is the policy also in
138 tgtList.assign(fSegments.begin(), fSegments.end());
140 // add all forwarded blocks
141 tgtList.insert(tgtList.begin(), fForwardedSegments.begin(), fForwardedSegments.end());
142 iResult=tgtList.size();
146 AliHLTComponentDataTypeList dtlist;
147 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
148 AliHLTDataSegmentList::iterator segment=fSegments.begin();
149 while (segment!=fSegments.end()) {
150 AliHLTComponentDataTypeList::iterator type=dtlist.begin();
151 while (type!=dtlist.end()) {
152 if ((*segment).fDataType==(*type)) {
153 tgtList.push_back(*segment);
167 int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockDataList& blockDescList)
169 // see header file for function documentation
173 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
175 AliHLTDataSegmentList tgtList;
176 // Matthias 26.07.2007 AliHLTSystem should behave the same way as PubSub
177 // so it does not matter if there are matching data types or not, unless
178 // we implement such a check in PubSub
179 if ((iResult=FindMatchingDataSegments(pConsumer, tgtList))>=0) {
180 AliHLTDataSegmentList::iterator segment=tgtList.begin();
181 while (segment!=tgtList.end()) {
182 // fill the block data descriptor
183 AliHLTComponentBlockData bd;
184 AliHLTComponent::FillBlockData(bd);
185 // This models the behavior of PubSub.
186 // For incoming data blocks, fOffset must be ignored by the
187 // processing component. It is set for bookkeeping in the framework.
188 // fPtr always points to the beginning of the data.
190 AliHLTUInt8_t* pTgt=*segment;
191 bd.fPtr=reinterpret_cast<void*>(pTgt);
192 bd.fSize=(*segment).fSegmentSize;
193 bd.fDataType=(*segment).fDataType;
194 bd.fSpecification=(*segment).fSpecification;
195 blockDescList.push_back(bd);
196 pDesc->SetActiveDataSegment(*segment);
197 HLTDebug("component %p (%s) subscribed to segment offset %d size %d data type %s %#x",
198 pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), bd.fOffset,
199 bd.fSize, (AliHLTComponent::DataType2Text(bd.fDataType)).c_str(),
203 // move this consumer to the active list
204 if (tgtList.size()==0) {
205 ChangeConsumerState(pDesc, fConsumers, fReleasedConsumers);
206 HLTDebug("no input data for component %p (%s) available", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
207 } else if (ChangeConsumerState(pDesc, fConsumers, fActiveConsumers)>=0) {
208 HLTDebug("component %p (%s) subscribed to data buffer %p", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), this);
210 // TODO: cleanup the consumer descriptor correctly
211 segment=tgtList.begin();
212 while (segment!=tgtList.end()) {
213 blockDescList.pop_back();
216 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
220 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
224 if (!FindConsumer(pConsumer)) {
225 HLTError("component %p is not a data consumer of data buffer %p", pConsumer, this);
227 HLTError("component %p is a valid data consumer of data buffer %p, but did not release it's buffer subscription", pConsumer, this);
232 // Matthias 26.07.2007 until now, data had to be present for successful subscription
233 // in order to be consistent with the PubSub framework, this restiction has been
235 //HLTError("data buffer %p is empty", this);
239 HLTError("invalid parameter");
245 int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc,
246 const AliHLTComponent* pConsumer,
247 const AliHLTTask* pOwnerTask)
249 // see header file for function documentation
251 if (pBlockDesc && pConsumer) {
252 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
254 if ((iResult=pDesc->CheckActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)))!=1) {
255 HLTWarning("data segment mismatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
256 // TODO: appropriate error handling, but so far optional
259 pDesc->ReleaseActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize));
261 if (GetNofPendingConsumers()==0 && fForwardedSegments.size()>0) {
262 // last consumer, release forwarded segments
263 ReleaseForwardedBlock(pBlockDesc, pOwnerTask);
265 pBlockDesc->fOffset=0;
266 pBlockDesc->fPtr=NULL;
268 if (pDesc->GetNofActiveSegments()==0) {
269 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
270 if (GetNofActiveConsumers()==0 && GetNofPendingConsumers()==0) {
271 // this is the last consumer, reset the consumer list and release the raw buffer
275 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
280 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
284 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
290 int AliHLTDataBuffer::ReleaseForwardedBlock(AliHLTComponentBlockData* pBlockDesc,
291 const AliHLTTask* pOwnerTask)
293 // see header file for function documentation
295 if (pBlockDesc && pOwnerTask) {
296 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
297 AliHLTDataSegmentList::iterator segment=fForwardedSegments.begin();
298 AliHLTTaskPList::iterator src=fForwardedSegmentSources.begin();
299 //HLTDebug("%p checking forwarded segments", this);
300 for (; segment!=fForwardedSegments.end(); segment++, src++) {
301 //HLTDebug("segment ptr=%p offset=%d size=%d\n"
302 // "block ptr=%p offset=%d size=%d", (*segment).fPtr, (*segment).fSegmentOffset, (*segment).fSegmentSize, pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize);
303 if ((*segment)==AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)) {
304 //HLTDebug("release segment of task %p", *src);
305 assert((*src)!=NULL);
307 if ((*src)->Release(pBlockDesc, pOwnerTask)>=0) {
308 HLTDebug("task %s (%p) released forwarded segment %p size %d of task %s (%p)",
309 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
310 (*src)->GetName(), *src);
312 HLTError("task %s (%p) failed releasing forwarded segment %p size %d of task %s (%p)",
313 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
314 (*src)->GetName(), *src);
317 fForwardedSegments.erase(segment);
318 fForwardedSegmentSources.erase(src);
323 HLTError("inavalid parameter: pBlockDesc=%p pOwnerTask=%p", pBlockDesc, pOwnerTask);
329 int AliHLTDataBuffer::Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc)
331 // see header file for function documentation
332 if (pSrcTask==NULL || pBlockDesc==NULL) return -EINVAL;
333 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
334 if (fForwardedSegments.size()!=fForwardedSegmentSources.size()) return -EFAULT;
335 fForwardedSegmentSources.push_back(pSrcTask);
336 fForwardedSegments.push_back(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize, pBlockDesc->fDataType, pBlockDesc->fSpecification));
340 AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
342 // see header file for function documentation
343 AliHLTUInt8_t* pTargetBuffer=NULL;
344 if (fpBuffer!=NULL) {
345 HLTWarning("data buffer not properly reset, possible memory leak\n");
347 fpBuffer=CreateRawBuffer(iMinSize);
349 pTargetBuffer=*fpBuffer;
351 HLTError("can not create raw buffer");
353 return pTargetBuffer;
356 int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
358 // see header file for function documentation
360 if (pTgt && arrayBlockData && iSize>=0) {
362 if (*fpBuffer==pTgt) {
363 AliHLTDataBuffer::AliHLTDataSegment segment;
364 for (int i=0; i<iSize; i++) {
365 // This function has to model the behavior of PubSub
366 // For output blocks only the fOffset value is used, this must be the offset
367 // relative to the output pointer. fPtr must be either NULL or the output
368 // pointer. In either case it is 'ignored' and set to the beginning of the
370 if (arrayBlockData[i].fPtr==NULL ||
371 arrayBlockData[i].fPtr==*fpBuffer) {
372 arrayBlockData[i].fPtr=*fpBuffer;
373 if ((arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->GetUsedSize()) ||
374 ((arrayBlockData[i].fOffset==~(AliHLTUInt32_t)0) && arrayBlockData[i].fSize==0)) {
375 segment.fSegmentOffset=arrayBlockData[i].fOffset;
376 segment.fPtr=(AliHLTUInt8_t*)arrayBlockData[i].fPtr;
377 segment.fSegmentSize=arrayBlockData[i].fSize;
378 segment.fDataType=arrayBlockData[i].fDataType;
379 segment.fSpecification=arrayBlockData[i].fSpecification;
380 fSegments.push_back(segment);
381 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
383 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
384 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->GetUsedSize());
388 HLTError("invalid pointer (%p) in block data specification (buffer %p size %d)."
389 "please note: for output blocks only the fOffset value is valid and must "
390 "be relative to the output buffer", arrayBlockData[i].fPtr, fpBuffer->GetPointer(), fpBuffer->GetUsedSize());
395 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->GetPointer(), fpBuffer);
399 HLTFatal("internal data structur mismatch");
403 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
409 int AliHLTDataBuffer::IsEmpty()
411 // see header file for function documentation
412 int iResult=(fpBuffer==NULL && fForwardedSegments.size()==0) || GetNofSegments()==0;
416 int AliHLTDataBuffer::GetNofSegments()
418 // see header file for function documentation
419 int iResult=fSegments.size() + fForwardedSegments.size();
423 int AliHLTDataBuffer::GetNofConsumers()
425 // see header file for function documentation
426 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
430 int AliHLTDataBuffer::GetNofPendingConsumers()
432 // see header file for function documentation
433 int iResult=fConsumers.size();
437 int AliHLTDataBuffer::GetNofActiveConsumers()
439 // see header file for function documentation
440 int iResult=fActiveConsumers.size();
444 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
446 // see header file for function documentation
447 AliHLTRawBuffer* pRawBuffer=NULL;
448 unsigned int reqSize=size+fgkSafetyPatternSize;
449 AliHLTRawBufferPList::iterator buffer=fgFreeBuffers.begin();
450 while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
451 if ((*buffer)->CheckSize(reqSize)) {
452 // assign this element
454 pRawBuffer->UseBuffer(size);
455 fgFreeBuffers.erase(buffer);
456 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());
457 fgActiveBuffers.push_back(pRawBuffer);
462 if (pRawBuffer==NULL) {
463 // no buffer found, create a new one
464 pRawBuffer=new AliHLTRawBuffer(reqSize);
466 if (pRawBuffer->GetPointer()) {
467 pRawBuffer->UseBuffer(size);
468 fgActiveBuffers.push_back(pRawBuffer);
469 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->GetPointer(), pRawBuffer->GetTotalSize(), pRawBuffer);
473 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
476 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
479 if (pRawBuffer!=NULL && fgkSafetyPatternSize>0) {
480 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "writing safety pattern to %p offset %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
481 pRawBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
486 int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
488 // see header file for function documentation
491 AliHLTRawBufferPList::iterator buffer=fgActiveBuffers.begin();
492 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
495 if (buffer!=fgActiveBuffers.end()) {
496 if (fgkSafetyPatternSize>0) {
497 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", (*buffer)->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(*buffer));
498 if ((*buffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
499 fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
503 fgFreeBuffers.push_back(*buffer);
504 fgActiveBuffers.erase(buffer);
506 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
510 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
517 int AliHLTDataBuffer::DeleteRawBuffers()
519 // see header file for function documentation
521 #ifdef ALIHLTSYSTEM_PROFILING
523 int iCount=fgFreeBuffers.size()+fgActiveBuffers.size();
524 #endif //ALIHLTSYSTEM_PROFILING
525 AliHLTRawBufferPList::iterator buffer;;
526 while ((buffer=fgFreeBuffers.begin())!=fgFreeBuffers.end()) {
527 #ifdef ALIHLTSYSTEM_PROFILING
528 iTotalSize+=(*buffer)->GetTotalSize();
529 #endif //ALIHLTSYSTEM_PROFILING
531 fgFreeBuffers.erase(buffer);
533 while ((buffer=fgActiveBuffers.begin())!=fgActiveBuffers.end()) {
534 #ifdef ALIHLTSYSTEM_PROFILING
535 iTotalSize+=(*buffer)->GetTotalSize();
536 #endif //ALIHLTSYSTEM_PROFILING
537 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
539 fgActiveBuffers.erase(buffer);
541 #ifdef ALIHLTSYSTEM_PROFILING
542 fgLogging.Logging(kHLTLogImportant, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
543 #endif //ALIHLTSYSTEM_PROFILING
547 int AliHLTDataBuffer::PrintStatistics()
549 // see header file for function documentation
553 AliHLTRawBufferPList::iterator buffer;;
554 for (buffer=fgFreeBuffers.begin(); buffer!=fgFreeBuffers.end(); buffer++) {
555 iFree+=(*buffer)->GetTotalSize();
557 for (buffer=fgActiveBuffers.begin(); buffer!=fgActiveBuffers.end(); buffer++) {
558 iActive+=(*buffer)->GetTotalSize();
560 fgLogging.Logging(kHLTLogInfo, "AliHLTDataBuffer::PrintStatistics", "data buffer handling", "Total memory allocation: %d byte; %d free buffers (%d byte) - %d active buffers (%d byte) ", iFree+iActive, fgFreeBuffers.size(), iFree, fgActiveBuffers.size(), iActive);
564 AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, AliHLTConsumerDescriptorPList &list) const
566 // see header file for function documentation
567 AliHLTConsumerDescriptor* pDesc=NULL;
568 AliHLTConsumerDescriptorPList::iterator desc=list.begin();
569 while (desc!=list.end() && pDesc==NULL) {
570 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
578 int AliHLTDataBuffer::ResetDataBuffer()
580 // see header file for function documentation
582 AliHLTRawBuffer* pBuffer=fpBuffer;
585 // cleanup forwarded segment lists
586 assert(fForwardedSegments.size()==0);
587 fForwardedSegments.clear();
588 fForwardedSegmentSources.clear();
590 // cleanup consumer states
591 AliHLTConsumerDescriptorPList::iterator desc;
592 // if (GetNofPendingConsumers()>0) {
593 // desc=fConsumers.begin();
594 // while (desc!=fConsumers.end()) {
595 // AliHLTComponent* pComp=(*desc)->GetComponent();
596 // HLTError("internal error: consumer %p (%s %p) did not get data from data buffer %p", *desc, pComp?pComp->GetComponentID():"", pComp, this);
600 desc=fReleasedConsumers.begin();
601 while (desc!=fReleasedConsumers.end()) {
602 AliHLTConsumerDescriptor* pDesc=*desc;
603 fReleasedConsumers.erase(desc);
604 desc=fReleasedConsumers.begin();
605 fConsumers.push_back(pDesc);
607 desc=fActiveConsumers.begin();
608 while (desc!=fActiveConsumers.end()) {
609 AliHLTConsumerDescriptor* pDesc=*desc;
610 HLTWarning("consumer %p (%s) was not released", pDesc, pDesc->GetComponent()?pDesc->GetComponent()->GetComponentID():"### invalid component ###");
611 fActiveConsumers.erase(desc);
612 desc=fActiveConsumers.begin();
613 fConsumers.push_back(pDesc);
617 AliHLTDataSegmentList::iterator segment=fSegments.begin();
618 while (segment!=fSegments.end()) {
619 fSegments.erase(segment);
620 segment=fSegments.begin();
623 // cleanup raw buffer
625 ReleaseRawBuffer(pBuffer);
630 int AliHLTDataBuffer::Reset()
632 // see header file for function documentation
633 return ResetDataBuffer();
636 // this is the version which works on lists of components instead of consumer descriptors
637 // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, AliHLTComponentPList &srcList, AliHLTComponentPList &tgtList)
641 // AliHLTComponentPList::iterator desc=srcList.begin();
642 // while (desc!=srcList.end()) {
643 // if ((*desc)==pConsumer) {
644 // srcList.erase(desc);
645 // tgtList.push_back(pConsumer);
650 // if (desc==srcList.end()) {
651 // HLTError("can not find consumer component %p in list", pConsumer);
655 // HLTError("invalid parameter");
661 int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, AliHLTConsumerDescriptorPList &srcList, AliHLTConsumerDescriptorPList &tgtList)
663 // see header file for function documentation
666 AliHLTConsumerDescriptorPList::iterator desc=srcList.begin();
667 while (desc!=srcList.end()) {
668 if ((*desc)==pDesc) {
670 tgtList.push_back(pDesc);
677 HLTError("can not find consumer descriptor %p in list", pDesc);
680 HLTError("invalid parameter");
686 int AliHLTDataBuffer::CleanupConsumerList()
688 // see header file for function documentation
691 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
692 while (desc!=fConsumers.end()) {
694 fConsumers.erase(desc);
695 desc=fConsumers.begin();
700 int AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, int bAllLists)
702 // see header file for function documentation
703 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
704 while (desc!=fConsumers.end()) {
705 if ((*desc)->GetComponent()==pConsumer)
709 if (bAllLists==0) return 0;
711 desc=fActiveConsumers.begin();
712 while (desc!=fActiveConsumers.end()) {
713 if ((*desc)->GetComponent()==pConsumer)
717 desc=fReleasedConsumers.begin();
718 while (desc!=fReleasedConsumers.end()) {
719 if ((*desc)->GetComponent()==pConsumer)
726 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size)
730 fPtr(static_cast<AliHLTUInt8_t*>(malloc(size))),
733 // see header file for class documentation
735 // refer to README to build package
737 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
744 AliHLTDataBuffer::AliHLTRawBuffer::~AliHLTRawBuffer()
754 int AliHLTDataBuffer::AliHLTRawBuffer::operator==(void* ptr) const
756 // see header file for function documentation
757 return fPtr == static_cast<AliHLTUInt8_t*>(ptr);
760 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(void* ptr) const
762 // see header file for function documentation
763 int iResult=fPtr <= static_cast<AliHLTUInt8_t*>(ptr);
764 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
768 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(void* ptr) const
770 // see header file for function documentation
771 int iResult=fPtr+fSize > static_cast<AliHLTUInt8_t*>(ptr);
772 //printf("%p: %p + %d > %p (%d)\n", this, fPtr, fSize, ptr, iResult);
776 int AliHLTDataBuffer::AliHLTRawBuffer::operator-(void* ptr) const
778 // see header file for function documentation
779 return static_cast<int>(static_cast<AliHLTUInt8_t*>(ptr)-fPtr);
782 AliHLTUInt8_t* AliHLTDataBuffer::AliHLTRawBuffer::UseBuffer(AliHLTUInt32_t size)
784 // see header file for function documentation
785 if (size>0 && fTotalSize>=size) {
787 fLastEventCount=AliHLTDataBuffer::fgEventCount;
793 int AliHLTDataBuffer::AliHLTRawBuffer::CheckSize(AliHLTUInt32_t size) const
795 // see header file for function documentation
796 if (fTotalSize<size) return 0;
798 if (fLastEventCount+1<AliHLTDataBuffer::fgEventCount) {
799 adjust=AliHLTDataBuffer::fgEventCount-fLastEventCount;
801 return (adjust>2) || ((fTotalSize-size)<(fgMargin<<adjust));
804 int AliHLTDataBuffer::AliHLTRawBuffer::Reset()
806 // see header file for function documentation
811 int AliHLTDataBuffer::AliHLTRawBuffer::WritePattern(const char* pattern, int size)
813 // see header file for function documentation
815 if (pattern!=NULL && size>0) {
816 if (fSize+size<=fTotalSize) {
817 memcpy(((char*)fPtr)+fSize, pattern, size);
826 int AliHLTDataBuffer::AliHLTRawBuffer::CheckPattern(const char* pattern, int size) const
828 // see header file for function documentation
830 if (pattern!=NULL && size>0) {
831 if (fSize+size<=fTotalSize) {
832 iResult=memcmp(((char*)fPtr)+fSize, pattern, size)!=0;