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 #define USE_ALIHLTRAWPAGE
40 typedef vector<AliHLTDataBuffer::AliHLTDataSegment> AliHLTDataSegmentList;
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTDataBuffer)
45 AliHLTDataBuffer::AliHLTDataBuffer()
53 fForwardedSegmentSources(),
56 // see header file for class documentation
58 // refer to README to build package
60 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
63 fActiveConsumers.empty();
64 fReleasedConsumers.empty();
68 int AliHLTDataBuffer::fgNofInstances=0;
69 AliHLTDataBuffer::AliHLTRawBufferPList AliHLTDataBuffer::fgFreeBuffers;
70 AliHLTDataBuffer::AliHLTRawBufferPList AliHLTDataBuffer::fgActiveBuffers;
71 AliHLTUInt32_t AliHLTDataBuffer::fgMargin=1024;
72 AliHLTLogging AliHLTDataBuffer::fgLogging;
73 const Int_t AliHLTDataBuffer::fgkSafetyPatternSize=16;
74 const char AliHLTDataBuffer::fgkSafetyPattern[]={0x28, 0x63, 0x29, 0x4d, 0x52, 0x49, 0x43, 0x48, 0x54, 0x45, 0x52, 0x20, 0x32, 0x30, 0x30, 0x37};
75 AliHLTUInt32_t AliHLTDataBuffer::fgEventCount=0;
77 AliHLTDataBuffer::~AliHLTDataBuffer()
79 // see header file for function documentation
80 CleanupConsumerList();
82 if (--fgNofInstances<=0) {
87 int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer)
89 // see header file for function documentation
92 if (FindConsumer(pConsumer)) {
93 HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
95 AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer);
97 fConsumers.push_back(pDesc);
98 HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
100 HLTError("memory allocation failed");
104 HLTError("invalid parameter: consumer component (nil)");
110 int AliHLTDataBuffer::FindMatchingDataBlocks(const AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
112 // see header file for function documentation
115 AliHLTDataSegmentList segments;
116 if ((iResult=FindMatchingDataSegments(pConsumer, segments))>=0) {
118 AliHLTDataSegmentList::iterator segment=segments.begin();
119 while (segment!=segments.end()) {
120 tgtList->push_back((*segment).fDataType);
124 iResult=segments.size();
132 int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
134 // see header file for function documentation
137 // Matthias 26.09.2007 relax the restriction to matching data blocks
138 // all blocks are passed to the consumer, which is the policy also in
140 tgtList.assign(fSegments.begin(), fSegments.end());
142 // add all forwarded blocks
143 tgtList.insert(tgtList.begin(), fForwardedSegments.begin(), fForwardedSegments.end());
144 iResult=tgtList.size();
148 AliHLTComponentDataTypeList dtlist;
149 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
150 AliHLTDataSegmentList::iterator segment=fSegments.begin();
151 while (segment!=fSegments.end()) {
152 AliHLTComponentDataTypeList::iterator type=dtlist.begin();
153 while (type!=dtlist.end()) {
154 if ((*segment).fDataType==(*type)) {
155 tgtList.push_back(*segment);
169 int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockDataList& blockDescList)
171 // see header file for function documentation
175 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
177 AliHLTDataSegmentList tgtList;
178 // Matthias 26.07.2007 AliHLTSystem should behave the same way as PubSub
179 // so it does not matter if there are matching data types or not, unless
180 // we implement such a check in PubSub
181 if ((iResult=FindMatchingDataSegments(pConsumer, tgtList))>=0) {
182 AliHLTDataSegmentList::iterator segment=tgtList.begin();
183 while (segment!=tgtList.end()) {
184 // fill the block data descriptor
185 AliHLTComponentBlockData bd;
186 AliHLTComponent::FillBlockData(bd);
187 // This models the behavior of PubSub.
188 // For incoming data blocks, fOffset must be ignored by the
189 // processing component. It is set for bookkeeping in the framework.
190 // fPtr always points to the beginning of the data.
192 AliHLTUInt8_t* pTgt=*segment;
193 bd.fPtr=reinterpret_cast<void*>(pTgt);
194 bd.fSize=(*segment).fSegmentSize;
195 bd.fDataType=(*segment).fDataType;
196 bd.fSpecification=(*segment).fSpecification;
197 blockDescList.push_back(bd);
198 pDesc->SetActiveDataSegment(*segment);
199 HLTDebug("component %p (%s) subscribed to segment offset %d size %d data type %s %#x",
200 pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), bd.fOffset,
201 bd.fSize, (AliHLTComponent::DataType2Text(bd.fDataType)).c_str(),
205 // move this consumer to the active list
206 if (tgtList.size()==0) {
207 ChangeConsumerState(pDesc, fConsumers, fReleasedConsumers);
208 HLTDebug("no input data for component %p (%s) available", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
209 } else if (ChangeConsumerState(pDesc, fConsumers, fActiveConsumers)>=0) {
210 HLTDebug("component %p (%s) subscribed to data buffer %p", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), this);
212 // TODO: cleanup the consumer descriptor correctly
213 segment=tgtList.begin();
214 while (segment!=tgtList.end()) {
215 blockDescList.pop_back();
218 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
222 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
226 if (!FindConsumer(pConsumer)) {
227 HLTError("component %p is not a data consumer of data buffer %p", pConsumer, this);
229 HLTError("component %p is a valid data consumer of data buffer %p, but did not release it's buffer subscription", pConsumer, this);
234 // Matthias 26.07.2007 until now, data had to be present for successful subscription
235 // in order to be consistent with the PubSub framework, this restiction has been
237 //HLTError("data buffer %p is empty", this);
241 HLTError("invalid parameter");
247 int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc,
248 const AliHLTComponent* pConsumer,
249 const AliHLTTask* pOwnerTask)
251 // see header file for function documentation
253 if (pBlockDesc && pConsumer) {
254 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
256 if ((iResult=pDesc->CheckActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)))!=1) {
257 HLTWarning("data segment mismatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
258 // TODO: appropriate error handling, but so far optional
261 pDesc->ReleaseActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize));
263 if (GetNofPendingConsumers()==0 && fForwardedSegments.size()>0) {
264 // last consumer, release forwarded segments
265 ReleaseForwardedBlock(pBlockDesc, pOwnerTask);
267 pBlockDesc->fOffset=0;
268 pBlockDesc->fPtr=NULL;
270 if (pDesc->GetNofActiveSegments()==0) {
271 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
272 if (GetNofActiveConsumers()==0 && GetNofPendingConsumers()==0) {
273 // this is the last consumer, reset the consumer list and release the raw buffer
277 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
282 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
286 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
292 int AliHLTDataBuffer::ReleaseForwardedBlock(AliHLTComponentBlockData* pBlockDesc,
293 const AliHLTTask* pOwnerTask)
295 // see header file for function documentation
297 if (pBlockDesc && pOwnerTask) {
298 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
299 AliHLTDataSegmentList::iterator segment=fForwardedSegments.begin();
300 AliHLTTaskPList::iterator src=fForwardedSegmentSources.begin();
301 //HLTDebug("%p checking forwarded segments", this);
302 for (; segment!=fForwardedSegments.end(); segment++, src++) {
303 //HLTDebug("segment ptr=%p offset=%d size=%d\n"
304 // "block ptr=%p offset=%d size=%d", (*segment).fPtr, (*segment).fSegmentOffset, (*segment).fSegmentSize, pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize);
305 if ((*segment)==AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)) {
306 //HLTDebug("release segment of task %p", *src);
307 assert((*src)!=NULL);
309 if ((*src)->Release(pBlockDesc, pOwnerTask)>=0) {
310 HLTDebug("task %s (%p) released forwarded segment %p size %d of task %s (%p)",
311 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
312 (*src)->GetName(), *src);
314 HLTError("task %s (%p) failed releasing forwarded segment %p size %d of task %s (%p)",
315 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
316 (*src)->GetName(), *src);
319 fForwardedSegments.erase(segment);
320 fForwardedSegmentSources.erase(src);
325 HLTError("inavalid parameter: pBlockDesc=%p pOwnerTask=%p", pBlockDesc, pOwnerTask);
331 int AliHLTDataBuffer::Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc)
333 // see header file for function documentation
334 if (pSrcTask==NULL || pBlockDesc==NULL) return -EINVAL;
335 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
336 if (fForwardedSegments.size()!=fForwardedSegmentSources.size()) return -EFAULT;
337 fForwardedSegmentSources.push_back(pSrcTask);
338 fForwardedSegments.push_back(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize, pBlockDesc->fDataType, pBlockDesc->fSpecification));
342 AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
344 // see header file for function documentation
345 AliHLTUInt8_t* pTargetBuffer=NULL;
346 if (fpBuffer!=NULL) {
347 HLTWarning("data buffer not properly reset, possible memory leak\n");
349 fpBuffer=CreateRawBuffer(iMinSize);
351 pTargetBuffer=*fpBuffer;
353 HLTError("can not create raw buffer");
355 return pTargetBuffer;
358 int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
360 // see header file for function documentation
362 if (pTgt && arrayBlockData && iSize>=0) {
364 if (*fpBuffer==pTgt) {
365 AliHLTDataBuffer::AliHLTDataSegment segment;
366 AliHLTUInt32_t maxSize=0;
367 for (int i=0; i<iSize; i++) {
368 // This function has to model the behavior of PubSub
369 // For output blocks only the fOffset value is used, this must be the offset
370 // relative to the output pointer. fPtr must be either NULL or the output
371 // pointer. In either case it is 'ignored' and set to the beginning of the
373 if (arrayBlockData[i].fPtr==NULL ||
374 arrayBlockData[i].fPtr==*fpBuffer) {
375 arrayBlockData[i].fPtr=*fpBuffer;
376 if ((arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->GetUsedSize()) ||
377 ((arrayBlockData[i].fOffset==~(AliHLTUInt32_t)0) && arrayBlockData[i].fSize==0)) {
378 segment.fSegmentOffset=arrayBlockData[i].fOffset;
379 segment.fPtr=(AliHLTUInt8_t*)arrayBlockData[i].fPtr;
380 segment.fSegmentSize=arrayBlockData[i].fSize;
381 segment.fDataType=arrayBlockData[i].fDataType;
382 segment.fSpecification=arrayBlockData[i].fSpecification;
383 fSegments.push_back(segment);
384 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
386 // find the actual size of the data
387 if ((arrayBlockData[i].fOffset!=~(AliHLTUInt32_t)0) &&
388 arrayBlockData[i].fOffset+arrayBlockData[i].fSize>maxSize) {
389 maxSize=arrayBlockData[i].fOffset+arrayBlockData[i].fSize;
392 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
393 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->GetUsedSize());
397 HLTError("invalid pointer (%p) in block data specification (buffer %p size %d)."
398 "please note: for output blocks only the fOffset value is valid and must "
399 "be relative to the output buffer", arrayBlockData[i].fPtr, fpBuffer->GetPointer(), fpBuffer->GetUsedSize());
403 // to be enabled if unit test is ready
404 #ifdef USE_ALIHLTRAWPAGE
405 iResult=SetRawBufferDataSize(fpBuffer, maxSize);
406 #endif //USE_ALIHLTRAWPAGE
408 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->GetPointer(), fpBuffer);
412 HLTFatal("internal data structur mismatch");
416 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
422 int AliHLTDataBuffer::IsEmpty()
424 // see header file for function documentation
425 int iResult=(fpBuffer==NULL && fForwardedSegments.size()==0) || GetNofSegments()==0;
429 int AliHLTDataBuffer::GetNofSegments()
431 // see header file for function documentation
432 int iResult=fSegments.size() + fForwardedSegments.size();
436 int AliHLTDataBuffer::GetNofConsumers()
438 // see header file for function documentation
439 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
443 int AliHLTDataBuffer::GetNofPendingConsumers()
445 // see header file for function documentation
446 int iResult=fConsumers.size();
450 int AliHLTDataBuffer::GetNofActiveConsumers()
452 // see header file for function documentation
453 int iResult=fActiveConsumers.size();
457 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
459 // see header file for function documentation
460 AliHLTRawBuffer* pRawBuffer=NULL;
461 unsigned int reqSize=size+fgkSafetyPatternSize;
462 #ifndef USE_ALIHLTRAWPAGE
463 AliHLTRawBufferPList::iterator buffer=fgFreeBuffers.begin();
464 while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
465 if ((*buffer)->CheckSize(reqSize)) {
466 // assign this element
468 pRawBuffer->UseBuffer(size);
469 fgFreeBuffers.erase(buffer);
470 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());
471 fgActiveBuffers.push_back(pRawBuffer);
476 if (pRawBuffer==NULL) {
477 // no buffer found, create a new one
478 pRawBuffer=new AliHLTRawBuffer(reqSize);
480 if (pRawBuffer->GetPointer()) {
481 pRawBuffer->UseBuffer(size);
482 fgActiveBuffers.push_back(pRawBuffer);
483 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->GetPointer(), pRawBuffer->GetTotalSize(), pRawBuffer);
487 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
490 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
494 pRawBuffer=AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(reqSize);
496 pRawBuffer->UseBuffer(size);
499 if (pRawBuffer!=NULL && fgkSafetyPatternSize>0) {
500 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "writing safety pattern to %p offset %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
501 pRawBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
506 int AliHLTDataBuffer::SetRawBufferDataSize(AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size) const
508 // see header file for function documentation
510 if (!pBuffer) return -EINVAL;
511 if (size>pBuffer->GetUsedSize()) {
512 HLTError("indicated data size %d exceeds data buffer %p (%d)", size, pBuffer->GetPointer(), pBuffer->GetUsedSize());
515 if (fgkSafetyPatternSize>0) {
516 if (pBuffer->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
517 HLTError("potential memory corruption: component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
520 // shrink the buffer and write new pattern at the end
521 #ifdef USE_ALIHLTRAWPAGE
522 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
524 pBuffer->UseBuffer(size);
525 if (rawpage->SetSize(pBuffer, size+fgkSafetyPatternSize)==0) {
528 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "failed to set size for raw buffer %p", pBuffer);
532 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
535 #else //!USE_ALIHLTRAWPAGE
536 pBuffer->UseBuffer(size);
537 #endif //USE_ALIHLTRAWPAGE
538 if (fgkSafetyPatternSize>0) {
539 pBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
544 int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
546 // see header file for function documentation
549 #ifdef USE_ALIHLTRAWPAGE
550 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
552 #else //!USE_ALIHLTRAWPAGE
553 AliHLTRawBufferPList::iterator buffer=fgActiveBuffers.begin();
554 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
557 if (buffer!=fgActiveBuffers.end())
558 #endif //USE_ALIHLTRAWPAGE
560 if (fgkSafetyPatternSize>0) {
561 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", pBuffer->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(pBuffer));
562 if ((pBuffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
563 fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
567 #ifdef USE_ALIHLTRAWPAGE
568 if (rawpage->Free(pBuffer)==0) {
570 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "failed to release raw buffer %p", pBuffer);
572 #else //!USE_ALIHLTRAWPAGE
573 fgFreeBuffers.push_back(pBuffer);
574 fgActiveBuffers.erase(buffer);
575 #endif //USE_ALIHLTRAWPAGE
577 #ifdef USE_ALIHLTRAWPAGE
578 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
579 #else //!USE_ALIHLTRAWPAGE
580 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
581 #endif //USE_ALIHLTRAWPAGE
585 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
592 int AliHLTDataBuffer::DeleteRawBuffers()
594 // see header file for function documentation
596 #ifdef ALIHLTSYSTEM_PROFILING
598 int iCount=fgFreeBuffers.size()+fgActiveBuffers.size();
599 #endif //ALIHLTSYSTEM_PROFILING
600 AliHLTRawBufferPList::iterator buffer;;
601 while ((buffer=fgFreeBuffers.begin())!=fgFreeBuffers.end()) {
602 #ifdef ALIHLTSYSTEM_PROFILING
603 iTotalSize+=(*buffer)->GetTotalSize();
604 #endif //ALIHLTSYSTEM_PROFILING
606 fgFreeBuffers.erase(buffer);
608 while ((buffer=fgActiveBuffers.begin())!=fgActiveBuffers.end()) {
609 #ifdef ALIHLTSYSTEM_PROFILING
610 iTotalSize+=(*buffer)->GetTotalSize();
611 #endif //ALIHLTSYSTEM_PROFILING
612 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
614 fgActiveBuffers.erase(buffer);
616 #ifdef ALIHLTSYSTEM_PROFILING
617 fgLogging.Logging(kHLTLogImportant, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
618 #endif //ALIHLTSYSTEM_PROFILING
622 int AliHLTDataBuffer::PrintStatistics()
624 // see header file for function documentation
626 #ifdef USE_ALIHLTRAWPAGE
628 AliHLTUInt32_t totalSize=0;
629 for (AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(NULL);
631 rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(rawpage)) {
633 totalSize+=rawpage->Size();
635 //if (rawpage) rawpage->Print("global");
636 fgLogging.Logging(kHLTLogInfo, "AliHLTDataBuffer::PrintStatistics", "data buffer handling", "total number of memory pages: %d total size %d", nofPages, totalSize);
638 #else //! USE_ALIHLTRAWPAGE
641 AliHLTRawBufferPList::iterator buffer;;
642 for (buffer=fgFreeBuffers.begin(); buffer!=fgFreeBuffers.end(); buffer++) {
643 iFree+=(*buffer)->GetTotalSize();
645 for (buffer=fgActiveBuffers.begin(); buffer!=fgActiveBuffers.end(); buffer++) {
646 iActive+=(*buffer)->GetTotalSize();
648 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);
649 #endif // USE_ALIHLTRAWPAGE
653 AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, AliHLTConsumerDescriptorPList &list) const
655 // see header file for function documentation
656 AliHLTConsumerDescriptor* pDesc=NULL;
657 AliHLTConsumerDescriptorPList::iterator desc=list.begin();
658 while (desc!=list.end() && pDesc==NULL) {
659 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
667 int AliHLTDataBuffer::ResetDataBuffer()
669 // see header file for function documentation
671 AliHLTRawBuffer* pBuffer=fpBuffer;
674 // cleanup forwarded segment lists
675 assert(fForwardedSegments.size()==0);
676 fForwardedSegments.clear();
677 fForwardedSegmentSources.clear();
679 // cleanup consumer states
680 AliHLTConsumerDescriptorPList::iterator desc;
681 // if (GetNofPendingConsumers()>0) {
682 // desc=fConsumers.begin();
683 // while (desc!=fConsumers.end()) {
684 // AliHLTComponent* pComp=(*desc)->GetComponent();
685 // HLTError("internal error: consumer %p (%s %p) did not get data from data buffer %p", *desc, pComp?pComp->GetComponentID():"", pComp, this);
689 desc=fReleasedConsumers.begin();
690 while (desc!=fReleasedConsumers.end()) {
691 AliHLTConsumerDescriptor* pDesc=*desc;
692 fReleasedConsumers.erase(desc);
693 desc=fReleasedConsumers.begin();
694 fConsumers.push_back(pDesc);
696 desc=fActiveConsumers.begin();
697 while (desc!=fActiveConsumers.end()) {
698 AliHLTConsumerDescriptor* pDesc=*desc;
699 HLTWarning("consumer %p (%s) was not released", pDesc, pDesc->GetComponent()?pDesc->GetComponent()->GetComponentID():"### invalid component ###");
700 fActiveConsumers.erase(desc);
701 desc=fActiveConsumers.begin();
702 fConsumers.push_back(pDesc);
706 AliHLTDataSegmentList::iterator segment=fSegments.begin();
707 while (segment!=fSegments.end()) {
708 fSegments.erase(segment);
709 segment=fSegments.begin();
712 // cleanup raw buffer
714 ReleaseRawBuffer(pBuffer);
719 int AliHLTDataBuffer::Reset()
721 // see header file for function documentation
722 return ResetDataBuffer();
725 // this is the version which works on lists of components instead of consumer descriptors
726 // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, AliHLTComponentPList &srcList, AliHLTComponentPList &tgtList)
730 // AliHLTComponentPList::iterator desc=srcList.begin();
731 // while (desc!=srcList.end()) {
732 // if ((*desc)==pConsumer) {
733 // srcList.erase(desc);
734 // tgtList.push_back(pConsumer);
739 // if (desc==srcList.end()) {
740 // HLTError("can not find consumer component %p in list", pConsumer);
744 // HLTError("invalid parameter");
750 int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, AliHLTConsumerDescriptorPList &srcList, AliHLTConsumerDescriptorPList &tgtList)
752 // see header file for function documentation
755 AliHLTConsumerDescriptorPList::iterator desc=srcList.begin();
756 while (desc!=srcList.end()) {
757 if ((*desc)==pDesc) {
759 tgtList.push_back(pDesc);
766 HLTError("can not find consumer descriptor %p in list", pDesc);
769 HLTError("invalid parameter");
775 int AliHLTDataBuffer::CleanupConsumerList()
777 // see header file for function documentation
780 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
781 while (desc!=fConsumers.end()) {
783 fConsumers.erase(desc);
784 desc=fConsumers.begin();
789 int AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, int bAllLists)
791 // see header file for function documentation
792 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
793 while (desc!=fConsumers.end()) {
794 if ((*desc)->GetComponent()==pConsumer)
798 if (bAllLists==0) return 0;
800 desc=fActiveConsumers.begin();
801 while (desc!=fActiveConsumers.end()) {
802 if ((*desc)->GetComponent()==pConsumer)
806 desc=fReleasedConsumers.begin();
807 while (desc!=fReleasedConsumers.end()) {
808 if ((*desc)->GetComponent()==pConsumer)
815 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size)
819 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(size)))
822 // see header file for class documentation
824 // refer to README to build package
826 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
833 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size, AliHLTUInt8_t* buffer)
836 , fExternalPtr(buffer)
840 // see header file for class documentation
843 AliHLTDataBuffer::AliHLTRawBuffer::~AliHLTRawBuffer()
845 if (fExternalPtr==NULL && fPtr) {
853 int AliHLTDataBuffer::AliHLTRawBuffer::operator==(void* ptr) const
855 // see header file for function documentation
856 return fPtr == static_cast<AliHLTUInt8_t*>(ptr);
859 int AliHLTDataBuffer::AliHLTRawBuffer::operator<(void* ptr) const
861 // see header file for function documentation
862 int iResult=fPtr < static_cast<AliHLTUInt8_t*>(ptr);
863 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
867 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(void* ptr) const
869 // see header file for function documentation
870 int iResult=fPtr <= static_cast<AliHLTUInt8_t*>(ptr);
871 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
875 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(void* ptr) const
877 // see header file for function documentation
878 int iResult=fPtr+fSize > static_cast<AliHLTUInt8_t*>(ptr);
879 //printf("%p: %p + %d > %p (%d)\n", this, fPtr, fSize, ptr, iResult);
883 int AliHLTDataBuffer::AliHLTRawBuffer::operator-(void* ptr) const
885 // see header file for function documentation
886 return static_cast<int>(static_cast<AliHLTUInt8_t*>(ptr)-fPtr);
889 int AliHLTDataBuffer::AliHLTRawBuffer::operator<(const AliHLTRawBuffer& op) const
891 // see header file for function documentation
892 return (fPtr+fSize < op.fPtr);
895 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(const AliHLTRawBuffer& op) const
897 // see header file for function documentation
898 return (fPtr+fSize <= op.fPtr);
901 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(const AliHLTRawBuffer& op) const
903 // see header file for function documentation
904 return (fPtr >= op.fPtr+op.fSize);
907 AliHLTUInt8_t* AliHLTDataBuffer::AliHLTRawBuffer::UseBuffer(AliHLTUInt32_t size)
909 // mark a portion of the buffer as used
910 if (size>0 && fTotalSize>=size) {
912 fLastEventCount=AliHLTDataBuffer::fgEventCount;
918 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawBuffer::Split(AliHLTUInt32_t size)
920 // split a buffer at specified size
921 // only possible for buffers with external memory
922 if (fTotalSize>size &&
923 (fSize==0 || fSize<=size) &&
924 fExternalPtr!=NULL) {
925 AliHLTRawBuffer* part2=new AliHLTRawBuffer(fTotalSize-size, fPtr+size);
931 cout << "can not split fTotalSize=" << fTotalSize << " fSize=" << fSize << " at size=" << size << endl;
936 int AliHLTDataBuffer::AliHLTRawBuffer::CheckSize(AliHLTUInt32_t size) const
938 // see header file for function documentation
939 if (fTotalSize<size) return 0;
941 if (fLastEventCount+1<AliHLTDataBuffer::fgEventCount) {
942 adjust=AliHLTDataBuffer::fgEventCount-fLastEventCount;
944 return (adjust>2) || ((fTotalSize-size)<(fgMargin<<adjust));
947 int AliHLTDataBuffer::AliHLTRawBuffer::Reset()
949 // see header file for function documentation
954 int AliHLTDataBuffer::AliHLTRawBuffer::WritePattern(const char* pattern, int size)
956 // see header file for function documentation
958 if (pattern!=NULL && size>0) {
959 if (fSize+size<=fTotalSize) {
960 memcpy(((char*)fPtr)+fSize, pattern, size);
969 int AliHLTDataBuffer::AliHLTRawBuffer::CheckPattern(const char* pattern, int size) const
971 // see header file for function documentation
973 if (pattern!=NULL && size>0) {
974 if (fSize+size<=fTotalSize) {
975 iResult=memcmp(((char*)fPtr)+fSize, pattern, size)!=0;
983 int AliHLTDataBuffer::AliHLTRawBuffer::Merge(const AliHLTDataBuffer::AliHLTRawBuffer& neighbor)
985 // Merge buffer with neighboring buffer.
986 // Only possible if the buffers are consecutive with out any gap.
988 if (!fExternalPtr || !neighbor.fExternalPtr) return -EPERM;
990 if (neighbor.fTotalSize==0 &&
991 fPtr < neighbor.fPtr &&
992 fPtr+fTotalSize > neighbor.fPtr) {
993 // special case for a buffer of zero size embedded into this buffer
998 neighbor.fPtr < fPtr &&
999 neighbor.fPtr+neighbor.fTotalSize > fPtr) {
1000 // special case for this buffer of size zero embedded into another buffer
1003 fTotalSize+=neighbor.fTotalSize;
1007 if (fPtr+fTotalSize == neighbor.fPtr) {
1008 fTotalSize+=neighbor.fTotalSize;
1012 if (fPtr == neighbor.fPtr+neighbor.fTotalSize) {
1015 fTotalSize+=neighbor.fTotalSize;
1022 void AliHLTDataBuffer::AliHLTRawBuffer::Print(const char* option)
1024 /// print buffer information
1025 if (strcmp(option, "min")!=0) {
1026 cout << "************* AliHLTRawBuffer status ***********" << endl;
1028 printf(" %p: buffer %p%s size %d used %d\n", this, fPtr, fExternalPtr?" (external)":"", fTotalSize, fSize); fflush(stdout);
1031 AliHLTDataBuffer::AliHLTRawPage::AliHLTRawPage(AliHLTUInt32_t pagesize)
1033 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(pagesize)))
1039 fFreeBuffers.push_back(new AliHLTRawBuffer(fSize, fPtr));
1045 AliHLTDataBuffer::AliHLTRawPage::~AliHLTRawPage()
1049 // do not free if the resources have not been completely freed
1050 HLTError("memory mismatch: not all allocated intances have been released");
1052 if (IsFragmented()) {
1053 HLTWarning("page still fragmented");
1055 AliHLTRawBufferPList::iterator element=fFreeBuffers.begin();
1056 while (element!=fFreeBuffers.end()) {
1057 if (*element) delete *element;
1058 element=fFreeBuffers.erase(element);
1068 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::Alloc(AliHLTUInt32_t size)
1070 /// alloc a buffer of specified size
1071 if (fFreeBuffers.size()==0) return NULL;
1073 for (AliHLTRawBufferPList::iterator iter=fFreeBuffers.begin();
1074 iter!=fFreeBuffers.end();
1076 if ((*iter)->GetTotalSize()==size) {
1077 AliHLTRawBuffer* thisbuffer=*iter;
1078 fFreeBuffers.erase(iter);
1079 fUsedBuffers.push_back(thisbuffer);
1081 } else if ((*iter)->GetTotalSize()>size) {
1082 AliHLTRawBuffer* thisbuffer=*iter;
1083 AliHLTRawBuffer* newbuffer=thisbuffer->Split(size);
1086 fUsedBuffers.push_back(thisbuffer);
1089 HLTWarning("failed to alloc raw buffer: cannot split raw buffer %p of size %d (used %d) at size %d", *iter, (*iter)->GetTotalSize(), (*iter)->GetUsedSize(), size);
1096 int AliHLTDataBuffer::AliHLTRawPage::Free(AliHLTRawBuffer* pBuffer)
1098 /// free a buffer and merge consecutive free buffers
1100 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1101 iter!=fUsedBuffers.end() && iResult>=0;
1103 if ((*iter)==pBuffer) {
1104 fUsedBuffers.erase(iter);
1105 AliHLTRawBufferPList::iterator prev=fFreeBuffers.begin();
1106 for (; prev!=fFreeBuffers.end() && iResult>=0; prev++) {
1107 if ((*pBuffer)<(*(*prev)) ||
1108 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1109 // check consecutive buffers
1110 if ((*(*prev)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize()) ||
1111 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1112 // the buffer to be released has a consecutive free buffer -> merge them
1113 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1117 HLTError("failed to merge consecutive/overlapping buffers %p and %p", pBuffer, (*prev));
1123 fFreeBuffers.insert(prev, pBuffer);
1126 if ((*pBuffer)>(*(*prev)) ||
1127 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1128 // check consecutive buffers
1129 if ((*pBuffer) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())||
1130 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1131 // the buffer to be released is consecutive to a free buffer -> merge them
1132 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1133 AliHLTRawBufferPList::iterator succ=prev+1;
1136 // check if the buffer and the following one are consecutive
1137 if (succ!=fFreeBuffers.end() &&
1138 (*(*succ)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1139 if ((iResult=pBuffer->Merge(*(*succ)))>=0) {
1141 fFreeBuffers.erase(succ);
1149 if (prev==fFreeBuffers.end()) {
1150 fFreeBuffers.push_back(pBuffer);
1153 // merge consecutive free buffers
1154 prev=fFreeBuffers.begin();
1155 for (AliHLTRawBufferPList::iterator current=prev+1; current!=fFreeBuffers.end() && iResult>=0; ) {
1156 // check if the buffer is embedded into the previous one
1157 if ((*current)->GetTotalSize()==0 && (*prev)->GetPointer()<=(*current)->GetPointer() && (*current)->GetPointer()<(*prev)->GetPointer()+(*prev)->GetTotalSize()) {
1158 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1159 current=fFreeBuffers.erase(current);
1162 HLTError("failed to merge embedded zero length buffer into preceeding buffer");
1166 // check if the buffer is consecutive to the previous one
1167 if ((*(*current)) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1168 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1169 current=fFreeBuffers.erase(current);
1172 HLTError("failed to merge consecutive free buffers");
1179 // buffer was part of this page
1183 // buffer not found in this page
1187 int AliHLTDataBuffer::AliHLTRawPage::SetSize(AliHLTDataBuffer::AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size)
1189 /// set the size of a raw buffer and release the remaining part
1191 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1192 iter!=fUsedBuffers.end() && iResult>=0;
1194 if ((*iter)==pBuffer) { // buffer was part of this page
1195 if ((*iter)->GetTotalSize()==size) return 0;
1196 if ((*iter)->GetTotalSize()<size) {
1197 HLTError("%d exceeds total size of buffer %p (%d used %d)\n", size, *iter, (*iter)->GetTotalSize(), (*iter)->GetUsedSize());
1200 AliHLTDataBuffer::AliHLTRawBuffer* freespace=(*iter)->Split(size);
1202 fUsedBuffers.push_back(freespace);
1205 HLTWarning("failed to relase unused memory: cannot split raw buffer %p of size %d (used %d) at size %d", *iter, (*iter)->GetTotalSize(), (*iter)->GetUsedSize(), size);
1210 // buffer not found in this page
1214 bool AliHLTDataBuffer::AliHLTRawPage::HasBuffer(AliHLTDataBuffer::AliHLTRawBuffer* pBuffer)
1216 /// check if the buffer is in this page
1217 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1218 iter!=fUsedBuffers.end();
1220 if ((*iter)==pBuffer) { // buffer was part of this page
1224 // buffer not found in this page
1228 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::Capacity() const
1230 /// get max available contiguous buffer
1231 AliHLTUInt32_t capacity=0;
1232 for (unsigned i=0; i<fFreeBuffers.size(); i++) {
1233 if (fFreeBuffers[i]->GetTotalSize()>capacity)
1234 capacity=fFreeBuffers[i]->GetTotalSize();
1239 void AliHLTDataBuffer::AliHLTRawPage::Print(const char* option)
1241 /// print page information
1242 if (strcmp(option, "global")==0) {
1243 cout << "number of global pages: " << fgGlobalPages.size() << endl;
1244 for (AliHLTRawPage* rawpage=NextPage(NULL);
1246 rawpage=NextPage(rawpage)) {
1251 cout << "************* AliHLTRawPage status ***********" << endl;
1252 cout << " instance " << this << endl;
1253 printf(" buffer %p size %d", fPtr, fSize);
1254 cout << " used buffers: " << fUsedBuffers.size() << endl;
1255 AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1256 for (; iter!=fUsedBuffers.end(); iter++) {
1257 cout << " "; (*iter)->Print("min");
1259 cout << " free buffers: " << fFreeBuffers.size() << endl;
1260 iter=fFreeBuffers.begin();
1261 for (; iter!=fFreeBuffers.end(); iter++) {
1262 cout << " "; (*iter)->Print("min");
1267 vector<AliHLTDataBuffer::AliHLTRawPage*> AliHLTDataBuffer::AliHLTRawPage::fgGlobalPages;
1269 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::fgGlobalPageSize=1024*1024*10;
1271 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(AliHLTUInt32_t size, int verbosity)
1273 // alloc a buffer of specified size from the global pages
1274 AliHLTDataBuffer::AliHLTRawBuffer* rawbuffer=NULL;
1275 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1277 for (page=fgGlobalPages.begin();page!=fgGlobalPages.end(); page++) {
1278 if ((rawbuffer=(*page)->Alloc(size))!=NULL) {
1280 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, *page);
1281 rawbuffer->Print("min");
1287 AliHLTUInt32_t rawPageSize=fgGlobalPageSize;
1288 if (rawPageSize<size) {
1289 if (rawPageSize*10<size ||
1290 rawPageSize*10>1024*1024*1024) {
1291 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "refusing to allocate buffer of size", size);
1296 AliHLTDataBuffer::AliHLTRawPage* rawpage=new AliHLTDataBuffer::AliHLTRawPage(rawPageSize);
1298 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "can not create raw page");
1301 fgGlobalPages.push_back(rawpage);
1302 if ((rawbuffer=rawpage->Alloc(size))!=NULL) {
1304 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, rawpage);
1305 rawbuffer->Print("min");
1313 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::FindPage(AliHLTDataBuffer::AliHLTRawBuffer* buffer)
1315 // find buffer in the global pages
1316 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1317 for (; page!=fgGlobalPages.end(); page++) {
1318 if ((*page)->HasBuffer(buffer)) {
1326 int AliHLTDataBuffer::AliHLTRawPage::GlobalClean()
1328 // cleanup the global pages */
1329 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1330 while (page!=fgGlobalPages.end()) {
1331 if (!(*page)->IsUsed()) {
1333 page=fgGlobalPages.erase(page);
1337 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalClean", "data buffer handling", "HLT memory page still in use, skipping cleanup, potential memory leak");
1345 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::NextPage(AliHLTDataBuffer::AliHLTRawPage* prev)
1347 // get next global page
1348 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1349 for (; page!=fgGlobalPages.end(); page++) {
1350 if (prev==NULL) return *page;
1351 if (*page!=prev) continue;
1352 if (++page!=fgGlobalPages.end()) return *page;