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