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 int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockDataList& blockDescList)
157 // see header file for function documentation
161 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
163 AliHLTDataSegmentList tgtList;
164 // Matthias 26.07.2007 AliHLTSystem should behave the same way as PubSub
165 // so it does not matter if there are matching data types or not, unless
166 // we implement such a check in PubSub
167 if ((iResult=FindMatchingDataSegments(pConsumer, tgtList))>=0) {
168 AliHLTDataSegmentList::iterator segment=tgtList.begin();
169 while (segment!=tgtList.end()) {
170 // fill the block data descriptor
171 AliHLTComponentBlockData bd;
172 AliHLTComponent::FillBlockData(bd);
173 // This models the behavior of PubSub.
174 // For incoming data blocks, fOffset must be ignored by the
175 // processing component. It is set for bookkeeping in the framework.
176 // fPtr always points to the beginning of the data.
178 AliHLTUInt8_t* pTgt=*segment;
179 bd.fPtr=reinterpret_cast<void*>(pTgt);
180 bd.fSize=(*segment).fSegmentSize;
181 bd.fDataType=(*segment).fDataType;
182 bd.fSpecification=(*segment).fSpecification;
183 blockDescList.push_back(bd);
184 pDesc->SetActiveDataSegment(*segment);
185 HLTDebug("component %p (%s) subscribed to segment offset %d size %d data type %s %#x",
186 pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), bd.fOffset,
187 bd.fSize, (AliHLTComponent::DataType2Text(bd.fDataType)).c_str(),
191 // move this consumer to the active list
192 if (tgtList.size()==0) {
193 ChangeConsumerState(pDesc, fConsumers, fReleasedConsumers);
194 HLTDebug("no input data for component %p (%s) available", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
195 } else if (ChangeConsumerState(pDesc, fConsumers, fActiveConsumers)>=0) {
196 HLTDebug("component %p (%s) subscribed to data buffer %p", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), this);
198 // TODO: cleanup the consumer descriptor correctly
199 segment=tgtList.begin();
200 while (segment!=tgtList.end()) {
201 blockDescList.pop_back();
204 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
208 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
212 if (!FindConsumer(pConsumer)) {
213 HLTError("component %p is not a data consumer of data buffer %p", pConsumer, this);
215 HLTError("component %p is a valid data consumer of data buffer %p, but did not release it's buffer subscription", pConsumer, this);
220 // Matthias 26.07.2007 until now, data had to be present for successful subscription
221 // in order to be consistent with the PubSub framework, this restiction has been
223 //HLTError("data buffer %p is empty", this);
227 HLTError("invalid parameter");
233 int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc,
234 const AliHLTComponent* pConsumer,
235 const AliHLTTask* pOwnerTask)
237 // see header file for function documentation
239 if (pBlockDesc && pConsumer) {
240 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
242 if ((iResult=pDesc->CheckActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)))!=1) {
243 HLTWarning("data segment mismatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
244 // TODO: appropriate error handling, but so far optional
247 pDesc->ReleaseActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize));
249 if (GetNofPendingConsumers()==0 && fForwardedSegments.size()>0) {
250 // last consumer, release forwarded segments
251 ReleaseForwardedBlock(pBlockDesc, pOwnerTask);
253 pBlockDesc->fOffset=0;
254 pBlockDesc->fPtr=NULL;
256 if (pDesc->GetNofActiveSegments()==0) {
257 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
258 if (GetNofActiveConsumers()==0 && GetNofPendingConsumers()==0) {
259 // this is the last consumer, reset the consumer list and release the raw buffer
263 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
268 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
272 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
278 int AliHLTDataBuffer::ReleaseForwardedBlock(AliHLTComponentBlockData* pBlockDesc,
279 const AliHLTTask* pOwnerTask)
281 // see header file for function documentation
283 if (pBlockDesc && pOwnerTask) {
284 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
285 AliHLTDataSegmentList::iterator segment=fForwardedSegments.begin();
286 AliHLTTaskPList::iterator src=fForwardedSegmentSources.begin();
287 //HLTDebug("%p checking forwarded segments", this);
288 for (; segment!=fForwardedSegments.end(); segment++, src++) {
289 //HLTDebug("segment ptr=%p offset=%d size=%d\n"
290 // "block ptr=%p offset=%d size=%d", (*segment).fPtr, (*segment).fSegmentOffset, (*segment).fSegmentSize, pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize);
291 if ((*segment)==AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)) {
292 //HLTDebug("release segment of task %p", *src);
293 assert((*src)!=NULL);
295 if ((*src)->Release(pBlockDesc, pOwnerTask)>=0) {
296 HLTDebug("task %s (%p) released forwarded segment %p size %d of task %s (%p)",
297 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
298 (*src)->GetName(), *src);
300 HLTError("task %s (%p) failed releasing forwarded segment %p size %d of task %s (%p)",
301 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
302 (*src)->GetName(), *src);
305 fForwardedSegments.erase(segment);
306 fForwardedSegmentSources.erase(src);
311 HLTError("inavalid parameter: pBlockDesc=%p pOwnerTask=%p", pBlockDesc, pOwnerTask);
317 int AliHLTDataBuffer::Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc)
319 // see header file for function documentation
320 if (pSrcTask==NULL || pBlockDesc==NULL) return -EINVAL;
321 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
322 if (fForwardedSegments.size()!=fForwardedSegmentSources.size()) return -EFAULT;
323 fForwardedSegmentSources.push_back(pSrcTask);
324 fForwardedSegments.push_back(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize, pBlockDesc->fDataType, pBlockDesc->fSpecification));
328 AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
330 // see header file for function documentation
331 AliHLTUInt8_t* pTargetBuffer=NULL;
332 if (fpBuffer!=NULL) {
333 HLTWarning("data buffer not properly reset, possible memory leak\n");
335 fpBuffer=CreateRawBuffer(iMinSize);
337 pTargetBuffer=*fpBuffer;
339 HLTError("can not create raw buffer");
341 return pTargetBuffer;
344 int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
346 // see header file for function documentation
348 if (pTgt && arrayBlockData && iSize>=0) {
350 if (*fpBuffer==pTgt) {
351 AliHLTDataBuffer::AliHLTDataSegment segment;
352 AliHLTUInt32_t maxSize=0;
353 for (int i=0; i<iSize; i++) {
354 // This function has to model the behavior of PubSub
355 // For output blocks only the fOffset value is used, this must be the offset
356 // relative to the output pointer. fPtr must be either NULL or the output
357 // pointer. In either case it is 'ignored' and set to the beginning of the
359 if (arrayBlockData[i].fPtr==NULL ||
360 arrayBlockData[i].fPtr==*fpBuffer) {
361 arrayBlockData[i].fPtr=*fpBuffer;
362 if ((arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->GetUsedSize()) ||
363 ((arrayBlockData[i].fOffset==~(AliHLTUInt32_t)0) && arrayBlockData[i].fSize==0)) {
364 segment.fSegmentOffset=arrayBlockData[i].fOffset;
365 segment.fPtr=(AliHLTUInt8_t*)arrayBlockData[i].fPtr;
366 segment.fSegmentSize=arrayBlockData[i].fSize;
367 segment.fDataType=arrayBlockData[i].fDataType;
368 segment.fSpecification=arrayBlockData[i].fSpecification;
369 fSegments.push_back(segment);
370 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
372 // find the actual size of the data
373 if ((arrayBlockData[i].fOffset!=~(AliHLTUInt32_t)0) &&
374 arrayBlockData[i].fOffset+arrayBlockData[i].fSize>maxSize) {
375 maxSize=arrayBlockData[i].fOffset+arrayBlockData[i].fSize;
378 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
379 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->GetUsedSize());
383 HLTError("invalid pointer (%p) in block data specification (buffer %p size %d)."
384 "please note: for output blocks only the fOffset value is valid and must "
385 "be relative to the output buffer", arrayBlockData[i].fPtr, fpBuffer->GetPointer(), fpBuffer->GetUsedSize());
389 // to be enabled if unit test is ready
390 #ifdef USE_ALIHLTRAWPAGE
391 iResult=SetRawBufferDataSize(fpBuffer, maxSize);
392 #endif //USE_ALIHLTRAWPAGE
394 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->GetPointer(), fpBuffer);
398 HLTFatal("internal data structur mismatch");
402 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
408 int AliHLTDataBuffer::IsEmpty()
410 // see header file for function documentation
411 int iResult=(fpBuffer==NULL && fForwardedSegments.size()==0) || GetNofSegments()==0;
415 int AliHLTDataBuffer::GetNofSegments() const
417 // see header file for function documentation
418 int iResult=fSegments.size() + fForwardedSegments.size();
422 int AliHLTDataBuffer::GetNofConsumers() const
424 // see header file for function documentation
425 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
429 int AliHLTDataBuffer::GetNofPendingConsumers() const
431 // see header file for function documentation
432 int iResult=fConsumers.size();
436 int AliHLTDataBuffer::GetNofActiveConsumers() const
438 // see header file for function documentation
439 int iResult=fActiveConsumers.size();
443 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
445 // see header file for function documentation
446 AliHLTRawBuffer* pRawBuffer=NULL;
447 unsigned int reqSize=size+fgkSafetyPatternSize;
448 #ifndef USE_ALIHLTRAWPAGE
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");
480 pRawBuffer=AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(reqSize);
482 pRawBuffer->UseBuffer(size);
485 if (pRawBuffer!=NULL && fgkSafetyPatternSize>0) {
486 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "writing safety pattern to %p offset %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
487 pRawBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
492 int AliHLTDataBuffer::SetRawBufferDataSize(AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size) const
494 // see header file for function documentation
496 if (!pBuffer) return -EINVAL;
497 if (size>pBuffer->GetUsedSize()) {
498 HLTError("indicated data size %d exceeds data buffer %p (%d)", size, pBuffer->GetPointer(), pBuffer->GetUsedSize());
501 if (fgkSafetyPatternSize>0) {
502 if (pBuffer->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
503 HLTError("potential memory corruption: component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
506 // shrink the buffer and write new pattern at the end
507 #ifdef USE_ALIHLTRAWPAGE
508 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
510 pBuffer->UseBuffer(size);
511 if (rawpage->SetSize(pBuffer, size+fgkSafetyPatternSize)==0) {
514 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "failed to set size for raw buffer %p", pBuffer);
518 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
521 #else //!USE_ALIHLTRAWPAGE
522 pBuffer->UseBuffer(size);
523 #endif //USE_ALIHLTRAWPAGE
524 if (fgkSafetyPatternSize>0) {
525 pBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
530 int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
532 // see header file for function documentation
535 #ifdef USE_ALIHLTRAWPAGE
536 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
538 #else //!USE_ALIHLTRAWPAGE
539 AliHLTRawBufferPList::iterator buffer=fgActiveBuffers.begin();
540 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
543 if (buffer!=fgActiveBuffers.end())
544 #endif //USE_ALIHLTRAWPAGE
546 if (fgkSafetyPatternSize>0) {
547 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", pBuffer->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(pBuffer));
548 if ((pBuffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
549 fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
553 #ifdef USE_ALIHLTRAWPAGE
554 if (rawpage->Free(pBuffer)==0) {
556 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "failed to release raw buffer %p", pBuffer);
558 #else //!USE_ALIHLTRAWPAGE
559 fgFreeBuffers.push_back(pBuffer);
560 fgActiveBuffers.erase(buffer);
561 #endif //USE_ALIHLTRAWPAGE
563 #ifdef USE_ALIHLTRAWPAGE
564 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
565 #else //!USE_ALIHLTRAWPAGE
566 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
567 #endif //USE_ALIHLTRAWPAGE
571 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
578 int AliHLTDataBuffer::DeleteRawBuffers()
580 // see header file for function documentation
582 #ifdef ALIHLTSYSTEM_PROFILING
584 int iCount=fgFreeBuffers.size()+fgActiveBuffers.size();
585 #endif //ALIHLTSYSTEM_PROFILING
586 AliHLTRawBufferPList::iterator buffer;;
587 while ((buffer=fgFreeBuffers.begin())!=fgFreeBuffers.end()) {
588 #ifdef ALIHLTSYSTEM_PROFILING
589 iTotalSize+=(*buffer)->GetTotalSize();
590 #endif //ALIHLTSYSTEM_PROFILING
592 fgFreeBuffers.erase(buffer);
594 while ((buffer=fgActiveBuffers.begin())!=fgActiveBuffers.end()) {
595 #ifdef ALIHLTSYSTEM_PROFILING
596 iTotalSize+=(*buffer)->GetTotalSize();
597 #endif //ALIHLTSYSTEM_PROFILING
598 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
600 fgActiveBuffers.erase(buffer);
602 #ifdef ALIHLTSYSTEM_PROFILING
603 fgLogging.Logging(kHLTLogImportant, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
604 #endif //ALIHLTSYSTEM_PROFILING
608 int AliHLTDataBuffer::PrintStatistics()
610 // see header file for function documentation
612 #ifdef USE_ALIHLTRAWPAGE
614 AliHLTUInt32_t totalSize=0;
615 for (AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(NULL);
617 rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(rawpage)) {
619 totalSize+=rawpage->Size();
620 if (fgLogging.CheckFilter(kHLTLogDebug)) rawpage->Print("");
622 //if (rawpage) rawpage->Print("global");
623 fgLogging.Logging(kHLTLogInfo, "AliHLTDataBuffer::PrintStatistics", "data buffer handling", "total number of memory pages: %d total size %d", nofPages, totalSize);
625 #else //! USE_ALIHLTRAWPAGE
628 AliHLTRawBufferPList::iterator buffer;;
629 for (buffer=fgFreeBuffers.begin(); buffer!=fgFreeBuffers.end(); buffer++) {
630 iFree+=(*buffer)->GetTotalSize();
632 for (buffer=fgActiveBuffers.begin(); buffer!=fgActiveBuffers.end(); buffer++) {
633 iActive+=(*buffer)->GetTotalSize();
635 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);
636 #endif // USE_ALIHLTRAWPAGE
640 AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, AliHLTConsumerDescriptorPList &list) const
642 // see header file for function documentation
643 AliHLTConsumerDescriptor* pDesc=NULL;
644 AliHLTConsumerDescriptorPList::iterator desc=list.begin();
645 while (desc!=list.end() && pDesc==NULL) {
646 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
654 int AliHLTDataBuffer::ResetDataBuffer()
656 // see header file for function documentation
658 AliHLTRawBuffer* pBuffer=fpBuffer;
661 // cleanup forwarded segment lists
662 assert(fForwardedSegments.size()==0);
663 fForwardedSegments.clear();
664 fForwardedSegmentSources.clear();
666 // cleanup consumer states
667 AliHLTConsumerDescriptorPList::iterator desc;
668 // if (GetNofPendingConsumers()>0) {
669 // desc=fConsumers.begin();
670 // while (desc!=fConsumers.end()) {
671 // AliHLTComponent* pComp=(*desc)->GetComponent();
672 // HLTError("internal error: consumer %p (%s %p) did not get data from data buffer %p", *desc, pComp?pComp->GetComponentID():"", pComp, this);
676 desc=fReleasedConsumers.begin();
677 while (desc!=fReleasedConsumers.end()) {
678 AliHLTConsumerDescriptor* pDesc=*desc;
679 fReleasedConsumers.erase(desc);
680 desc=fReleasedConsumers.begin();
681 fConsumers.push_back(pDesc);
683 desc=fActiveConsumers.begin();
684 while (desc!=fActiveConsumers.end()) {
685 AliHLTConsumerDescriptor* pDesc=*desc;
686 HLTWarning("consumer %p (%s) was not released", pDesc, pDesc->GetComponent()?pDesc->GetComponent()->GetComponentID():"### invalid component ###");
687 fActiveConsumers.erase(desc);
688 desc=fActiveConsumers.begin();
689 fConsumers.push_back(pDesc);
693 AliHLTDataSegmentList::iterator segment=fSegments.begin();
694 while (segment!=fSegments.end()) {
695 fSegments.erase(segment);
696 segment=fSegments.begin();
699 // cleanup raw buffer
701 ReleaseRawBuffer(pBuffer);
706 int AliHLTDataBuffer::Reset()
708 // see header file for function documentation
709 return ResetDataBuffer();
712 // this is the version which works on lists of components instead of consumer descriptors
713 // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, AliHLTComponentPList &srcList, AliHLTComponentPList &tgtList)
717 // AliHLTComponentPList::iterator desc=srcList.begin();
718 // while (desc!=srcList.end()) {
719 // if ((*desc)==pConsumer) {
720 // srcList.erase(desc);
721 // tgtList.push_back(pConsumer);
726 // if (desc==srcList.end()) {
727 // HLTError("can not find consumer component %p in list", pConsumer);
731 // HLTError("invalid parameter");
737 int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, AliHLTConsumerDescriptorPList &srcList, AliHLTConsumerDescriptorPList &tgtList)
739 // see header file for function documentation
742 AliHLTConsumerDescriptorPList::iterator desc=srcList.begin();
743 while (desc!=srcList.end()) {
744 if ((*desc)==pDesc) {
746 tgtList.push_back(pDesc);
753 HLTError("can not find consumer descriptor %p in list", pDesc);
756 HLTError("invalid parameter");
762 int AliHLTDataBuffer::CleanupConsumerList()
764 // see header file for function documentation
767 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
768 while (desc!=fConsumers.end()) {
770 fConsumers.erase(desc);
771 desc=fConsumers.begin();
776 int AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, int bAllLists)
778 // see header file for function documentation
779 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
780 while (desc!=fConsumers.end()) {
781 if ((*desc)->GetComponent()==pConsumer)
785 if (bAllLists==0) return 0;
787 desc=fActiveConsumers.begin();
788 while (desc!=fActiveConsumers.end()) {
789 if ((*desc)->GetComponent()==pConsumer)
793 desc=fReleasedConsumers.begin();
794 while (desc!=fReleasedConsumers.end()) {
795 if ((*desc)->GetComponent()==pConsumer)
802 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size)
806 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(size)))
809 // see header file for class documentation
811 // refer to README to build package
813 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
820 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size, AliHLTUInt8_t* buffer)
823 , fExternalPtr(buffer)
827 // see header file for class documentation
830 AliHLTDataBuffer::AliHLTRawBuffer::~AliHLTRawBuffer()
832 // see header file for class documentation
833 if (fExternalPtr==NULL && fPtr) {
841 int AliHLTDataBuffer::AliHLTRawBuffer::operator==(void* ptr) const
843 // see header file for function documentation
844 return fPtr == static_cast<AliHLTUInt8_t*>(ptr);
847 int AliHLTDataBuffer::AliHLTRawBuffer::operator<(void* ptr) const
849 // see header file for function documentation
850 int iResult=fPtr < static_cast<AliHLTUInt8_t*>(ptr);
851 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
855 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(void* ptr) const
857 // see header file for function documentation
858 int iResult=fPtr <= static_cast<AliHLTUInt8_t*>(ptr);
859 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
863 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(void* ptr) const
865 // see header file for function documentation
866 int iResult=fPtr+fSize > static_cast<AliHLTUInt8_t*>(ptr);
867 //printf("%p: %p + %d > %p (%d)\n", this, fPtr, fSize, ptr, iResult);
871 int AliHLTDataBuffer::AliHLTRawBuffer::operator-(void* ptr) const
873 // see header file for function documentation
874 return static_cast<int>(static_cast<AliHLTUInt8_t*>(ptr)-fPtr);
877 int AliHLTDataBuffer::AliHLTRawBuffer::operator<(const AliHLTRawBuffer& op) const
879 // see header file for function documentation
880 return (fPtr+fSize < op.fPtr);
883 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(const AliHLTRawBuffer& op) const
885 // see header file for function documentation
886 return (fPtr+fSize <= op.fPtr);
889 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(const AliHLTRawBuffer& op) const
891 // see header file for function documentation
892 return (fPtr >= op.fPtr+op.fSize);
895 AliHLTUInt8_t* AliHLTDataBuffer::AliHLTRawBuffer::UseBuffer(AliHLTUInt32_t size)
897 // mark a portion of the buffer as used
898 if (fTotalSize>=size) {
900 fLastEventCount=AliHLTDataBuffer::fgEventCount;
901 // only return pointer if there is a portion of the buffer used
902 if (size>0) return fPtr;
907 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawBuffer::Split(AliHLTUInt32_t size)
909 // split a buffer at specified size
910 // only possible for buffers with external memory
911 if (fTotalSize>size &&
912 (fSize==0 || fSize<=size) && // used size must fit into the first part
913 fExternalPtr!=NULL) {
914 AliHLTRawBuffer* part2=new AliHLTRawBuffer(fTotalSize-size, fPtr+size);
920 //cout << "can not split fTotalSize=" << fTotalSize << " fSize=" << fSize << " at size=" << size << endl;
925 int AliHLTDataBuffer::AliHLTRawBuffer::CheckSize(AliHLTUInt32_t size) const
927 // see header file for function documentation
928 if (fTotalSize<size) return 0;
930 if (fLastEventCount+1<AliHLTDataBuffer::fgEventCount) {
931 adjust=AliHLTDataBuffer::fgEventCount-fLastEventCount;
933 return (adjust>2) || ((fTotalSize-size)<(fgMargin<<adjust));
936 int AliHLTDataBuffer::AliHLTRawBuffer::Reset()
938 // see header file for function documentation
943 int AliHLTDataBuffer::AliHLTRawBuffer::WritePattern(const char* pattern, int size)
945 // see header file for function documentation
947 if (pattern!=NULL && size>0) {
948 if (fSize+size<=fTotalSize) {
949 memcpy(((char*)fPtr)+fSize, pattern, size);
958 int AliHLTDataBuffer::AliHLTRawBuffer::CheckPattern(const char* pattern, int size) const
960 // see header file for function documentation
962 if (pattern!=NULL && size>0) {
963 if (fSize+size<=fTotalSize) {
964 iResult=memcmp(((char*)fPtr)+fSize, pattern, size)!=0;
972 int AliHLTDataBuffer::AliHLTRawBuffer::Merge(const AliHLTDataBuffer::AliHLTRawBuffer& neighbor)
974 // Merge buffer with neighboring buffer.
975 // Only possible if the buffers are consecutive with out any gap.
977 if (!fExternalPtr || !neighbor.fExternalPtr) return -EPERM;
979 if (neighbor.fTotalSize==0 &&
980 fPtr < neighbor.fPtr &&
981 fPtr+fTotalSize > neighbor.fPtr) {
982 // special case for a buffer of zero size embedded into this buffer
987 neighbor.fPtr < fPtr &&
988 neighbor.fPtr+neighbor.fTotalSize > fPtr) {
989 // special case for this buffer of size zero embedded into another buffer
992 fTotalSize+=neighbor.fTotalSize;
996 if (fPtr+fTotalSize == neighbor.fPtr) {
997 fTotalSize+=neighbor.fTotalSize;
1001 if (fPtr == neighbor.fPtr+neighbor.fTotalSize) {
1004 fTotalSize+=neighbor.fTotalSize;
1011 void AliHLTDataBuffer::AliHLTRawBuffer::Print(const char* option) const
1013 /// print buffer information
1014 if (strcmp(option, "min")!=0) {
1015 cout << "************* AliHLTRawBuffer status ***********" << endl;
1017 printf(" %p: buffer %p%s size %d used %d\n", this, fPtr, fExternalPtr?" (external)":"", fTotalSize, fSize); fflush(stdout);
1020 AliHLTDataBuffer::AliHLTRawPage::AliHLTRawPage(AliHLTUInt32_t pagesize)
1022 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(pagesize)))
1028 fFreeBuffers.push_back(new AliHLTRawBuffer(fSize, fPtr));
1034 AliHLTDataBuffer::AliHLTRawPage::~AliHLTRawPage()
1038 // do not free if the resources have not been completely freed
1039 HLTError("memory mismatch: not all allocated intances have been released");
1041 if (IsFragmented()) {
1042 HLTWarning("page still fragmented");
1044 AliHLTRawBufferPList::iterator element=fFreeBuffers.begin();
1045 while (element!=fFreeBuffers.end()) {
1046 if (*element) delete *element;
1047 element=fFreeBuffers.erase(element);
1057 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::Alloc(AliHLTUInt32_t size)
1059 /// alloc a buffer of specified size
1060 if (fFreeBuffers.size()==0) return NULL;
1062 for (AliHLTRawBufferPList::iterator iter=fFreeBuffers.begin();
1063 iter!=fFreeBuffers.end();
1065 if ((*iter)->GetTotalSize()==size) {
1066 AliHLTRawBuffer* thisbuffer=*iter;
1067 fFreeBuffers.erase(iter);
1068 fUsedBuffers.push_back(thisbuffer);
1070 } else if ((*iter)->GetTotalSize()>size) {
1071 AliHLTRawBuffer* thisbuffer=*iter;
1072 AliHLTRawBuffer* newbuffer=thisbuffer->Split(size);
1075 fUsedBuffers.push_back(thisbuffer);
1078 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);
1085 int AliHLTDataBuffer::AliHLTRawPage::Free(AliHLTRawBuffer* pBuffer)
1087 /// free a buffer and merge consecutive free buffers
1089 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1090 iter!=fUsedBuffers.end() && iResult>=0;
1092 if ((*iter)==pBuffer) {
1093 fUsedBuffers.erase(iter);
1094 AliHLTRawBufferPList::iterator prev=fFreeBuffers.begin();
1095 for (; prev!=fFreeBuffers.end() && iResult>=0; prev++) {
1096 if ((*pBuffer)<(*(*prev)) ||
1097 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1098 // check consecutive buffers
1099 if ((*(*prev)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize()) ||
1100 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1101 // the buffer to be released has a consecutive free buffer -> merge them
1102 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1106 HLTError("failed to merge consecutive/overlapping buffers %p and %p", pBuffer, (*prev));
1112 fFreeBuffers.insert(prev, pBuffer);
1115 if ((*pBuffer)>(*(*prev)) ||
1116 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1117 // check consecutive buffers
1118 if ((*pBuffer) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())||
1119 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1120 // the buffer to be released is consecutive to a free buffer -> merge them
1121 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1122 AliHLTRawBufferPList::iterator succ=prev+1;
1125 // check if the buffer and the following one are consecutive
1126 if (succ!=fFreeBuffers.end() &&
1127 (*(*succ)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1128 if ((iResult=pBuffer->Merge(*(*succ)))>=0) {
1130 fFreeBuffers.erase(succ);
1138 if (prev==fFreeBuffers.end()) {
1139 fFreeBuffers.push_back(pBuffer);
1142 // merge consecutive free buffers
1143 prev=fFreeBuffers.begin();
1144 for (AliHLTRawBufferPList::iterator current=prev+1; current!=fFreeBuffers.end() && iResult>=0; ) {
1145 // check if the buffer is embedded into the previous one
1146 if ((*current)->GetTotalSize()==0 && (*prev)->GetPointer()<=(*current)->GetPointer() && (*current)->GetPointer()<(*prev)->GetPointer()+(*prev)->GetTotalSize()) {
1147 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1148 current=fFreeBuffers.erase(current);
1151 HLTError("failed to merge embedded zero length buffer into preceeding buffer");
1155 // check if the buffer is consecutive to the previous one
1156 if ((*(*current)) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1157 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1158 current=fFreeBuffers.erase(current);
1161 HLTError("failed to merge consecutive free buffers");
1168 // buffer was part of this page
1172 // buffer not found in this page
1176 int AliHLTDataBuffer::AliHLTRawPage::SetSize(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size)
1178 /// set the size of a raw buffer and release the remaining part
1180 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1181 iter!=fUsedBuffers.end() && iResult>=0;
1183 if ((*iter)==pBuffer) { // buffer was part of this page
1184 if ((*iter)->GetTotalSize()==size) return 0;
1185 if ((*iter)->GetTotalSize()<size) {
1186 HLTError("%d exceeds total size of buffer %p (%d used %d)\n", size, *iter, (*iter)->GetTotalSize(), (*iter)->GetUsedSize());
1189 AliHLTDataBuffer::AliHLTRawBuffer* freespace=(*iter)->Split(size);
1191 fUsedBuffers.push_back(freespace);
1194 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);
1199 // buffer not found in this page
1203 bool AliHLTDataBuffer::AliHLTRawPage::HasBuffer(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer)
1205 /// check if the buffer is in this page
1206 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1207 iter!=fUsedBuffers.end();
1209 if ((*iter)==pBuffer) { // buffer was part of this page
1213 // buffer not found in this page
1217 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::Capacity() const
1219 /// get max available contiguous buffer
1220 AliHLTUInt32_t capacity=0;
1221 for (unsigned i=0; i<fFreeBuffers.size(); i++) {
1222 if (fFreeBuffers[i]->GetTotalSize()>capacity)
1223 capacity=fFreeBuffers[i]->GetTotalSize();
1228 void AliHLTDataBuffer::AliHLTRawPage::Print(const char* option)
1230 /// print page information
1231 if (strcmp(option, "global")==0) {
1232 cout << "number of global pages: " << fgGlobalPages.size() << endl;
1233 for (AliHLTRawPage* rawpage=NextPage(NULL);
1235 rawpage=NextPage(rawpage)) {
1240 cout << "************* AliHLTRawPage status ***********" << endl;
1241 cout << " instance " << this << endl;
1242 printf(" buffer %p size %d", fPtr, fSize);
1243 cout << " used buffers: " << fUsedBuffers.size() << endl;
1244 AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1245 for (; iter!=fUsedBuffers.end(); iter++) {
1246 cout << " "; (*iter)->Print("min");
1248 cout << " free buffers: " << fFreeBuffers.size() << endl;
1249 iter=fFreeBuffers.begin();
1250 for (; iter!=fFreeBuffers.end(); iter++) {
1251 cout << " "; (*iter)->Print("min");
1256 vector<AliHLTDataBuffer::AliHLTRawPage*> AliHLTDataBuffer::AliHLTRawPage::fgGlobalPages;
1258 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::fgGlobalPageSize=30*1024*1024;
1260 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(AliHLTUInt32_t size, int verbosity)
1262 // alloc a buffer of specified size from the global pages
1263 AliHLTDataBuffer::AliHLTRawBuffer* rawbuffer=NULL;
1264 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1266 for (page=fgGlobalPages.begin();page!=fgGlobalPages.end(); page++) {
1267 if ((rawbuffer=(*page)->Alloc(size))!=NULL) {
1269 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, *page);
1270 rawbuffer->Print("min");
1276 AliHLTUInt32_t rawPageSize=fgGlobalPageSize;
1277 if (rawPageSize<size) {
1278 if (rawPageSize*10<size) {
1279 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "refusing to allocate buffer of size %d", size);
1284 AliHLTDataBuffer::AliHLTRawPage* rawpage=new AliHLTDataBuffer::AliHLTRawPage(rawPageSize);
1286 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "can not create raw page");
1290 // check is there is at least one unused page which can be replaced by the newly created one
1291 for (page=fgGlobalPages.begin(); page!=fgGlobalPages.end(); page++) {
1292 if ((*page)->IsUsed()) continue;
1294 fgGlobalPages.erase(page);
1295 break; // delete only one page to be replaced by the new page
1297 fgGlobalPages.push_back(rawpage);
1298 if ((rawbuffer=rawpage->Alloc(size))!=NULL) {
1300 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, rawpage);
1301 rawbuffer->Print("min");
1309 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::FindPage(AliHLTDataBuffer::AliHLTRawBuffer* buffer)
1311 // find buffer in the global pages
1312 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1313 for (; page!=fgGlobalPages.end(); page++) {
1314 if ((*page)->HasBuffer(buffer)) {
1322 int AliHLTDataBuffer::AliHLTRawPage::GlobalClean()
1324 // cleanup the global pages */
1325 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1326 while (page!=fgGlobalPages.end()) {
1327 if (!(*page)->IsUsed()) {
1329 page=fgGlobalPages.erase(page);
1333 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalClean", "data buffer handling", "HLT memory page still in use, skipping cleanup, potential memory leak");
1341 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::NextPage(const AliHLTDataBuffer::AliHLTRawPage* prev)
1343 // get next global page
1344 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1345 for (; page!=fgGlobalPages.end(); page++) {
1346 if (prev==NULL) return *page;
1347 if (*page!=prev) continue;
1348 if (++page!=fgGlobalPages.end()) return *page;
1354 void AliHLTDataBuffer::AliHLTDataSegment::Print(const char* /*option*/) const
1356 // print info for data segment
1357 cout << "AliHLTDataSegment " << this
1358 << " " << AliHLTComponent::DataType2Text(fDataType)
1359 << " " << hex << fSpecification << dec
1360 << " Ptr " << (void*)fPtr
1361 << " offset " << fSegmentOffset
1362 << " size " << fSegmentSize
1366 void AliHLTDataBuffer::AliHLTForwardedDataSegment::Print(const char* option) const
1368 // print info for data segment
1369 cout << "AliHLTForwardeDataSegment " << this << endl;
1370 cout << " my : "; AliHLTDataSegment::Print(option);
1371 cout << " parent: "; fParentSegment.Print(option);
1373 if (fParentTask) fParentTask->Print("");
1374 else cout << "nil" << endl;
1377 void AliHLTDataBuffer::Print(const char* option) const
1379 // print info for data buffer
1381 cout << "AliHLTDataBuffer " << this << endl;
1382 cout << " raw buffer " << fpBuffer << endl;
1385 fpBuffer->Print(option);
1388 cout << " total segments: " << GetNofSegments() << endl;
1389 cout << " data segments: " << fSegments.size() << endl;
1390 for (i=0; i<fSegments.size(); i++) {
1392 fSegments[i].Print(option);
1395 cout << " forwarded segments: " << fForwardedSegments.size() << endl;
1396 for (i=0; i<fForwardedSegments.size(); i++) {
1398 fForwardedSegments[i].Print(option);
1401 cout << " consumers: " << GetNofConsumers() << endl;
1402 for (i=0; i<fConsumers.size(); i++) {
1404 fConsumers[i]->Print(option);
1407 cout << " active consumers: " << GetNofActiveConsumers() << endl;
1408 for (i=0; i<fActiveConsumers.size(); i++) {
1410 fActiveConsumers[i]->Print(option);
1413 cout << " released consumers: " << fReleasedConsumers.size() << endl;
1414 for (i=0; i<fReleasedConsumers.size(); i++) {
1416 fReleasedConsumers[i]->Print(option);