Primary ionisation electrons come now correctly ordered from FLUKA.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
CommitLineData
f23a6e1a 1// $Id$
2
3/**************************************************************************
9be2600f 4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
f23a6e1a 6 * *
9be2600f 7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 * for The ALICE HLT Project. *
f23a6e1a 10 * *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
19
bfccbf68 20/** @file AliHLTComponent.cxx
21 @author Matthias Richter, Timm Steinbeck
22 @date
23 @brief Base class implementation for HLT components. */
f23a6e1a 24
0c0c9d99 25#if __GNUC__>= 3
f23a6e1a 26using namespace std;
27#endif
28
66043029 29//#include "AliHLTStdIncludes.h"
f23a6e1a 30#include "AliHLTComponent.h"
31#include "AliHLTComponentHandler.h"
a655eae3 32#include "AliHLTMessage.h"
70ed7d01 33#include "TString.h"
a655eae3 34#include "TObjArray.h"
79c114b5 35#include "TObjectTable.h"
a655eae3 36#include "TClass.h"
90ebac25 37#include "TStopwatch.h"
79c114b5 38#include "AliHLTMemoryFile.h"
ec25e4ca 39#include <cassert>
f23a6e1a 40
b22e91eb 41/** ROOT macro for the implementation of ROOT specific class methods */
90ebac25 42ClassImp(AliHLTComponent);
43
44/** stopwatch macro using the stopwatch guard */
45#define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
46//#define ALIHLTCOMPONENT_STOPWATCH(type)
47
48/** stopwatch macro for operations of the base class */
49#define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
50/** stopwatch macro for operations of the detector algorithm (DA) */
51#define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
f23a6e1a 52
f23a6e1a 53AliHLTComponent::AliHLTComponent()
85869391 54 :
53feaef5 55 fEnvironment(),
3cde846d 56 fCurrentEvent(0),
a655eae3 57 fEventCount(-1),
58 fFailedEvents(0),
59 fCurrentEventData(),
60 fpInputBlocks(NULL),
61 fCurrentInputBlock(-1),
62 fSearchDataType(kAliHLTVoidDataType),
63 fClassName(),
64 fpInputObjects(NULL),
65 fpOutputBuffer(NULL),
66 fOutputBufferSize(0),
67 fOutputBufferFilled(0),
90ebac25 68 fOutputBlocks(),
79c114b5 69 fpStopwatches(new TObjArray(kSWTypeCount)),
559631d5 70 fMemFiles(),
71 fpRunDesc(NULL),
72 fpDDLList(NULL)
73
70ed7d01 74{
75 // see header file for class documentation
76 // or
77 // refer to README to build package
78 // or
79 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
f23a6e1a 80 memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
70ed7d01 81 if (fgpComponentHandler)
82 fgpComponentHandler->ScheduleRegister(this);
7c781d33 83 //SetLocalLoggingLevel(kHLTLogDefault);
70ed7d01 84}
85
f23a6e1a 86AliHLTComponent::~AliHLTComponent()
87{
70ed7d01 88 // see header file for function documentation
8451168b 89 CleanupInputObjects();
4498d7d1 90 if (fpStopwatches!=NULL) delete fpStopwatches;
91 fpStopwatches=NULL;
79c114b5 92 vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin();
93 while (element!=fMemFiles.end()) {
94 if (*element) {
95 if ((*element)->IsClosed()==0) {
96 HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
97 // close but do not flush as we dont know whether the buffer is still valid
29312178 98 (*element)->CloseMemoryFile(0);
79c114b5 99 }
100 delete *element;
101 *element=NULL;
102 }
103 element++;
104 }
f23a6e1a 105}
106
70ed7d01 107AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
b22e91eb 108
85869391 109int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite)
110{
70ed7d01 111 // see header file for function documentation
85869391 112 int iResult=0;
70ed7d01 113 if (fgpComponentHandler==NULL || bOverwrite!=0)
114 fgpComponentHandler=pCH;
85869391 115 else
116 iResult=-EPERM;
117 return iResult;
118}
119
70ed7d01 120int AliHLTComponent::UnsetGlobalComponentHandler()
121{
122 // see header file for function documentation
85869391 123 return SetGlobalComponentHandler(NULL,1);
124}
125
70ed7d01 126int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv )
f23a6e1a 127{
70ed7d01 128 // see header file for function documentation
f23a6e1a 129 int iResult=0;
130 if (environ) {
131 memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
70ed7d01 132 fEnvironment.fParam=environParam;
f23a6e1a 133 }
8451168b 134 const char** pArguments=NULL;
135 int iNofChildArgs=0;
136 TString argument="";
137 int bMissingParam=0;
138 if (argc>0) {
139 pArguments=new const char*[argc];
140 if (pArguments) {
141 for (int i=0; i<argc && iResult>=0; i++) {
142 argument=argv[i];
143 if (argument.IsNull()) continue;
144
145 // benchmark
146 if (argument.CompareTo("benchmark")==0) {
147
148 // loglevel
149 } else if (argument.CompareTo("loglevel")==0) {
150 if ((bMissingParam=(++i>=argc))) break;
151 TString parameter(argv[i]);
152 parameter.Remove(TString::kLeading, ' '); // remove all blanks
153 if (parameter.BeginsWith("0x") &&
154 parameter.Replace(0,2,"",0).IsHex()) {
155 AliHLTComponentLogSeverity loglevel=kHLTLogNone;
7a5ccd96 156 sscanf(parameter.Data(),"%x", (unsigned int*)&loglevel);
8451168b 157 SetLocalLoggingLevel(loglevel);
158 } else {
159 HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
160 iResult=-EINVAL;
161 }
162 } else {
163 pArguments[iNofChildArgs++]=argv[i];
164 }
165 }
166 } else {
167 iResult=-ENOMEM;
168 }
169 }
170 if (bMissingParam) {
171 HLTError("missing parameter for argument %s", argument.Data());
172 iResult=-EINVAL;
173 }
174 if (iResult>=0) {
175 iResult=DoInit(iNofChildArgs, pArguments);
176 }
3cde846d 177 if (iResult>=0) fEventCount=0;
8451168b 178 if (pArguments) delete [] pArguments;
f23a6e1a 179 return iResult;
180}
181
182int AliHLTComponent::Deinit()
183{
70ed7d01 184 // see header file for function documentation
f23a6e1a 185 int iResult=0;
186 iResult=DoDeinit();
559631d5 187 if (fpRunDesc) {
188 HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
189 AliHLTRunDesc* pRunDesc=fpRunDesc;
190 fpRunDesc=NULL;
191 delete pRunDesc;
192 }
f23a6e1a 193 return iResult;
194}
fa2e9b7c 195
53feaef5 196int AliHLTComponent::DoInit( int argc, const char** argv )
197{
70ed7d01 198 // see header file for function documentation
53feaef5 199 if (argc==0 && argv==NULL) {
200 // this is currently just to get rid of the warning "unused parameter"
201 }
66043029 202 fEventCount=0;
53feaef5 203 return 0;
204}
205
206int AliHLTComponent::DoDeinit()
207{
70ed7d01 208 // see header file for function documentation
66043029 209 fEventCount=0;
53feaef5 210 return 0;
211}
212
de6593d0 213int AliHLTComponent::GetOutputDataTypes(vector<AliHLTComponentDataType>& /*tgtList*/)
214{
215 return 0;
216}
217
70ed7d01 218void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
219{
220 // see header file for function documentation
9ce4bf4a 221 memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
222 strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
223 strcat( output, ":" );
224 strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
fa2e9b7c 225}
226
9ce4bf4a 227string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
228{
70ed7d01 229 // see header file for function documentation
9ce4bf4a 230 string out("");
3cde846d 231
9ce4bf4a 232 if (type==kAliHLTVoidDataType) {
233 out="VOID:VOID";
234 } else {
3cde846d 235 // some gymnastics in order to avoid a '0' which is part of either or both
236 // ID and origin terminating the whole string. Unfortunately, string doesn't
237 // stop appending at the '0' if the number of elements to append was
238 // explicitely specified
239 string tmp("");
240 tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
241 out.append(tmp.c_str());
9ce4bf4a 242 out.append(":");
3cde846d 243 tmp="";
244 tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
245 out.append(tmp.c_str());
9ce4bf4a 246 }
247 return out;
248}
249
250
70ed7d01 251void* AliHLTComponent::AllocMemory( unsigned long size )
252{
253 // see header file for function documentation
85869391 254 if (fEnvironment.fAllocMemoryFunc)
255 return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
9ce4bf4a 256 HLTFatal("no memory allocation handler registered");
85869391 257 return NULL;
258}
259
8ede8717 260int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
70ed7d01 261 AliHLTComponentBlockData** outputBlocks )
262{
263 // see header file for function documentation
9ce4bf4a 264 if ( blockCount==NULL || outputBlocks==NULL )
2d7ff710 265 return -EFAULT;
fa2e9b7c 266 AliHLTUInt32_t count = blocks.size();
267 if ( !count )
268 {
269 *blockCount = 0;
270 *outputBlocks = NULL;
271 return 0;
272 }
8ede8717 273 *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
fa2e9b7c 274 if ( !*outputBlocks )
2d7ff710 275 return -ENOMEM;
ca8524df 276 for ( unsigned long i = 0; i < count; i++ ) {
fa2e9b7c 277 (*outputBlocks)[i] = blocks[i];
ca8524df 278 if (blocks[i].fDataType==kAliHLTAnyDataType) {
5f5b708b 279 (*outputBlocks)[i].fDataType=GetOutputDataType();
280 /* data type was set to the output data type by the PubSub AliRoot
281 Wrapper component, if data type of the block was ********:****.
282 Now handled by the component base class in order to have same
283 behavior when running embedded in AliRoot
ca8524df 284 memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
285 memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
5f5b708b 286 */
ca8524df 287 }
288 }
fa2e9b7c 289 *blockCount = count;
290 return 0;
291
292}
0c0c9d99 293
70ed7d01 294int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd )
295{
296 // see header file for function documentation
85869391 297 if (fEnvironment.fGetEventDoneDataFunc)
298 return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
299 return -ENOSYS;
300}
301
8ede8717 302int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList)
0c0c9d99 303{
70ed7d01 304 // see header file for function documentation
0c0c9d99 305 int iResult=0;
306 if (pConsumer) {
8ede8717 307 vector<AliHLTComponentDataType> ctlist;
0c0c9d99 308 ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
8ede8717 309 vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
5f5b708b 310 //AliHLTComponentDataType ouptdt=GetOutputDataType();
311 //PrintDataTypeContent(ouptdt, "publisher \'%s\'");
0c0c9d99 312 while (type!=ctlist.end() && iResult==0) {
5f5b708b 313 //PrintDataTypeContent((*type), "consumer \'%s\'");
9ce4bf4a 314 if ((*type)==GetOutputDataType() ||
315 (*type)==kAliHLTAnyDataType) {
0c0c9d99 316 if (tgtList) tgtList->push_back(*type);
317 iResult++;
9ce4bf4a 318 // this loop has to be changed in case of multiple output types
0c0c9d99 319 break;
320 }
321 type++;
322 }
323 } else {
324 iResult=-EINVAL;
325 }
326 return iResult;
327}
2d7ff710 328
5f5b708b 329void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const
330{
66043029 331 // see header file for function documentation
5f5b708b 332 const char* fmt="publisher \'%s\'";
333 if (format) fmt=format;
334 HLTMessage(fmt, (DataType2Text(dt)).c_str());
335 HLTMessage("%x %x %x %x %x %x %x %x : %x %x %x %x",
336 dt.fID[0],
337 dt.fID[1],
338 dt.fID[2],
339 dt.fID[3],
340 dt.fID[4],
341 dt.fID[5],
342 dt.fID[6],
343 dt.fID[7],
344 dt.fOrigin[0],
345 dt.fOrigin[1],
346 dt.fOrigin[2],
347 dt.fOrigin[3]);
348}
349
70ed7d01 350void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const
351{
352 // see header file for function documentation
2d7ff710 353 blockData.fStructSize = sizeof(blockData);
354 FillShmData( blockData.fShmKey );
355 blockData.fOffset = ~(AliHLTUInt32_t)0;
356 blockData.fPtr = NULL;
357 blockData.fSize = 0;
358 FillDataType( blockData.fDataType );
a655eae3 359 blockData.fSpecification = kAliHLTVoidDataSpec;
2d7ff710 360}
361
70ed7d01 362void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const
363{
364 // see header file for function documentation
2d7ff710 365 shmData.fStructSize = sizeof(shmData);
366 shmData.fShmType = gkAliHLTComponentInvalidShmType;
367 shmData.fShmID = gkAliHLTComponentInvalidShmID;
368}
369
70ed7d01 370void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const
371{
372 // see header file for function documentation
ca8524df 373 dataType=kAliHLTAnyDataType;
2d7ff710 374}
375
70ed7d01 376void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt)
377{
378 // see header file for function documentation
2d7ff710 379 memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
380 memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
381}
382
70ed7d01 383void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin)
384{
385 // see header file for function documentation
2d7ff710 386 tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
387 memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
388 memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
389
9ce4bf4a 390 if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
2d7ff710 391 HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
392 }
393 strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
394
9ce4bf4a 395 if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
2d7ff710 396 HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
397 }
398 strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
399}
9ce4bf4a 400
401void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
402{
70ed7d01 403 // see header file for function documentation
9ce4bf4a 404 memset(&evtData, 0, sizeof(AliHLTComponentEventData));
405 evtData.fStructSize=sizeof(AliHLTComponentEventData);
406}
407
70ed7d01 408void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt)
409{
410 // see header file for function documentation
9ce4bf4a 411 TString msg;
412 msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
413 for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
414 if (dt.fID[i]!=0) msg+=dt.fID[i];
415 else msg+="\\0";
416 }
417 msg+="\" Origin=\"";
418 for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
419 if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
420 else msg+="\\0";
421 }
422 msg+="\"";
3cde846d 423 AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
9ce4bf4a 424}
425
70ed7d01 426int AliHLTComponent::GetEventCount() const
3cde846d 427{
70ed7d01 428 // see header file for function documentation
3cde846d 429 return fEventCount;
430}
431
432int AliHLTComponent::IncrementEventCounter()
433{
70ed7d01 434 // see header file for function documentation
3cde846d 435 if (fEventCount>=0) fEventCount++;
436 return fEventCount;
437}
438
66043029 439int AliHLTComponent::GetNumberOfInputBlocks() const
a655eae3 440{
441 // see header file for function documentation
442 if (fpInputBlocks!=NULL) {
443 return fCurrentEventData.fBlockCnt;
444 }
445 return 0;
446}
447
448const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
449 const char* classname,
450 int bForce)
451{
452 // see header file for function documentation
90ebac25 453 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 454 fSearchDataType=dt;
455 if (classname) fClassName=classname;
456 else fClassName.clear();
1edbbe49 457 int idx=FindInputBlock(fSearchDataType, 0, 1);
a655eae3 458 TObject* pObj=NULL;
459 if (idx>=0) {
79c114b5 460 HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
a655eae3 461 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
462 fCurrentInputBlock=idx;
463 } else {
464 }
465 }
466 return pObj;
467}
468
469const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID,
470 const char* dtOrigin,
471 const char* classname,
472 int bForce)
473{
474 // see header file for function documentation
90ebac25 475 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 476 AliHLTComponentDataType dt;
477 SetDataType(dt, dtID, dtOrigin);
478 return GetFirstInputObject(dt, classname, bForce);
479}
480
481const TObject* AliHLTComponent::GetNextInputObject(int bForce)
482{
483 // see header file for function documentation
90ebac25 484 ALIHLTCOMPONENT_BASE_STOPWATCH();
1edbbe49 485 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
a655eae3 486 //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
487 TObject* pObj=NULL;
488 if (idx>=0) {
489 if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
490 fCurrentInputBlock=idx;
491 }
492 }
493 return pObj;
494}
495
1edbbe49 496int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
a655eae3 497{
498 // see header file for function documentation
499 int iResult=-ENOENT;
500 if (fpInputBlocks!=NULL) {
501 int idx=startIdx<0?0:startIdx;
4b98eadb 502 for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
1edbbe49 503 if (bObject!=0) {
504 if (fpInputBlocks[idx].fPtr==NULL) continue;
3294f81a 505 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
506 if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
1edbbe49 507 }
a655eae3 508 if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
509 iResult=idx;
510 }
511 }
512 }
513 return iResult;
514}
515
516TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
517{
518 // see header file for function documentation
519 TObject* pObj=NULL;
520 if (fpInputBlocks!=NULL) {
4b98eadb 521 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 522 if (fpInputBlocks[idx].fPtr) {
3294f81a 523 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
a655eae3 524 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
8451168b 525 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
3294f81a 526 AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
66043029 527 TClass* objclass=msg.GetClass();
528 pObj=msg.ReadObject(objclass);
529 if (pObj && objclass) {
530 HLTDebug("object %p type %s created", pObj, objclass->GetName());
a655eae3 531 } else {
532 }
1edbbe49 533 //} else {
534 } else if (bForce!=0) {
a655eae3 535 HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
536 }
537 } else {
538 HLTFatal("block descriptor empty");
539 }
540 } else {
541 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
542 }
543 } else {
544 HLTError("no input blocks available");
545 }
546
547 return pObj;
548}
549
298ef463 550TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
a655eae3 551{
552 // see header file for function documentation
553 if (fpInputObjects==NULL) {
554 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
555 }
556 TObject* pObj=NULL;
557 if (fpInputObjects) {
558 pObj=fpInputObjects->At(idx);
559 if (pObj==NULL) {
560 pObj=CreateInputObject(idx, bForce);
561 if (pObj) {
562 fpInputObjects->AddAt(pObj, idx);
563 }
564 }
565 } else {
566 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
567 }
568 return pObj;
569}
570
8451168b 571int AliHLTComponent::CleanupInputObjects()
572{
66043029 573 // see header file for function documentation
8451168b 574 if (!fpInputObjects) return 0;
575 TObjArray* array=fpInputObjects;
576 fpInputObjects=NULL;
577 for (int i=0; i<array->GetEntries(); i++) {
578 TObject* pObj=array->At(i);
79c114b5 579 // grrr, garbage collection strikes back: When read via AliHLTMessage
580 // (CreateInputObject), and written to a TFile afterwards, the
581 // TFile::Close calls ROOOT's garbage collection. No clue why the
582 // object ended up in the key list and needs to be deleted
583 if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj;
8451168b 584 }
585 delete array;
90ebac25 586 return 0;
8451168b 587}
588
a655eae3 589AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
590{
591 // see header file for function documentation
90ebac25 592 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 593 AliHLTComponentDataType dt=kAliHLTVoidDataType;
594 int idx=fCurrentInputBlock;
595 if (pObject) {
596 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
597 } else {
598 HLTError("unknown object %p", pObject);
599 }
600 }
601 if (idx>=0) {
4b98eadb 602 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 603 dt=fpInputBlocks[idx].fDataType;
604 } else {
605 HLTFatal("severe internal error, index out of range");
606 }
607 }
608 return dt;
609}
610
611AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
612{
613 // see header file for function documentation
90ebac25 614 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 615 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
616 int idx=fCurrentInputBlock;
617 if (pObject) {
618 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
619 } else {
620 HLTError("unknown object %p", pObject);
621 }
622 }
623 if (idx>=0) {
4b98eadb 624 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 625 iSpec=fpInputBlocks[idx].fSpecification;
626 } else {
627 HLTFatal("severe internal error, index out of range");
628 }
629 }
630 return iSpec;
631}
632
633const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
634{
635 // see header file for function documentation
90ebac25 636 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 637 fSearchDataType=dt;
638 fClassName.clear();
639 int idx=FindInputBlock(fSearchDataType, 0);
640 const AliHLTComponentBlockData* pBlock=NULL;
641 if (idx>=0) {
642 // check for fpInputBlocks pointer done in FindInputBlock
643 pBlock=&fpInputBlocks[idx];
1edbbe49 644 fCurrentInputBlock=idx;
a655eae3 645 }
646 return pBlock;
647}
648
649const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
650 const char* dtOrigin)
651{
652 // see header file for function documentation
90ebac25 653 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 654 AliHLTComponentDataType dt;
655 SetDataType(dt, dtID, dtOrigin);
656 return GetFirstInputBlock(dt);
657}
658
ec25e4ca 659const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index)
660{
661 // see header file for function documentation
662 ALIHLTCOMPONENT_BASE_STOPWATCH();
663 assert( 0 <= index and index < fCurrentEventData.fBlockCnt );
664 return &fpInputBlocks[index];
665}
666
a655eae3 667const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
668{
669 // see header file for function documentation
90ebac25 670 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 671 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
672 const AliHLTComponentBlockData* pBlock=NULL;
673 if (idx>=0) {
674 // check for fpInputBlocks pointer done in FindInputBlock
675 pBlock=&fpInputBlocks[idx];
1edbbe49 676 fCurrentInputBlock=idx;
a655eae3 677 }
678 return pBlock;
679}
680
66043029 681int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
a655eae3 682{
683 // see header file for function documentation
684 int iResult=-ENOENT;
685 if (fpInputBlocks!=NULL) {
686 if (pBlock) {
687 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
132ca004 688 iResult=(int)(pBlock-fpInputBlocks);
a655eae3 689 }
690 } else {
691 iResult=-EINVAL;
692 }
693 }
694 return iResult;
695}
696
697AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
698{
699 // see header file for function documentation
90ebac25 700 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 701 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
702 int idx=fCurrentInputBlock;
703 if (pBlock) {
704 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
705 } else {
706 HLTError("unknown Block %p", pBlock);
707 }
708 }
709 if (idx>=0) {
710 // check for fpInputBlocks pointer done in FindInputBlock
711 iSpec=fpInputBlocks[idx].fSpecification;
712 }
713 return iSpec;
714}
715
79c114b5 716int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
717 void* pHeader, int headerSize)
a655eae3 718{
719 // see header file for function documentation
90ebac25 720 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 721 int iResult=0;
722 if (pObject) {
723 AliHLTMessage msg(kMESS_OBJECT);
724 msg.WriteObject(pObject);
725 Int_t iMsgLength=msg.Length();
726 if (iMsgLength>0) {
727 msg.SetLength(); // sets the length to the first (reserved) word
79c114b5 728 iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize);
a655eae3 729 if (iResult>=0) {
8451168b 730 HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
a655eae3 731 }
732 } else {
733 HLTError("object serialization failed for object %p", pObject);
734 iResult=-ENOMSG;
735 }
736 } else {
737 iResult=-EINVAL;
738 }
739 return iResult;
740}
741
79c114b5 742int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
743 void* pHeader, int headerSize)
a655eae3 744{
745 // see header file for function documentation
90ebac25 746 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 747 AliHLTComponentDataType dt;
748 SetDataType(dt, dtID, dtOrigin);
79c114b5 749 return PushBack(pObject, dt, spec, pHeader, headerSize);
a655eae3 750}
751
9d9ffd37 752int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
753 void* pHeader, int headerSize)
a655eae3 754{
755 // see header file for function documentation
90ebac25 756 ALIHLTCOMPONENT_BASE_STOPWATCH();
9d9ffd37 757 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
a655eae3 758}
759
9d9ffd37 760int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
761 void* pHeader, int headerSize)
a655eae3 762{
763 // see header file for function documentation
90ebac25 764 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 765 AliHLTComponentDataType dt;
766 SetDataType(dt, dtID, dtOrigin);
9d9ffd37 767 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
a655eae3 768}
769
79c114b5 770int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
771 void* pHeader, int iHeaderSize)
a655eae3 772{
773 // see header file for function documentation
774 int iResult=0;
79c114b5 775 int iBlkSize = iBufferSize + iHeaderSize;
a655eae3 776 if (pBuffer) {
79c114b5 777 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
a655eae3 778 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
779 AliHLTComponentBlockData bd;
780 FillBlockData( bd );
781 bd.fOffset = fOutputBufferFilled;
79c114b5 782 bd.fSize = iBlkSize;
a655eae3 783 bd.fDataType = dt;
784 bd.fSpecification = spec;
79c114b5 785 if (pHeader!=NULL && pHeader!=pTgt) {
786 memcpy(pTgt, pHeader, iHeaderSize);
787 }
788
789 pTgt += (AliHLTUInt8_t) iHeaderSize;
790
a655eae3 791 if (pBuffer!=NULL && pBuffer!=pTgt) {
79c114b5 792 memcpy(pTgt, pBuffer, iBufferSize);
793
4b98eadb 794 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
79c114b5 795 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
a655eae3 796 }
797 fOutputBufferFilled+=bd.fSize;
798 fOutputBlocks.push_back( bd );
79c114b5 799 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
a655eae3 800 } else {
801 if (fpOutputBuffer) {
79c114b5 802 HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize);
a655eae3 803 } else {
804 HLTError("output buffer not available");
805 }
806 iResult=-ENOSPC;
807 }
808 } else {
809 iResult=-EINVAL;
810 }
811 return iResult;
812}
813
8451168b 814int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
815{
66043029 816 // see header file for function documentation
8451168b 817 if (!pObject) return -EINVAL;
818 AliHLTMessage msg(kMESS_OBJECT);
819 msg.WriteObject(pObject);
820 return msg.Length();
821}
822
79c114b5 823AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
824 const char* dtOrigin,
825 AliHLTUInt32_t spec)
826{
827 // see header file for function documentation
828 ALIHLTCOMPONENT_BASE_STOPWATCH();
829 AliHLTComponentDataType dt;
830 SetDataType(dt, dtID, dtOrigin);
831 return CreateMemoryFile(capacity, dt, spec);
832}
833
834AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
835 const AliHLTComponentDataType& dt,
836 AliHLTUInt32_t spec)
837{
838 // see header file for function documentation
839 ALIHLTCOMPONENT_BASE_STOPWATCH();
840 AliHLTMemoryFile* pFile=NULL;
83fec083 841 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
79c114b5 842 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
843 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
844 if (pFile) {
83fec083 845 unsigned int nofBlocks=fOutputBlocks.size();
79c114b5 846 if (nofBlocks+1>fMemFiles.size()) {
847 fMemFiles.resize(nofBlocks+1, NULL);
848 }
849 if (nofBlocks<fMemFiles.size()) {
850 fMemFiles[nofBlocks]=pFile;
851 AliHLTComponentBlockData bd;
852 FillBlockData( bd );
853 bd.fOffset = fOutputBufferFilled;
79c114b5 854 bd.fSize = capacity;
855 bd.fDataType = dt;
856 bd.fSpecification = spec;
857 fOutputBufferFilled+=bd.fSize;
858 fOutputBlocks.push_back( bd );
859 } else {
860 HLTError("can not allocate/grow object array");
29312178 861 pFile->CloseMemoryFile(0);
79c114b5 862 delete pFile;
863 pFile=NULL;
864 }
865 }
866 } else {
867 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
868 }
869 return pFile;
870}
871
872AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
873 const char* dtOrigin,
874 AliHLTUInt32_t spec,
875 float capacity)
876{
877 // see header file for function documentation
878 ALIHLTCOMPONENT_BASE_STOPWATCH();
879 AliHLTComponentDataType dt;
880 SetDataType(dt, dtID, dtOrigin);
881 int size=fOutputBufferSize-fOutputBufferFilled;
882 if (capacity<0 || capacity>1.0) {
883 HLTError("invalid parameter: capacity %f", capacity);
884 return NULL;
885 }
886 size=(int)(size*capacity);
887 return CreateMemoryFile(size, dt, spec);
888}
889
890AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
891 AliHLTUInt32_t spec,
892 float capacity)
893{
894 // see header file for function documentation
895 ALIHLTCOMPONENT_BASE_STOPWATCH();
896 int size=fOutputBufferSize-fOutputBufferFilled;
897 if (capacity<0 || capacity>1.0) {
898 HLTError("invalid parameter: capacity %f", capacity);
899 return NULL;
900 }
901 size=(int)(size*capacity);
902 return CreateMemoryFile(size, dt, spec);
903}
904
905int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
906 const char* key, int option)
907{
908 int iResult=0;
909 if (pFile && pObject) {
910 pFile->cd();
911 iResult=pObject->Write(key, option);
912 if (iResult>0) {
913 // success
914 } else {
915 iResult=-pFile->GetErrno();
916 if (iResult==-ENOSPC) {
917 HLTError("error writing memory file, buffer too small");
918 }
919 }
920 } else {
921 iResult=-EINVAL;
922 }
923 return iResult;
924}
925
926int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
927{
928 int iResult=0;
929 if (pFile) {
930 vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin();
931 int i=0;
932 while (element!=fMemFiles.end() && iResult>=0) {
933 if (*element && *element==pFile) {
29312178 934 iResult=pFile->CloseMemoryFile();
79c114b5 935
936 // sync memory files and descriptors
937 if (iResult>=0) {
938 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
939 }
940 delete *element;
941 *element=NULL;
942 return iResult;
943 }
944 element++; i++;
945 }
946 HLTError("can not find memory file %p", pFile);
947 iResult=-ENOENT;
948 } else {
949 iResult=-EINVAL;
950 }
951 return iResult;
952}
953
29312178 954int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData /*edd*/)
a655eae3 955{
956 // see header file for function documentation
957 int iResult=-ENOSYS;
958 //#warning function not yet implemented
959 HLTWarning("function not yet implemented");
960 return iResult;
961}
962
3cde846d 963int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
964 const AliHLTComponentBlockData* blocks,
965 AliHLTComponentTriggerData& trigData,
966 AliHLTUInt8_t* outputPtr,
967 AliHLTUInt32_t& size,
968 AliHLTUInt32_t& outputBlockCnt,
969 AliHLTComponentBlockData*& outputBlocks,
970 AliHLTComponentEventDoneData*& edd )
971{
70ed7d01 972 // see header file for function documentation
90ebac25 973 ALIHLTCOMPONENT_BASE_STOPWATCH();
3cde846d 974 int iResult=0;
975 fCurrentEvent=evtData.fEventID;
a655eae3 976 fCurrentEventData=evtData;
977 fpInputBlocks=blocks;
978 fCurrentInputBlock=-1;
979 fSearchDataType=kAliHLTAnyDataType;
980 fpOutputBuffer=outputPtr;
981 fOutputBufferSize=size;
982 fOutputBufferFilled=0;
983 fOutputBlocks.clear();
559631d5 984
985 // find special events
986 if (fpInputBlocks) {
83fec083 987 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
559631d5 988 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
989 // start of run
990 if (fpRunDesc==NULL) {
991 fpRunDesc=new AliHLTRunDesc;
992 if (fpRunDesc) {
993 if ((iResult=CopyStruct(fpRunDesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) {
994 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
995 }
996 } else {
997 iResult=-ENOMEM;
998 }
999 } else {
1000 HLTWarning("already received SOR event run no %d, ignoring SOR", fpRunDesc->fRunNo);
1001 }
1002 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1003 if (fpRunDesc!=NULL) {
1004 if (fpRunDesc) {
1005 AliHLTRunDesc rundesc;
1006 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) {
1007 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1008 HLTWarning("run no missmatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1009 } else {
1010 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1011 }
1012 }
1013 AliHLTRunDesc* pRunDesc=fpRunDesc;
1014 fpRunDesc=NULL;
1015 delete pRunDesc;
1016 }
1017 } else {
1018 HLTWarning("did not receive SOR, ignoring EOR");
1019 }
1020 // end of run
1021 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1022 // DDL list
1023 }
1024 }
1025 }
a655eae3 1026
1027 vector<AliHLTComponentBlockData> blockData;
90ebac25 1028 { // dont delete, sets the scope for the stopwatch guard
1029 ALIHLTCOMPONENT_DA_STOPWATCH();
1030 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1031 } // end of the scope of the stopwatch guard
a655eae3 1032 if (iResult>=0) {
1033 if (fOutputBlocks.size()>0) {
1034 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
79c114b5 1035
1036 // sync memory files and descriptors
1037 vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin();
1038 int i=0;
1039 while (element!=fMemFiles.end() && iResult>=0) {
1040 if (*element) {
1041 if ((*element)->IsClosed()==0) {
1042 HLTWarning("memory file has not been closed, force flush");
1043 iResult=CloseMemoryFile(*element);
1044 }
1045 }
1046 element++; i++;
1047 }
1048
1049 if (iResult>=0) {
1050 // create the descriptor list
1051 if (blockData.size()>0) {
1052 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1053 iResult=-EFAULT;
1054 } else {
1055 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1056 size=fOutputBufferFilled;
1057 }
a655eae3 1058 }
1059 } else {
1060 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1061 }
1062 if (iResult<0) {
1063 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1064 }
1065 }
1066 if (iResult<0) {
1067 outputBlockCnt=0;
1068 outputBlocks=NULL;
1069 }
8451168b 1070 CleanupInputObjects();
f8bc6d99 1071 if (iResult>=0) {
1072 IncrementEventCounter();
1073 }
3cde846d 1074 return iResult;
1075}
a655eae3 1076
90ebac25 1077AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1078 :
1079 fpStopwatch(NULL),
1080 fpPrec(NULL)
1081{
1082 // standard constructor (not for use)
1083}
1084
1085AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1086 :
1087 fpStopwatch(pStopwatch),
1088 fpPrec(NULL)
1089{
1090 // constructor
1091
1092 // check for already existing guard
1093 if (fgpCurrent) fpPrec=fgpCurrent;
1094 fgpCurrent=this;
1095
1096 // stop the preceeding guard if it controls a different stopwatch
1097 int bStart=1;
1098 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1099
1100 // start the stopwatch if the current guard controls a different one
1101 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
1102}
1103
e419b223 1104AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
90ebac25 1105 :
1106 fpStopwatch(NULL),
1107 fpPrec(NULL)
1108{
e419b223 1109 //
1110 // copy constructor not for use
1111 //
1112}
1113
1114AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
1115{
1116 //
1117 // assignment operator not for use
1118 //
1119 fpStopwatch=NULL;
1120 fpPrec=NULL;
1121 return *this;
90ebac25 1122}
1123
1124AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
1125
1126AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
1127{
1128 // destructor
1129
1130 // resume the preceeding guard if it controls a different stopwatch
1131 int bStop=1;
1132 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
1133
1134 // stop the stopwatch if the current guard controls a different one
1135 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
1136
1137 // resume to the preceeding guard
1138 fgpCurrent=fpPrec;
1139}
1140
1141int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
1142{
1143 // see header file for function documentation
1144 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
1145 return fpStopwatch!=pSucc?1:0;
1146}
1147
1148int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
1149{
1150 // see header file for function documentation
1151 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
1152 return fpStopwatch!=pSucc?1:0;
1153}
1154
1155int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
1156{
1157 // see header file for function documentation
1158 int iResult=0;
1159 if (pSW!=NULL && type<kSWTypeCount) {
1160 if (fpStopwatches) {
1161 TObject* pObj=fpStopwatches->At((int)type);
1162 if (pSW==NULL // explicit reset
1163 || pObj==NULL) { // explicit set
1164 fpStopwatches->AddAt(pSW, (int)type);
1165 } else if (pObj!=pSW) {
1166 HLTWarning("stopwatch %d already set, reset first", (int)type);
1167 iResult=-EBUSY;
1168 }
1169 }
1170 } else {
1171 iResult=-EINVAL;
1172 }
1173 return iResult;
1174}
1175
1176int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
1177{
1178 // see header file for function documentation
1179 if (pStopwatches==NULL) return -EINVAL;
1180
1181 int iResult=0;
1182 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
1183 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
1184 return iResult;
1185}
559631d5 1186
1187AliHLTUInt32_t AliHLTComponent::GetRunNo() const
1188{
29312178 1189 // see header file for function documentation
559631d5 1190 if (fpRunDesc==NULL) return 0;
1191 return fpRunDesc->fRunNo;
1192}
1193
1194AliHLTUInt32_t AliHLTComponent::GetRunType() const
1195{
29312178 1196 // see header file for function documentation
559631d5 1197 if (fpRunDesc==NULL) return 0;
1198 return fpRunDesc->fRunType;
1199}
1200
83fec083 1201int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
559631d5 1202 const char* structname, const char* eventname)
1203{
29312178 1204 // see header file for function documentation
559631d5 1205 int iResult=0;
1206 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
1207 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
1208 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
1209 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
3294f81a 1210 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
559631d5 1211 if (fpInputBlocks[iBlockNo].fSize!=copy) {
1212 HLTWarning("%s event: missmatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
1213 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
1214 }
1215 if (copy!=iStructSize) {
1216 HLTWarning("%s event: missmatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
1217 if (copy>iStructSize) {
1218 copy=iStructSize;
1219 } else {
1220 memset(pTgt, 0, iStructSize);
1221 }
1222 }
3294f81a 1223 memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
559631d5 1224 *pTgt=iStructSize;
1225 iResult=copy;
1226 } else {
1227 HLTWarning("%s event: missing data block", eventname);
1228 }
1229 } else {
1230 iResult=-ENODATA;
1231 }
1232 } else {
1233 HLTError("invalid struct");
1234 iResult=-EINVAL;
1235 }
1236 return iResult;
1237}