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