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