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