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();
154 // NOTE: the remaining code is disabled
155 // to be deleted at cleanup
157 AliHLTComponentDataTypeList dtlist;
158 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
159 AliHLTDataSegmentList::iterator segment=fSegments.begin();
160 while (segment!=fSegments.end()) {
161 AliHLTComponentDataTypeList::iterator type=dtlist.begin();
162 while (type!=dtlist.end()) {
163 if ((*segment).fDataType==(*type)) {
164 tgtList.push_back(*segment);
178 int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockDataList& blockDescList)
180 // see header file for function documentation
184 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
186 AliHLTDataSegmentList tgtList;
187 // Matthias 26.07.2007 AliHLTSystem should behave the same way as PubSub
188 // so it does not matter if there are matching data types or not, unless
189 // we implement such a check in PubSub
190 if ((iResult=FindMatchingDataSegments(pConsumer, tgtList))>=0) {
191 AliHLTDataSegmentList::iterator segment=tgtList.begin();
192 while (segment!=tgtList.end()) {
193 // fill the block data descriptor
194 AliHLTComponentBlockData bd;
195 AliHLTComponent::FillBlockData(bd);
196 // This models the behavior of PubSub.
197 // For incoming data blocks, fOffset must be ignored by the
198 // processing component. It is set for bookkeeping in the framework.
199 // fPtr always points to the beginning of the data.
201 AliHLTUInt8_t* pTgt=*segment;
202 bd.fPtr=reinterpret_cast<void*>(pTgt);
203 bd.fSize=(*segment).fSegmentSize;
204 bd.fDataType=(*segment).fDataType;
205 bd.fSpecification=(*segment).fSpecification;
206 blockDescList.push_back(bd);
207 pDesc->SetActiveDataSegment(*segment);
208 HLTDebug("component %p (%s) subscribed to segment offset %d size %d data type %s %#x",
209 pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), bd.fOffset,
210 bd.fSize, (AliHLTComponent::DataType2Text(bd.fDataType)).c_str(),
214 // move this consumer to the active list
215 if (tgtList.size()==0) {
216 ChangeConsumerState(pDesc, fConsumers, fReleasedConsumers);
217 HLTDebug("no input data for component %p (%s) available", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
218 } else if (ChangeConsumerState(pDesc, fConsumers, fActiveConsumers)>=0) {
219 HLTDebug("component %p (%s) subscribed to data buffer %p", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), this);
221 // TODO: cleanup the consumer descriptor correctly
222 segment=tgtList.begin();
223 while (segment!=tgtList.end()) {
224 blockDescList.pop_back();
227 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
231 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
235 if (!FindConsumer(pConsumer)) {
236 HLTError("component %p is not a data consumer of data buffer %p", pConsumer, this);
238 HLTError("component %p is a valid data consumer of data buffer %p, but did not release it's buffer subscription", pConsumer, this);
243 // Matthias 26.07.2007 until now, data had to be present for successful subscription
244 // in order to be consistent with the PubSub framework, this restiction has been
246 //HLTError("data buffer %p is empty", this);
250 HLTError("invalid parameter");
256 int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc,
257 const AliHLTComponent* pConsumer,
258 const AliHLTTask* pOwnerTask)
260 // see header file for function documentation
262 if (pBlockDesc && pConsumer) {
263 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
265 if ((iResult=pDesc->CheckActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)))!=1) {
266 HLTWarning("data segment mismatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
267 // TODO: appropriate error handling, but so far optional
270 pDesc->ReleaseActiveDataSegment(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize));
272 if (GetNofPendingConsumers()==0 && fForwardedSegments.size()>0) {
273 // last consumer, release forwarded segments
274 ReleaseForwardedBlock(pBlockDesc, pOwnerTask);
276 pBlockDesc->fOffset=0;
277 pBlockDesc->fPtr=NULL;
279 if (pDesc->GetNofActiveSegments()==0) {
280 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
281 if (GetNofActiveConsumers()==0 && GetNofPendingConsumers()==0) {
282 // this is the last consumer, reset the consumer list and release the raw buffer
286 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
291 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
295 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
301 int AliHLTDataBuffer::ReleaseForwardedBlock(AliHLTComponentBlockData* pBlockDesc,
302 const AliHLTTask* pOwnerTask)
304 // see header file for function documentation
306 if (pBlockDesc && pOwnerTask) {
307 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
308 AliHLTDataSegmentList::iterator segment=fForwardedSegments.begin();
309 AliHLTTaskPList::iterator src=fForwardedSegmentSources.begin();
310 //HLTDebug("%p checking forwarded segments", this);
311 for (; segment!=fForwardedSegments.end(); segment++, src++) {
312 //HLTDebug("segment ptr=%p offset=%d size=%d\n"
313 // "block ptr=%p offset=%d size=%d", (*segment).fPtr, (*segment).fSegmentOffset, (*segment).fSegmentSize, pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize);
314 if ((*segment)==AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize)) {
315 //HLTDebug("release segment of task %p", *src);
316 assert((*src)!=NULL);
318 if ((*src)->Release(pBlockDesc, pOwnerTask)>=0) {
319 HLTDebug("task %s (%p) released forwarded segment %p size %d of task %s (%p)",
320 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
321 (*src)->GetName(), *src);
323 HLTError("task %s (%p) failed releasing forwarded segment %p size %d of task %s (%p)",
324 pOwnerTask->GetName(), pOwnerTask, (*segment).GetPtr(), (*segment).GetSize(),
325 (*src)->GetName(), *src);
328 fForwardedSegments.erase(segment);
329 fForwardedSegmentSources.erase(src);
334 HLTError("inavalid parameter: pBlockDesc=%p pOwnerTask=%p", pBlockDesc, pOwnerTask);
340 int AliHLTDataBuffer::Forward(AliHLTTask* pSrcTask, AliHLTComponentBlockData* pBlockDesc)
342 // see header file for function documentation
343 if (pSrcTask==NULL || pBlockDesc==NULL) return -EINVAL;
344 assert(fForwardedSegments.size()==fForwardedSegmentSources.size());
345 if (fForwardedSegments.size()!=fForwardedSegmentSources.size()) return -EFAULT;
346 fForwardedSegmentSources.push_back(pSrcTask);
347 fForwardedSegments.push_back(AliHLTDataSegment(pBlockDesc->fPtr, pBlockDesc->fOffset, pBlockDesc->fSize, pBlockDesc->fDataType, pBlockDesc->fSpecification));
351 AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
353 // see header file for function documentation
354 AliHLTUInt8_t* pTargetBuffer=NULL;
355 if (fpBuffer!=NULL) {
356 HLTWarning("data buffer not properly reset, possible memory leak\n");
358 fpBuffer=CreateRawBuffer(iMinSize);
360 pTargetBuffer=*fpBuffer;
362 HLTError("can not create raw buffer");
364 return pTargetBuffer;
367 int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
369 // see header file for function documentation
371 if (pTgt && arrayBlockData && iSize>=0) {
373 if (*fpBuffer==pTgt) {
374 AliHLTDataBuffer::AliHLTDataSegment segment;
375 AliHLTUInt32_t maxSize=0;
376 for (int i=0; i<iSize; i++) {
377 // This function has to model the behavior of PubSub
378 // For output blocks only the fOffset value is used, this must be the offset
379 // relative to the output pointer. fPtr must be either NULL or the output
380 // pointer. In either case it is 'ignored' and set to the beginning of the
382 if (arrayBlockData[i].fPtr==NULL ||
383 arrayBlockData[i].fPtr==*fpBuffer) {
384 arrayBlockData[i].fPtr=*fpBuffer;
385 if ((arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->GetUsedSize()) ||
386 ((arrayBlockData[i].fOffset==~(AliHLTUInt32_t)0) && arrayBlockData[i].fSize==0)) {
387 segment.fSegmentOffset=arrayBlockData[i].fOffset;
388 segment.fPtr=(AliHLTUInt8_t*)arrayBlockData[i].fPtr;
389 segment.fSegmentSize=arrayBlockData[i].fSize;
390 segment.fDataType=arrayBlockData[i].fDataType;
391 segment.fSpecification=arrayBlockData[i].fSpecification;
392 fSegments.push_back(segment);
393 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
395 // find the actual size of the data
396 if ((arrayBlockData[i].fOffset!=~(AliHLTUInt32_t)0) &&
397 arrayBlockData[i].fOffset+arrayBlockData[i].fSize>maxSize) {
398 maxSize=arrayBlockData[i].fOffset+arrayBlockData[i].fSize;
401 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
402 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->GetUsedSize());
406 HLTError("invalid pointer (%p) in block data specification (buffer %p size %d)."
407 "please note: for output blocks only the fOffset value is valid and must "
408 "be relative to the output buffer", arrayBlockData[i].fPtr, fpBuffer->GetPointer(), fpBuffer->GetUsedSize());
412 // to be enabled if unit test is ready
413 #ifdef USE_ALIHLTRAWPAGE
414 iResult=SetRawBufferDataSize(fpBuffer, maxSize);
415 #endif //USE_ALIHLTRAWPAGE
417 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->GetPointer(), fpBuffer);
421 HLTFatal("internal data structur mismatch");
425 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
431 int AliHLTDataBuffer::IsEmpty()
433 // see header file for function documentation
434 int iResult=(fpBuffer==NULL && fForwardedSegments.size()==0) || GetNofSegments()==0;
438 int AliHLTDataBuffer::GetNofSegments() const
440 // see header file for function documentation
441 int iResult=fSegments.size() + fForwardedSegments.size();
445 int AliHLTDataBuffer::GetNofConsumers() const
447 // see header file for function documentation
448 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
452 int AliHLTDataBuffer::GetNofPendingConsumers() const
454 // see header file for function documentation
455 int iResult=fConsumers.size();
459 int AliHLTDataBuffer::GetNofActiveConsumers() const
461 // see header file for function documentation
462 int iResult=fActiveConsumers.size();
466 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
468 // see header file for function documentation
469 AliHLTRawBuffer* pRawBuffer=NULL;
470 unsigned int reqSize=size+fgkSafetyPatternSize;
471 #ifndef USE_ALIHLTRAWPAGE
472 AliHLTRawBufferPList::iterator buffer=fgFreeBuffers.begin();
473 while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
474 if ((*buffer)->CheckSize(reqSize)) {
475 // assign this element
477 pRawBuffer->UseBuffer(size);
478 fgFreeBuffers.erase(buffer);
479 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());
480 fgActiveBuffers.push_back(pRawBuffer);
485 if (pRawBuffer==NULL) {
486 // no buffer found, create a new one
487 pRawBuffer=new AliHLTRawBuffer(reqSize);
489 if (pRawBuffer->GetPointer()) {
490 pRawBuffer->UseBuffer(size);
491 fgActiveBuffers.push_back(pRawBuffer);
492 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->GetPointer(), pRawBuffer->GetTotalSize(), pRawBuffer);
496 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
499 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
503 pRawBuffer=AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(reqSize);
505 pRawBuffer->UseBuffer(size);
508 if (pRawBuffer!=NULL && fgkSafetyPatternSize>0) {
509 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "writing safety pattern to %p offset %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
510 pRawBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
515 int AliHLTDataBuffer::SetRawBufferDataSize(AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size) const
517 // see header file for function documentation
519 if (!pBuffer) return -EINVAL;
520 if (size>pBuffer->GetUsedSize()) {
521 HLTError("indicated data size %d exceeds data buffer %p (%d)", size, pBuffer->GetPointer(), pBuffer->GetUsedSize());
524 if (fgkSafetyPatternSize>0) {
525 if (pBuffer->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
526 HLTError("potential memory corruption: component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
529 // shrink the buffer and write new pattern at the end
530 #ifdef USE_ALIHLTRAWPAGE
531 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
533 pBuffer->UseBuffer(size);
534 if (rawpage->SetSize(pBuffer, size+fgkSafetyPatternSize)==0) {
537 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "failed to set size for raw buffer %p", pBuffer);
541 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
544 #else //!USE_ALIHLTRAWPAGE
545 pBuffer->UseBuffer(size);
546 #endif //USE_ALIHLTRAWPAGE
547 if (fgkSafetyPatternSize>0) {
548 pBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
553 int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
555 // see header file for function documentation
558 #ifdef USE_ALIHLTRAWPAGE
559 AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
561 #else //!USE_ALIHLTRAWPAGE
562 AliHLTRawBufferPList::iterator buffer=fgActiveBuffers.begin();
563 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
566 if (buffer!=fgActiveBuffers.end())
567 #endif //USE_ALIHLTRAWPAGE
569 if (fgkSafetyPatternSize>0) {
570 //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", pBuffer->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(pBuffer));
571 if ((pBuffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
572 fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
576 #ifdef USE_ALIHLTRAWPAGE
577 if (rawpage->Free(pBuffer)==0) {
579 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "failed to release raw buffer %p", pBuffer);
581 #else //!USE_ALIHLTRAWPAGE
582 fgFreeBuffers.push_back(pBuffer);
583 fgActiveBuffers.erase(buffer);
584 #endif //USE_ALIHLTRAWPAGE
586 #ifdef USE_ALIHLTRAWPAGE
587 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
588 #else //!USE_ALIHLTRAWPAGE
589 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
590 #endif //USE_ALIHLTRAWPAGE
594 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
601 int AliHLTDataBuffer::DeleteRawBuffers()
603 // see header file for function documentation
605 #ifdef ALIHLTSYSTEM_PROFILING
607 int iCount=fgFreeBuffers.size()+fgActiveBuffers.size();
608 #endif //ALIHLTSYSTEM_PROFILING
609 AliHLTRawBufferPList::iterator buffer;;
610 while ((buffer=fgFreeBuffers.begin())!=fgFreeBuffers.end()) {
611 #ifdef ALIHLTSYSTEM_PROFILING
612 iTotalSize+=(*buffer)->GetTotalSize();
613 #endif //ALIHLTSYSTEM_PROFILING
615 fgFreeBuffers.erase(buffer);
617 while ((buffer=fgActiveBuffers.begin())!=fgActiveBuffers.end()) {
618 #ifdef ALIHLTSYSTEM_PROFILING
619 iTotalSize+=(*buffer)->GetTotalSize();
620 #endif //ALIHLTSYSTEM_PROFILING
621 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
623 fgActiveBuffers.erase(buffer);
625 #ifdef ALIHLTSYSTEM_PROFILING
626 fgLogging.Logging(kHLTLogImportant, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
627 #endif //ALIHLTSYSTEM_PROFILING
631 int AliHLTDataBuffer::PrintStatistics()
633 // see header file for function documentation
635 #ifdef USE_ALIHLTRAWPAGE
637 AliHLTUInt32_t totalSize=0;
638 for (AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(NULL);
640 rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(rawpage)) {
642 totalSize+=rawpage->Size();
643 if (fgLogging.CheckFilter(kHLTLogDebug)) rawpage->Print("");
645 //if (rawpage) rawpage->Print("global");
646 fgLogging.Logging(kHLTLogInfo, "AliHLTDataBuffer::PrintStatistics", "data buffer handling", "total number of memory pages: %d total size %d", nofPages, totalSize);
648 #else //! USE_ALIHLTRAWPAGE
651 AliHLTRawBufferPList::iterator buffer;;
652 for (buffer=fgFreeBuffers.begin(); buffer!=fgFreeBuffers.end(); buffer++) {
653 iFree+=(*buffer)->GetTotalSize();
655 for (buffer=fgActiveBuffers.begin(); buffer!=fgActiveBuffers.end(); buffer++) {
656 iActive+=(*buffer)->GetTotalSize();
658 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);
659 #endif // USE_ALIHLTRAWPAGE
663 AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, AliHLTConsumerDescriptorPList &list) const
665 // see header file for function documentation
666 AliHLTConsumerDescriptor* pDesc=NULL;
667 AliHLTConsumerDescriptorPList::iterator desc=list.begin();
668 while (desc!=list.end() && pDesc==NULL) {
669 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
677 int AliHLTDataBuffer::ResetDataBuffer()
679 // see header file for function documentation
681 AliHLTRawBuffer* pBuffer=fpBuffer;
684 // cleanup forwarded segment lists
685 assert(fForwardedSegments.size()==0);
686 fForwardedSegments.clear();
687 fForwardedSegmentSources.clear();
689 // cleanup consumer states
690 AliHLTConsumerDescriptorPList::iterator desc;
691 // if (GetNofPendingConsumers()>0) {
692 // desc=fConsumers.begin();
693 // while (desc!=fConsumers.end()) {
694 // AliHLTComponent* pComp=(*desc)->GetComponent();
695 // HLTError("internal error: consumer %p (%s %p) did not get data from data buffer %p", *desc, pComp?pComp->GetComponentID():"", pComp, this);
699 desc=fReleasedConsumers.begin();
700 while (desc!=fReleasedConsumers.end()) {
701 AliHLTConsumerDescriptor* pDesc=*desc;
702 fReleasedConsumers.erase(desc);
703 desc=fReleasedConsumers.begin();
704 fConsumers.push_back(pDesc);
706 desc=fActiveConsumers.begin();
707 while (desc!=fActiveConsumers.end()) {
708 AliHLTConsumerDescriptor* pDesc=*desc;
709 HLTWarning("consumer %p (%s) was not released", pDesc, pDesc->GetComponent()?pDesc->GetComponent()->GetComponentID():"### invalid component ###");
710 fActiveConsumers.erase(desc);
711 desc=fActiveConsumers.begin();
712 fConsumers.push_back(pDesc);
716 AliHLTDataSegmentList::iterator segment=fSegments.begin();
717 while (segment!=fSegments.end()) {
718 fSegments.erase(segment);
719 segment=fSegments.begin();
722 // cleanup raw buffer
724 ReleaseRawBuffer(pBuffer);
729 int AliHLTDataBuffer::Reset()
731 // see header file for function documentation
732 return ResetDataBuffer();
735 // this is the version which works on lists of components instead of consumer descriptors
736 // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, AliHLTComponentPList &srcList, AliHLTComponentPList &tgtList)
740 // AliHLTComponentPList::iterator desc=srcList.begin();
741 // while (desc!=srcList.end()) {
742 // if ((*desc)==pConsumer) {
743 // srcList.erase(desc);
744 // tgtList.push_back(pConsumer);
749 // if (desc==srcList.end()) {
750 // HLTError("can not find consumer component %p in list", pConsumer);
754 // HLTError("invalid parameter");
760 int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, AliHLTConsumerDescriptorPList &srcList, AliHLTConsumerDescriptorPList &tgtList)
762 // see header file for function documentation
765 AliHLTConsumerDescriptorPList::iterator desc=srcList.begin();
766 while (desc!=srcList.end()) {
767 if ((*desc)==pDesc) {
769 tgtList.push_back(pDesc);
776 HLTError("can not find consumer descriptor %p in list", pDesc);
779 HLTError("invalid parameter");
785 int AliHLTDataBuffer::CleanupConsumerList()
787 // see header file for function documentation
790 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
791 while (desc!=fConsumers.end()) {
793 fConsumers.erase(desc);
794 desc=fConsumers.begin();
799 int AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, int bAllLists)
801 // see header file for function documentation
802 AliHLTConsumerDescriptorPList::iterator desc=fConsumers.begin();
803 while (desc!=fConsumers.end()) {
804 if ((*desc)->GetComponent()==pConsumer)
808 if (bAllLists==0) return 0;
810 desc=fActiveConsumers.begin();
811 while (desc!=fActiveConsumers.end()) {
812 if ((*desc)->GetComponent()==pConsumer)
816 desc=fReleasedConsumers.begin();
817 while (desc!=fReleasedConsumers.end()) {
818 if ((*desc)->GetComponent()==pConsumer)
825 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size)
829 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(size)))
832 // see header file for class documentation
834 // refer to README to build package
836 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
843 AliHLTDataBuffer::AliHLTRawBuffer::AliHLTRawBuffer(AliHLTUInt32_t size, AliHLTUInt8_t* buffer)
846 , fExternalPtr(buffer)
850 // see header file for class documentation
853 AliHLTDataBuffer::AliHLTRawBuffer::~AliHLTRawBuffer()
855 // see header file for class documentation
856 if (fExternalPtr==NULL && fPtr) {
864 int AliHLTDataBuffer::AliHLTRawBuffer::operator==(void* ptr) const
866 // see header file for function documentation
867 return fPtr == static_cast<AliHLTUInt8_t*>(ptr);
870 int AliHLTDataBuffer::AliHLTRawBuffer::operator<(void* ptr) const
872 // see header file for function documentation
873 int iResult=fPtr < static_cast<AliHLTUInt8_t*>(ptr);
874 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
878 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(void* ptr) const
880 // see header file for function documentation
881 int iResult=fPtr <= static_cast<AliHLTUInt8_t*>(ptr);
882 //printf("%p: %p <= %p (%d)\n", this, fPtr, ptr, iResult);
886 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(void* ptr) const
888 // see header file for function documentation
889 int iResult=fPtr+fSize > static_cast<AliHLTUInt8_t*>(ptr);
890 //printf("%p: %p + %d > %p (%d)\n", this, fPtr, fSize, ptr, iResult);
894 int AliHLTDataBuffer::AliHLTRawBuffer::operator-(void* ptr) const
896 // see header file for function documentation
897 return static_cast<int>(static_cast<AliHLTUInt8_t*>(ptr)-fPtr);
900 int AliHLTDataBuffer::AliHLTRawBuffer::operator<(const AliHLTRawBuffer& op) const
902 // see header file for function documentation
903 return (fPtr+fSize < op.fPtr);
906 int AliHLTDataBuffer::AliHLTRawBuffer::operator<=(const AliHLTRawBuffer& op) const
908 // see header file for function documentation
909 return (fPtr+fSize <= op.fPtr);
912 int AliHLTDataBuffer::AliHLTRawBuffer::operator>(const AliHLTRawBuffer& op) const
914 // see header file for function documentation
915 return (fPtr >= op.fPtr+op.fSize);
918 AliHLTUInt8_t* AliHLTDataBuffer::AliHLTRawBuffer::UseBuffer(AliHLTUInt32_t size)
920 // mark a portion of the buffer as used
921 if (size>0 && fTotalSize>=size) {
923 fLastEventCount=AliHLTDataBuffer::fgEventCount;
929 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawBuffer::Split(AliHLTUInt32_t size)
931 // split a buffer at specified size
932 // only possible for buffers with external memory
933 if (fTotalSize>size &&
934 (fSize==0 || fSize<=size) &&
935 fExternalPtr!=NULL) {
936 AliHLTRawBuffer* part2=new AliHLTRawBuffer(fTotalSize-size, fPtr+size);
942 //cout << "can not split fTotalSize=" << fTotalSize << " fSize=" << fSize << " at size=" << size << endl;
947 int AliHLTDataBuffer::AliHLTRawBuffer::CheckSize(AliHLTUInt32_t size) const
949 // see header file for function documentation
950 if (fTotalSize<size) return 0;
952 if (fLastEventCount+1<AliHLTDataBuffer::fgEventCount) {
953 adjust=AliHLTDataBuffer::fgEventCount-fLastEventCount;
955 return (adjust>2) || ((fTotalSize-size)<(fgMargin<<adjust));
958 int AliHLTDataBuffer::AliHLTRawBuffer::Reset()
960 // see header file for function documentation
965 int AliHLTDataBuffer::AliHLTRawBuffer::WritePattern(const char* pattern, int size)
967 // see header file for function documentation
969 if (pattern!=NULL && size>0) {
970 if (fSize+size<=fTotalSize) {
971 memcpy(((char*)fPtr)+fSize, pattern, size);
980 int AliHLTDataBuffer::AliHLTRawBuffer::CheckPattern(const char* pattern, int size) const
982 // see header file for function documentation
984 if (pattern!=NULL && size>0) {
985 if (fSize+size<=fTotalSize) {
986 iResult=memcmp(((char*)fPtr)+fSize, pattern, size)!=0;
994 int AliHLTDataBuffer::AliHLTRawBuffer::Merge(const AliHLTDataBuffer::AliHLTRawBuffer& neighbor)
996 // Merge buffer with neighboring buffer.
997 // Only possible if the buffers are consecutive with out any gap.
999 if (!fExternalPtr || !neighbor.fExternalPtr) return -EPERM;
1001 if (neighbor.fTotalSize==0 &&
1002 fPtr < neighbor.fPtr &&
1003 fPtr+fTotalSize > neighbor.fPtr) {
1004 // special case for a buffer of zero size embedded into this buffer
1008 if (fTotalSize==0 &&
1009 neighbor.fPtr < fPtr &&
1010 neighbor.fPtr+neighbor.fTotalSize > fPtr) {
1011 // special case for this buffer of size zero embedded into another buffer
1014 fTotalSize+=neighbor.fTotalSize;
1018 if (fPtr+fTotalSize == neighbor.fPtr) {
1019 fTotalSize+=neighbor.fTotalSize;
1023 if (fPtr == neighbor.fPtr+neighbor.fTotalSize) {
1026 fTotalSize+=neighbor.fTotalSize;
1033 void AliHLTDataBuffer::AliHLTRawBuffer::Print(const char* option) const
1035 /// print buffer information
1036 if (strcmp(option, "min")!=0) {
1037 cout << "************* AliHLTRawBuffer status ***********" << endl;
1039 printf(" %p: buffer %p%s size %d used %d\n", this, fPtr, fExternalPtr?" (external)":"", fTotalSize, fSize); fflush(stdout);
1042 AliHLTDataBuffer::AliHLTRawPage::AliHLTRawPage(AliHLTUInt32_t pagesize)
1044 , fPtr(static_cast<AliHLTUInt8_t*>(malloc(pagesize)))
1050 fFreeBuffers.push_back(new AliHLTRawBuffer(fSize, fPtr));
1056 AliHLTDataBuffer::AliHLTRawPage::~AliHLTRawPage()
1060 // do not free if the resources have not been completely freed
1061 HLTError("memory mismatch: not all allocated intances have been released");
1063 if (IsFragmented()) {
1064 HLTWarning("page still fragmented");
1066 AliHLTRawBufferPList::iterator element=fFreeBuffers.begin();
1067 while (element!=fFreeBuffers.end()) {
1068 if (*element) delete *element;
1069 element=fFreeBuffers.erase(element);
1079 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::Alloc(AliHLTUInt32_t size)
1081 /// alloc a buffer of specified size
1082 if (fFreeBuffers.size()==0) return NULL;
1084 for (AliHLTRawBufferPList::iterator iter=fFreeBuffers.begin();
1085 iter!=fFreeBuffers.end();
1087 if ((*iter)->GetTotalSize()==size) {
1088 AliHLTRawBuffer* thisbuffer=*iter;
1089 fFreeBuffers.erase(iter);
1090 fUsedBuffers.push_back(thisbuffer);
1092 } else if ((*iter)->GetTotalSize()>size) {
1093 AliHLTRawBuffer* thisbuffer=*iter;
1094 AliHLTRawBuffer* newbuffer=thisbuffer->Split(size);
1097 fUsedBuffers.push_back(thisbuffer);
1100 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);
1107 int AliHLTDataBuffer::AliHLTRawPage::Free(AliHLTRawBuffer* pBuffer)
1109 /// free a buffer and merge consecutive free buffers
1111 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1112 iter!=fUsedBuffers.end() && iResult>=0;
1114 if ((*iter)==pBuffer) {
1115 fUsedBuffers.erase(iter);
1116 AliHLTRawBufferPList::iterator prev=fFreeBuffers.begin();
1117 for (; prev!=fFreeBuffers.end() && iResult>=0; prev++) {
1118 if ((*pBuffer)<(*(*prev)) ||
1119 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1120 // check consecutive buffers
1121 if ((*(*prev)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize()) ||
1122 ((*prev)->GetTotalSize()==0 && pBuffer->GetPointer()<=(*prev)->GetPointer() && (*prev)->GetPointer()<=pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1123 // the buffer to be released has a consecutive free buffer -> merge them
1124 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1128 HLTError("failed to merge consecutive/overlapping buffers %p and %p", pBuffer, (*prev));
1134 fFreeBuffers.insert(prev, pBuffer);
1137 if ((*pBuffer)>(*(*prev)) ||
1138 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1139 // check consecutive buffers
1140 if ((*pBuffer) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())||
1141 (pBuffer->GetTotalSize()==0 && (*prev)->GetPointer()<=pBuffer->GetPointer() && pBuffer->GetPointer()<=(*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1142 // the buffer to be released is consecutive to a free buffer -> merge them
1143 if ((iResult=pBuffer->Merge(*(*prev)))>=0) {
1144 AliHLTRawBufferPList::iterator succ=prev+1;
1147 // check if the buffer and the following one are consecutive
1148 if (succ!=fFreeBuffers.end() &&
1149 (*(*succ)) == (pBuffer->GetPointer()+pBuffer->GetTotalSize())) {
1150 if ((iResult=pBuffer->Merge(*(*succ)))>=0) {
1152 fFreeBuffers.erase(succ);
1160 if (prev==fFreeBuffers.end()) {
1161 fFreeBuffers.push_back(pBuffer);
1164 // merge consecutive free buffers
1165 prev=fFreeBuffers.begin();
1166 for (AliHLTRawBufferPList::iterator current=prev+1; current!=fFreeBuffers.end() && iResult>=0; ) {
1167 // check if the buffer is embedded into the previous one
1168 if ((*current)->GetTotalSize()==0 && (*prev)->GetPointer()<=(*current)->GetPointer() && (*current)->GetPointer()<(*prev)->GetPointer()+(*prev)->GetTotalSize()) {
1169 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1170 current=fFreeBuffers.erase(current);
1173 HLTError("failed to merge embedded zero length buffer into preceeding buffer");
1177 // check if the buffer is consecutive to the previous one
1178 if ((*(*current)) == ((*prev)->GetPointer()+(*prev)->GetTotalSize())) {
1179 if ((iResult=(*prev)->Merge(*(*current)))>=0) {
1180 current=fFreeBuffers.erase(current);
1183 HLTError("failed to merge consecutive free buffers");
1190 // buffer was part of this page
1194 // buffer not found in this page
1198 int AliHLTDataBuffer::AliHLTRawPage::SetSize(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size)
1200 /// set the size of a raw buffer and release the remaining part
1202 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1203 iter!=fUsedBuffers.end() && iResult>=0;
1205 if ((*iter)==pBuffer) { // buffer was part of this page
1206 if ((*iter)->GetTotalSize()==size) return 0;
1207 if ((*iter)->GetTotalSize()<size) {
1208 HLTError("%d exceeds total size of buffer %p (%d used %d)\n", size, *iter, (*iter)->GetTotalSize(), (*iter)->GetUsedSize());
1211 AliHLTDataBuffer::AliHLTRawBuffer* freespace=(*iter)->Split(size);
1213 fUsedBuffers.push_back(freespace);
1216 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);
1221 // buffer not found in this page
1225 bool AliHLTDataBuffer::AliHLTRawPage::HasBuffer(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer)
1227 /// check if the buffer is in this page
1228 for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1229 iter!=fUsedBuffers.end();
1231 if ((*iter)==pBuffer) { // buffer was part of this page
1235 // buffer not found in this page
1239 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::Capacity() const
1241 /// get max available contiguous buffer
1242 AliHLTUInt32_t capacity=0;
1243 for (unsigned i=0; i<fFreeBuffers.size(); i++) {
1244 if (fFreeBuffers[i]->GetTotalSize()>capacity)
1245 capacity=fFreeBuffers[i]->GetTotalSize();
1250 void AliHLTDataBuffer::AliHLTRawPage::Print(const char* option)
1252 /// print page information
1253 if (strcmp(option, "global")==0) {
1254 cout << "number of global pages: " << fgGlobalPages.size() << endl;
1255 for (AliHLTRawPage* rawpage=NextPage(NULL);
1257 rawpage=NextPage(rawpage)) {
1262 cout << "************* AliHLTRawPage status ***********" << endl;
1263 cout << " instance " << this << endl;
1264 printf(" buffer %p size %d", fPtr, fSize);
1265 cout << " used buffers: " << fUsedBuffers.size() << endl;
1266 AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
1267 for (; iter!=fUsedBuffers.end(); iter++) {
1268 cout << " "; (*iter)->Print("min");
1270 cout << " free buffers: " << fFreeBuffers.size() << endl;
1271 iter=fFreeBuffers.begin();
1272 for (; iter!=fFreeBuffers.end(); iter++) {
1273 cout << " "; (*iter)->Print("min");
1278 vector<AliHLTDataBuffer::AliHLTRawPage*> AliHLTDataBuffer::AliHLTRawPage::fgGlobalPages;
1280 AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::fgGlobalPageSize=30*1024*1024;
1282 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(AliHLTUInt32_t size, int verbosity)
1284 // alloc a buffer of specified size from the global pages
1285 AliHLTDataBuffer::AliHLTRawBuffer* rawbuffer=NULL;
1286 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1288 for (page=fgGlobalPages.begin();page!=fgGlobalPages.end(); page++) {
1289 if ((rawbuffer=(*page)->Alloc(size))!=NULL) {
1291 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, *page);
1292 rawbuffer->Print("min");
1298 AliHLTUInt32_t rawPageSize=fgGlobalPageSize;
1299 if (rawPageSize<size) {
1300 if (rawPageSize*10<size) {
1301 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "refusing to allocate buffer of size %d", size);
1306 AliHLTDataBuffer::AliHLTRawPage* rawpage=new AliHLTDataBuffer::AliHLTRawPage(rawPageSize);
1308 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "can not create raw page");
1312 // check is there is at least one unused page which can be replaced by the newly created one
1313 for (page=fgGlobalPages.begin(); page!=fgGlobalPages.end(); page++) {
1314 if ((*page)->IsUsed()) continue;
1316 fgGlobalPages.erase(page);
1317 break; // delete only one page to be replaced by the new page
1319 fgGlobalPages.push_back(rawpage);
1320 if ((rawbuffer=rawpage->Alloc(size))!=NULL) {
1322 log.Logging(kHLTLogInfo, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "allocated raw buffer %p from page %p\n", rawbuffer, rawpage);
1323 rawbuffer->Print("min");
1331 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::FindPage(AliHLTDataBuffer::AliHLTRawBuffer* buffer)
1333 // find buffer in the global pages
1334 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1335 for (; page!=fgGlobalPages.end(); page++) {
1336 if ((*page)->HasBuffer(buffer)) {
1344 int AliHLTDataBuffer::AliHLTRawPage::GlobalClean()
1346 // cleanup the global pages */
1347 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1348 while (page!=fgGlobalPages.end()) {
1349 if (!(*page)->IsUsed()) {
1351 page=fgGlobalPages.erase(page);
1355 log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalClean", "data buffer handling", "HLT memory page still in use, skipping cleanup, potential memory leak");
1363 AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::NextPage(const AliHLTDataBuffer::AliHLTRawPage* prev)
1365 // get next global page
1366 vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
1367 for (; page!=fgGlobalPages.end(); page++) {
1368 if (prev==NULL) return *page;
1369 if (*page!=prev) continue;
1370 if (++page!=fgGlobalPages.end()) return *page;
1376 void AliHLTDataBuffer::AliHLTDataSegment::Print(const char* /*option*/) const
1378 // print info for data segment
1379 cout << "AliHLTDataSegment " << this
1380 << " " << AliHLTComponent::DataType2Text(fDataType)
1381 << " " << hex << fSpecification << dec
1382 << " Ptr " << (void*)fPtr
1383 << " offset " << fSegmentOffset
1384 << " size " << fSegmentSize
1388 void AliHLTDataBuffer::AliHLTForwardedDataSegment::Print(const char* option) const
1390 // print info for data segment
1391 cout << "AliHLTForwardeDataSegment " << this << endl;
1392 cout << " my : "; AliHLTDataSegment::Print(option);
1393 cout << " parent: "; fParentSegment.Print(option);
1395 if (fParentTask) fParentTask->Print("");
1396 else cout << "nil" << endl;
1399 void AliHLTDataBuffer::Print(const char* option) const
1401 // print info for data buffer
1403 cout << "AliHLTDataBuffer " << this << endl;
1404 cout << " raw buffer " << fpBuffer << endl;
1407 fpBuffer->Print(option);
1410 cout << " total segments: " << GetNofSegments() << endl;
1411 cout << " data segments: " << fSegments.size() << endl;
1412 for (i=0; i<fSegments.size(); i++) {
1414 fSegments[i].Print(option);
1417 cout << " forwarded segments: " << fForwardedSegments.size() << endl;
1418 for (i=0; i<fForwardedSegments.size(); i++) {
1420 fForwardedSegments[i].Print(option);
1423 cout << " consumers: " << GetNofConsumers() << endl;
1424 for (i=0; i<fConsumers.size(); i++) {
1426 fConsumers[i]->Print(option);
1429 cout << " active consumers: " << GetNofActiveConsumers() << endl;
1430 for (i=0; i<fActiveConsumers.size(); i++) {
1432 fActiveConsumers[i]->Print(option);
1435 cout << " released consumers: " << fReleasedConsumers.size() << endl;
1436 for (i=0; i<fReleasedConsumers.size(); i++) {
1438 fReleasedConsumers[i]->Print(option);