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