Getter for dipole position needed by MUON. (G. Martinez)
[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"
90ebac25 35#include "TStopwatch.h"
f23a6e1a 36
b22e91eb 37/** ROOT macro for the implementation of ROOT specific class methods */
90ebac25 38ClassImp(AliHLTComponent);
39
40/** stopwatch macro using the stopwatch guard */
41#define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
42//#define ALIHLTCOMPONENT_STOPWATCH(type)
43
44/** stopwatch macro for operations of the base class */
45#define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
46/** stopwatch macro for operations of the detector algorithm (DA) */
47#define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
f23a6e1a 48
f23a6e1a 49AliHLTComponent::AliHLTComponent()
85869391 50 :
53feaef5 51 fEnvironment(),
3cde846d 52 fCurrentEvent(0),
a655eae3 53 fEventCount(-1),
54 fFailedEvents(0),
55 fCurrentEventData(),
56 fpInputBlocks(NULL),
57 fCurrentInputBlock(-1),
58 fSearchDataType(kAliHLTVoidDataType),
59 fClassName(),
60 fpInputObjects(NULL),
61 fpOutputBuffer(NULL),
62 fOutputBufferSize(0),
63 fOutputBufferFilled(0),
90ebac25 64 fOutputBlocks(),
65 fpStopwatches(new TObjArray(kSWTypeCount))
70ed7d01 66{
67 // see header file for class documentation
68 // or
69 // refer to README to build package
70 // or
71 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
f23a6e1a 72 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
70ed7d01 73 if (fgpComponentHandler)
74 fgpComponentHandler->ScheduleRegister(this);
8451168b 75 SetLocalLoggingLevel(kHLTLogDefault);
70ed7d01 76}
77
78AliHLTComponent::AliHLTComponent(const AliHLTComponent&)
79 :
9253e11b 80 AliHLTLogging(),
70ed7d01 81 fEnvironment(),
82 fCurrentEvent(0),
a655eae3 83 fEventCount(-1),
84 fFailedEvents(0),
85 fCurrentEventData(),
86 fpInputBlocks(NULL),
87 fCurrentInputBlock(-1),
88 fSearchDataType(kAliHLTVoidDataType),
89 fClassName(),
90 fpInputObjects(NULL),
91 fpOutputBuffer(NULL),
92 fOutputBufferSize(0),
93 fOutputBufferFilled(0),
90ebac25 94 fOutputBlocks(),
95 fpStopwatches(NULL)
70ed7d01 96{
97 // see header file for class documentation
98 HLTFatal("copy constructor untested");
99}
100
101AliHLTComponent& AliHLTComponent::operator=(const AliHLTComponent&)
102{
103 // see header file for class documentation
104 HLTFatal("assignment operator untested");
105 return *this;
f23a6e1a 106}
107
108AliHLTComponent::~AliHLTComponent()
109{
70ed7d01 110 // see header file for function documentation
8451168b 111 CleanupInputObjects();
f23a6e1a 112}
113
70ed7d01 114AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
b22e91eb 115
85869391 116int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
117{
70ed7d01 118 // see header file for function documentation
85869391 119 int iResult=0;
70ed7d01 120 if (fgpComponentHandler==NULL || bOverwrite!=0)
121 fgpComponentHandler=pCH;
85869391 122 else
123 iResult=-EPERM;
124 return iResult;
125}
126
70ed7d01 127int AliHLTComponent::UnsetGlobalComponentHandler()
128{
129 // see header file for function documentation
85869391 130 return SetGlobalComponentHandler(NULL,1);
131}
132
70ed7d01 133int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv )
f23a6e1a 134{
70ed7d01 135 // see header file for function documentation
f23a6e1a 136 int iResult=0;
137 if (environ) {
138 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
70ed7d01 139 fEnvironment.fParam=environParam;
f23a6e1a 140 }
8451168b 141 const char** pArguments=NULL;
142 int iNofChildArgs=0;
143 TString argument="";
144 int bMissingParam=0;
145 if (argc>0) {
146 pArguments=new const char*[argc];
147 if (pArguments) {
148 for (int i=0; i<argc && iResult>=0; i++) {
149 argument=argv[i];
150 if (argument.IsNull()) continue;
151
152 // benchmark
153 if (argument.CompareTo("benchmark")==0) {
154
155 // loglevel
156 } else if (argument.CompareTo("loglevel")==0) {
157 if ((bMissingParam=(++i>=argc))) break;
158 TString parameter(argv[i]);
159 parameter.Remove(TString::kLeading, ' '); // remove all blanks
160 if (parameter.BeginsWith("0x") &&
161 parameter.Replace(0,2,"",0).IsHex()) {
162 AliHLTComponentLogSeverity loglevel=kHLTLogNone;
7a5ccd96 163 sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel);
8451168b 164 SetLocalLoggingLevel(loglevel);
165 } else {
166 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
167 iResult=-EINVAL;
168 }
169 } else {
170 pArguments[iNofChildArgs++]=argv[i];
171 }
172 }
173 } else {
174 iResult=-ENOMEM;
175 }
176 }
177 if (bMissingParam) {
178 HLTError("missing parameter for argument %s", argument.Data());
179 iResult=-EINVAL;
180 }
181 if (iResult>=0) {
182 iResult=DoInit(iNofChildArgs, pArguments);
183 }
3cde846d 184 if (iResult>=0) fEventCount=0;
8451168b 185 if (pArguments) delete [] pArguments;
f23a6e1a 186 return iResult;
187}
188
189int AliHLTComponent::Deinit()
190{
70ed7d01 191 // see header file for function documentation
f23a6e1a 192 int iResult=0;
193 iResult=DoDeinit();
194 return iResult;
195}
fa2e9b7c 196
53feaef5 197int AliHLTComponent::DoInit( int argc, const char** argv )
198{
70ed7d01 199 // see header file for function documentation
53feaef5 200 if (argc==0 && argv==NULL) {
201 // this is currently just to get rid of the warning "unused parameter"
202 }
203 return 0;
204}
205
206int AliHLTComponent::DoDeinit()
207{
70ed7d01 208 // see header file for function documentation
53feaef5 209 return 0;
210}
211
70ed7d01 212void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
213{
214 // see header file for function documentation
9ce4bf4a 215 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
216 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
217 strcat( output, ":" );
218 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
fa2e9b7c 219}
220
9ce4bf4a 221string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
222{
70ed7d01 223 // see header file for function documentation
9ce4bf4a 224 string out("");
3cde846d 225
9ce4bf4a 226 if (type==kAliHLTVoidDataType) {
227 out="VOID:VOID";
228 } else {
3cde846d 229 // some gymnastics in order to avoid a '0' which is part of either or both
230 // ID and origin terminating the whole string. Unfortunately, string doesn't
231 // stop appending at the '0' if the number of elements to append was
232 // explicitely specified
233 string tmp("");
234 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
235 out.append(tmp.c_str());
9ce4bf4a 236 out.append(":");
3cde846d 237 tmp="";
238 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
239 out.append(tmp.c_str());
9ce4bf4a 240 }
241 return out;
242}
243
244
70ed7d01 245void* AliHLTComponent::AllocMemory( unsigned long size )
246{
247 // see header file for function documentation
85869391 248 if (fEnvironment.fAllocMemoryFunc)
249 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
9ce4bf4a 250 HLTFatal("no memory allocation handler registered");
85869391 251 return NULL;
252}
253
8ede8717 254int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
70ed7d01 255 AliHLTComponentBlockData** outputBlocks )
256{
257 // see header file for function documentation
9ce4bf4a 258 if ( blockCount==NULL || outputBlocks==NULL )
2d7ff710 259 return -EFAULT;
fa2e9b7c 260 AliHLTUInt32_t count = blocks.size();
261 if ( !count )
262 {
263 *blockCount = 0;
264 *outputBlocks = NULL;
265 return 0;
266 }
8ede8717 267 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
fa2e9b7c 268 if ( !*outputBlocks )
2d7ff710 269 return -ENOMEM;
ca8524df 270 for ( unsigned long i = 0; i < count; i++ ) {
fa2e9b7c 271 (*outputBlocks)[i] = blocks[i];
ca8524df 272 if (blocks[i].fDataType==kAliHLTAnyDataType) {
5f5b708b 273 (*outputBlocks)[i].fDataType=GetOutputDataType();
274 /* data type was set to the output data type by the PubSub AliRoot
275 Wrapper component, if data type of the block was ********:****.
276 Now handled by the component base class in order to have same
277 behavior when running embedded in AliRoot
ca8524df 278 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
279 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
5f5b708b 280 */
ca8524df 281 }
282 }
fa2e9b7c 283 *blockCount = count;
284 return 0;
285
286}
0c0c9d99 287
70ed7d01 288int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
289{
290 // see header file for function documentation
85869391 291 if (fEnvironment.fGetEventDoneDataFunc)
292 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
293 return -ENOSYS;
294}
295
8ede8717 296int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 297{
70ed7d01 298 // see header file for function documentation
0c0c9d99 299 int iResult=0;
300 if (pConsumer) {
8ede8717 301 vector<AliHLTComponentDataType> ctlist;
0c0c9d99 302 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
8ede8717 303 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
5f5b708b 304 //AliHLTComponentDataType ouptdt=GetOutputDataType();
305 //PrintDataTypeContent(ouptdt, "publisher \'%s\'");
0c0c9d99 306 while (type!=ctlist.end() && iResult==0) {
5f5b708b 307 //PrintDataTypeContent((*type), "consumer \'%s\'");
9ce4bf4a 308 if ((*type)==GetOutputDataType() ||
309 (*type)==kAliHLTAnyDataType) {
0c0c9d99 310 if (tgtList) tgtList->push_back(*type);
311 iResult++;
9ce4bf4a 312 // this loop has to be changed in case of multiple output types
0c0c9d99 313 break;
314 }
315 type++;
316 }
317 } else {
318 iResult=-EINVAL;
319 }
320 return iResult;
321}
2d7ff710 322
5f5b708b 323void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const
324{
325 const char* fmt="publisher \'%s\'";
326 if (format) fmt=format;
327 HLTMessage(fmt, (DataType2Text(dt)).c_str());
328 HLTMessage("%x %x %x %x %x %x %x %x : %x %x %x %x",
329 dt.fID[0],
330 dt.fID[1],
331 dt.fID[2],
332 dt.fID[3],
333 dt.fID[4],
334 dt.fID[5],
335 dt.fID[6],
336 dt.fID[7],
337 dt.fOrigin[0],
338 dt.fOrigin[1],
339 dt.fOrigin[2],
340 dt.fOrigin[3]);
341}
342
70ed7d01 343void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const
344{
345 // see header file for function documentation
2d7ff710 346 blockData.fStructSize = sizeof(blockData);
347 FillShmData( blockData.fShmKey );
348 blockData.fOffset = ~(AliHLTUInt32_t)0;
349 blockData.fPtr = NULL;
350 blockData.fSize = 0;
351 FillDataType( blockData.fDataType );
a655eae3 352 blockData.fSpecification = kAliHLTVoidDataSpec;
2d7ff710 353}
354
70ed7d01 355void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const
356{
357 // see header file for function documentation
2d7ff710 358 shmData.fStructSize = sizeof(shmData);
359 shmData.fShmType = gkAliHLTComponentInvalidShmType;
360 shmData.fShmID = gkAliHLTComponentInvalidShmID;
361}
362
70ed7d01 363void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const
364{
365 // see header file for function documentation
ca8524df 366 dataType=kAliHLTAnyDataType;
2d7ff710 367}
368
70ed7d01 369void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
370{
371 // see header file for function documentation
2d7ff710 372 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
373 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
374}
375
70ed7d01 376void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
377{
378 // see header file for function documentation
2d7ff710 379 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
380 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
381 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
382
9ce4bf4a 383 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
2d7ff710 384 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
385 }
386 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
387
9ce4bf4a 388 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
2d7ff710 389 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
390 }
391 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
392}
9ce4bf4a 393
394void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
395{
70ed7d01 396 // see header file for function documentation
9ce4bf4a 397 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
398 evtData.fStructSize=sizeof(AliHLTComponentEventData);
399}
400
70ed7d01 401void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
402{
403 // see header file for function documentation
9ce4bf4a 404 TString msg;
405 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
406 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
407 if (dt.fID[i]!=0) msg+=dt.fID[i];
408 else msg+="\\0";
409 }
410 msg+="\" Origin=\"";
411 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
412 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
413 else msg+="\\0";
414 }
415 msg+="\"";
3cde846d 416 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
9ce4bf4a 417}
418
70ed7d01 419int AliHLTComponent::GetEventCount() const
3cde846d 420{
70ed7d01 421 // see header file for function documentation
3cde846d 422 return fEventCount;
423}
424
425int AliHLTComponent::IncrementEventCounter()
426{
70ed7d01 427 // see header file for function documentation
3cde846d 428 if (fEventCount>=0) fEventCount++;
429 return fEventCount;
430}
431
a655eae3 432int AliHLTComponent::GetNumberOfInputBlocks()
433{
434 // see header file for function documentation
435 if (fpInputBlocks!=NULL) {
436 return fCurrentEventData.fBlockCnt;
437 }
438 return 0;
439}
440
441const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
442 const char* classname,
443 int bForce)
444{
445 // see header file for function documentation
90ebac25 446 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 447 fSearchDataType=dt;
448 if (classname) fClassName=classname;
449 else fClassName.clear();
450 int idx=FindInputBlock(fSearchDataType, 0);
8451168b 451 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
a655eae3 452 TObject* pObj=NULL;
453 if (idx>=0) {
454 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
455 fCurrentInputBlock=idx;
456 } else {
457 }
458 }
459 return pObj;
460}
461
462const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
463 const char* dtOrigin,
464 const char* classname,
465 int bForce)
466{
467 // see header file for function documentation
90ebac25 468 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 469 AliHLTComponentDataType dt;
470 SetDataType(dt, dtID, dtOrigin);
471 return GetFirstInputObject(dt, classname, bForce);
472}
473
474const TObject* AliHLTComponent::GetNextInputObject(int bForce)
475{
476 // see header file for function documentation
90ebac25 477 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 478 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
479 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
480 TObject* pObj=NULL;
481 if (idx>=0) {
482 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
483 fCurrentInputBlock=idx;
484 }
485 }
486 return pObj;
487}
488
489int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx)
490{
491 // see header file for function documentation
492 int iResult=-ENOENT;
493 if (fpInputBlocks!=NULL) {
494 int idx=startIdx<0?0:startIdx;
4b98eadb 495 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
a655eae3 496 if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
497 iResult=idx;
498 }
499 }
500 }
501 return iResult;
502}
503
504TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
505{
506 // see header file for function documentation
507 TObject* pObj=NULL;
508 if (fpInputBlocks!=NULL) {
4b98eadb 509 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 510 if (fpInputBlocks[idx].fPtr) {
511 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
512 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
8451168b 513 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
a655eae3 514 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
515 pObj=msg.ReadObject(msg.GetClass());
516 if (pObj && msg.GetClass()) {
8451168b 517 HLTDebug("object %p type %s created", pObj, msg.GetClass()->GetName());
a655eae3 518 } else {
519 }
520 } else {
521 // } else if (bForce!=0) {
522 HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
523 }
524 } else {
525 HLTFatal("block descriptor empty");
526 }
527 } else {
528 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
529 }
530 } else {
531 HLTError("no input blocks available");
532 }
533
534 return pObj;
535}
536
537TObject* AliHLTComponent::GetInputObject(int idx, const char* classname, int bForce)
538{
539 // see header file for function documentation
540 if (fpInputObjects==NULL) {
541 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
542 }
543 TObject* pObj=NULL;
544 if (fpInputObjects) {
545 pObj=fpInputObjects->At(idx);
546 if (pObj==NULL) {
547 pObj=CreateInputObject(idx, bForce);
548 if (pObj) {
549 fpInputObjects->AddAt(pObj, idx);
550 }
551 }
552 } else {
553 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
554 }
555 return pObj;
556}
557
8451168b 558int AliHLTComponent::CleanupInputObjects()
559{
560 if (!fpInputObjects) return 0;
561 TObjArray* array=fpInputObjects;
562 fpInputObjects=NULL;
563 for (int i=0; i<array->GetEntries(); i++) {
564 TObject* pObj=array->At(i);
565 if (pObj) delete pObj;
566 }
567 delete array;
90ebac25 568 return 0;
8451168b 569}
570
a655eae3 571AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
572{
573 // see header file for function documentation
90ebac25 574 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 575 AliHLTComponentDataType dt=kAliHLTVoidDataType;
576 int idx=fCurrentInputBlock;
577 if (pObject) {
578 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
579 } else {
580 HLTError("unknown object %p", pObject);
581 }
582 }
583 if (idx>=0) {
4b98eadb 584 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 585 dt=fpInputBlocks[idx].fDataType;
586 } else {
587 HLTFatal("severe internal error, index out of range");
588 }
589 }
590 return dt;
591}
592
593AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
594{
595 // see header file for function documentation
90ebac25 596 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 597 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
598 int idx=fCurrentInputBlock;
599 if (pObject) {
600 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
601 } else {
602 HLTError("unknown object %p", pObject);
603 }
604 }
605 if (idx>=0) {
4b98eadb 606 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 607 iSpec=fpInputBlocks[idx].fSpecification;
608 } else {
609 HLTFatal("severe internal error, index out of range");
610 }
611 }
612 return iSpec;
613}
614
615const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
616{
617 // see header file for function documentation
90ebac25 618 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 619 fSearchDataType=dt;
620 fClassName.clear();
621 int idx=FindInputBlock(fSearchDataType, 0);
622 const AliHLTComponentBlockData* pBlock=NULL;
623 if (idx>=0) {
624 // check for fpInputBlocks pointer done in FindInputBlock
625 pBlock=&fpInputBlocks[idx];
626 }
627 return pBlock;
628}
629
630const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
631 const char* dtOrigin)
632{
633 // see header file for function documentation
90ebac25 634 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 635 AliHLTComponentDataType dt;
636 SetDataType(dt, dtID, dtOrigin);
637 return GetFirstInputBlock(dt);
638}
639
640const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
641{
642 // see header file for function documentation
90ebac25 643 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 644 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
645 const AliHLTComponentBlockData* pBlock=NULL;
646 if (idx>=0) {
647 // check for fpInputBlocks pointer done in FindInputBlock
648 pBlock=&fpInputBlocks[idx];
649 }
650 return pBlock;
651}
652
653int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock)
654{
655 // see header file for function documentation
656 int iResult=-ENOENT;
657 if (fpInputBlocks!=NULL) {
658 if (pBlock) {
659 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
132ca004 660 iResult=(int)(pBlock-fpInputBlocks);
a655eae3 661 }
662 } else {
663 iResult=-EINVAL;
664 }
665 }
666 return iResult;
667}
668
669AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
670{
671 // see header file for function documentation
90ebac25 672 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 673 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
674 int idx=fCurrentInputBlock;
675 if (pBlock) {
676 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
677 } else {
678 HLTError("unknown Block %p", pBlock);
679 }
680 }
681 if (idx>=0) {
682 // check for fpInputBlocks pointer done in FindInputBlock
683 iSpec=fpInputBlocks[idx].fSpecification;
684 }
685 return iSpec;
686}
687
688int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
689{
690 // see header file for function documentation
90ebac25 691 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 692 int iResult=0;
693 if (pObject) {
694 AliHLTMessage msg(kMESS_OBJECT);
695 msg.WriteObject(pObject);
696 Int_t iMsgLength=msg.Length();
697 if (iMsgLength>0) {
698 msg.SetLength(); // sets the length to the first (reserved) word
699 iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec);
700 if (iResult>=0) {
8451168b 701 HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
a655eae3 702 }
703 } else {
704 HLTError("object serialization failed for object %p", pObject);
705 iResult=-ENOMSG;
706 }
707 } else {
708 iResult=-EINVAL;
709 }
710 return iResult;
711}
712
713int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
714{
715 // see header file for function documentation
90ebac25 716 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 717 AliHLTComponentDataType dt;
718 SetDataType(dt, dtID, dtOrigin);
719 return PushBack(pObject, dt, spec);
720}
721
722int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
723{
724 // see header file for function documentation
90ebac25 725 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 726 return InsertOutputBlock(pBuffer, iSize, dt, spec);
727}
728
729int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
730{
731 // see header file for function documentation
90ebac25 732 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 733 AliHLTComponentDataType dt;
734 SetDataType(dt, dtID, dtOrigin);
735 return PushBack(pBuffer, iSize, dt, spec);
736}
737
738int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
739{
740 // see header file for function documentation
741 int iResult=0;
742 if (pBuffer) {
7a5ccd96 743 if (fpOutputBuffer && iSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
a655eae3 744 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
745 AliHLTComponentBlockData bd;
746 FillBlockData( bd );
747 bd.fOffset = fOutputBufferFilled;
748 bd.fPtr = pTgt;
749 bd.fSize = iSize;
750 bd.fDataType = dt;
751 bd.fSpecification = spec;
752 if (pBuffer!=NULL && pBuffer!=pTgt) {
753 memcpy(pTgt, pBuffer, iSize);
4b98eadb 754 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
a655eae3 755 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iSize, pBuffer, pTgt, firstWord);
756 }
757 fOutputBufferFilled+=bd.fSize;
758 fOutputBlocks.push_back( bd );
759 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iSize, DataType2Text(dt).c_str(), spec);
760 } else {
761 if (fpOutputBuffer) {
762 HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iSize);
763 } else {
764 HLTError("output buffer not available");
765 }
766 iResult=-ENOSPC;
767 }
768 } else {
769 iResult=-EINVAL;
770 }
771 return iResult;
772}
773
8451168b 774int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
775{
776 if (!pObject) return -EINVAL;
777 AliHLTMessage msg(kMESS_OBJECT);
778 msg.WriteObject(pObject);
779 return msg.Length();
780}
781
a655eae3 782int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
783{
784 // see header file for function documentation
785 int iResult=-ENOSYS;
786 //#warning function not yet implemented
787 HLTWarning("function not yet implemented");
788 return iResult;
789}
790
3cde846d 791int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
792 const AliHLTComponentBlockData* blocks,
793 AliHLTComponentTriggerData& trigData,
794 AliHLTUInt8_t* outputPtr,
795 AliHLTUInt32_t& size,
796 AliHLTUInt32_t& outputBlockCnt,
797 AliHLTComponentBlockData*& outputBlocks,
798 AliHLTComponentEventDoneData*& edd )
799{
70ed7d01 800 // see header file for function documentation
90ebac25 801 ALIHLTCOMPONENT_BASE_STOPWATCH();
3cde846d 802 int iResult=0;
803 fCurrentEvent=evtData.fEventID;
a655eae3 804 fCurrentEventData=evtData;
805 fpInputBlocks=blocks;
806 fCurrentInputBlock=-1;
807 fSearchDataType=kAliHLTAnyDataType;
808 fpOutputBuffer=outputPtr;
809 fOutputBufferSize=size;
810 fOutputBufferFilled=0;
811 fOutputBlocks.clear();
812
813 vector<AliHLTComponentBlockData> blockData;
90ebac25 814 { // dont delete, sets the scope for the stopwatch guard
815 ALIHLTCOMPONENT_DA_STOPWATCH();
816 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
817 } // end of the scope of the stopwatch guard
a655eae3 818 if (iResult>=0) {
819 if (fOutputBlocks.size()>0) {
820 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
821 if (blockData.size()>0) {
822 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
823 iResult=-EFAULT;
824 } else {
825 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
826 size=fOutputBufferFilled;
827 }
828 } else {
829 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
830 }
831 if (iResult<0) {
832 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
833 }
834 }
835 if (iResult<0) {
836 outputBlockCnt=0;
837 outputBlocks=NULL;
838 }
8451168b 839 CleanupInputObjects();
3cde846d 840 IncrementEventCounter();
841 return iResult;
842}
a655eae3 843
90ebac25 844AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
845 :
846 fpStopwatch(NULL),
847 fpPrec(NULL)
848{
849 // standard constructor (not for use)
850}
851
852AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
853 :
854 fpStopwatch(pStopwatch),
855 fpPrec(NULL)
856{
857 // constructor
858
859 // check for already existing guard
860 if (fgpCurrent) fpPrec=fgpCurrent;
861 fgpCurrent=this;
862
863 // stop the preceeding guard if it controls a different stopwatch
864 int bStart=1;
865 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
866
867 // start the stopwatch if the current guard controls a different one
868 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
869}
870
871AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(AliHLTStopwatchGuard&)
872 :
873 fpStopwatch(NULL),
874 fpPrec(NULL)
875{
876 // copy constructor (not for use)
877}
878
879AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
880
881AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
882{
883 // destructor
884
885 // resume the preceeding guard if it controls a different stopwatch
886 int bStop=1;
887 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
888
889 // stop the stopwatch if the current guard controls a different one
890 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
891
892 // resume to the preceeding guard
893 fgpCurrent=fpPrec;
894}
895
896int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
897{
898 // see header file for function documentation
899 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
900 return fpStopwatch!=pSucc?1:0;
901}
902
903int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
904{
905 // see header file for function documentation
906 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
907 return fpStopwatch!=pSucc?1:0;
908}
909
910int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
911{
912 // see header file for function documentation
913 int iResult=0;
914 if (pSW!=NULL && type<kSWTypeCount) {
915 if (fpStopwatches) {
916 TObject* pObj=fpStopwatches->At((int)type);
917 if (pSW==NULL // explicit reset
918 || pObj==NULL) { // explicit set
919 fpStopwatches->AddAt(pSW, (int)type);
920 } else if (pObj!=pSW) {
921 HLTWarning("stopwatch %d already set, reset first", (int)type);
922 iResult=-EBUSY;
923 }
924 }
925 } else {
926 iResult=-EINVAL;
927 }
928 return iResult;
929}
930
931int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
932{
933 // see header file for function documentation
934 if (pStopwatches==NULL) return -EINVAL;
935
936 int iResult=0;
937 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
938 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
939 return iResult;
940}