]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTComponent.cxx
Moving AliMillepede from MUON to libSTEER
[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;
7c3234da 505 AliHLTUInt8_t* pSrc=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[idx].fPtr);
506 pSrc+=fpInputBlocks[idx].fOffset;
507 if (*reinterpret_cast<AliHLTUInt32_t*>(pSrc)!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
1edbbe49 508 }
a655eae3 509 if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
510 iResult=idx;
511 }
512 }
513 }
514 return iResult;
515}
516
517TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
518{
519 // see header file for function documentation
520 TObject* pObj=NULL;
521 if (fpInputBlocks!=NULL) {
4b98eadb 522 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 523 if (fpInputBlocks[idx].fPtr) {
7c3234da 524 AliHLTUInt8_t* pSrc=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[idx].fPtr);
525 pSrc+=fpInputBlocks[idx].fOffset;
526 AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pSrc);
a655eae3 527 if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
8451168b 528 HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
7c3234da 529 AliHLTMessage msg((void*)pSrc, fpInputBlocks[idx].fSize);
66043029 530 TClass* objclass=msg.GetClass();
531 pObj=msg.ReadObject(objclass);
532 if (pObj && objclass) {
533 HLTDebug("object %p type %s created", pObj, objclass->GetName());
a655eae3 534 } else {
535 }
1edbbe49 536 //} else {
537 } else if (bForce!=0) {
a655eae3 538 HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
539 }
540 } else {
541 HLTFatal("block descriptor empty");
542 }
543 } else {
544 HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
545 }
546 } else {
547 HLTError("no input blocks available");
548 }
549
550 return pObj;
551}
552
298ef463 553TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
a655eae3 554{
555 // see header file for function documentation
556 if (fpInputObjects==NULL) {
557 fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
558 }
559 TObject* pObj=NULL;
560 if (fpInputObjects) {
561 pObj=fpInputObjects->At(idx);
562 if (pObj==NULL) {
563 pObj=CreateInputObject(idx, bForce);
564 if (pObj) {
565 fpInputObjects->AddAt(pObj, idx);
566 }
567 }
568 } else {
569 HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
570 }
571 return pObj;
572}
573
8451168b 574int AliHLTComponent::CleanupInputObjects()
575{
66043029 576 // see header file for function documentation
8451168b 577 if (!fpInputObjects) return 0;
578 TObjArray* array=fpInputObjects;
579 fpInputObjects=NULL;
580 for (int i=0; i<array->GetEntries(); i++) {
581 TObject* pObj=array->At(i);
79c114b5 582 // grrr, garbage collection strikes back: When read via AliHLTMessage
583 // (CreateInputObject), and written to a TFile afterwards, the
584 // TFile::Close calls ROOOT's garbage collection. No clue why the
585 // object ended up in the key list and needs to be deleted
586 if (pObj && gObjectTable->PtrIsValid(pObj)) delete pObj;
8451168b 587 }
588 delete array;
90ebac25 589 return 0;
8451168b 590}
591
a655eae3 592AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
593{
594 // see header file for function documentation
90ebac25 595 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 596 AliHLTComponentDataType dt=kAliHLTVoidDataType;
597 int idx=fCurrentInputBlock;
598 if (pObject) {
599 if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
600 } else {
601 HLTError("unknown object %p", pObject);
602 }
603 }
604 if (idx>=0) {
4b98eadb 605 if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
a655eae3 606 dt=fpInputBlocks[idx].fDataType;
607 } else {
608 HLTFatal("severe internal error, index out of range");
609 }
610 }
611 return dt;
612}
613
614AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
615{
616 // see header file for function documentation
90ebac25 617 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 618 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
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 iSpec=fpInputBlocks[idx].fSpecification;
629 } else {
630 HLTFatal("severe internal error, index out of range");
631 }
632 }
633 return iSpec;
634}
635
636const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
637{
638 // see header file for function documentation
90ebac25 639 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 640 fSearchDataType=dt;
641 fClassName.clear();
642 int idx=FindInputBlock(fSearchDataType, 0);
643 const AliHLTComponentBlockData* pBlock=NULL;
644 if (idx>=0) {
645 // check for fpInputBlocks pointer done in FindInputBlock
646 pBlock=&fpInputBlocks[idx];
1edbbe49 647 fCurrentInputBlock=idx;
a655eae3 648 }
649 return pBlock;
650}
651
652const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID,
653 const char* dtOrigin)
654{
655 // see header file for function documentation
90ebac25 656 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 657 AliHLTComponentDataType dt;
658 SetDataType(dt, dtID, dtOrigin);
659 return GetFirstInputBlock(dt);
660}
661
ec25e4ca 662const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index)
663{
664 // see header file for function documentation
665 ALIHLTCOMPONENT_BASE_STOPWATCH();
666 assert( 0 <= index and index < fCurrentEventData.fBlockCnt );
667 return &fpInputBlocks[index];
668}
669
a655eae3 670const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
671{
672 // see header file for function documentation
90ebac25 673 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 674 int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
675 const AliHLTComponentBlockData* pBlock=NULL;
676 if (idx>=0) {
677 // check for fpInputBlocks pointer done in FindInputBlock
678 pBlock=&fpInputBlocks[idx];
1edbbe49 679 fCurrentInputBlock=idx;
a655eae3 680 }
681 return pBlock;
682}
683
66043029 684int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
a655eae3 685{
686 // see header file for function documentation
687 int iResult=-ENOENT;
688 if (fpInputBlocks!=NULL) {
689 if (pBlock) {
690 if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
132ca004 691 iResult=(int)(pBlock-fpInputBlocks);
a655eae3 692 }
693 } else {
694 iResult=-EINVAL;
695 }
696 }
697 return iResult;
698}
699
700AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
701{
702 // see header file for function documentation
90ebac25 703 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 704 AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
705 int idx=fCurrentInputBlock;
706 if (pBlock) {
707 if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
708 } else {
709 HLTError("unknown Block %p", pBlock);
710 }
711 }
712 if (idx>=0) {
713 // check for fpInputBlocks pointer done in FindInputBlock
714 iSpec=fpInputBlocks[idx].fSpecification;
715 }
716 return iSpec;
717}
718
79c114b5 719int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
720 void* pHeader, int headerSize)
a655eae3 721{
722 // see header file for function documentation
90ebac25 723 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 724 int iResult=0;
725 if (pObject) {
726 AliHLTMessage msg(kMESS_OBJECT);
727 msg.WriteObject(pObject);
728 Int_t iMsgLength=msg.Length();
729 if (iMsgLength>0) {
730 msg.SetLength(); // sets the length to the first (reserved) word
79c114b5 731 iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec, pHeader, headerSize);
a655eae3 732 if (iResult>=0) {
8451168b 733 HLTDebug("object %s (%p) size %d inserted to output", pObject->ClassName(), pObject, iMsgLength);
a655eae3 734 }
735 } else {
736 HLTError("object serialization failed for object %p", pObject);
737 iResult=-ENOMSG;
738 }
739 } else {
740 iResult=-EINVAL;
741 }
742 return iResult;
743}
744
79c114b5 745int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
746 void* pHeader, int headerSize)
a655eae3 747{
748 // see header file for function documentation
90ebac25 749 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 750 AliHLTComponentDataType dt;
751 SetDataType(dt, dtID, dtOrigin);
79c114b5 752 return PushBack(pObject, dt, spec, pHeader, headerSize);
a655eae3 753}
754
9d9ffd37 755int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
756 void* pHeader, int headerSize)
a655eae3 757{
758 // see header file for function documentation
90ebac25 759 ALIHLTCOMPONENT_BASE_STOPWATCH();
9d9ffd37 760 return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
a655eae3 761}
762
9d9ffd37 763int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
764 void* pHeader, int headerSize)
a655eae3 765{
766 // see header file for function documentation
90ebac25 767 ALIHLTCOMPONENT_BASE_STOPWATCH();
a655eae3 768 AliHLTComponentDataType dt;
769 SetDataType(dt, dtID, dtOrigin);
9d9ffd37 770 return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
a655eae3 771}
772
79c114b5 773int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
774 void* pHeader, int iHeaderSize)
a655eae3 775{
776 // see header file for function documentation
777 int iResult=0;
79c114b5 778 int iBlkSize = iBufferSize + iHeaderSize;
a655eae3 779 if (pBuffer) {
79c114b5 780 if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
a655eae3 781 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
782 AliHLTComponentBlockData bd;
783 FillBlockData( bd );
784 bd.fOffset = fOutputBufferFilled;
7c3234da 785 bd.fPtr = fpOutputBuffer;
79c114b5 786 bd.fSize = iBlkSize;
a655eae3 787 bd.fDataType = dt;
788 bd.fSpecification = spec;
79c114b5 789 if (pHeader!=NULL && pHeader!=pTgt) {
790 memcpy(pTgt, pHeader, iHeaderSize);
791 }
792
793 pTgt += (AliHLTUInt8_t) iHeaderSize;
794
a655eae3 795 if (pBuffer!=NULL && pBuffer!=pTgt) {
79c114b5 796 memcpy(pTgt, pBuffer, iBufferSize);
797
4b98eadb 798 //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer);
79c114b5 799 //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
a655eae3 800 }
801 fOutputBufferFilled+=bd.fSize;
802 fOutputBlocks.push_back( bd );
79c114b5 803 //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
a655eae3 804 } else {
805 if (fpOutputBuffer) {
79c114b5 806 HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iBlkSize);
a655eae3 807 } else {
808 HLTError("output buffer not available");
809 }
810 iResult=-ENOSPC;
811 }
812 } else {
813 iResult=-EINVAL;
814 }
815 return iResult;
816}
817
8451168b 818int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
819{
66043029 820 // see header file for function documentation
8451168b 821 if (!pObject) return -EINVAL;
822 AliHLTMessage msg(kMESS_OBJECT);
823 msg.WriteObject(pObject);
824 return msg.Length();
825}
826
79c114b5 827AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
828 const char* dtOrigin,
829 AliHLTUInt32_t spec)
830{
831 // see header file for function documentation
832 ALIHLTCOMPONENT_BASE_STOPWATCH();
833 AliHLTComponentDataType dt;
834 SetDataType(dt, dtID, dtOrigin);
835 return CreateMemoryFile(capacity, dt, spec);
836}
837
838AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
839 const AliHLTComponentDataType& dt,
840 AliHLTUInt32_t spec)
841{
842 // see header file for function documentation
843 ALIHLTCOMPONENT_BASE_STOPWATCH();
844 AliHLTMemoryFile* pFile=NULL;
83fec083 845 if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
79c114b5 846 AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
847 pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
848 if (pFile) {
83fec083 849 unsigned int nofBlocks=fOutputBlocks.size();
79c114b5 850 if (nofBlocks+1>fMemFiles.size()) {
851 fMemFiles.resize(nofBlocks+1, NULL);
852 }
853 if (nofBlocks<fMemFiles.size()) {
854 fMemFiles[nofBlocks]=pFile;
855 AliHLTComponentBlockData bd;
856 FillBlockData( bd );
857 bd.fOffset = fOutputBufferFilled;
7c3234da 858 bd.fPtr = fpOutputBuffer;
79c114b5 859 bd.fSize = capacity;
860 bd.fDataType = dt;
861 bd.fSpecification = spec;
862 fOutputBufferFilled+=bd.fSize;
863 fOutputBlocks.push_back( bd );
864 } else {
865 HLTError("can not allocate/grow object array");
29312178 866 pFile->CloseMemoryFile(0);
79c114b5 867 delete pFile;
868 pFile=NULL;
869 }
870 }
871 } else {
872 HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
873 }
874 return pFile;
875}
876
877AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
878 const char* dtOrigin,
879 AliHLTUInt32_t spec,
880 float capacity)
881{
882 // see header file for function documentation
883 ALIHLTCOMPONENT_BASE_STOPWATCH();
884 AliHLTComponentDataType dt;
885 SetDataType(dt, dtID, dtOrigin);
886 int size=fOutputBufferSize-fOutputBufferFilled;
887 if (capacity<0 || capacity>1.0) {
888 HLTError("invalid parameter: capacity %f", capacity);
889 return NULL;
890 }
891 size=(int)(size*capacity);
892 return CreateMemoryFile(size, dt, spec);
893}
894
895AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
896 AliHLTUInt32_t spec,
897 float capacity)
898{
899 // see header file for function documentation
900 ALIHLTCOMPONENT_BASE_STOPWATCH();
901 int size=fOutputBufferSize-fOutputBufferFilled;
902 if (capacity<0 || capacity>1.0) {
903 HLTError("invalid parameter: capacity %f", capacity);
904 return NULL;
905 }
906 size=(int)(size*capacity);
907 return CreateMemoryFile(size, dt, spec);
908}
909
910int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
911 const char* key, int option)
912{
913 int iResult=0;
914 if (pFile && pObject) {
915 pFile->cd();
916 iResult=pObject->Write(key, option);
917 if (iResult>0) {
918 // success
919 } else {
920 iResult=-pFile->GetErrno();
921 if (iResult==-ENOSPC) {
922 HLTError("error writing memory file, buffer too small");
923 }
924 }
925 } else {
926 iResult=-EINVAL;
927 }
928 return iResult;
929}
930
931int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
932{
933 int iResult=0;
934 if (pFile) {
935 vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin();
936 int i=0;
937 while (element!=fMemFiles.end() && iResult>=0) {
938 if (*element && *element==pFile) {
29312178 939 iResult=pFile->CloseMemoryFile();
79c114b5 940
941 // sync memory files and descriptors
942 if (iResult>=0) {
943 fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
944 }
945 delete *element;
946 *element=NULL;
947 return iResult;
948 }
949 element++; i++;
950 }
951 HLTError("can not find memory file %p", pFile);
952 iResult=-ENOENT;
953 } else {
954 iResult=-EINVAL;
955 }
956 return iResult;
957}
958
29312178 959int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData /*edd*/)
a655eae3 960{
961 // see header file for function documentation
962 int iResult=-ENOSYS;
963 //#warning function not yet implemented
964 HLTWarning("function not yet implemented");
965 return iResult;
966}
967
3cde846d 968int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
969 const AliHLTComponentBlockData* blocks,
970 AliHLTComponentTriggerData& trigData,
971 AliHLTUInt8_t* outputPtr,
972 AliHLTUInt32_t& size,
973 AliHLTUInt32_t& outputBlockCnt,
974 AliHLTComponentBlockData*& outputBlocks,
975 AliHLTComponentEventDoneData*& edd )
976{
70ed7d01 977 // see header file for function documentation
90ebac25 978 ALIHLTCOMPONENT_BASE_STOPWATCH();
3cde846d 979 int iResult=0;
980 fCurrentEvent=evtData.fEventID;
a655eae3 981 fCurrentEventData=evtData;
982 fpInputBlocks=blocks;
983 fCurrentInputBlock=-1;
984 fSearchDataType=kAliHLTAnyDataType;
985 fpOutputBuffer=outputPtr;
986 fOutputBufferSize=size;
987 fOutputBufferFilled=0;
988 fOutputBlocks.clear();
559631d5 989
990 // find special events
991 if (fpInputBlocks) {
83fec083 992 for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
559631d5 993 if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
994 // start of run
995 if (fpRunDesc==NULL) {
996 fpRunDesc=new AliHLTRunDesc;
997 if (fpRunDesc) {
998 if ((iResult=CopyStruct(fpRunDesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) {
999 HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1000 }
1001 } else {
1002 iResult=-ENOMEM;
1003 }
1004 } else {
1005 HLTWarning("already received SOR event run no %d, ignoring SOR", fpRunDesc->fRunNo);
1006 }
1007 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1008 if (fpRunDesc!=NULL) {
1009 if (fpRunDesc) {
1010 AliHLTRunDesc rundesc;
1011 if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), i, "AliHLTRunDesc", "SOR"))>0) {
1012 if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1013 HLTWarning("run no missmatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1014 } else {
1015 HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1016 }
1017 }
1018 AliHLTRunDesc* pRunDesc=fpRunDesc;
1019 fpRunDesc=NULL;
1020 delete pRunDesc;
1021 }
1022 } else {
1023 HLTWarning("did not receive SOR, ignoring EOR");
1024 }
1025 // end of run
1026 } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1027 // DDL list
1028 }
1029 }
1030 }
a655eae3 1031
1032 vector<AliHLTComponentBlockData> blockData;
90ebac25 1033 { // dont delete, sets the scope for the stopwatch guard
1034 ALIHLTCOMPONENT_DA_STOPWATCH();
1035 iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1036 } // end of the scope of the stopwatch guard
a655eae3 1037 if (iResult>=0) {
1038 if (fOutputBlocks.size()>0) {
1039 //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
79c114b5 1040
1041 // sync memory files and descriptors
1042 vector<AliHLTMemoryFile*>::iterator element=fMemFiles.begin();
1043 int i=0;
1044 while (element!=fMemFiles.end() && iResult>=0) {
1045 if (*element) {
1046 if ((*element)->IsClosed()==0) {
1047 HLTWarning("memory file has not been closed, force flush");
1048 iResult=CloseMemoryFile(*element);
1049 }
1050 }
1051 element++; i++;
1052 }
1053
1054 if (iResult>=0) {
1055 // create the descriptor list
1056 if (blockData.size()>0) {
1057 HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1058 iResult=-EFAULT;
1059 } else {
1060 iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1061 size=fOutputBufferFilled;
1062 }
a655eae3 1063 }
1064 } else {
1065 iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1066 }
1067 if (iResult<0) {
1068 HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1069 }
1070 }
1071 if (iResult<0) {
1072 outputBlockCnt=0;
1073 outputBlocks=NULL;
1074 }
8451168b 1075 CleanupInputObjects();
f8bc6d99 1076 if (iResult>=0) {
1077 IncrementEventCounter();
1078 }
3cde846d 1079 return iResult;
1080}
a655eae3 1081
90ebac25 1082AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1083 :
1084 fpStopwatch(NULL),
1085 fpPrec(NULL)
1086{
1087 // standard constructor (not for use)
1088}
1089
1090AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1091 :
1092 fpStopwatch(pStopwatch),
1093 fpPrec(NULL)
1094{
1095 // constructor
1096
1097 // check for already existing guard
1098 if (fgpCurrent) fpPrec=fgpCurrent;
1099 fgpCurrent=this;
1100
1101 // stop the preceeding guard if it controls a different stopwatch
1102 int bStart=1;
1103 if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1104
1105 // start the stopwatch if the current guard controls a different one
1106 if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
1107}
1108
e419b223 1109AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
90ebac25 1110 :
1111 fpStopwatch(NULL),
1112 fpPrec(NULL)
1113{
e419b223 1114 //
1115 // copy constructor not for use
1116 //
1117}
1118
1119AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
1120{
1121 //
1122 // assignment operator not for use
1123 //
1124 fpStopwatch=NULL;
1125 fpPrec=NULL;
1126 return *this;
90ebac25 1127}
1128
1129AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
1130
1131AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
1132{
1133 // destructor
1134
1135 // resume the preceeding guard if it controls a different stopwatch
1136 int bStop=1;
1137 if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
1138
1139 // stop the stopwatch if the current guard controls a different one
1140 if (fpStopwatch && bStop==1) fpStopwatch->Stop();
1141
1142 // resume to the preceeding guard
1143 fgpCurrent=fpPrec;
1144}
1145
1146int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
1147{
1148 // see header file for function documentation
1149 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
1150 return fpStopwatch!=pSucc?1:0;
1151}
1152
1153int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
1154{
1155 // see header file for function documentation
1156 if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
1157 return fpStopwatch!=pSucc?1:0;
1158}
1159
1160int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type)
1161{
1162 // see header file for function documentation
1163 int iResult=0;
1164 if (pSW!=NULL && type<kSWTypeCount) {
1165 if (fpStopwatches) {
1166 TObject* pObj=fpStopwatches->At((int)type);
1167 if (pSW==NULL // explicit reset
1168 || pObj==NULL) { // explicit set
1169 fpStopwatches->AddAt(pSW, (int)type);
1170 } else if (pObj!=pSW) {
1171 HLTWarning("stopwatch %d already set, reset first", (int)type);
1172 iResult=-EBUSY;
1173 }
1174 }
1175 } else {
1176 iResult=-EINVAL;
1177 }
1178 return iResult;
1179}
1180
1181int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
1182{
1183 // see header file for function documentation
1184 if (pStopwatches==NULL) return -EINVAL;
1185
1186 int iResult=0;
1187 for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
1188 SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
1189 return iResult;
1190}
559631d5 1191
1192AliHLTUInt32_t AliHLTComponent::GetRunNo() const
1193{
29312178 1194 // see header file for function documentation
559631d5 1195 if (fpRunDesc==NULL) return 0;
1196 return fpRunDesc->fRunNo;
1197}
1198
1199AliHLTUInt32_t AliHLTComponent::GetRunType() const
1200{
29312178 1201 // see header file for function documentation
559631d5 1202 if (fpRunDesc==NULL) return 0;
1203 return fpRunDesc->fRunType;
1204}
1205
83fec083 1206int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
559631d5 1207 const char* structname, const char* eventname)
1208{
29312178 1209 // see header file for function documentation
559631d5 1210 int iResult=0;
1211 if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
1212 if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
1213 AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
1214 if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
1215 AliHLTUInt8_t* pSrc=((AliHLTUInt8_t*)fpInputBlocks[iBlockNo].fPtr)+fpInputBlocks[iBlockNo].fOffset;
1216 AliHLTUInt32_t copy=*((AliHLTUInt32_t*)pSrc);
1217 if (fpInputBlocks[iBlockNo].fSize!=copy) {
1218 HLTWarning("%s event: missmatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
1219 if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
1220 }
1221 if (copy!=iStructSize) {
1222 HLTWarning("%s event: missmatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
1223 if (copy>iStructSize) {
1224 copy=iStructSize;
1225 } else {
1226 memset(pTgt, 0, iStructSize);
1227 }
1228 }
1229 memcpy(pTgt, pSrc, copy);
1230 *pTgt=iStructSize;
1231 iResult=copy;
1232 } else {
1233 HLTWarning("%s event: missing data block", eventname);
1234 }
1235 } else {
1236 iResult=-ENODATA;
1237 }
1238 } else {
1239 HLTError("invalid struct");
1240 iResult=-EINVAL;
1241 }
1242 return iResult;
1243}