]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTDataBuffer.cxx
Air with increased transport cuts close to qb28.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataBuffer.cxx
CommitLineData
3f2a1b1c 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
b22e91eb 18/** @file AliHLTDataBuffer.cxx
19 @author Matthias Richter
20 @date
21 @brief Handling of Data Buffers for HLT components.
22*/
3f2a1b1c 23
0c0c9d99 24#if __GNUC__>= 3
3f2a1b1c 25using namespace std;
26#endif
27
28#include "AliHLTDataBuffer.h"
6235cd38 29#include "AliHLTConsumerDescriptor.h"
b22e91eb 30#include "AliHLTComponent.h"
66043029 31#include <cerrno>
32//#include <string>
33//#include "AliHLTSystem.h"
3f2a1b1c 34
b22e91eb 35/** ROOT macro for the implementation of ROOT specific class methods */
3f2a1b1c 36ClassImp(AliHLTDataBuffer)
37
3f2a1b1c 38AliHLTDataBuffer::AliHLTDataBuffer()
85869391 39 :
40 fSegments(),
41 fConsumers(),
42 fActiveConsumers(),
43 fReleasedConsumers(),
44 fpBuffer(NULL),
45 fFlags(0)
3f2a1b1c 46{
70ed7d01 47 // see header file for class documentation
48 // or
49 // refer to README to build package
50 // or
51 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
85869391 52 fSegments.empty();
53 fConsumers.empty();
54 fActiveConsumers.empty();
55 fReleasedConsumers.empty();
70ed7d01 56 fgNofInstances++;
3f2a1b1c 57}
58
85869391 59AliHLTDataBuffer::AliHLTDataBuffer(const AliHLTDataBuffer&)
60 :
53feaef5 61 TObject(),
62 AliHLTLogging(),
85869391 63 fSegments(),
64 fConsumers(),
65 fActiveConsumers(),
66 fReleasedConsumers(),
67 fpBuffer(NULL),
68 fFlags(0)
69{
70ed7d01 70 // see header file for function documentation
85869391 71 HLTFatal("copy constructor untested");
72}
73
74AliHLTDataBuffer& AliHLTDataBuffer::operator=(const AliHLTDataBuffer&)
75{
70ed7d01 76 // see header file for function documentation
85869391 77 HLTFatal("assignment operator untested");
78 return *this;
79}
80
70ed7d01 81int AliHLTDataBuffer::fgNofInstances=0;
6235cd38 82vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTDataBuffer::fgFreeBuffers;
83vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTDataBuffer::fgActiveBuffers;
70ed7d01 84AliHLTUInt32_t AliHLTDataBuffer::fgMargin=1024;
b22e91eb 85AliHLTLogging AliHLTDataBuffer::fgLogging;
8451168b 86const Int_t AliHLTDataBuffer::fgkSafetyPatternSize=16;
87const char AliHLTDataBuffer::fgkSafetyPattern[]={0x28, 0x63, 0x29, 0x4d, 0x52, 0x49, 0x43, 0x48, 0x54, 0x45, 0x52, 0x20, 0x32, 0x30, 0x30, 0x37};
b22e91eb 88
3f2a1b1c 89AliHLTDataBuffer::~AliHLTDataBuffer()
90{
70ed7d01 91 // see header file for function documentation
92 if (--fgNofInstances<=0) {
3f2a1b1c 93 DeleteRawBuffers();
94 }
95 CleanupConsumerList();
96}
97
0c0c9d99 98int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer)
3f2a1b1c 99{
70ed7d01 100 // see header file for function documentation
3f2a1b1c 101 int iResult=0;
102 if (pConsumer) {
9ce4bf4a 103 if (FindConsumer(pConsumer)) {
104 HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
105 }
0c0c9d99 106 AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer);
3f2a1b1c 107 if (pDesc) {
108 fConsumers.push_back(pDesc);
9ce4bf4a 109 HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
3f2a1b1c 110 } else {
111 HLTError("memory allocation failed");
112 iResult=-ENOMEM;
113 }
114 } else {
9ce4bf4a 115 HLTError("invalid parameter: consumer component (nil)");
3f2a1b1c 116 iResult=-EINVAL;
117 }
118 return iResult;
119}
120
8ede8717 121int AliHLTDataBuffer::FindMatchingDataBlocks(const AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 122{
70ed7d01 123 // see header file for function documentation
0c0c9d99 124 int iResult=0;
125 if (pConsumer) {
6235cd38 126 vector<AliHLTDataBuffer::AliHLTDataSegment> segments;
0c0c9d99 127 if ((iResult=FindMatchingDataSegments(pConsumer, segments))>=0) {
128 if (tgtList) {
6235cd38 129 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=segments.begin();
0c0c9d99 130 while (segment!=segments.end()) {
131 tgtList->push_back((*segment).fDataType);
132 segment++;
133 }
134 }
135 iResult=segments.size();
136 }
137 } else {
138 iResult=-EINVAL;
139 }
140 return iResult;
141}
142
6235cd38 143int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
0c0c9d99 144{
70ed7d01 145 // see header file for function documentation
0c0c9d99 146 int iResult=0;
147 if (pConsumer) {
8ede8717 148 vector<AliHLTComponentDataType> dtlist;
0c0c9d99 149 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
6235cd38 150 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=fSegments.begin();
0c0c9d99 151 while (segment!=fSegments.end()) {
8ede8717 152 vector<AliHLTComponentDataType>::iterator type=dtlist.begin();
0c0c9d99 153 while (type!=dtlist.end()) {
9ce4bf4a 154 if ((*segment).fDataType==(*type) ||
155 (*type)==kAliHLTAnyDataType) {
0c0c9d99 156 tgtList.push_back(*segment);
157 iResult++;
158 break;
159 }
160 type++;
161 }
162 segment++;
163 }
164 } else {
165 iResult=-EINVAL;
166 }
167 return iResult;
168}
169
8ede8717 170int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockData* arrayBlockDesc, int iArraySize)
3f2a1b1c 171{
70ed7d01 172 // see header file for function documentation
3f2a1b1c 173 int iResult=0;
0c0c9d99 174 if (pConsumer && arrayBlockDesc) {
3f2a1b1c 175 if (fpBuffer) {
0c0c9d99 176 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
3f2a1b1c 177 if (pDesc) {
6235cd38 178 vector<AliHLTDataBuffer::AliHLTDataSegment> tgtList;
0c0c9d99 179 /* TODO: think about a good policy for this check
180 * is it enough that at least one segment is available, or have all to be available?
181 * or is it possible to have optional segments?
182 */
183 if ((iResult=FindMatchingDataSegments(pConsumer, tgtList))>0) {
184 int i =0;
6235cd38 185 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=tgtList.begin();
0c0c9d99 186 while (segment!=tgtList.end() && i<iArraySize) {
3f2a1b1c 187 // fill the block data descriptor
8ede8717 188 arrayBlockDesc[i].fStructSize=sizeof(AliHLTComponentBlockData);
3f2a1b1c 189 // the shared memory key is not used in AliRoot
8ede8717 190 arrayBlockDesc[i].fShmKey.fStructSize=sizeof(AliHLTComponentShmData);
191 arrayBlockDesc[i].fShmKey.fShmType=gkAliHLTComponentInvalidShmType;
192 arrayBlockDesc[i].fShmKey.fShmID=gkAliHLTComponentInvalidShmID;
0c0c9d99 193 arrayBlockDesc[i].fOffset=(*segment).fSegmentOffset;
194 arrayBlockDesc[i].fPtr=fpBuffer->fPtr;
195 arrayBlockDesc[i].fSize=(*segment).fSegmentSize;
196 arrayBlockDesc[i].fDataType=(*segment).fDataType;
197 arrayBlockDesc[i].fSpecification=(*segment).fSpecification;
198 pDesc->SetActiveDataSegment(arrayBlockDesc[i].fOffset, arrayBlockDesc[i].fSize);
199 HLTDebug("component %p (%s) subscribed to segment #%d offset %d", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), i, arrayBlockDesc[i].fOffset);
200 i++;
201 segment++;
202 }
203 // move this consumer to the active list
204 if (ChangeConsumerState(pDesc, fConsumers, fActiveConsumers)>=0) {
205 HLTDebug("component %p (%s) subscribed to data buffer %p", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID(), this);
3f2a1b1c 206 } else {
0c0c9d99 207 // TODO: cleanup the consumer descriptor correctly
8ede8717 208 memset(arrayBlockDesc, 0, iArraySize*sizeof(AliHLTComponentBlockData));
3f2a1b1c 209 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
210 iResult=-EACCES;
211 }
212 } else {
0c0c9d99 213 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
3f2a1b1c 214 iResult=-EBADF;
215 }
216 } else {
0c0c9d99 217 HLTError("component %p is not a data consumer of data buffer %s", pConsumer, this);
3f2a1b1c 218 iResult=-ENOENT;
219 }
220 } else {
221 HLTError("data buffer %p is empty", this);
222 iResult=-ENODATA;
223 }
224 } else {
225 HLTError("invalid parameter");
226 iResult=-EINVAL;
227 }
228 return iResult;
229}
230
8ede8717 231int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTComponent* pConsumer)
3f2a1b1c 232{
70ed7d01 233 // see header file for function documentation
3f2a1b1c 234 int iResult=0;
235 if (pBlockDesc && pConsumer) {
0c0c9d99 236 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fActiveConsumers);
237 if (pDesc) {
238 if ((iResult=pDesc->CheckActiveDataSegment(pBlockDesc->fOffset, pBlockDesc->fSize))!=1) {
239 HLTWarning("data segment missmatch, component %p has not subscribed to a segment with offset %#x and size %d", pConsumer, pBlockDesc->fOffset, pBlockDesc->fSize);
240 // TODO: appropriate error handling, but so far optional
241 iResult=0;
242 } else {
243 pDesc->ReleaseActiveDataSegment(pBlockDesc->fOffset, pBlockDesc->fSize);
3f2a1b1c 244 pBlockDesc->fOffset=0;
245 pBlockDesc->fPtr=NULL;
246 pBlockDesc->fSize=0;
0c0c9d99 247 }
248 if (pDesc->GetNofActiveSegments()==0) {
3f2a1b1c 249 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
250 if (GetNofActiveConsumers()==0) {
0c0c9d99 251 // this is the last consumer, reset the consumer list and release the raw buffer
3f2a1b1c 252 ResetDataBuffer();
3f2a1b1c 253 }
254 } else {
255 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
256 iResult=-EACCES;
257 }
3f2a1b1c 258 }
0c0c9d99 259 } else {
260 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
261 iResult=-ENOENT;
262 }
3f2a1b1c 263 } else {
264 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
265 iResult=-EINVAL;
266 }
267 return iResult;
268}
269
270AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
271{
70ed7d01 272 // see header file for function documentation
3f2a1b1c 273 AliHLTUInt8_t* pTargetBuffer=NULL;
274 fpBuffer=CreateRawBuffer(iMinSize);
9ce4bf4a 275 if (fpBuffer) {
276 pTargetBuffer=(AliHLTUInt8_t*)fpBuffer->fPtr;
277 } else {
278 HLTError("can not create raw buffer");
279 }
3f2a1b1c 280 return pTargetBuffer;
281}
282
8ede8717 283int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
3f2a1b1c 284{
70ed7d01 285 // see header file for function documentation
3f2a1b1c 286 int iResult=0;
287 if (pTgt && arrayBlockData && iSize>=0) {
0c0c9d99 288 if (fpBuffer) {
289 if (fpBuffer->fPtr==(void*)pTgt) {
6235cd38 290 AliHLTDataBuffer::AliHLTDataSegment segment;
0c0c9d99 291 for (int i=0; i<iSize; i++) {
9ce4bf4a 292 if (arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->fSize) {
0c0c9d99 293 segment.fSegmentOffset=arrayBlockData[i].fOffset;
294 segment.fSegmentSize=arrayBlockData[i].fSize;
295 segment.fDataType=arrayBlockData[i].fDataType;
296 segment.fSpecification=arrayBlockData[i].fSpecification;
297 fSegments.push_back(segment);
9ce4bf4a 298 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
0c0c9d99 299 } else {
9ce4bf4a 300 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
301 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->fSize);
8451168b 302 iResult=-E2BIG;
0c0c9d99 303 }
304 }
3f2a1b1c 305 } else {
0c0c9d99 306 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->fPtr, fpBuffer);
8451168b 307 iResult=-EINVAL;
3f2a1b1c 308 }
0c0c9d99 309 } else {
310 HLTFatal("internal data structur missmatch");
311 iResult=-EFAULT;
3f2a1b1c 312 }
313 } else {
0c0c9d99 314 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
3f2a1b1c 315 iResult=-EINVAL;
316 }
317 return iResult;
318}
319
320int AliHLTDataBuffer::IsEmpty()
321{
70ed7d01 322 // see header file for function documentation
3f2a1b1c 323 int iResult=fpBuffer==NULL || GetNofSegments()==0;
324 return iResult;
325}
326
327int AliHLTDataBuffer::GetNofSegments()
328{
70ed7d01 329 // see header file for function documentation
3f2a1b1c 330 int iResult=fSegments.size();
331 return iResult;
332}
333
334int AliHLTDataBuffer::GetNofConsumers()
335{
70ed7d01 336 // see header file for function documentation
3f2a1b1c 337 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
338 return iResult;
339}
340
341int AliHLTDataBuffer::GetNofActiveConsumers()
342{
70ed7d01 343 // see header file for function documentation
3f2a1b1c 344 int iResult=fActiveConsumers.size();
345 return iResult;
346}
347
6235cd38 348AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
3f2a1b1c 349{
70ed7d01 350 // see header file for function documentation
3f2a1b1c 351 AliHLTRawBuffer* pRawBuffer=NULL;
7a5ccd96 352 unsigned int reqSize=size+fgkSafetyPatternSize;
70ed7d01 353 vector<AliHLTRawBuffer*>::iterator buffer=fgFreeBuffers.begin();
354 while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
8451168b 355 if ((*buffer)->fTotalSize>=reqSize && ((*buffer)->fTotalSize-reqSize)<fgMargin) {
3f2a1b1c 356 // assign this element
357 pRawBuffer=*buffer;
358 pRawBuffer->fSize=size;
70ed7d01 359 fgFreeBuffers.erase(buffer);
0c0c9d99 360 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->fTotalSize, pRawBuffer->fPtr);
70ed7d01 361 fgActiveBuffers.push_back(pRawBuffer);
0c0c9d99 362 break;
3f2a1b1c 363 }
0c0c9d99 364 buffer++;
3f2a1b1c 365 }
366 if (pRawBuffer==NULL) {
0c0c9d99 367 // no buffer found, create a new one
3f2a1b1c 368 pRawBuffer=new AliHLTRawBuffer;
369 if (pRawBuffer) {
8451168b 370 pRawBuffer->fPtr=malloc(reqSize);
3f2a1b1c 371 if (pRawBuffer->fPtr) {
372 pRawBuffer->fSize=size;
8451168b 373 pRawBuffer->fTotalSize=reqSize;
70ed7d01 374 fgActiveBuffers.push_back(pRawBuffer);
0c0c9d99 375 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->fPtr, pRawBuffer->fTotalSize, pRawBuffer);
8451168b 376 if (fgkSafetyPatternSize>0) {
377 memcpy(((char*)pRawBuffer->fPtr)+pRawBuffer->fSize, fgkSafetyPattern, fgkSafetyPatternSize);
378 }
3f2a1b1c 379 } else {
380 delete pRawBuffer;
381 pRawBuffer=NULL;
0c0c9d99 382 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
3f2a1b1c 383 }
384 } else {
0c0c9d99 385 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
3f2a1b1c 386 }
387 }
388 return pRawBuffer;
389}
390
391int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
392{
70ed7d01 393 // see header file for function documentation
3f2a1b1c 394 int iResult=0;
395 if (pBuffer) {
70ed7d01 396 vector<AliHLTRawBuffer*>::iterator buffer=fgActiveBuffers.begin();
397 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
3f2a1b1c 398 buffer++;
399 }
70ed7d01 400 if (buffer!=fgActiveBuffers.end()) {
8451168b 401 if (fgkSafetyPatternSize>0) {
402 if (memcmp(((char*)(*buffer)->fPtr)+(*buffer)->fSize, fgkSafetyPattern, fgkSafetyPatternSize)!=0) {
403 fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", (*buffer)->fPtr, (*buffer)->fSize);
404 }
405 }
3f2a1b1c 406 (*buffer)->fSize=0;
70ed7d01 407 fgFreeBuffers.push_back(*buffer);
408 fgActiveBuffers.erase(buffer);
3f2a1b1c 409 } else {
0c0c9d99 410 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
3f2a1b1c 411 iResult=-ENOENT;
412 }
413 } else {
0c0c9d99 414 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
3f2a1b1c 415 iResult=-EINVAL;
416 }
417 return iResult;
418}
419
420
421int AliHLTDataBuffer::DeleteRawBuffers()
422{
70ed7d01 423 // see header file for function documentation
3f2a1b1c 424 int iResult=0;
70ed7d01 425 vector<AliHLTRawBuffer*>::iterator buffer=fgFreeBuffers.begin();
426 while (buffer!=fgFreeBuffers.end()) {
3f2a1b1c 427 free((*buffer)->fPtr);
428 delete *buffer;
70ed7d01 429 fgFreeBuffers.erase(buffer);
430 buffer=fgFreeBuffers.begin();
3f2a1b1c 431 }
70ed7d01 432 buffer=fgActiveBuffers.begin();
433 while (buffer!=fgActiveBuffers.end()) {
0c0c9d99 434 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->fPtr, (*buffer)->fTotalSize);
3f2a1b1c 435 free((*buffer)->fPtr);
436 delete *buffer;
70ed7d01 437 fgActiveBuffers.erase(buffer);
438 buffer=fgActiveBuffers.begin();
3f2a1b1c 439 }
440 return iResult;
441}
442
70ed7d01 443AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, vector<AliHLTConsumerDescriptor*> &list) const
3f2a1b1c 444{
70ed7d01 445 // see header file for function documentation
3f2a1b1c 446 AliHLTConsumerDescriptor* pDesc=NULL;
447 vector<AliHLTConsumerDescriptor*>::iterator desc=list.begin();
448 while (desc!=list.end() && pDesc==NULL) {
0c0c9d99 449 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
3f2a1b1c 450 pDesc=*desc;
451 }
0c0c9d99 452 desc++;
3f2a1b1c 453 }
454 return pDesc;
455}
456
0c0c9d99 457int AliHLTDataBuffer::ResetDataBuffer()
458{
70ed7d01 459 // see header file for function documentation
3f2a1b1c 460 int iResult=0;
0c0c9d99 461 AliHLTRawBuffer* pBuffer=fpBuffer;
3f2a1b1c 462 fpBuffer=NULL;
9ce4bf4a 463
464 // cleanup consumer states
3f2a1b1c 465 vector<AliHLTConsumerDescriptor*>::iterator desc=fReleasedConsumers.begin();
466 while (desc!=fReleasedConsumers.end()) {
467 AliHLTConsumerDescriptor* pDesc=*desc;
468 fReleasedConsumers.erase(desc);
469 desc=fReleasedConsumers.begin();
470 fConsumers.push_back(pDesc);
471 }
472 desc=fActiveConsumers.begin();
473 while (desc!=fActiveConsumers.end()) {
474 AliHLTConsumerDescriptor* pDesc=*desc;
475 HLTWarning("consumer %p was not released", pDesc);
476 fActiveConsumers.erase(desc);
477 desc=fActiveConsumers.begin();
478 fConsumers.push_back(pDesc);
479 }
9ce4bf4a 480
481 // cleanup segments
6235cd38 482 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=fSegments.begin();
9ce4bf4a 483 while (segment!=fSegments.end()) {
484 fSegments.erase(segment);
485 segment=fSegments.begin();
486 }
487
488 // cleanup raw buffer
489 if (pBuffer) {
490 ReleaseRawBuffer(pBuffer);
491 }
3f2a1b1c 492 return iResult;
493}
494
9ce4bf4a 495int AliHLTDataBuffer::Reset()
496{
70ed7d01 497 // see header file for function documentation
9ce4bf4a 498 return ResetDataBuffer();
499}
500
0c0c9d99 501// this is the version which works on lists of components instead of consumer descriptors
502// int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, vector<AliHLTComponent*> &srcList, vector<AliHLTComponent*> &tgtList)
503// {
504// int iResult=0;
505// if (pDesc) {
506// vector<AliHLTComponent*>::iterator desc=srcList.begin();
507// while (desc!=srcList.end()) {
508// if ((*desc)==pConsumer) {
509// srcList.erase(desc);
510// tgtList.push_back(pConsumer);
511// break;
512// }
513// desc++;
514// }
515// if (desc==srcList.end()) {
516// HLTError("can not find consumer component %p in list", pConsumer);
517// iResult=-ENOENT;
518// }
519// } else {
520// HLTError("invalid parameter");
521// iResult=-EINVAL;
522// }
523// return iResult;
524// }
525
3f2a1b1c 526int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, vector<AliHLTConsumerDescriptor*> &srcList, vector<AliHLTConsumerDescriptor*> &tgtList)
527{
70ed7d01 528 // see header file for function documentation
9ce4bf4a 529 int iResult=-ENOENT;
3f2a1b1c 530 if (pDesc) {
531 vector<AliHLTConsumerDescriptor*>::iterator desc=srcList.begin();
532 while (desc!=srcList.end()) {
533 if ((*desc)==pDesc) {
534 srcList.erase(desc);
535 tgtList.push_back(pDesc);
9ce4bf4a 536 iResult=0;
3f2a1b1c 537 break;
538 }
0c0c9d99 539 desc++;
3f2a1b1c 540 }
9ce4bf4a 541 if (iResult<0) {
3f2a1b1c 542 HLTError("can not find consumer descriptor %p in list", pDesc);
3f2a1b1c 543 }
544 } else {
545 HLTError("invalid parameter");
546 iResult=-EINVAL;
547 }
548 return iResult;
549}
550
70ed7d01 551int AliHLTDataBuffer::CleanupConsumerList()
552{
553 // see header file for function documentation
3f2a1b1c 554 int iResult=0;
555 ResetDataBuffer();
556 vector<AliHLTConsumerDescriptor*>::iterator desc=fConsumers.begin();
557 while (desc!=fConsumers.end()) {
558 delete *desc;
559 fConsumers.erase(desc);
560 desc=fConsumers.begin();
561 }
562 return iResult;
563}
9ce4bf4a 564
70ed7d01 565int AliHLTDataBuffer::FindConsumer(AliHLTComponent* pConsumer, int bAllLists)
566{
567 // see header file for function documentation
9ce4bf4a 568 vector<AliHLTConsumerDescriptor*>::iterator desc=fConsumers.begin();
569 while (desc!=fConsumers.end()) {
570 if ((*desc)->GetComponent()==pConsumer)
571 return 1;
572 desc++;
573 }
574 if (bAllLists==0) return 0;
575
576 desc=fActiveConsumers.begin();
577 while (desc!=fActiveConsumers.end()) {
578 if ((*desc)->GetComponent()==pConsumer)
579 return 1;
580 desc++;
581 }
582 desc=fReleasedConsumers.begin();
583 while (desc!=fReleasedConsumers.end()) {
584 if ((*desc)->GetComponent()==pConsumer)
585 return 1;
586 desc++;
587 }
588 return 0;
589}