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