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