// $Id$
//**************************************************************************
-//* This file is property of and copyright by the ALICE HLT Project *
+//* This file is property of and copyright by the *
//* ALICE Experiment at CERN, All rights reserved. *
//* *
//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
//* provided "as is" without express or implied warranty. *
//**************************************************************************
-/** @file AliHLTDataBuffer.cxx
- @author Matthias Richter
- @date
- @brief Handling of Data Buffers for HLT components.
-*/
-
-#if __GNUC__>= 3
-using namespace std;
-#endif
+// @file AliHLTDataBuffer.cxx
+// @author Matthias Richter
+// @date
+// @brief Handling of Data Buffers for HLT components.
+// @note Only used in the AliRoot framework
#include "AliHLTDataBuffer.h"
#include "AliHLTConsumerDescriptor.h"
//#include <string>
//#include "AliHLTSystem.h"
-typedef vector<AliHLTDataBuffer::AliHLTDataSegment> AliHLTDataSegmentList;
+using std::cout;
/** ROOT macro for the implementation of ROOT specific class methods */
ClassImp(AliHLTDataBuffer)
return iResult;
}
-int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
+int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* /*pConsumer*/,
+ AliHLTDataSegmentList& tgtList)
{
// see header file for function documentation
int iResult=0;
tgtList.insert(tgtList.begin(), fForwardedSegments.begin(), fForwardedSegments.end());
iResult=tgtList.size();
return iResult;
-
- if (pConsumer) {
- AliHLTComponentDataTypeList dtlist;
- ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
- AliHLTDataSegmentList::iterator segment=fSegments.begin();
- while (segment!=fSegments.end()) {
- AliHLTComponentDataTypeList::iterator type=dtlist.begin();
- while (type!=dtlist.end()) {
- if ((*segment).fDataType==(*type)) {
- tgtList.push_back(*segment);
- iResult++;
- break;
- }
- type++;
- }
- segment++;
- }
- } else {
- iResult=-EINVAL;
- }
- return iResult;
}
int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockDataList& blockDescList)
}
}
// to be enabled if unit test is ready
- //iResult=SetRawBufferDataSize(fpBuffer, maxSize);
+ iResult=SetRawBufferDataSize(fpBuffer, maxSize);
} else {
HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->GetPointer(), fpBuffer);
iResult=-EINVAL;
return iResult;
}
-int AliHLTDataBuffer::GetNofSegments()
+int AliHLTDataBuffer::GetNofSegments() const
{
// see header file for function documentation
int iResult=fSegments.size() + fForwardedSegments.size();
return iResult;
}
-int AliHLTDataBuffer::GetNofConsumers()
+int AliHLTDataBuffer::GetNofConsumers() const
{
// see header file for function documentation
int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
return iResult;
}
-int AliHLTDataBuffer::GetNofPendingConsumers()
+int AliHLTDataBuffer::GetNofPendingConsumers() const
{
// see header file for function documentation
int iResult=fConsumers.size();
return iResult;
}
-int AliHLTDataBuffer::GetNofActiveConsumers()
+int AliHLTDataBuffer::GetNofActiveConsumers() const
{
// see header file for function documentation
int iResult=fActiveConsumers.size();
// see header file for function documentation
AliHLTRawBuffer* pRawBuffer=NULL;
unsigned int reqSize=size+fgkSafetyPatternSize;
- AliHLTRawBufferPList::iterator buffer=fgFreeBuffers.begin();
- while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
- if ((*buffer)->CheckSize(reqSize)) {
- // assign this element
- pRawBuffer=*buffer;
- pRawBuffer->UseBuffer(size);
- fgFreeBuffers.erase(buffer);
- 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());
- fgActiveBuffers.push_back(pRawBuffer);
- break;
- }
- buffer++;
- }
- if (pRawBuffer==NULL) {
- // no buffer found, create a new one
- pRawBuffer=new AliHLTRawBuffer(reqSize);
- if (pRawBuffer) {
- if (pRawBuffer->GetPointer()) {
- pRawBuffer->UseBuffer(size);
- fgActiveBuffers.push_back(pRawBuffer);
- fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->GetPointer(), pRawBuffer->GetTotalSize(), pRawBuffer);
- } else {
- delete pRawBuffer;
- pRawBuffer=NULL;
- fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
- }
- } else {
- fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
- }
+ pRawBuffer=AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(reqSize);
+ if (pRawBuffer) {
+ pRawBuffer->UseBuffer(size);
}
if (pRawBuffer!=NULL && fgkSafetyPatternSize>0) {
//fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "writing safety pattern to %p offset %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
}
}
// shrink the buffer and write new pattern at the end
- pBuffer->UseBuffer(size);
+ AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
+ if (rawpage) {
+ pBuffer->UseBuffer(size);
+ if (rawpage->SetSize(pBuffer, size+fgkSafetyPatternSize)==0) {
+ // nothing to do
+ } else {
+ fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "failed to set size for raw buffer %p", pBuffer);
+ iResult=-EFAULT;
+ }
+ } else {
+ fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::SetRawBufferDataSize", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
+ iResult=-ENOENT;
+ }
if (fgkSafetyPatternSize>0) {
pBuffer->WritePattern(fgkSafetyPattern, fgkSafetyPatternSize);
}
// see header file for function documentation
int iResult=0;
if (pBuffer) {
- AliHLTRawBufferPList::iterator buffer=fgActiveBuffers.begin();
- while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
- buffer++;
- }
- if (buffer!=fgActiveBuffers.end()) {
+ AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::FindPage(pBuffer);
+ if (rawpage)
+ {
if (fgkSafetyPatternSize>0) {
- //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", (*buffer)->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(*buffer));
- if ((*buffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
- fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", (*buffer)->GetPointer(), (*buffer)->GetUsedSize());
+ //fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "comparing safety pattern at %p offset %d", pBuffer->GetPointer(), reinterpret_cast<AliHLTUInt32_t>(pBuffer));
+ if ((pBuffer)->CheckPattern(fgkSafetyPattern, fgkSafetyPatternSize)) {
+ fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", pBuffer->GetPointer(), pBuffer->GetUsedSize());
}
}
- (*buffer)->Reset();
- fgFreeBuffers.push_back(*buffer);
- fgActiveBuffers.erase(buffer);
+ pBuffer->Reset();
+ if (rawpage->Free(pBuffer)==0) {
+ } else {
+ fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "failed to release raw buffer %p", pBuffer);
+ }
} else {
- fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
+ fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw page for buffer %p", pBuffer);
iResult=-ENOENT;
}
} else {
#ifdef ALIHLTSYSTEM_PROFILING
iTotalSize+=(*buffer)->GetTotalSize();
#endif //ALIHLTSYSTEM_PROFILING
- fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
+ fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->GetPointer(), (*buffer)->GetTotalSize());
delete *buffer;
fgActiveBuffers.erase(buffer);
}
#ifdef ALIHLTSYSTEM_PROFILING
- fgLogging.Logging(kHLTLogImportant, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
+ fgLogging.Logging(kHLTLogImportant, "AliHLTDataBuffer::DeleteRawBuffer", "data buffer handling", "Total memory allocation: %d byte in %d buffers", iTotalSize, iCount);
#endif //ALIHLTSYSTEM_PROFILING
return iResult;
}
{
// see header file for function documentation
int iResult=0;
- int iFree=0;
- int iActive=0;
- AliHLTRawBufferPList::iterator buffer;;
- for (buffer=fgFreeBuffers.begin(); buffer!=fgFreeBuffers.end(); buffer++) {
- iFree+=(*buffer)->GetTotalSize();
- }
- for (buffer=fgActiveBuffers.begin(); buffer!=fgActiveBuffers.end(); buffer++) {
- iActive+=(*buffer)->GetTotalSize();
+ int nofPages=0;
+ AliHLTUInt32_t totalSize=0;
+ for (AliHLTDataBuffer::AliHLTRawPage* rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(NULL);
+ rawpage!=NULL;
+ rawpage=AliHLTDataBuffer::AliHLTRawPage::NextPage(rawpage)) {
+ nofPages++;
+ totalSize+=rawpage->Size();
+ if (fgLogging.CheckFilter(kHLTLogDebug)) rawpage->Print("");
}
- 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);
+ //if (rawpage) rawpage->Print("global");
+ fgLogging.Logging(kHLTLogInfo, "AliHLTDataBuffer::PrintStatistics", "data buffer handling", "total number of memory pages: %d total size %d", nofPages, totalSize);
+
return iResult;
}
AliHLTDataBuffer::AliHLTRawBuffer::~AliHLTRawBuffer()
{
+ // see header file for class documentation
if (fExternalPtr==NULL && fPtr) {
free(fPtr);
}
AliHLTUInt8_t* AliHLTDataBuffer::AliHLTRawBuffer::UseBuffer(AliHLTUInt32_t size)
{
// mark a portion of the buffer as used
- if (size>0 && fTotalSize>=size) {
+ if (fTotalSize>=size) {
fSize=size;
fLastEventCount=AliHLTDataBuffer::fgEventCount;
- return fPtr;
+ // only return pointer if there is a portion of the buffer used
+ if (size>0) return fPtr;
}
return NULL;
}
// split a buffer at specified size
// only possible for buffers with external memory
if (fTotalSize>size &&
- (fSize==0 || fSize<size) &&
+ (fSize==0 || fSize<=size) && // used size must fit into the first part
fExternalPtr!=NULL) {
AliHLTRawBuffer* part2=new AliHLTRawBuffer(fTotalSize-size, fPtr+size);
if (part2) {
return -EINVAL;
}
-void AliHLTDataBuffer::AliHLTRawBuffer::Print(const char* option)
+void AliHLTDataBuffer::AliHLTRawBuffer::Print(const char* option) const
{
/// print buffer information
if (strcmp(option, "min")!=0) {
return 1;
}
-int AliHLTDataBuffer::AliHLTRawPage::SetSize(AliHLTDataBuffer::AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size)
+int AliHLTDataBuffer::AliHLTRawPage::SetSize(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer, AliHLTUInt32_t size)
{
/// set the size of a raw buffer and release the remaining part
int iResult=0;
return 1;
}
-bool AliHLTDataBuffer::AliHLTRawPage::HasBuffer(AliHLTDataBuffer::AliHLTRawBuffer* pBuffer)
+bool AliHLTDataBuffer::AliHLTRawPage::HasBuffer(const AliHLTDataBuffer::AliHLTRawBuffer* pBuffer)
{
/// check if the buffer is in this page
for (AliHLTRawBufferPList::iterator iter=fUsedBuffers.begin();
vector<AliHLTDataBuffer::AliHLTRawPage*> AliHLTDataBuffer::AliHLTRawPage::fgGlobalPages;
-AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::fgGlobalPageSize=1024*1024*10;
+AliHLTUInt32_t AliHLTDataBuffer::AliHLTRawPage::fgGlobalPageSize=30*1024*1024;
AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc(AliHLTUInt32_t size, int verbosity)
{
}
}
if (!rawbuffer) {
- AliHLTDataBuffer::AliHLTRawPage* rawpage=new AliHLTDataBuffer::AliHLTRawPage(fgGlobalPageSize);
+ AliHLTUInt32_t rawPageSize=fgGlobalPageSize;
+ if (rawPageSize<size) {
+ if (rawPageSize*10<size) {
+ log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "refusing to allocate buffer of size %d", size);
+ return NULL;
+ }
+ rawPageSize=size;
+ }
+ AliHLTDataBuffer::AliHLTRawPage* rawpage=new AliHLTDataBuffer::AliHLTRawPage(rawPageSize);
if (!rawpage) {
log.Logging(kHLTLogError, "AliHLTDataBuffer::AliHLTRawPage::GlobalAlloc", "data buffer handling", "can not create raw page");
return NULL;
}
+
+ // check is there is at least one unused page which can be replaced by the newly created one
+ for (page=fgGlobalPages.begin(); page!=fgGlobalPages.end(); page++) {
+ if ((*page)->IsUsed()) continue;
+ delete *page;
+ fgGlobalPages.erase(page);
+ break; // delete only one page to be replaced by the new page
+ }
fgGlobalPages.push_back(rawpage);
if ((rawbuffer=rawpage->Alloc(size))!=NULL) {
if (verbosity>1) {
return 0;
}
-AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::NextPage(AliHLTDataBuffer::AliHLTRawPage* prev)
+AliHLTDataBuffer::AliHLTRawPage* AliHLTDataBuffer::AliHLTRawPage::NextPage(const AliHLTDataBuffer::AliHLTRawPage* prev)
{
// get next global page
vector<AliHLTDataBuffer::AliHLTRawPage*>::iterator page=fgGlobalPages.begin();
}
return NULL;
}
+
+void AliHLTDataBuffer::AliHLTDataSegment::Print(const char* /*option*/) const
+{
+ // print info for data segment
+ cout << "AliHLTDataSegment " << this
+ << " " << AliHLTComponent::DataType2Text(fDataType)
+ << " " << hex << fSpecification << dec
+ << " Ptr " << (void*)fPtr
+ << " offset " << fSegmentOffset
+ << " size " << fSegmentSize
+ << endl;
+}
+
+void AliHLTDataBuffer::AliHLTForwardedDataSegment::Print(const char* option) const
+{
+ // print info for data segment
+ cout << "AliHLTForwardeDataSegment " << this << endl;
+ cout << " my : "; AliHLTDataSegment::Print(option);
+ cout << " parent: "; fParentSegment.Print(option);
+ cout << " task : ";
+ if (fParentTask) fParentTask->Print("");
+ else cout << "nil" << endl;
+}
+
+void AliHLTDataBuffer::Print(const char* option) const
+{
+ // print info for data buffer
+ unsigned i=0;
+ cout << "AliHLTDataBuffer " << this << endl;
+ cout << " raw buffer " << fpBuffer << endl;
+ if (fpBuffer) {
+ cout << " ";
+ fpBuffer->Print(option);
+ }
+
+ cout << " total segments: " << GetNofSegments() << endl;
+ cout << " data segments: " << fSegments.size() << endl;
+ for (i=0; i<fSegments.size(); i++) {
+ cout << " ";
+ fSegments[i].Print(option);
+ }
+
+ cout << " forwarded segments: " << fForwardedSegments.size() << endl;
+ for (i=0; i<fForwardedSegments.size(); i++) {
+ cout << " ";
+ fForwardedSegments[i].Print(option);
+ }
+
+ cout << " consumers: " << GetNofConsumers() << endl;
+ for (i=0; i<fConsumers.size(); i++) {
+ cout << " ";
+ fConsumers[i]->Print(option);
+ }
+
+ cout << " active consumers: " << GetNofActiveConsumers() << endl;
+ for (i=0; i<fActiveConsumers.size(); i++) {
+ cout << " ";
+ fActiveConsumers[i]->Print(option);
+ }
+
+ cout << " released consumers: " << fReleasedConsumers.size() << endl;
+ for (i=0; i<fReleasedConsumers.size(); i++) {
+ cout << " ";
+ fReleasedConsumers[i]->Print(option);
+ }
+
+}