]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTDataBuffer.cxx
Coding conventions
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataBuffer.cxx
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
18 /** @file   AliHLTDataBuffer.cxx
19     @author Matthias Richter
20     @date   
21     @brief  Handling of Data Buffers for HLT components.
22 */
23
24 #if __GNUC__>= 3
25 using namespace std;
26 #endif
27
28 #include "AliHLTDataBuffer.h"
29 #include "AliHLTConsumerDescriptor.h"
30 #include "AliHLTComponent.h"
31 #include <cerrno>
32 //#include <string>
33 //#include "AliHLTSystem.h"
34
35 /** ROOT macro for the implementation of ROOT specific class methods */
36 ClassImp(AliHLTDataBuffer)
37
38 AliHLTDataBuffer::AliHLTDataBuffer()
39   :
40   fSegments(),
41   fConsumers(),
42   fActiveConsumers(),
43   fReleasedConsumers(),
44   fpBuffer(NULL),
45   fFlags(0)
46 {
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
52   fSegments.empty();
53   fConsumers.empty();
54   fActiveConsumers.empty();
55   fReleasedConsumers.empty();
56   fgNofInstances++;
57 }
58
59 AliHLTDataBuffer::AliHLTDataBuffer(const AliHLTDataBuffer&)
60   :
61   TObject(),
62   AliHLTLogging(),
63   fSegments(),
64   fConsumers(),
65   fActiveConsumers(),
66   fReleasedConsumers(),
67   fpBuffer(NULL),
68   fFlags(0)
69 {
70   // see header file for function documentation
71   HLTFatal("copy constructor untested");
72 }
73
74 AliHLTDataBuffer& AliHLTDataBuffer::operator=(const AliHLTDataBuffer&)
75
76   // see header file for function documentation
77   HLTFatal("assignment operator untested");
78   return *this;
79 }
80
81 int AliHLTDataBuffer::fgNofInstances=0;
82 vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTDataBuffer::fgFreeBuffers;
83 vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTDataBuffer::fgActiveBuffers;
84 AliHLTUInt32_t AliHLTDataBuffer::fgMargin=1024;
85 AliHLTLogging AliHLTDataBuffer::fgLogging;
86 const Int_t AliHLTDataBuffer::fgkSafetyPatternSize=16;
87 const char AliHLTDataBuffer::fgkSafetyPattern[]={0x28, 0x63, 0x29, 0x4d, 0x52, 0x49, 0x43, 0x48, 0x54, 0x45, 0x52, 0x20, 0x32, 0x30, 0x30, 0x37};
88
89 AliHLTDataBuffer::~AliHLTDataBuffer()
90 {
91   // see header file for function documentation
92   if (--fgNofInstances<=0) {
93     DeleteRawBuffers();
94   }
95   CleanupConsumerList();
96 }
97
98 int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer)
99 {
100   // see header file for function documentation
101   int iResult=0;
102   if (pConsumer) {
103     if (FindConsumer(pConsumer)) {
104       HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
105     }
106     AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer);
107     if (pDesc) {
108       fConsumers.push_back(pDesc);
109       HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
110     } else {
111       HLTError("memory allocation failed");
112       iResult=-ENOMEM;
113     }
114   } else {
115     HLTError("invalid parameter: consumer component (nil)");
116     iResult=-EINVAL;
117   }
118   return iResult;
119 }
120
121 int AliHLTDataBuffer::FindMatchingDataBlocks(const AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
122 {
123   // see header file for function documentation
124   int iResult=0;
125   if (pConsumer) {
126     vector<AliHLTDataBuffer::AliHLTDataSegment> segments;
127     if ((iResult=FindMatchingDataSegments(pConsumer, segments))>=0) {
128       if (tgtList) {
129         vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=segments.begin();
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
143 int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
144 {
145   // see header file for function documentation
146   int iResult=0;
147   if (pConsumer) {
148     vector<AliHLTComponentDataType> dtlist;
149     ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
150     vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=fSegments.begin();
151     while (segment!=fSegments.end()) {
152       vector<AliHLTComponentDataType>::iterator type=dtlist.begin();
153       while (type!=dtlist.end()) {
154         if ((*segment).fDataType==(*type) ||
155             (*type)==kAliHLTAnyDataType) {
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
170 int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockData* arrayBlockDesc, int iArraySize)
171 {
172   // see header file for function documentation
173   int iResult=0;
174   if (pConsumer && arrayBlockDesc) {
175     if (fpBuffer) {
176       AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
177       if (pDesc) {
178         vector<AliHLTDataBuffer::AliHLTDataSegment> tgtList;
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;
185           vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=tgtList.begin();
186           while (segment!=tgtList.end() && i<iArraySize) {
187             // fill the block data descriptor
188             arrayBlockDesc[i].fStructSize=sizeof(AliHLTComponentBlockData);
189             // the shared memory key is not used in AliRoot
190             arrayBlockDesc[i].fShmKey.fStructSize=sizeof(AliHLTComponentShmData);
191             arrayBlockDesc[i].fShmKey.fShmType=gkAliHLTComponentInvalidShmType;
192             arrayBlockDesc[i].fShmKey.fShmID=gkAliHLTComponentInvalidShmID;
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);
206           } else {
207             // TODO: cleanup the consumer descriptor correctly
208             memset(arrayBlockDesc, 0, iArraySize*sizeof(AliHLTComponentBlockData));
209             HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
210             iResult=-EACCES;
211           }
212         } else {
213           HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
214           iResult=-EBADF;
215         }
216       } else {
217         HLTError("component %p is not a data consumer of data buffer %s", pConsumer, this);
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
231 int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTComponent* pConsumer)
232 {
233   // see header file for function documentation
234   int iResult=0;
235   if (pBlockDesc && pConsumer) {
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);
244         pBlockDesc->fOffset=0;
245         pBlockDesc->fPtr=NULL;
246         pBlockDesc->fSize=0;
247       }
248       if (pDesc->GetNofActiveSegments()==0) {
249         if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
250           if (GetNofActiveConsumers()==0) {
251             // this is the last consumer, reset the consumer list and release the raw buffer
252             ResetDataBuffer();
253           }
254         } else {
255           HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
256           iResult=-EACCES;
257         }
258       }
259     } else {
260       HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
261       iResult=-ENOENT;
262     }
263   } else {
264     HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
265     iResult=-EINVAL;
266   }
267   return iResult;
268 }
269
270 AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
271 {
272   // see header file for function documentation
273   AliHLTUInt8_t* pTargetBuffer=NULL;
274   fpBuffer=CreateRawBuffer(iMinSize);
275   if (fpBuffer) {
276     pTargetBuffer=(AliHLTUInt8_t*)fpBuffer->fPtr;
277   } else {
278     HLTError("can not create raw buffer");
279   }
280   return pTargetBuffer;
281 }
282
283 int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
284 {
285   // see header file for function documentation
286   int iResult=0;
287   if (pTgt && arrayBlockData && iSize>=0) {
288     if (fpBuffer) {
289       if (fpBuffer->fPtr==(void*)pTgt) {
290         AliHLTDataBuffer::AliHLTDataSegment segment;
291         memset(&segment, 0, sizeof(AliHLTDataBuffer::AliHLTDataSegment));
292         for (int i=0; i<iSize; i++) {
293           if (arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->fSize) {
294             segment.fSegmentOffset=arrayBlockData[i].fOffset;
295             segment.fSegmentSize=arrayBlockData[i].fSize;
296             segment.fDataType=arrayBlockData[i].fDataType;
297             segment.fSpecification=arrayBlockData[i].fSpecification;
298             fSegments.push_back(segment);
299             HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
300           } else {
301             HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
302             HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->fSize);
303             iResult=-E2BIG;
304           }
305         }
306       } else {
307         HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->fPtr, fpBuffer);
308         iResult=-EINVAL;
309       }
310     } else {
311       HLTFatal("internal data structur missmatch");
312       iResult=-EFAULT;
313     }
314   } else {
315     HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
316     iResult=-EINVAL;
317   }
318   return iResult;
319 }
320
321 int AliHLTDataBuffer::IsEmpty()
322 {
323   // see header file for function documentation
324   int iResult=fpBuffer==NULL || GetNofSegments()==0;
325   return iResult;
326 }
327
328 int AliHLTDataBuffer::GetNofSegments()
329 {
330   // see header file for function documentation
331   int iResult=fSegments.size();
332   return iResult;
333 }
334
335 int AliHLTDataBuffer::GetNofConsumers()
336 {
337   // see header file for function documentation
338   int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
339   return iResult;
340 }
341
342 int AliHLTDataBuffer::GetNofActiveConsumers()
343 {
344   // see header file for function documentation
345   int iResult=fActiveConsumers.size();
346   return iResult;
347 }
348
349 AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
350 {
351   // see header file for function documentation
352   AliHLTRawBuffer* pRawBuffer=NULL;
353   unsigned int reqSize=size+fgkSafetyPatternSize;
354   vector<AliHLTRawBuffer*>::iterator buffer=fgFreeBuffers.begin();
355   while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
356     if ((*buffer)->fTotalSize>=reqSize && ((*buffer)->fTotalSize-reqSize)<fgMargin) {
357       // assign this element
358       pRawBuffer=*buffer;
359       pRawBuffer->fSize=size;
360       fgFreeBuffers.erase(buffer);
361       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);
362       fgActiveBuffers.push_back(pRawBuffer);
363       break;
364     }
365     buffer++;
366   }
367   if (pRawBuffer==NULL) {
368     // no buffer found, create a new one
369     pRawBuffer=new AliHLTRawBuffer;
370     if (pRawBuffer) {
371       memset(pRawBuffer, 0, sizeof(AliHLTRawBuffer));
372       pRawBuffer->fPtr=malloc(reqSize);
373       if (pRawBuffer->fPtr) {
374         pRawBuffer->fSize=size;
375         pRawBuffer->fTotalSize=reqSize;
376         fgActiveBuffers.push_back(pRawBuffer);
377         fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->fPtr, pRawBuffer->fTotalSize, pRawBuffer);
378         if (fgkSafetyPatternSize>0) {
379           memcpy(((char*)pRawBuffer->fPtr)+pRawBuffer->fSize, fgkSafetyPattern, fgkSafetyPatternSize);
380         }
381       } else {
382         delete pRawBuffer;
383         pRawBuffer=NULL;
384         fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
385       } 
386     } else {
387       fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
388     }
389   }
390   return pRawBuffer;
391 }
392
393 int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
394 {
395   // see header file for function documentation
396   int iResult=0;
397   if (pBuffer) {
398     vector<AliHLTRawBuffer*>::iterator buffer=fgActiveBuffers.begin();
399     while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
400       buffer++;
401     }
402     if (buffer!=fgActiveBuffers.end()) {
403       if (fgkSafetyPatternSize>0) {
404         if (memcmp(((char*)(*buffer)->fPtr)+(*buffer)->fSize, fgkSafetyPattern, fgkSafetyPatternSize)!=0) {
405           fgLogging.Logging(kHLTLogFatal, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "component has written beyond end of data buffer %p size %d", (*buffer)->fPtr, (*buffer)->fSize);
406         }
407       }
408       (*buffer)->fSize=0;
409       fgFreeBuffers.push_back(*buffer);
410       fgActiveBuffers.erase(buffer);
411     } else {
412       fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
413       iResult=-ENOENT;
414     }
415   } else {
416     fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
417     iResult=-EINVAL;
418   }
419   return iResult;
420 }
421
422
423 int AliHLTDataBuffer::DeleteRawBuffers() 
424 {
425   // see header file for function documentation
426   int iResult=0;
427   vector<AliHLTRawBuffer*>::iterator buffer=fgFreeBuffers.begin();
428   while (buffer!=fgFreeBuffers.end()) {
429     free((*buffer)->fPtr);
430     delete *buffer;
431     fgFreeBuffers.erase(buffer);
432     buffer=fgFreeBuffers.begin();
433   }
434   buffer=fgActiveBuffers.begin();
435   while (buffer!=fgActiveBuffers.end()) {
436     fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "request to delete active raw buffer container (raw buffer %p, size %d)", (*buffer)->fPtr, (*buffer)->fTotalSize);
437     free((*buffer)->fPtr);
438     delete *buffer;
439     fgActiveBuffers.erase(buffer);
440     buffer=fgActiveBuffers.begin();
441   }
442   return iResult;
443 }
444
445 AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, vector<AliHLTConsumerDescriptor*> &list) const
446 {
447   // see header file for function documentation
448   AliHLTConsumerDescriptor* pDesc=NULL;
449   vector<AliHLTConsumerDescriptor*>::iterator desc=list.begin();
450   while (desc!=list.end() && pDesc==NULL) {
451     if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
452       pDesc=*desc;
453     }
454     desc++;
455   }
456   return pDesc;
457 }
458
459 int AliHLTDataBuffer::ResetDataBuffer() 
460 {
461   // see header file for function documentation
462   int iResult=0;
463   AliHLTRawBuffer* pBuffer=fpBuffer;
464   fpBuffer=NULL;
465
466   // cleanup consumer states
467   vector<AliHLTConsumerDescriptor*>::iterator desc=fReleasedConsumers.begin();
468   while (desc!=fReleasedConsumers.end()) {
469     AliHLTConsumerDescriptor* pDesc=*desc;
470     fReleasedConsumers.erase(desc);
471     desc=fReleasedConsumers.begin();
472     fConsumers.push_back(pDesc);
473   }
474   desc=fActiveConsumers.begin();
475   while (desc!=fActiveConsumers.end()) {
476     AliHLTConsumerDescriptor* pDesc=*desc;
477     HLTWarning("consumer %p was not released", pDesc);
478     fActiveConsumers.erase(desc);
479     desc=fActiveConsumers.begin();
480     fConsumers.push_back(pDesc);
481   }
482
483   // cleanup segments
484   vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=fSegments.begin();
485   while (segment!=fSegments.end()) {
486     fSegments.erase(segment);
487     segment=fSegments.begin();
488   }
489
490   // cleanup raw buffer
491   if (pBuffer) {
492     ReleaseRawBuffer(pBuffer);
493   }
494   return iResult;
495 }
496
497 int AliHLTDataBuffer::Reset()
498 {
499   // see header file for function documentation
500   return ResetDataBuffer();
501 }
502
503 // this is the version which works on lists of components instead of consumer descriptors
504 // int AliHLTDataBuffer::ChangeConsumerState(AliHLTComponent* pConsumer, vector<AliHLTComponent*> &srcList, vector<AliHLTComponent*> &tgtList)
505 // {
506 //   int iResult=0;
507 //   if (pDesc) {
508 //     vector<AliHLTComponent*>::iterator desc=srcList.begin();
509 //     while (desc!=srcList.end()) {
510 //       if ((*desc)==pConsumer) {
511 //      srcList.erase(desc);
512 //      tgtList.push_back(pConsumer);
513 //      break;
514 //       }
515 //      desc++;
516 //     }
517 //     if (desc==srcList.end()) {
518 //       HLTError("can not find consumer component %p in list", pConsumer);
519 //       iResult=-ENOENT;
520 //     }
521 //   } else {
522 //     HLTError("invalid parameter");
523 //     iResult=-EINVAL;
524 //   }
525 //   return iResult;
526 // }
527
528 int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, vector<AliHLTConsumerDescriptor*> &srcList, vector<AliHLTConsumerDescriptor*> &tgtList)
529 {
530   // see header file for function documentation
531   int iResult=-ENOENT;
532   if (pDesc) {
533     vector<AliHLTConsumerDescriptor*>::iterator desc=srcList.begin();
534     while (desc!=srcList.end()) {
535       if ((*desc)==pDesc) {
536         srcList.erase(desc);
537         tgtList.push_back(pDesc);
538         iResult=0;
539         break;
540       }
541       desc++;
542     }
543     if (iResult<0) {
544       HLTError("can not find consumer descriptor %p in list", pDesc);
545     }
546   } else {
547     HLTError("invalid parameter");
548     iResult=-EINVAL;
549   }
550   return iResult;
551 }
552
553 int AliHLTDataBuffer::CleanupConsumerList() 
554 {
555   // see header file for function documentation
556   int iResult=0;
557   ResetDataBuffer();
558   vector<AliHLTConsumerDescriptor*>::iterator desc=fConsumers.begin();
559   while (desc!=fConsumers.end()) {
560     delete *desc;
561     fConsumers.erase(desc);
562     desc=fConsumers.begin();
563   }
564   return iResult;
565 }
566
567 int AliHLTDataBuffer::FindConsumer(AliHLTComponent* pConsumer, int bAllLists)
568 {
569   // see header file for function documentation
570   vector<AliHLTConsumerDescriptor*>::iterator desc=fConsumers.begin();
571   while (desc!=fConsumers.end()) {
572     if ((*desc)->GetComponent()==pConsumer)
573       return 1;
574     desc++;
575   }
576   if (bAllLists==0) return 0;
577
578   desc=fActiveConsumers.begin();
579   while (desc!=fActiveConsumers.end()) {
580     if ((*desc)->GetComponent()==pConsumer)
581       return 1;
582     desc++;
583   }
584   desc=fReleasedConsumers.begin();
585   while (desc!=fReleasedConsumers.end()) {
586     if ((*desc)->GetComponent()==pConsumer)
587       return 1;
588     desc++;
589   }
590   return 0;
591 }