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