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.
23 // @note Only used in the AliRoot framework
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 #define USE_ALIHLTRAWPAGE
46 typedef vector<AliHLTDataBuffer::AliHLTDataSegment> AliHLTDataSegmentList;
48 /** ROOT macro for the implementation of ROOT specific class methods */
49 ClassImp(AliHLTDataBuffer)
51 AliHLTDataBuffer::AliHLTDataBuffer()
59 fForwardedSegmentSources(),
62 // see header file for class documentation
64 // refer to README to build package
66 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
69 fActiveConsumers.empty();
70 fReleasedConsumers.empty();
74 int AliHLTDataBuffer::fgNofInstances=0;
75 AliHLTDataBuffer::AliHLTRawBufferPList AliHLTDataBuffer::fgFreeBuffers;
76 AliHLTDataBuffer::AliHLTRawBufferPList AliHLTDataBuffer::fgActiveBuffers;
77 AliHLTUInt32_t AliHLTDataBuffer::fgMargin=1024;
78 AliHLTLogging AliHLTDataBuffer::fgLogging;
79 const Int_t AliHLTDataBuffer::fgkSafetyPatternSize=16;
80 const char AliHLTDataBuffer::fgkSafetyPattern[]={0x28, 0x63, 0x29, 0x4d, 0x52, 0x49, 0x43, 0x48, 0x54, 0x45, 0x52, 0x20, 0x32, 0x30, 0x30, 0x37};
81 AliHLTUInt32_t AliHLTDataBuffer::fgEventCount=0;
83 AliHLTDataBuffer::~AliHLTDataBuffer()
85 // see header file for function documentation
86 CleanupConsumerList();
88 if (--fgNofInstances<=0) {
93 int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer)
95 // see header file for function documentation
98 if (FindConsumer(pConsumer)) {
99 HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
101 AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer);
103 fConsumers.push_back(pDesc);
104 HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
106 HLTError("memory allocation failed");
110 HLTError("invalid parameter: consumer component (nil)");
116 int AliHLTDataBuffer::FindMatchingDataBlocks(const AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList)
118 // see header file for function documentation
121 AliHLTDataSegmentList segments;
122 if ((iResult=FindMatchingDataSegments(pConsumer, segments))>=0) {
124 AliHLTDataSegmentList::iterator segment=segments.begin();
125 while (segment!=segments.end()) {
126 tgtList->push_back((*segment).fDataType);
130 iResult=segments.size();
138 int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer,
139 vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
141 // see header file for function documentation
144 // Matthias 26.09.2007 relax the restriction to matching data blocks
145 // all blocks are passed to the consumer, which is the policy also in
147 tgtList.assign(fSegments.begin(), fSegments.end());
149 // add all forwarded blocks
150 tgtList.insert(tgtList.begin(), fForwardedSegments.begin(), fForwardedSegments.end());
151 iResult=tgtList.size();
155 AliHLTComponentDataTypeList dtlist;
156 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
157 AliHLTDataSegmentList::iterator segment=fSegments.begin();
158 while (segment!=fSegments.end()) {
159 AliHLTComponentDataTypeList::iterator type=dtlist.begin();
160 while (type!=dtlist.end()) {
161 if ((*segment).fDataType==(*type)) {
162 tgtList.push_back(*segment);
176 int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockDataList& blockDescList)
178 // see header file for function documentation
182 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
184 AliHLTDataSegmentList tgtList;
185 // Matthias 26.07.2007 AliHLTSystem should behave the same way as PubSub
186 // so it does not matter if there are matching data types or not, unless
187 // we implement such a check in PubSub
188 if ((iResult=FindMatchingDataSegments(pConsumer, tgtList))>=0) {
189 AliHLTDataSegmentList::iterator segment=tgtList.begin();
190 while (segment!=tgtList.end()) {
191 // fill the block data descriptor
192 AliHLTComponentBlockData bd;
193 AliHLTComponent::FillBlockData(bd);
194 // This models the behavior of PubSub.
195 // For incoming data blocks, fOffset must be ignored by the
196 // processing component. It is set for bookkeeping in the framework.
197 // fPtr always points to the beginning of the data.
199 AliHLTUInt8_t* pTgt=*segment;
200 bd.fPtr=reinterpret_cast<void*>(pTgt);
201 bd.fSize=(*segment).fSegmentSize;
202 bd.fDataType=(*segment).fDataType;
203 bd.fSpecification=(*segment).fSpecification;
204 blockDescList.push_back(bd);
205 pDesc->SetActiveDataSegment(*segment);
206 HLTDebug("component %p (%s) subscribed to segment offset %d size %d data type %s %#x",
207 pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), bd.fOffset,
208 bd.fSize, (AliHLTComponent::DataType2Text(bd.fDataType)).c_str(),
212 // move this consumer to the active list
213 if (tgtList.size()==0) {
214 ChangeConsumerState(pDesc, fConsumers, fReleasedConsumers);
215 HLTDebug("no input data for component %p (%s) available", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
216 } else if (ChangeConsumerState(pDesc, fConsumers, fActiveConsumers)>=0) {
217 HLTDebug("component %p (%s) subscribed to data buffer %p", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), this);
219 // TODO: cleanup the consumer descriptor correctly
220 segment=tgtList.begin();
221 while (segment!=tgtList.end()) {
222 blockDescList.pop_back();
225 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
229 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
233 if (!FindConsumer(pConsumer)) {
234 HLTError("component %p is not a data consumer of data buffer %p", pConsumer, this);
236 HLTError("component %p is a valid data consumer of data buffer %p, but did not release it's buffer subscription", pConsumer, this);
241 // Matthias 26.07.2007 until now, data had to be present for successful subscription
242 // in order to be consistent with the PubSub framework, this restiction has been
244 //HLTError("data buffer %p is empty", this);
248 HLTError("invalid parameter");
254 int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc,
255 const AliHLTComponent* pConsumer,
256 const AliHLTTask* pOwnerTask)
258 // see header file for function documentation
260 if (pBlockDesc && pConsumer) {
261 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
263 if ((iResult=pDesc->CheckActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)))!=1) {
264 HLTWarning("data segment mismatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
265 // TODO: appropriate error handling, but so far optional
268 pDesc->ReleaseActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize));
270 if (GetNofPendingConsumers()==0 && fForwardedSegments.size()>0) {
271 // last consumer, release forwarded segments
272 ReleaseForwardedBlock(pBlockDesc, pOwnerTask);
274 pBlockDesc->fOffset=0;
275 pBlockDesc->fPtr=NULL;
277 if (pDesc->GetNofActiveSegments()==0) {
278 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
279 if (GetNofActiveConsumers()==0 && GetNofPendingConsumers()==0) {
280 // this is the last consumer, reset the consumer list and release the raw buffer
284 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
289 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
293 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
299 int AliHLTDataBuffer::ReleaseForwardedBlock(AliHLTComponentBlockData* pBlockDesc,
300 const AliHLTTask* pOwnerTask)
302 // see header file for function documentation
304 if (pBlockDesc && pOwnerTask) {
305 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
306 AliHLTDataSegmentList::iterator segment=fForwardedSegments.begin();
307 AliHLTTaskPList::iterator src=fForwardedSegmentSources.begin();
308 //HLTDebug("%p checking forwarded segments", this);
309 for (; segment!=fForwardedSegments.end(); segment++, src++) {
310 //HLTDebug("segment ptr=%p offset=%d size=%d\n"
311 // "block ptr=%p offset=%d size=%d", (*segment).fPtr, (*segment).fSegmentOffset, (*segment).fSegmentSize, pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize);
312 if ((*segment)==AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)) {
313 //HLTDebug("release segment of task %p", *src);
314 assert((*src)!=NULL);
316 if ((*src)->Release(pBlockDesc, pOwnerTask)>=0) {
317 HLTDebug("task %s (%p) released forwarded segment %p size %d of task %s (%p)",
318 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
319 (*src)->GetName(), *src);
321 HLTError("task %s (%p) failed releasing forwarded segment %p size %d of task %s (%p)",
322 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
323 (*src)->GetName(), *src);
326 fForwardedSegments.erase(segment);
327 fForwardedSegmentSources.erase(src);
332 HLTError("inavalid parameter: pBlockDesc=%p pOwnerTask=%p", pBlockDesc, pOwnerTask);
338 int AliHLTDataBuffer::Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc)
340 // see header file for function documentation
341 if (pSrcTask==NULL || pBlockDesc==NULL) return -EINVAL;
342 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
343 if (fForwardedSegments.size()!=fForwardedSegmentSources.size()) return -EFAULT;
344 fForwardedSegmentSources.push_back(pSrcTask);
345 fForwardedSegments.push_back(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize, pBlockDesc->fDataType, pBlockDesc->fSpecification));
349 AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
351 // see header file for function documentation
352 AliHLTUInt8_t* pTargetBuffer=NULL;
353 if (fpBuffer!=NULL) {
354 HLTWarning("data buffer not properly reset, possible memory leak\n");
356 fpBuffer=CreateRawBuffer(iMinSize);
358 pTargetBuffer=*fpBuffer;
360 HLTError("can not create raw buffer");
362 return pTargetBuffer;
365 int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
367 // see header file for function documentation
369 if (pTgt && arrayBlockData && iSize>=0) {
371 if (*fpBuffer==pTgt) {
372 AliHLTDataBuffer::AliHLTDataSegment segment;
373 AliHLTUInt32_t maxSize=0;
374 for (int i=0; i<iSize; i++) {
375 // This function has to model the behavior of PubSub
376 // For output blocks only the fOffset value is used, this must be the offset
377 // relative to the output pointer. fPtr must be either NULL or the output
378 // pointer. In either case it is 'ignored' and set to the beginning of the
380 if (arrayBlockData[i].fPtr==NULL ||
381 arrayBlockData[i].fPtr==*fpBuffer) {
382 arrayBlockData[i].fPtr=*fpBuffer;
383 if ((arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->GetUsedSize()) ||
384 ((arrayBlockData[i].fOffset==~(AliHLTUInt32_t)0) && arrayBlockData[i].fSize==0)) {
385 segment.fSegmentOffset=arrayBlockData[i].fOffset;
386 segment.fPtr=(AliHLTUInt8_t*)arrayBlockData[i].fPtr;
387 segment.fSegmentSize=arrayBlockData[i].fSize;
388 segment.fDataType=arrayBlockData[i].fDataType;
389 segment.fSpecification=arrayBlockData[i].fSpecification;
390 fSegments.push_back(segment);
391 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
393 // find the actual size of the data
394 if ((arrayBlockData[i].fOffset!=~(AliHLTUInt32_t)0) &&
395 arrayBlockData[i].fOffset+arrayBlockData[i].fSize>maxSize) {
396 maxSize=arrayBlockData[i].fOffset+arrayBlockData[i].fSize;
399 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
400 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->GetUsedSize());
404 HLTError("invalid pointer (%p) in block data specification (buffer %p size %d)."
405 "please note: for output blocks only the fOffset value is valid and must "
406 "be relative to the output buffer", arrayBlockData[i].fPtr, fpBuffer->GetPointer(), fpBuffer->GetUsedSize());
410 // to be enabled if unit test is ready
411 #ifdef USE_ALIHLTRAWPAGE
412 iResult=SetRawBufferDataSize(fpBuffer, maxSize);
413 #endif //USE_ALIHLTRAWPAGE
415 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->GetPointer(), fpBuffer);
419 HLTFatal("internal data structur mismatch");
423 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
429 int AliHLTDataBuffer::IsEmpty()
431 // see header file for function documentation
432 int iResult=(fpBuffer==NULL && fForwardedSegments.size()==0) || GetNofSegments()==0;
436 int AliHLTDataBuffer::GetNofSegments()
438 // see header file for function documentation
439 int iResult=fSegments.size() + fForwardedSegments.size();
443 int AliHLTDataBuffer::GetNofConsumers()
445 // see header file for function documentation
446 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
450 int AliHLTDataBuffer::GetNofPendingConsumers()
452 // see header file for function documentation
453 int iResult=fConsumers.size();
457 int AliHLTDataBuffer::GetNofActiveConsumers()
459 // see header file for function documentation
460 int iResult=fActiveConsumers.size();
464 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
466 // see header file for function documentation
467 AliHLTRawBuffer* pRawBuffer=NULL;
468 unsigned int reqSize=size+fgkSafetyPatternSize;
469 #ifndef USE_ALIHLTRAWPAGE
470 AliHLTRawBufferPList::iterator buffer=fgFreeBuffers.begin();
471 while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
472 if ((*buffer)->CheckSize(reqSize)) {
473 // assign this element
475 pRawBuffer->UseBuffer(size);
476 fgFreeBuffers.erase(buffer);
477 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());
478 fgActiveBuffers.push_back(pRawBuffer);
483 if (pRawBuffer==NULL) {
484 // no buffer found, create a new one
485 pRawBuffer=new AliHLTRawBuffer(reqSize);
487 if (pRawBuffer->GetPointer()) {
488 pRawBuffer->UseBuffer(size);
489 fgActiveBuffers.push_back(pRawBuffer);
490 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->GetPointer(), pRawBuffer->GetTotalSize(), pRawBuffer);
494 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
497 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
501 pRawBuffer=AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(reqSize);
503 pRawBuffer->UseBuffer(size);
506 if (pRawBuffer!=NULL && fgkSafetyPatternSize>0) {
507 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "writing safety pattern to %p offset %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
508 pRawBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
513 int AliHLTDataBuffer::SetRawBufferDataSize(AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size) const
515 // see header file for function documentation
517 if (!pBuffer) return -EINVAL;
518 if (size>pBuffer->GetUsedSize()) {
519 HLTError("indicated data size %d exceeds data buffer %p (%d)", size, pBuffer->GetPointer(), pBuffer->GetUsedSize());
522 if (fgkSafetyPatternSize>0) {
523 if (pBuffer->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
524 HLTError("potential memory corruption: component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
527 // shrink the buffer and write new pattern at the end
528 #ifdef USE_ALIHLTRAWPAGE
529 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
531 pBuffer->UseBuffer(size);
532 if (rawpage->SetSize(pBuffer, size+fgkSafetyPatternSize)==0) {
535 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "failed to set size for raw buffer %p", pBuffer);
539 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
542 #else //!USE_ALIHLTRAWPAGE
543 pBuffer->UseBuffer(size);
544 #endif //USE_ALIHLTRAWPAGE
545 if (fgkSafetyPatternSize>0) {
546 pBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
551 int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
553 // see header file for function documentation
556 #ifdef USE_ALIHLTRAWPAGE
557 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
559 #else //!USE_ALIHLTRAWPAGE
560 AliHLTRawBufferPList::iterator buffer=fgActiveBuffers.begin();
561 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
564 if (buffer!=fgActiveBuffers.end())
565 #endif //USE_ALIHLTRAWPAGE
567 if (fgkSafetyPatternSize>0) {
568 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", pBuffer->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(pBuffer));
569 if ((pBuffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
570 fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
574 #ifdef USE_ALIHLTRAWPAGE
575 if (rawpage->Free(pBuffer)==0) {
577 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "failed to release raw buffer %p", pBuffer);
579 #else //!USE_ALIHLTRAWPAGE
580 fgFreeBuffers.push_back(pBuffer);
581 fgActiveBuffers.erase(buffer);
582 #endif //USE_ALIHLTRAWPAGE
584 #ifdef USE_ALIHLTRAWPAGE
585 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
586 #else //!USE_ALIHLTRAWPAGE
587 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
588 #endif //USE_ALIHLTRAWPAGE
592 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
599 int AliHLTDataBuffer::DeleteRawBuffers()
601 // see header file for function documentation
603 #ifdef ALIHLTSYSTEM_PROFILING
605 int iCount=fgFreeBuffers.size()+fgActiveBuffers.size();
606 #endif //ALIHLTSYSTEM_PROFILING
607 AliHLTRawBufferPList::iterator buffer;;
608 while ((buffer=fgFreeBuffers.begin())!=fgFreeBuffers.end()) {
609 #ifdef ALIHLTSYSTEM_PROFILING
610 iTotalSize+=(*buffer)->GetTotalSize();
611 #endif //ALIHLTSYSTEM_PROFILING
613 fgFreeBuffers.erase(buffer);
615 while ((buffer=fgActiveBuffers.begin())!=fgActiveBuffers.end()) {
616 #ifdef ALIHLTSYSTEM_PROFILING
617 iTotalSize+=(*buffer)->GetTotalSize();
618 #endif //ALIHLTSYSTEM_PROFILING
619 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
621 fgActiveBuffers.erase(buffer);
623 #ifdef ALIHLTSYSTEM_PROFILING
624 fgLogging.Logging(kHLTLogImportant, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
625 #endif //ALIHLTSYSTEM_PROFILING
629 int AliHLTDataBuffer::PrintStatistics()
631 // see header file for function documentation
633 #ifdef USE_ALIHLTRAWPAGE
635 AliHLTUInt32_t totalSize=0;
636 for (AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(NULL);
638 rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(rawpage)) {
640 totalSize+=rawpage->Size();
642 //if (rawpage) rawpage->Print("global");
643 fgLogging.Logging(kHLTLogInfo, "AliHLTDataBuffer::PrintStatistics", "data buffer handling", "total number of memory pages: %d total size %d", nofPages, totalSize);
645 #else //! USE_ALIHLTRAWPAGE
648 AliHLTRawBufferPList::iterator buffer;;
649 for (buffer=fgFreeBuffers.begin(); buffer!=fgFreeBuffers.end(); buffer++) {
650 iFree+=(*buffer)->GetTotalSize();
652 for (buffer=fgActiveBuffers.begin(); buffer!=fgActiveBuffers.end(); buffer++) {
653 iActive+=(*buffer)->GetTotalSize();
655 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);
656 #endif // USE_ALIHLTRAWPAGE
660 AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, AliHLTConsumerDescriptorPList &list) const
662 // see header file for function documentation
663 AliHLTConsumerDescriptor* pDesc=NULL;
664 AliHLTConsumerDescriptorPList::iterator desc=list.begin();
665 while (desc!=list.end() && pDesc==NULL) {
666 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
674 int AliHLTDataBuffer::ResetDataBuffer()
676 // see header file for function documentation
678 AliHLTRawBuffer* pBuffer=fpBuffer;
681 // cleanup forwarded segment lists
682 assert(fForwardedSegments.size()==0);
683 fForwardedSegments.clear();
684 fForwardedSegmentSources.clear();
686 // cleanup consumer states
687 AliHLTConsumerDescriptorPList::iterator desc;
688 // if (GetNofPendingConsumers()>0) {
689 // desc=fConsumers.begin();
690 // while (desc!=fConsumers.end()) {
691 // AliHLTComponent* pComp=(*desc)->GetComponent();
692 // HLTError("internal error: consumer %p (%s %p) did not get data from data buffer %p", *desc, pComp?pComp->GetComponentID():"", pComp, this);
696 desc=fReleasedConsumers.begin();
697 while (desc!=fReleasedConsumers.end()) {
698 AliHLTConsumerDescriptor* pDesc=*desc;
699 fReleasedConsumers.erase(desc);
700 desc=fReleasedConsumers.begin();
701 fConsumers.push_back(pDesc);
703 desc=fActiveConsumers.begin();
704 while (desc!=fActiveConsumers.end()) {
705 AliHLTConsumerDescriptor* pDesc=*desc;
706 HLTWarning("consumer %p (%s) was not released", pDesc, pDesc->GetComponent()?pDesc->GetComponent()->GetComponentID():"### invalid component ###");
707 fActiveConsumers.erase(desc);
708 desc=fActiveConsumers.begin();
709 fConsumers.push_back(pDesc);
713 AliHLTDataSegmentList::iterator segment=fSegments.begin();
714 while (segment!=fSegments.end()) {
715 fSegments.erase(segment);
716 segment=fSegments.begin();
719 // cleanup raw buffer
721 ReleaseRawBuffer(pBuffer);
726 int AliHLTDataBuffer::Reset()
728 // see header file for function documentation
729 return ResetDataBuffer();
732 // this is the version which works on lists of components instead of consumer descriptors
733 // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, AliHLTComponentPList &srcList, AliHLTComponentPList &tgtList)
737 // AliHLTComponentPList::iterator desc=srcList.begin();
738 // while (desc!=srcList.end()) {
739 // if ((*desc)==pConsumer) {
740 // srcList.erase(desc);
741 // tgtList.push_back(pConsumer);
746 // if (desc==srcList.end()) {
747 // HLTError("can not find consumer component %p in list", pConsumer);
751 // HLTError("invalid parameter");
757 int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, AliHLTConsumerDescriptorPList &srcList, AliHLTConsumerDescriptorPList &tgtList)
759 // see header file for function documentation
762 AliHLTConsumerDescriptorPList::iterator desc=srcList.begin();
763 while (desc!=srcList.end()) {
764 if ((*desc)==pDesc) {
766 tgtList.push_back(pDesc);
773 HLTError("can not find consumer descriptor %p in list", pDesc);
776 HLTError("invalid parameter");
782 int AliHLTDataBuffer::CleanupConsumerList()
784 // see header file for function documentation
787 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
788 while (desc!=fConsumers.end()) {
790 fConsumers.erase(desc);
791 desc=fConsumers.begin();
796 int AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, int bAllLists)
798 // see header file for function documentation
799 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
800 while (desc!=fConsumers.end()) {
801 if ((*desc)->GetComponent()==pConsumer)
805 if (bAllLists==0) return 0;
807 desc=fActiveConsumers.begin();
808 while (desc!=fActiveConsumers.end()) {
809 if ((*desc)->GetComponent()==pConsumer)
813 desc=fReleasedConsumers.begin();
814 while (desc!=fReleasedConsumers.end()) {
815 if ((*desc)->GetComponent()==pConsumer)
822 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size)
826 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(size)))
829 // see header file for class documentation
831 // refer to README to build package
833 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
840 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size, AliHLTUInt8_t* buffer)
843 , fExternalPtr(buffer)
847 // see header file for class documentation
850 AliHLTDataBuffer::AliHLTRawBuffer::~AliHLTRawBuffer()
852 // see header file for class documentation
853 if (fExternalPtr==NULL && fPtr) {
861 int AliHLTDataBuffer::AliHLTRawBuffer::operator==(void* ptr) const
863 // see header file for function documentation
864 return fPtr == static_cast<AliHLTUInt8_t*>(ptr);
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 <= static_cast<AliHLTUInt8_t*>(ptr);
879 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
883 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(void* ptr) const
885 // see header file for function documentation
886 int iResult=fPtr+fSize > static_cast<AliHLTUInt8_t*>(ptr);
887 //printf("%p: %p + %d > %p (%d)\n", this, fPtr, fSize, ptr, iResult);
891 int AliHLTDataBuffer::AliHLTRawBuffer::operator-(void* ptr) const
893 // see header file for function documentation
894 return static_cast<int>(static_cast<AliHLTUInt8_t*>(ptr)-fPtr);
897 int AliHLTDataBuffer::AliHLTRawBuffer::operator<(const AliHLTRawBuffer& op) const
899 // see header file for function documentation
900 return (fPtr+fSize < op.fPtr);
903 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(const AliHLTRawBuffer& op) const
905 // see header file for function documentation
906 return (fPtr+fSize <= op.fPtr);
909 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(const AliHLTRawBuffer& op) const
911 // see header file for function documentation
912 return (fPtr >= op.fPtr+op.fSize);
915 AliHLTUInt8_t* AliHLTDataBuffer::AliHLTRawBuffer::UseBuffer(AliHLTUInt32_t size)
917 // mark a portion of the buffer as used
918 if (size>0 && fTotalSize>=size) {
920 fLastEventCount=AliHLTDataBuffer::fgEventCount;
926 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawBuffer::Split(AliHLTUInt32_t size)
928 // split a buffer at specified size
929 // only possible for buffers with external memory
930 if (fTotalSize>size &&
931 (fSize==0 || fSize<=size) &&
932 fExternalPtr!=NULL) {
933 AliHLTRawBuffer* part2=new AliHLTRawBuffer(fTotalSize-size, fPtr+size);
939 //cout << "can not split fTotalSize=" << fTotalSize << " fSize=" << fSize << " at size=" << size << endl;
944 int AliHLTDataBuffer::AliHLTRawBuffer::CheckSize(AliHLTUInt32_t size) const
946 // see header file for function documentation
947 if (fTotalSize<size) return 0;
949 if (fLastEventCount+1<AliHLTDataBuffer::fgEventCount) {
950 adjust=AliHLTDataBuffer::fgEventCount-fLastEventCount;
952 return (adjust>2) || ((fTotalSize-size)<(fgMargin<<adjust));
955 int AliHLTDataBuffer::AliHLTRawBuffer::Reset()
957 // see header file for function documentation
962 int AliHLTDataBuffer::AliHLTRawBuffer::WritePattern(const char* pattern, int size)
964 // see header file for function documentation
966 if (pattern!=NULL && size>0) {
967 if (fSize+size<=fTotalSize) {
968 memcpy(((char*)fPtr)+fSize, pattern, size);
977 int AliHLTDataBuffer::AliHLTRawBuffer::CheckPattern(const char* pattern, int size) const
979 // see header file for function documentation
981 if (pattern!=NULL && size>0) {
982 if (fSize+size<=fTotalSize) {
983 iResult=memcmp(((char*)fPtr)+fSize, pattern, size)!=0;
991 int AliHLTDataBuffer::AliHLTRawBuffer::Merge(const AliHLTDataBuffer::AliHLTRawBuffer& neighbor)
993 // Merge buffer with neighboring buffer.
994 // Only possible if the buffers are consecutive with out any gap.
996 if (!fExternalPtr || !neighbor.fExternalPtr) return -EPERM;
998 if (neighbor.fTotalSize==0 &&
999 fPtr < neighbor.fPtr &&
1000 fPtr+fTotalSize > neighbor.fPtr) {
1001 // special case for a buffer of zero size embedded into this buffer
1005 if (fTotalSize==0 &&
1006 neighbor.fPtr < fPtr &&
1007 neighbor.fPtr+neighbor.fTotalSize > fPtr) {
1008 // special case for this buffer of size zero embedded into another buffer
1011 fTotalSize+=neighbor.fTotalSize;
1015 if (fPtr+fTotalSize == neighbor.fPtr) {
1016 fTotalSize+=neighbor.fTotalSize;
1020 if (fPtr == neighbor.fPtr+neighbor.fTotalSize) {
1023 fTotalSize+=neighbor.fTotalSize;
1030 void AliHLTDataBuffer::AliHLTRawBuffer::Print(const char* option)
1032 /// print buffer information
1033 if (strcmp(option, "min")!=0) {
1034 cout << "************* AliHLTRawBuffer status ***********" << endl;
1036 printf(" %p: buffer %p%s size %d used %d\n", this, fPtr, fExternalPtr?" (external)":"", fTotalSize, fSize); fflush(stdout);
1039 AliHLTDataBuffer::AliHLTRawPage::AliHLTRawPage(AliHLTUInt32_t pagesize)
1041 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(pagesize)))
1047 fFreeBuffers.push_back(new AliHLTRawBuffer(fSize, fPtr));
1053 AliHLTDataBuffer::AliHLTRawPage::~AliHLTRawPage()
1057 // do not free if the resources have not been completely freed
1058 HLTError("memory mismatch: not all allocated intances have been released");
1060 if (IsFragmented()) {
1061 HLTWarning("page still fragmented");
1063 AliHLTRawBufferPList::iterator element=fFreeBuffers.begin();
1064 while (element!=fFreeBuffers.end()) {
1065 if (*element) delete *element;
1066 element=fFreeBuffers.erase(element);
1076 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::Alloc(AliHLTUInt32_t size)
1078 /// alloc a buffer of specified size
1079 if (fFreeBuffers.size()==0) return NULL;
1081 for (AliHLTRawBufferPList::iterator iter=fFreeBuffers.begin();
1082 iter!=fFreeBuffers.end();
1084 if ((*iter)->GetTotalSize()==size) {
1085 AliHLTRawBuffer* thisbuffer=*iter;
1086 fFreeBuffers.erase(iter);
1087 fUsedBuffers.push_back(thisbuffer);
1089 } else if ((*iter)->GetTotalSize()>size) {
1090 AliHLTRawBuffer* thisbuffer=*iter;
1091 AliHLTRawBuffer* newbuffer=thisbuffer->Split(size);
1094 fUsedBuffers.push_back(thisbuffer);
1097 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);
1104 int AliHLTDataBuffer::AliHLTRawPage::Free(AliHLTRawBuffer* pBuffer)
1106 /// free a buffer and merge consecutive free buffers
1108 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1109 iter!=fUsedBuffers.end() && iResult>=0;
1111 if ((*iter)==pBuffer) {
1112 fUsedBuffers.erase(iter);
1113 AliHLTRawBufferPList::iterator prev=fFreeBuffers.begin();
1114 for (; prev!=fFreeBuffers.end() && iResult>=0; prev++) {
1115 if ((*pBuffer)<(*(*prev)) ||
1116 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1117 // check consecutive buffers
1118 if ((*(*prev)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize()) ||
1119 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1120 // the buffer to be released has a consecutive free buffer -> merge them
1121 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1125 HLTError("failed to merge consecutive/overlapping buffers %p and %p", pBuffer, (*prev));
1131 fFreeBuffers.insert(prev, pBuffer);
1134 if ((*pBuffer)>(*(*prev)) ||
1135 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1136 // check consecutive buffers
1137 if ((*pBuffer) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())||
1138 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1139 // the buffer to be released is consecutive to a free buffer -> merge them
1140 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1141 AliHLTRawBufferPList::iterator succ=prev+1;
1144 // check if the buffer and the following one are consecutive
1145 if (succ!=fFreeBuffers.end() &&
1146 (*(*succ)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1147 if ((iResult=pBuffer->Merge(*(*succ)))>=0) {
1149 fFreeBuffers.erase(succ);
1157 if (prev==fFreeBuffers.end()) {
1158 fFreeBuffers.push_back(pBuffer);
1161 // merge consecutive free buffers
1162 prev=fFreeBuffers.begin();
1163 for (AliHLTRawBufferPList::iterator current=prev+1; current!=fFreeBuffers.end() && iResult>=0; ) {
1164 // check if the buffer is embedded into the previous one
1165 if ((*current)->GetTotalSize()==0 && (*prev)->GetPointer()<=(*current)->GetPointer() && (*current)->GetPointer()<(*prev)->GetPointer()+(*prev)->GetTotalSize()) {
1166 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1167 current=fFreeBuffers.erase(current);
1170 HLTError("failed to merge embedded zero length buffer into preceeding buffer");
1174 // check if the buffer is consecutive to the previous one
1175 if ((*(*current)) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1176 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1177 current=fFreeBuffers.erase(current);
1180 HLTError("failed to merge consecutive free buffers");
1187 // buffer was part of this page
1191 // buffer not found in this page
1195 int AliHLTDataBuffer::AliHLTRawPage::SetSize(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size)
1197 /// set the size of a raw buffer and release the remaining part
1199 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1200 iter!=fUsedBuffers.end() && iResult>=0;
1202 if ((*iter)==pBuffer) { // buffer was part of this page
1203 if ((*iter)->GetTotalSize()==size) return 0;
1204 if ((*iter)->GetTotalSize()<size) {
1205 HLTError("%d exceeds total size of buffer %p (%d used %d)\n", size, *iter, (*iter)->GetTotalSize(), (*iter)->GetUsedSize());
1208 AliHLTDataBuffer::AliHLTRawBuffer* freespace=(*iter)->Split(size);
1210 fUsedBuffers.push_back(freespace);
1213 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);
1218 // buffer not found in this page
1222 bool AliHLTDataBuffer::AliHLTRawPage::HasBuffer(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer)
1224 /// check if the buffer is in this page
1225 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1226 iter!=fUsedBuffers.end();
1228 if ((*iter)==pBuffer) { // buffer was part of this page
1232 // buffer not found in this page
1236 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::Capacity() const
1238 /// get max available contiguous buffer
1239 AliHLTUInt32_t capacity=0;
1240 for (unsigned i=0; i<fFreeBuffers.size(); i++) {
1241 if (fFreeBuffers[i]->GetTotalSize()>capacity)
1242 capacity=fFreeBuffers[i]->GetTotalSize();
1247 void AliHLTDataBuffer::AliHLTRawPage::Print(const char* option)
1249 /// print page information
1250 if (strcmp(option, "global")==0) {
1251 cout << "number of global pages: " << fgGlobalPages.size() << endl;
1252 for (AliHLTRawPage* rawpage=NextPage(NULL);
1254 rawpage=NextPage(rawpage)) {
1259 cout << "************* AliHLTRawPage status ***********" << endl;
1260 cout << " instance " << this << endl;
1261 printf(" buffer %p size %d", fPtr, fSize);
1262 cout << " used buffers: " << fUsedBuffers.size() << endl;
1263 AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1264 for (; iter!=fUsedBuffers.end(); iter++) {
1265 cout << " "; (*iter)->Print("min");
1267 cout << " free buffers: " << fFreeBuffers.size() << endl;
1268 iter=fFreeBuffers.begin();
1269 for (; iter!=fFreeBuffers.end(); iter++) {
1270 cout << " "; (*iter)->Print("min");
1275 vector<AliHLTDataBuffer::AliHLTRawPage*> AliHLTDataBuffer::AliHLTRawPage::fgGlobalPages;
1277 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::fgGlobalPageSize=50*1024*1024;
1279 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(AliHLTUInt32_t size, int verbosity)
1281 // alloc a buffer of specified size from the global pages
1282 AliHLTDataBuffer::AliHLTRawBuffer* rawbuffer=NULL;
1283 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1285 for (page=fgGlobalPages.begin();page!=fgGlobalPages.end(); page++) {
1286 if ((rawbuffer=(*page)->Alloc(size))!=NULL) {
1288 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, *page);
1289 rawbuffer->Print("min");
1295 AliHLTUInt32_t rawPageSize=fgGlobalPageSize;
1296 if (rawPageSize<size) {
1297 if (rawPageSize*10<size) {
1298 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "refusing to allocate buffer of size %d", size);
1303 AliHLTDataBuffer::AliHLTRawPage* rawpage=new AliHLTDataBuffer::AliHLTRawPage(rawPageSize);
1305 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "can not create raw page");
1308 fgGlobalPages.push_back(rawpage);
1309 if ((rawbuffer=rawpage->Alloc(size))!=NULL) {
1311 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, rawpage);
1312 rawbuffer->Print("min");
1320 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::FindPage(AliHLTDataBuffer::AliHLTRawBuffer* buffer)
1322 // find buffer in the global pages
1323 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1324 for (; page!=fgGlobalPages.end(); page++) {
1325 if ((*page)->HasBuffer(buffer)) {
1333 int AliHLTDataBuffer::AliHLTRawPage::GlobalClean()
1335 // cleanup the global pages */
1336 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1337 while (page!=fgGlobalPages.end()) {
1338 if (!(*page)->IsUsed()) {
1340 page=fgGlobalPages.erase(page);
1344 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalClean", "data buffer handling", "HLT memory page still in use, skipping cleanup, potential memory leak");
1352 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::NextPage(const AliHLTDataBuffer::AliHLTRawPage* prev)
1354 // get next global page
1355 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1356 for (; page!=fgGlobalPages.end(); page++) {
1357 if (prev==NULL) return *page;
1358 if (*page!=prev) continue;
1359 if (++page!=fgGlobalPages.end()) return *page;