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