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