Additional protection
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
CommitLineData
f23a6e1a 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 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
f23a6e1a 8 * for The ALICE Off-line 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
bfccbf68 19/** @file AliHLTComponent.cxx
20 @author Matthias Richter, Timm Steinbeck
21 @date
22 @brief Base class implementation for HLT components. */
f23a6e1a 23
0c0c9d99 24#if __GNUC__>= 3
f23a6e1a 25using namespace std;
26#endif
27
85869391 28#include "AliHLTStdIncludes.h"
f23a6e1a 29#include "AliHLTComponent.h"
30#include "AliHLTComponentHandler.h"
a655eae3 31#include "AliHLTMessage.h"
70ed7d01 32#include "TString.h"
a655eae3 33#include "TObjArray.h"
34#include "TClass.h"
f23a6e1a 35
b22e91eb 36/** ROOT macro for the implementation of ROOT specific class methods */
f23a6e1a 37ClassImp(AliHLTComponent)
38
f23a6e1a 39AliHLTComponent::AliHLTComponent()
85869391 40 :
53feaef5 41 fEnvironment(),
3cde846d 42 fCurrentEvent(0),
a655eae3 43 fEventCount(-1),
44 fFailedEvents(0),
45 fCurrentEventData(),
46 fpInputBlocks(NULL),
47 fCurrentInputBlock(-1),
48 fSearchDataType(kAliHLTVoidDataType),
49 fClassName(),
50 fpInputObjects(NULL),
51 fpOutputBuffer(NULL),
52 fOutputBufferSize(0),
53 fOutputBufferFilled(0),
54 fOutputBlocks()
70ed7d01 55{
56 // see header file for class documentation
57 // or
58 // refer to README to build package
59 // or
60 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
f23a6e1a 61 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
70ed7d01 62 if (fgpComponentHandler)
63 fgpComponentHandler->ScheduleRegister(this);
64}
65
66AliHLTComponent::AliHLTComponent(const AliHLTComponent&)
67 :
68 fEnvironment(),
69 fCurrentEvent(0),
a655eae3 70 fEventCount(-1),
71 fFailedEvents(0),
72 fCurrentEventData(),
73 fpInputBlocks(NULL),
74 fCurrentInputBlock(-1),
75 fSearchDataType(kAliHLTVoidDataType),
76 fClassName(),
77 fpInputObjects(NULL),
78 fpOutputBuffer(NULL),
79 fOutputBufferSize(0),
80 fOutputBufferFilled(0),
81 fOutputBlocks()
70ed7d01 82{
83 // see header file for class documentation
84 HLTFatal("copy constructor untested");
85}
86
87AliHLTComponent& AliHLTComponent::operator=(const AliHLTComponent&)
88{
89 // see header file for class documentation
90 HLTFatal("assignment operator untested");
91 return *this;
f23a6e1a 92}
93
94AliHLTComponent::~AliHLTComponent()
95{
70ed7d01 96 // see header file for function documentation
f23a6e1a 97}
98
70ed7d01 99AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
b22e91eb 100
85869391 101int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
102{
70ed7d01 103 // see header file for function documentation
85869391 104 int iResult=0;
70ed7d01 105 if (fgpComponentHandler==NULL || bOverwrite!=0)
106 fgpComponentHandler=pCH;
85869391 107 else
108 iResult=-EPERM;
109 return iResult;
110}
111
70ed7d01 112int AliHLTComponent::UnsetGlobalComponentHandler()
113{
114 // see header file for function documentation
85869391 115 return SetGlobalComponentHandler(NULL,1);
116}
117
70ed7d01 118int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv )
f23a6e1a 119{
70ed7d01 120 // see header file for function documentation
f23a6e1a 121 int iResult=0;
122 if (environ) {
123 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
70ed7d01 124 fEnvironment.fParam=environParam;
f23a6e1a 125 }
126 iResult=DoInit(argc, argv);
3cde846d 127 if (iResult>=0) fEventCount=0;
f23a6e1a 128 return iResult;
129}
130
131int AliHLTComponent::Deinit()
132{
70ed7d01 133 // see header file for function documentation
f23a6e1a 134 int iResult=0;
135 iResult=DoDeinit();
136 return iResult;
137}
fa2e9b7c 138
53feaef5 139int AliHLTComponent::DoInit( int argc, const char** argv )
140{
70ed7d01 141 // see header file for function documentation
53feaef5 142 if (argc==0 && argv==NULL) {
143 // this is currently just to get rid of the warning "unused parameter"
144 }
145 return 0;
146}
147
148int AliHLTComponent::DoDeinit()
149{
70ed7d01 150 // see header file for function documentation
53feaef5 151 return 0;
152}
153
70ed7d01 154void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
155{
156 // see header file for function documentation
9ce4bf4a 157 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
158 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
159 strcat( output, ":" );
160 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
fa2e9b7c 161}
162
9ce4bf4a 163string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
164{
70ed7d01 165 // see header file for function documentation
9ce4bf4a 166 string out("");
3cde846d 167
9ce4bf4a 168 if (type==kAliHLTVoidDataType) {
169 out="VOID:VOID";
170 } else {
3cde846d 171 // some gymnastics in order to avoid a '0' which is part of either or both
172 // ID and origin terminating the whole string. Unfortunately, string doesn't
173 // stop appending at the '0' if the number of elements to append was
174 // explicitely specified
175 string tmp("");
176 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
177 out.append(tmp.c_str());
9ce4bf4a 178 out.append(":");
3cde846d 179 tmp="";
180 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
181 out.append(tmp.c_str());
9ce4bf4a 182 }
183 return out;
184}
185
186
70ed7d01 187void* AliHLTComponent::AllocMemory( unsigned long size )
188{
189 // see header file for function documentation
85869391 190 if (fEnvironment.fAllocMemoryFunc)
191 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
9ce4bf4a 192 HLTFatal("no memory allocation handler registered");
85869391 193 return NULL;
194}
195
8ede8717 196int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
70ed7d01 197 AliHLTComponentBlockData** outputBlocks )
198{
199 // see header file for function documentation
9ce4bf4a 200 if ( blockCount==NULL || outputBlocks==NULL )
2d7ff710 201 return -EFAULT;
fa2e9b7c 202 AliHLTUInt32_t count = blocks.size();
203 if ( !count )
204 {
205 *blockCount = 0;
206 *outputBlocks = NULL;
207 return 0;
208 }
8ede8717 209 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
fa2e9b7c 210 if ( !*outputBlocks )
2d7ff710 211 return -ENOMEM;
ca8524df 212 for ( unsigned long i = 0; i < count; i++ ) {
fa2e9b7c 213 (*outputBlocks)[i] = blocks[i];
ca8524df 214 if (blocks[i].fDataType==kAliHLTAnyDataType) {
215 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
216 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
217 }
218 }
fa2e9b7c 219 *blockCount = count;
220 return 0;
221
222}
0c0c9d99 223
70ed7d01 224int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
225{
226 // see header file for function documentation
85869391 227 if (fEnvironment.fGetEventDoneDataFunc)
228 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
229 return -ENOSYS;
230}
231
8ede8717 232int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 233{
70ed7d01 234 // see header file for function documentation
0c0c9d99 235 int iResult=0;
236 if (pConsumer) {
8ede8717 237 vector<AliHLTComponentDataType> ctlist;
0c0c9d99 238 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
8ede8717 239 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
0c0c9d99 240 while (type!=ctlist.end() && iResult==0) {
9ce4bf4a 241 if ((*type)==GetOutputDataType() ||
242 (*type)==kAliHLTAnyDataType) {
0c0c9d99 243 if (tgtList) tgtList->push_back(*type);
244 iResult++;
9ce4bf4a 245 // this loop has to be changed in case of multiple output types
0c0c9d99 246 break;
247 }
248 type++;
249 }
250 } else {
251 iResult=-EINVAL;
252 }
253 return iResult;
254}
2d7ff710 255
70ed7d01 256void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const
257{
258 // see header file for function documentation
2d7ff710 259 blockData.fStructSize = sizeof(blockData);
260 FillShmData( blockData.fShmKey );
261 blockData.fOffset = ~(AliHLTUInt32_t)0;
262 blockData.fPtr = NULL;
263 blockData.fSize = 0;
264 FillDataType( blockData.fDataType );
a655eae3 265 blockData.fSpecification = kAliHLTVoidDataSpec;
2d7ff710 266}
267
70ed7d01 268void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const
269{
270 // see header file for function documentation
2d7ff710 271 shmData.fStructSize = sizeof(shmData);
272 shmData.fShmType = gkAliHLTComponentInvalidShmType;
273 shmData.fShmID = gkAliHLTComponentInvalidShmID;
274}
275
70ed7d01 276void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const
277{
278 // see header file for function documentation
ca8524df 279 dataType=kAliHLTAnyDataType;
2d7ff710 280}
281
70ed7d01 282void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
283{
284 // see header file for function documentation
2d7ff710 285 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
286 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
287}
288
70ed7d01 289void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
290{
291 // see header file for function documentation
2d7ff710 292 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
293 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
294 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
295
9ce4bf4a 296 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
2d7ff710 297 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
298 }
299 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
300
9ce4bf4a 301 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
2d7ff710 302 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
303 }
304 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
305}
9ce4bf4a 306
307void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
308{
70ed7d01 309 // see header file for function documentation
9ce4bf4a 310 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
311 evtData.fStructSize=sizeof(AliHLTComponentEventData);
312}
313
70ed7d01 314void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
315{
316 // see header file for function documentation
9ce4bf4a 317 TString msg;
318 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
319 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
320 if (dt.fID[i]!=0) msg+=dt.fID[i];
321 else msg+="\\0";
322 }
323 msg+="\" Origin=\"";
324 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
325 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
326 else msg+="\\0";
327 }
328 msg+="\"";
3cde846d 329 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
9ce4bf4a 330}
331
70ed7d01 332int AliHLTComponent::GetEventCount() const
3cde846d 333{
70ed7d01 334 // see header file for function documentation
3cde846d 335 return fEventCount;
336}
337
338int AliHLTComponent::IncrementEventCounter()
339{
70ed7d01 340 // see header file for function documentation
3cde846d 341 if (fEventCount>=0) fEventCount++;
342 return fEventCount;
343}
344
a655eae3 345int AliHLTComponent::GetNumberOfInputBlocks()
346{
347 // see header file for function documentation
348 if (fpInputBlocks!=NULL) {
349 return fCurrentEventData.fBlockCnt;
350 }
351 return 0;
352}
353
354const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
355 const char* classname,
356 int bForce)
357{
358 // see header file for function documentation
359 fSearchDataType=dt;
360 if (classname) fClassName=classname;
361 else fClassName.clear();
362 int idx=FindInputBlock(fSearchDataType, 0);
363 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
364 TObject* pObj=NULL;
365 if (idx>=0) {
366 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
367 fCurrentInputBlock=idx;
368 } else {
369 }
370 }
371 return pObj;
372}
373
374const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
375 const char* dtOrigin,
376 const char* classname,
377 int bForce)
378{
379 // see header file for function documentation
380 AliHLTComponentDataType dt;
381 SetDataType(dt, dtID, dtOrigin);
382 return GetFirstInputObject(dt, classname, bForce);
383}
384
385const TObject* AliHLTComponent::GetNextInputObject(int bForce)
386{
387 // see header file for function documentation
388 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
389 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
390 TObject* pObj=NULL;
391 if (idx>=0) {
392 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
393 fCurrentInputBlock=idx;
394 }
395 }
396 return pObj;
397}
398
399int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx)
400{
401 // see header file for function documentation
402 int iResult=-ENOENT;
403 if (fpInputBlocks!=NULL) {
404 int idx=startIdx<0?0:startIdx;
4b98eadb 405 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
a655eae3 406 if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
407 iResult=idx;
408 }
409 }
410 }
411 return iResult;
412}
413
414TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
415{
416 // see header file for function documentation
417 TObject* pObj=NULL;
418 if (fpInputBlocks!=NULL) {
4b98eadb 419 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 420 if (fpInputBlocks[idx].fPtr) {
421 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
422 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
423 //HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
424 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
425 pObj=msg.ReadObject(msg.GetClass());
426 if (pObj && msg.GetClass()) {
427 //HLTDebug("object %p type %s created", pObj, msg.GetClass()->GetName());
428 } else {
429 }
430 } else {
431 // } else if (bForce!=0) {
432 HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
433 }
434 } else {
435 HLTFatal("block descriptor empty");
436 }
437 } else {
438 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
439 }
440 } else {
441 HLTError("no input blocks available");
442 }
443
444 return pObj;
445}
446
447TObject* AliHLTComponent::GetInputObject(int idx, const char* classname, int bForce)
448{
449 // see header file for function documentation
450 if (fpInputObjects==NULL) {
451 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
452 }
453 TObject* pObj=NULL;
454 if (fpInputObjects) {
455 pObj=fpInputObjects->At(idx);
456 if (pObj==NULL) {
457 pObj=CreateInputObject(idx, bForce);
458 if (pObj) {
459 fpInputObjects->AddAt(pObj, idx);
460 }
461 }
462 } else {
463 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
464 }
465 return pObj;
466}
467
468AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
469{
470 // see header file for function documentation
471 AliHLTComponentDataType dt=kAliHLTVoidDataType;
472 int idx=fCurrentInputBlock;
473 if (pObject) {
474 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
475 } else {
476 HLTError("unknown object %p", pObject);
477 }
478 }
479 if (idx>=0) {
4b98eadb 480 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 481 dt=fpInputBlocks[idx].fDataType;
482 } else {
483 HLTFatal("severe internal error, index out of range");
484 }
485 }
486 return dt;
487}
488
489AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
490{
491 // see header file for function documentation
492 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
493 int idx=fCurrentInputBlock;
494 if (pObject) {
495 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
496 } else {
497 HLTError("unknown object %p", pObject);
498 }
499 }
500 if (idx>=0) {
4b98eadb 501 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 502 iSpec=fpInputBlocks[idx].fSpecification;
503 } else {
504 HLTFatal("severe internal error, index out of range");
505 }
506 }
507 return iSpec;
508}
509
510const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
511{
512 // see header file for function documentation
513 fSearchDataType=dt;
514 fClassName.clear();
515 int idx=FindInputBlock(fSearchDataType, 0);
516 const AliHLTComponentBlockData* pBlock=NULL;
517 if (idx>=0) {
518 // check for fpInputBlocks pointer done in FindInputBlock
519 pBlock=&fpInputBlocks[idx];
520 }
521 return pBlock;
522}
523
524const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
525 const char* dtOrigin)
526{
527 // see header file for function documentation
528 AliHLTComponentDataType dt;
529 SetDataType(dt, dtID, dtOrigin);
530 return GetFirstInputBlock(dt);
531}
532
533const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
534{
535 // see header file for function documentation
536 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
537 const AliHLTComponentBlockData* pBlock=NULL;
538 if (idx>=0) {
539 // check for fpInputBlocks pointer done in FindInputBlock
540 pBlock=&fpInputBlocks[idx];
541 }
542 return pBlock;
543}
544
545int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock)
546{
547 // see header file for function documentation
548 int iResult=-ENOENT;
549 if (fpInputBlocks!=NULL) {
550 if (pBlock) {
551 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
132ca004 552 iResult=(int)(pBlock-fpInputBlocks);
a655eae3 553 }
554 } else {
555 iResult=-EINVAL;
556 }
557 }
558 return iResult;
559}
560
561AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
562{
563 // see header file for function documentation
564 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
565 int idx=fCurrentInputBlock;
566 if (pBlock) {
567 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
568 } else {
569 HLTError("unknown Block %p", pBlock);
570 }
571 }
572 if (idx>=0) {
573 // check for fpInputBlocks pointer done in FindInputBlock
574 iSpec=fpInputBlocks[idx].fSpecification;
575 }
576 return iSpec;
577}
578
579int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
580{
581 // see header file for function documentation
582 int iResult=0;
583 if (pObject) {
584 AliHLTMessage msg(kMESS_OBJECT);
585 msg.WriteObject(pObject);
586 Int_t iMsgLength=msg.Length();
587 if (iMsgLength>0) {
588 msg.SetLength(); // sets the length to the first (reserved) word
589 iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec);
590 if (iResult>=0) {
591 //HLTDebug("object %s (%p) inserted to output", pObject->ClassName(), pObject);
592 }
593 } else {
594 HLTError("object serialization failed for object %p", pObject);
595 iResult=-ENOMSG;
596 }
597 } else {
598 iResult=-EINVAL;
599 }
600 return iResult;
601}
602
603int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
604{
605 // see header file for function documentation
606 AliHLTComponentDataType dt;
607 SetDataType(dt, dtID, dtOrigin);
608 return PushBack(pObject, dt, spec);
609}
610
611int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
612{
613 // see header file for function documentation
614 return InsertOutputBlock(pBuffer, iSize, dt, spec);
615}
616
617int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
618{
619 // see header file for function documentation
620 AliHLTComponentDataType dt;
621 SetDataType(dt, dtID, dtOrigin);
622 return PushBack(pBuffer, iSize, dt, spec);
623}
624
625int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
626{
627 // see header file for function documentation
628 int iResult=0;
629 if (pBuffer) {
630 if (fpOutputBuffer && (fOutputBufferSize-fOutputBufferFilled)) {
631 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
632 AliHLTComponentBlockData bd;
633 FillBlockData( bd );
634 bd.fOffset = fOutputBufferFilled;
635 bd.fPtr = pTgt;
636 bd.fSize = iSize;
637 bd.fDataType = dt;
638 bd.fSpecification = spec;
639 if (pBuffer!=NULL && pBuffer!=pTgt) {
640 memcpy(pTgt, pBuffer, iSize);
4b98eadb 641 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
a655eae3 642 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iSize, pBuffer, pTgt, firstWord);
643 }
644 fOutputBufferFilled+=bd.fSize;
645 fOutputBlocks.push_back( bd );
646 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iSize, DataType2Text(dt).c_str(), spec);
647 } else {
648 if (fpOutputBuffer) {
649 HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iSize);
650 } else {
651 HLTError("output buffer not available");
652 }
653 iResult=-ENOSPC;
654 }
655 } else {
656 iResult=-EINVAL;
657 }
658 return iResult;
659}
660
661int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
662{
663 // see header file for function documentation
664 int iResult=-ENOSYS;
665 //#warning function not yet implemented
666 HLTWarning("function not yet implemented");
667 return iResult;
668}
669
3cde846d 670int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
671 const AliHLTComponentBlockData* blocks,
672 AliHLTComponentTriggerData& trigData,
673 AliHLTUInt8_t* outputPtr,
674 AliHLTUInt32_t& size,
675 AliHLTUInt32_t& outputBlockCnt,
676 AliHLTComponentBlockData*& outputBlocks,
677 AliHLTComponentEventDoneData*& edd )
678{
70ed7d01 679 // see header file for function documentation
3cde846d 680 int iResult=0;
681 fCurrentEvent=evtData.fEventID;
a655eae3 682 fCurrentEventData=evtData;
683 fpInputBlocks=blocks;
684 fCurrentInputBlock=-1;
685 fSearchDataType=kAliHLTAnyDataType;
686 fpOutputBuffer=outputPtr;
687 fOutputBufferSize=size;
688 fOutputBufferFilled=0;
689 fOutputBlocks.clear();
690
691 vector<AliHLTComponentBlockData> blockData;
692 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
693 if (iResult>=0) {
694 if (fOutputBlocks.size()>0) {
695 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
696 if (blockData.size()>0) {
697 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
698 iResult=-EFAULT;
699 } else {
700 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
701 size=fOutputBufferFilled;
702 }
703 } else {
704 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
705 }
706 if (iResult<0) {
707 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
708 }
709 }
710 if (iResult<0) {
711 outputBlockCnt=0;
712 outputBlocks=NULL;
713 }
3cde846d 714 IncrementEventCounter();
715 return iResult;
716}
a655eae3 717