]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTDataBuffer.cxx
removed warnings
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTDataBuffer.cxx
CommitLineData
3f2a1b1c 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * for The ALICE Off-line Project. *
8 * *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
17
b22e91eb 18/** @file AliHLTDataBuffer.cxx
19 @author Matthias Richter
20 @date
21 @brief Handling of Data Buffers for HLT components.
22*/
3f2a1b1c 23
0c0c9d99 24#if __GNUC__>= 3
3f2a1b1c 25using namespace std;
26#endif
27
28#include "AliHLTDataBuffer.h"
6235cd38 29#include "AliHLTConsumerDescriptor.h"
b22e91eb 30#include "AliHLTComponent.h"
3f2a1b1c 31#include <string>
32#include "AliHLTSystem.h"
33
b22e91eb 34/** ROOT macro for the implementation of ROOT specific class methods */
3f2a1b1c 35ClassImp(AliHLTDataBuffer)
36
3f2a1b1c 37AliHLTDataBuffer::AliHLTDataBuffer()
85869391 38 :
39 fSegments(),
40 fConsumers(),
41 fActiveConsumers(),
42 fReleasedConsumers(),
43 fpBuffer(NULL),
44 fFlags(0)
3f2a1b1c 45{
70ed7d01 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
85869391 51 fSegments.empty();
52 fConsumers.empty();
53 fActiveConsumers.empty();
54 fReleasedConsumers.empty();
70ed7d01 55 fgNofInstances++;
3f2a1b1c 56}
57
85869391 58AliHLTDataBuffer::AliHLTDataBuffer(const AliHLTDataBuffer&)
59 :
53feaef5 60 TObject(),
61 AliHLTLogging(),
85869391 62 fSegments(),
63 fConsumers(),
64 fActiveConsumers(),
65 fReleasedConsumers(),
66 fpBuffer(NULL),
67 fFlags(0)
68{
70ed7d01 69 // see header file for function documentation
85869391 70 HLTFatal("copy constructor untested");
71}
72
73AliHLTDataBuffer& AliHLTDataBuffer::operator=(const AliHLTDataBuffer&)
74{
70ed7d01 75 // see header file for function documentation
85869391 76 HLTFatal("assignment operator untested");
77 return *this;
78}
79
70ed7d01 80int AliHLTDataBuffer::fgNofInstances=0;
6235cd38 81vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTDataBuffer::fgFreeBuffers;
82vector<AliHLTDataBuffer::AliHLTRawBuffer*> AliHLTDataBuffer::fgActiveBuffers;
70ed7d01 83AliHLTUInt32_t AliHLTDataBuffer::fgMargin=1024;
b22e91eb 84AliHLTLogging AliHLTDataBuffer::fgLogging;
8451168b 85const Int_t AliHLTDataBuffer::fgkSafetyPatternSize=16;
86const char AliHLTDataBuffer::fgkSafetyPattern[]={0x28, 0x63, 0x29, 0x4d, 0x52, 0x49, 0x43, 0x48, 0x54, 0x45, 0x52, 0x20, 0x32, 0x30, 0x30, 0x37};
b22e91eb 87
3f2a1b1c 88AliHLTDataBuffer::~AliHLTDataBuffer()
89{
70ed7d01 90 // see header file for function documentation
91 if (--fgNofInstances<=0) {
3f2a1b1c 92 DeleteRawBuffers();
93 }
94 CleanupConsumerList();
95}
96
0c0c9d99 97int AliHLTDataBuffer::SetConsumer(AliHLTComponent* pConsumer)
3f2a1b1c 98{
70ed7d01 99 // see header file for function documentation
3f2a1b1c 100 int iResult=0;
101 if (pConsumer) {
9ce4bf4a 102 if (FindConsumer(pConsumer)) {
103 HLTWarning("consumer %s (%p) already set to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
104 }
0c0c9d99 105 AliHLTConsumerDescriptor* pDesc=new AliHLTConsumerDescriptor(pConsumer);
3f2a1b1c 106 if (pDesc) {
107 fConsumers.push_back(pDesc);
9ce4bf4a 108 HLTDebug("set consumer %s (%p) to data buffer %p", pConsumer->GetComponentID(), pConsumer, this);
3f2a1b1c 109 } else {
110 HLTError("memory allocation failed");
111 iResult=-ENOMEM;
112 }
113 } else {
9ce4bf4a 114 HLTError("invalid parameter: consumer component (nil)");
3f2a1b1c 115 iResult=-EINVAL;
116 }
117 return iResult;
118}
119
8ede8717 120int AliHLTDataBuffer::FindMatchingDataBlocks(const AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 121{
70ed7d01 122 // see header file for function documentation
0c0c9d99 123 int iResult=0;
124 if (pConsumer) {
6235cd38 125 vector<AliHLTDataBuffer::AliHLTDataSegment> segments;
0c0c9d99 126 if ((iResult=FindMatchingDataSegments(pConsumer, segments))>=0) {
127 if (tgtList) {
6235cd38 128 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=segments.begin();
0c0c9d99 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
6235cd38 142int AliHLTDataBuffer::FindMatchingDataSegments(const AliHLTComponent* pConsumer, vector<AliHLTDataBuffer::AliHLTDataSegment>& tgtList)
0c0c9d99 143{
70ed7d01 144 // see header file for function documentation
0c0c9d99 145 int iResult=0;
146 if (pConsumer) {
8ede8717 147 vector<AliHLTComponentDataType> dtlist;
0c0c9d99 148 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(dtlist);
6235cd38 149 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=fSegments.begin();
0c0c9d99 150 while (segment!=fSegments.end()) {
8ede8717 151 vector<AliHLTComponentDataType>::iterator type=dtlist.begin();
0c0c9d99 152 while (type!=dtlist.end()) {
9ce4bf4a 153 if ((*segment).fDataType==(*type) ||
154 (*type)==kAliHLTAnyDataType) {
0c0c9d99 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
8ede8717 169int AliHLTDataBuffer::Subscribe(const AliHLTComponent* pConsumer, AliHLTComponentBlockData* arrayBlockDesc, int iArraySize)
3f2a1b1c 170{
70ed7d01 171 // see header file for function documentation
3f2a1b1c 172 int iResult=0;
0c0c9d99 173 if (pConsumer && arrayBlockDesc) {
3f2a1b1c 174 if (fpBuffer) {
0c0c9d99 175 AliHLTConsumerDescriptor* pDesc=FindConsumer(pConsumer, fConsumers);
3f2a1b1c 176 if (pDesc) {
6235cd38 177 vector<AliHLTDataBuffer::AliHLTDataSegment> tgtList;
0c0c9d99 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;
6235cd38 184 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=tgtList.begin();
0c0c9d99 185 while (segment!=tgtList.end() && i<iArraySize) {
3f2a1b1c 186 // fill the block data descriptor
8ede8717 187 arrayBlockDesc[i].fStructSize=sizeof(AliHLTComponentBlockData);
3f2a1b1c 188 // the shared memory key is not used in AliRoot
8ede8717 189 arrayBlockDesc[i].fShmKey.fStructSize=sizeof(AliHLTComponentShmData);
190 arrayBlockDesc[i].fShmKey.fShmType=gkAliHLTComponentInvalidShmType;
191 arrayBlockDesc[i].fShmKey.fShmID=gkAliHLTComponentInvalidShmID;
0c0c9d99 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);
3f2a1b1c 205 } else {
0c0c9d99 206 // TODO: cleanup the consumer descriptor correctly
8ede8717 207 memset(arrayBlockDesc, 0, iArraySize*sizeof(AliHLTComponentBlockData));
3f2a1b1c 208 HLTError("can not activate consumer %p for data buffer %p", pConsumer, this);
209 iResult=-EACCES;
210 }
211 } else {
0c0c9d99 212 HLTError("unresolved data segment(s) for component %p (%s)", pConsumer, ((AliHLTComponent*)pConsumer)->GetComponentID());
3f2a1b1c 213 iResult=-EBADF;
214 }
215 } else {
0c0c9d99 216 HLTError("component %p is not a data consumer of data buffer %s", pConsumer, this);
3f2a1b1c 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
8ede8717 230int AliHLTDataBuffer::Release(AliHLTComponentBlockData* pBlockDesc, const AliHLTComponent* pConsumer)
3f2a1b1c 231{
70ed7d01 232 // see header file for function documentation
3f2a1b1c 233 int iResult=0;
234 if (pBlockDesc && pConsumer) {
0c0c9d99 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);
3f2a1b1c 243 pBlockDesc->fOffset=0;
244 pBlockDesc->fPtr=NULL;
245 pBlockDesc->fSize=0;
0c0c9d99 246 }
247 if (pDesc->GetNofActiveSegments()==0) {
3f2a1b1c 248 if ((iResult=ChangeConsumerState(pDesc, fActiveConsumers, fReleasedConsumers))>=0) {
249 if (GetNofActiveConsumers()==0) {
0c0c9d99 250 // this is the last consumer, reset the consumer list and release the raw buffer
3f2a1b1c 251 ResetDataBuffer();
3f2a1b1c 252 }
253 } else {
254 HLTError("can not deactivate consumer %p for data buffer %p", pConsumer, this);
255 iResult=-EACCES;
256 }
3f2a1b1c 257 }
0c0c9d99 258 } else {
259 HLTWarning("component %p has currently not subscribed to the data buffer %p", pConsumer, this);
260 iResult=-ENOENT;
261 }
3f2a1b1c 262 } else {
263 HLTError("inavalid parameter: pBlockDesc=%p pConsumer=%p", pBlockDesc, pConsumer);
264 iResult=-EINVAL;
265 }
266 return iResult;
267}
268
269AliHLTUInt8_t* AliHLTDataBuffer::GetTargetBuffer(int iMinSize)
270{
70ed7d01 271 // see header file for function documentation
3f2a1b1c 272 AliHLTUInt8_t* pTargetBuffer=NULL;
273 fpBuffer=CreateRawBuffer(iMinSize);
9ce4bf4a 274 if (fpBuffer) {
275 pTargetBuffer=(AliHLTUInt8_t*)fpBuffer->fPtr;
276 } else {
277 HLTError("can not create raw buffer");
278 }
3f2a1b1c 279 return pTargetBuffer;
280}
281
8ede8717 282int AliHLTDataBuffer::SetSegments(AliHLTUInt8_t* pTgt, AliHLTComponentBlockData* arrayBlockData, int iSize)
3f2a1b1c 283{
70ed7d01 284 // see header file for function documentation
3f2a1b1c 285 int iResult=0;
286 if (pTgt && arrayBlockData && iSize>=0) {
0c0c9d99 287 if (fpBuffer) {
288 if (fpBuffer->fPtr==(void*)pTgt) {
6235cd38 289 AliHLTDataBuffer::AliHLTDataSegment segment;
290 memset(&segment, 0, sizeof(AliHLTDataBuffer::AliHLTDataSegment));
0c0c9d99 291 for (int i=0; i<iSize; i++) {
9ce4bf4a 292 if (arrayBlockData[i].fOffset+arrayBlockData[i].fSize<=fpBuffer->fSize) {
0c0c9d99 293 segment.fSegmentOffset=arrayBlockData[i].fOffset;
294 segment.fSegmentSize=arrayBlockData[i].fSize;
295 segment.fDataType=arrayBlockData[i].fDataType;
296 segment.fSpecification=arrayBlockData[i].fSpecification;
297 fSegments.push_back(segment);
9ce4bf4a 298 HLTDebug("set segment %s with size %d at offset %d", AliHLTComponent::DataType2Text(segment.fDataType).data(), segment.fSegmentSize, segment.fSegmentOffset);
0c0c9d99 299 } else {
9ce4bf4a 300 HLTError("block data specification %#d (%s) exceeds size of data buffer", i, AliHLTComponent::DataType2Text(arrayBlockData[i].fDataType).data());
301 HLTError("block offset=%d, block size=%d, buffer size=%d", arrayBlockData[i].fOffset, arrayBlockData[i].fSize, fpBuffer->fSize);
8451168b 302 iResult=-E2BIG;
0c0c9d99 303 }
304 }
3f2a1b1c 305 } else {
0c0c9d99 306 HLTError("this data buffer (%p) does not match the internal data buffer %p of raw buffer %p", pTgt, fpBuffer->fPtr, fpBuffer);
8451168b 307 iResult=-EINVAL;
3f2a1b1c 308 }
0c0c9d99 309 } else {
310 HLTFatal("internal data structur missmatch");
311 iResult=-EFAULT;
3f2a1b1c 312 }
313 } else {
0c0c9d99 314 HLTError("invalid parameter: pTgtBuffer=%p arrayBlockData=%p", pTgt, arrayBlockData);
3f2a1b1c 315 iResult=-EINVAL;
316 }
317 return iResult;
318}
319
320int AliHLTDataBuffer::IsEmpty()
321{
70ed7d01 322 // see header file for function documentation
3f2a1b1c 323 int iResult=fpBuffer==NULL || GetNofSegments()==0;
324 return iResult;
325}
326
327int AliHLTDataBuffer::GetNofSegments()
328{
70ed7d01 329 // see header file for function documentation
3f2a1b1c 330 int iResult=fSegments.size();
331 return iResult;
332}
333
334int AliHLTDataBuffer::GetNofConsumers()
335{
70ed7d01 336 // see header file for function documentation
3f2a1b1c 337 int iResult=fConsumers.size() + GetNofActiveConsumers() + fReleasedConsumers.size();
338 return iResult;
339}
340
341int AliHLTDataBuffer::GetNofActiveConsumers()
342{
70ed7d01 343 // see header file for function documentation
3f2a1b1c 344 int iResult=fActiveConsumers.size();
345 return iResult;
346}
347
6235cd38 348AliHLTDataBuffer::AliHLTRawBuffer* AliHLTDataBuffer::CreateRawBuffer(AliHLTUInt32_t size)
3f2a1b1c 349{
70ed7d01 350 // see header file for function documentation
3f2a1b1c 351 AliHLTRawBuffer* pRawBuffer=NULL;
7a5ccd96 352 unsigned int reqSize=size+fgkSafetyPatternSize;
70ed7d01 353 vector<AliHLTRawBuffer*>::iterator buffer=fgFreeBuffers.begin();
354 while (buffer!=fgFreeBuffers.end() && pRawBuffer==NULL) {
8451168b 355 if ((*buffer)->fTotalSize>=reqSize && ((*buffer)->fTotalSize-reqSize)<fgMargin) {
3f2a1b1c 356 // assign this element
357 pRawBuffer=*buffer;
358 pRawBuffer->fSize=size;
70ed7d01 359 fgFreeBuffers.erase(buffer);
0c0c9d99 360 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "raw buffer container %p provided for request of %d bytes (total %d available in buffer %p)", pRawBuffer, size, pRawBuffer->fTotalSize, pRawBuffer->fPtr);
70ed7d01 361 fgActiveBuffers.push_back(pRawBuffer);
0c0c9d99 362 break;
3f2a1b1c 363 }
0c0c9d99 364 buffer++;
3f2a1b1c 365 }
366 if (pRawBuffer==NULL) {
0c0c9d99 367 // no buffer found, create a new one
3f2a1b1c 368 pRawBuffer=new AliHLTRawBuffer;
369 if (pRawBuffer) {
370 memset(pRawBuffer, 0, sizeof(AliHLTRawBuffer));
8451168b 371 pRawBuffer->fPtr=malloc(reqSize);
3f2a1b1c 372 if (pRawBuffer->fPtr) {
373 pRawBuffer->fSize=size;
8451168b 374 pRawBuffer->fTotalSize=reqSize;
70ed7d01 375 fgActiveBuffers.push_back(pRawBuffer);
0c0c9d99 376 fgLogging.Logging(kHLTLogDebug, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "new raw buffer %p of size %d created (container %p)", pRawBuffer->fPtr, pRawBuffer->fTotalSize, pRawBuffer);
8451168b 377 if (fgkSafetyPatternSize>0) {
378 memcpy(((char*)pRawBuffer->fPtr)+pRawBuffer->fSize, fgkSafetyPattern, fgkSafetyPatternSize);
379 }
3f2a1b1c 380 } else {
381 delete pRawBuffer;
382 pRawBuffer=NULL;
0c0c9d99 383 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
3f2a1b1c 384 }
385 } else {
0c0c9d99 386 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::CreateRawBuffer", "data buffer handling", "memory allocation failed");
3f2a1b1c 387 }
388 }
389 return pRawBuffer;
390}
391
392int AliHLTDataBuffer::ReleaseRawBuffer(AliHLTRawBuffer* pBuffer)
393{
70ed7d01 394 // see header file for function documentation
3f2a1b1c 395 int iResult=0;
396 if (pBuffer) {
70ed7d01 397 vector<AliHLTRawBuffer*>::iterator buffer=fgActiveBuffers.begin();
398 while (buffer!=fgActiveBuffers.end() && (*buffer)!=pBuffer) {
3f2a1b1c 399 buffer++;
400 }
70ed7d01 401 if (buffer!=fgActiveBuffers.end()) {
8451168b 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 }
3f2a1b1c 407 (*buffer)->fSize=0;
70ed7d01 408 fgFreeBuffers.push_back(*buffer);
409 fgActiveBuffers.erase(buffer);
3f2a1b1c 410 } else {
0c0c9d99 411 fgLogging.Logging(kHLTLogWarning, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "can not find raw buffer container %p in the list of active containers", pBuffer);
3f2a1b1c 412 iResult=-ENOENT;
413 }
414 } else {
0c0c9d99 415 fgLogging.Logging(kHLTLogError, "AliHLTDataBuffer::ReleaseRawBuffer", "data buffer handling", "invalid parameter");
3f2a1b1c 416 iResult=-EINVAL;
417 }
418 return iResult;
419}
420
421
422int AliHLTDataBuffer::DeleteRawBuffers()
423{
70ed7d01 424 // see header file for function documentation
3f2a1b1c 425 int iResult=0;
70ed7d01 426 vector<AliHLTRawBuffer*>::iterator buffer=fgFreeBuffers.begin();
427 while (buffer!=fgFreeBuffers.end()) {
3f2a1b1c 428 free((*buffer)->fPtr);
429 delete *buffer;
70ed7d01 430 fgFreeBuffers.erase(buffer);
431 buffer=fgFreeBuffers.begin();
3f2a1b1c 432 }
70ed7d01 433 buffer=fgActiveBuffers.begin();
434 while (buffer!=fgActiveBuffers.end()) {
0c0c9d99 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);
3f2a1b1c 436 free((*buffer)->fPtr);
437 delete *buffer;
70ed7d01 438 fgActiveBuffers.erase(buffer);
439 buffer=fgActiveBuffers.begin();
3f2a1b1c 440 }
441 return iResult;
442}
443
70ed7d01 444AliHLTConsumerDescriptor* AliHLTDataBuffer::FindConsumer(const AliHLTComponent* pConsumer, vector<AliHLTConsumerDescriptor*> &list) const
3f2a1b1c 445{
70ed7d01 446 // see header file for function documentation
3f2a1b1c 447 AliHLTConsumerDescriptor* pDesc=NULL;
448 vector<AliHLTConsumerDescriptor*>::iterator desc=list.begin();
449 while (desc!=list.end() && pDesc==NULL) {
0c0c9d99 450 if ((pConsumer==NULL || (*desc)->GetComponent()==pConsumer)) {
3f2a1b1c 451 pDesc=*desc;
452 }
0c0c9d99 453 desc++;
3f2a1b1c 454 }
455 return pDesc;
456}
457
0c0c9d99 458int AliHLTDataBuffer::ResetDataBuffer()
459{
70ed7d01 460 // see header file for function documentation
3f2a1b1c 461 int iResult=0;
0c0c9d99 462 AliHLTRawBuffer* pBuffer=fpBuffer;
3f2a1b1c 463 fpBuffer=NULL;
9ce4bf4a 464
465 // cleanup consumer states
3f2a1b1c 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 }
9ce4bf4a 481
482 // cleanup segments
6235cd38 483 vector<AliHLTDataBuffer::AliHLTDataSegment>::iterator segment=fSegments.begin();
9ce4bf4a 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 }
3f2a1b1c 493 return iResult;
494}
495
9ce4bf4a 496int AliHLTDataBuffer::Reset()
497{
70ed7d01 498 // see header file for function documentation
9ce4bf4a 499 return ResetDataBuffer();
500}
501
0c0c9d99 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
3f2a1b1c 527int AliHLTDataBuffer::ChangeConsumerState(AliHLTConsumerDescriptor* pDesc, vector<AliHLTConsumerDescriptor*> &srcList, vector<AliHLTConsumerDescriptor*> &tgtList)
528{
70ed7d01 529 // see header file for function documentation
9ce4bf4a 530 int iResult=-ENOENT;
3f2a1b1c 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);
9ce4bf4a 537 iResult=0;
3f2a1b1c 538 break;
539 }
0c0c9d99 540 desc++;
3f2a1b1c 541 }
9ce4bf4a 542 if (iResult<0) {
3f2a1b1c 543 HLTError("can not find consumer descriptor %p in list", pDesc);
3f2a1b1c 544 }
545 } else {
546 HLTError("invalid parameter");
547 iResult=-EINVAL;
548 }
549 return iResult;
550}
551
70ed7d01 552int AliHLTDataBuffer::CleanupConsumerList()
553{
554 // see header file for function documentation
3f2a1b1c 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}
9ce4bf4a 565
70ed7d01 566int AliHLTDataBuffer::FindConsumer(AliHLTComponent* pConsumer, int bAllLists)
567{
568 // see header file for function documentation
9ce4bf4a 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}