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