]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponent.cxx
adding AliHLTComponent base class methods to access event properties orbit,
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
1 // $Id$
2
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 //**************************************************************************
19
20 /** @file   AliHLTComponent.cxx
21     @author Matthias Richter, Timm Steinbeck
22     @date   
23     @brief  Base class implementation for HLT components. */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28
29 //#include "AliHLTStdIncludes.h"
30 #include "AliHLTComponent.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTMessage.h"
33 #include "AliHLTCTPData.h"
34 #include "TString.h"
35 #include "TMath.h"
36 #include "TObjArray.h"
37 #include "TObjectTable.h"
38 #include "TClass.h"
39 #include "TStopwatch.h"
40 #include "TFormula.h"
41 #include "AliHLTMemoryFile.h"
42 #include "AliHLTMisc.h"
43 #include <cassert>
44 #include <stdint.h>
45
46 /**
47  * default compression level for ROOT objects
48  */
49 #define ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION 5
50 #define ALIHLTCOMPONENT_STATTIME_SCALER 1000000
51
52 /** ROOT macro for the implementation of ROOT specific class methods */
53 ClassImp(AliHLTComponent);
54
55 /** stopwatch macro using the stopwatch guard */
56 #define ALIHLTCOMPONENT_STOPWATCH(type) AliHLTStopwatchGuard swguard(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)type)):NULL)
57 //#define ALIHLTCOMPONENT_STOPWATCH(type) 
58
59 /** stopwatch macro for operations of the base class */
60 #define ALIHLTCOMPONENT_BASE_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWBase)
61 /** stopwatch macro for operations of the detector algorithm (DA) */
62 #define ALIHLTCOMPONENT_DA_STOPWATCH() ALIHLTCOMPONENT_STOPWATCH(kSWDA)
63
64 AliHLTComponent::AliHLTComponent()
65   :
66   fEnvironment(),
67   fCurrentEvent(0),
68   fEventCount(-1),
69   fFailedEvents(0),
70   fCurrentEventData(),
71   fpInputBlocks(NULL),
72   fCurrentInputBlock(-1),
73   fSearchDataType(kAliHLTVoidDataType),
74   fClassName(),
75   fpInputObjects(NULL),
76   fpOutputBuffer(NULL),
77   fOutputBufferSize(0),
78   fOutputBufferFilled(0),
79   fOutputBlocks(),
80   fpStopwatches(new TObjArray(kSWTypeCount)),
81   fMemFiles(),
82   fpRunDesc(NULL),
83   fpDDLList(NULL),
84   fCDBSetRunNoFunc(false),
85   fChainId(),
86   fChainIdCrc(0),
87   fpBenchmark(NULL),
88   fRequireSteeringBlocks(false),
89   fEventType(gkAliEventTypeUnknown),
90   fComponentArgs(),
91   fEventDoneData(NULL),
92   fEventDoneDataSize(0),
93   fCompressionLevel(ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION)
94   , fLastObjectSize(0)
95   , fpCTPData(NULL)
96 {
97   // see header file for class documentation
98   // or
99   // refer to README to build package
100   // or
101   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
102   memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
103   if (fgpComponentHandler)
104     fgpComponentHandler->ScheduleRegister(this);
105   //SetLocalLoggingLevel(kHLTLogDefault);
106 }
107
108 AliHLTComponent::~AliHLTComponent()
109 {
110   // see header file for function documentation
111   if (fpBenchmark) delete fpBenchmark;
112   fpBenchmark=NULL;
113
114   CleanupInputObjects();
115   if (fpStopwatches!=NULL) delete fpStopwatches;
116   fpStopwatches=NULL;
117   AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
118   while (element!=fMemFiles.end()) {
119     if (*element) {
120       if ((*element)->IsClosed()==0) {
121         HLTWarning("memory file has not been closed, possible data loss or incomplete buffer");
122         // close but do not flush as we dont know whether the buffer is still valid
123         (*element)->CloseMemoryFile(0);
124       }
125       delete *element;
126       *element=NULL;
127     }
128     element++;
129   }
130   if (fpRunDesc) {
131     delete fpRunDesc;
132     fpRunDesc=NULL;
133   }
134   if (fEventDoneData)
135     delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
136   fEventDoneData=NULL;
137
138   if (fpCTPData) {
139     delete fpCTPData;
140   }
141   fpCTPData=NULL;
142 }
143
144 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
145
146 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) 
147 {
148   // see header file for function documentation
149   int iResult=0;
150   if (fgpComponentHandler==NULL || bOverwrite!=0)
151     fgpComponentHandler=pCH;
152   else
153     iResult=-EPERM;
154   return iResult;
155 }
156
157 int AliHLTComponent::UnsetGlobalComponentHandler() 
158 {
159   // see header file for function documentation
160   return SetGlobalComponentHandler(NULL,1);
161 }
162
163 int AliHLTComponent::SetComponentEnvironment(const AliHLTAnalysisEnvironment* comenv, void* environParam)
164 {
165   // see header file for function documentation
166   HLTLogKeyword(fChainId.c_str());
167   int iResult=0;
168   if (comenv) {
169     memset(&fEnvironment, 0, sizeof(AliHLTAnalysisEnvironment));
170     memcpy(&fEnvironment, comenv, comenv->fStructSize<sizeof(AliHLTAnalysisEnvironment)?comenv->fStructSize:sizeof(AliHLTAnalysisEnvironment));
171     fEnvironment.fStructSize=sizeof(AliHLTAnalysisEnvironment);
172     fEnvironment.fParam=environParam;
173   }
174   return iResult;
175 }
176
177 int AliHLTComponent::Init(const AliHLTAnalysisEnvironment* comenv, void* environParam, int argc, const char** argv )
178 {
179   // see header file for function documentation
180   HLTLogKeyword(fChainId.c_str());
181   int iResult=0;
182   if (comenv) {
183     SetComponentEnvironment(comenv, environParam);
184   }
185   fComponentArgs="";
186   const char** pArguments=NULL;
187   int iNofChildArgs=0;
188   TString argument="";
189   int bMissingParam=0;
190   if (argc>0) {
191     pArguments=new const char*[argc];
192     if (pArguments) {
193       for (int i=0; i<argc && iResult>=0; i++) {
194         if (fComponentArgs.size()>0) fComponentArgs+=" ";
195         fComponentArgs+=argv[i];
196         argument=argv[i];
197         if (argument.IsNull()) continue;
198
199         // benchmark
200         if (argument.CompareTo("-benchmark")==0) {
201
202           // -loglevel=
203         } else if (argument.BeginsWith("-loglevel=")) {
204           TString parameter=argument.ReplaceAll("-loglevel=", "");
205           parameter.Remove(TString::kLeading, ' '); // remove all blanks
206           if (parameter.BeginsWith("0x") &&
207               parameter.Replace(0,2,"",0).IsHex()) {
208             unsigned int loglevel=kHLTLogNone;
209             sscanf(parameter.Data(),"%x", &loglevel);
210             SetLocalLoggingLevel((AliHLTComponentLogSeverity)loglevel);
211           } else {
212             HLTError("wrong parameter for argument %s, hex number expected", argument.Data());
213             iResult=-EINVAL;
214           }
215           // -object-compression=
216         } else if (argument.BeginsWith("-object-compression=")) {
217           argument.ReplaceAll("-object-compression=", "");
218           if (argument.IsDigit()) {
219             fCompressionLevel=argument.Atoi();
220             if (fCompressionLevel<0 || fCompressionLevel>9) {
221               HLTWarning("invalid compression level %d, setting to default %d", fCompressionLevel, ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION);
222               fCompressionLevel=ALIHLTCOMPONENT_DEFAULT_OBJECT_COMPRESSION;
223             }
224           } else {
225             HLTError("wrong parameter for argument -object-compression, number expected");
226           }
227         } else {
228           pArguments[iNofChildArgs++]=argv[i];
229         }
230       }
231     } else {
232       iResult=-ENOMEM;
233     }
234   }
235   if (bMissingParam) {
236     HLTError("missing parameter for argument %s", argument.Data());
237     iResult=-EINVAL;
238   }
239   if (iResult>=0) {
240     iResult=DoInit(iNofChildArgs, pArguments);
241   }
242   if (iResult>=0) {
243     fEventCount=0;
244
245     // find out if the component wants to get the steering events
246     // explicitly
247     AliHLTComponentDataTypeList inputDt;
248     GetInputDataTypes(inputDt);
249     for (AliHLTComponentDataTypeList::iterator dt=inputDt.begin();
250          dt!=inputDt.end() && !fRequireSteeringBlocks;
251          dt++) {
252       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeSOR);
253       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeRunType);
254       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeEOR);
255       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeDDL);
256       fRequireSteeringBlocks|=MatchExactly(*dt,kAliHLTDataTypeComponentStatistics);
257     }
258   }
259   if (pArguments) delete [] pArguments;
260
261 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
262   // benchmarking stopwatch for the component statistics
263   fpBenchmark=new TStopwatch;
264 #endif
265
266   return iResult;
267 }
268
269 int AliHLTComponent::Deinit()
270 {
271   // see header file for function documentation
272   HLTLogKeyword(fChainId.c_str());
273   int iResult=0;
274   iResult=DoDeinit();
275   if (fpRunDesc) {
276     // TODO: the warning should be kept, but the condition is wrong since the
277     // AliHLTRunDesc is set before the SOR event in the SetRunDescription
278     // method. A couple of state flags should be defined but that is a bit more
279     // work to do. For the moment disable the warning (2009-07-01)
280     //HLTWarning("did not receive EOR for run %d", fpRunDesc->fRunNo);
281     AliHLTRunDesc* pRunDesc=fpRunDesc;
282     fpRunDesc=NULL;
283     delete pRunDesc;
284   }
285   if (fpCTPData) {
286     delete fpCTPData;
287   }
288   fpCTPData=NULL;
289
290   fEventCount=0;
291   return iResult;
292 }
293
294 int AliHLTComponent::InitCDB(const char* cdbPath, AliHLTComponentHandler* pHandler)
295 {
296   // see header file for function documentation
297   int iResult=0;
298   HLTInfo("Using CDB: %s", cdbPath);
299   if (pHandler) {
300   // I have to think about separating the library handling from the
301   // component handler. Requiring the component handler here is not
302   // the cleanest solution.
303   // We presume the library already to be loaded, which is the case
304   // because it is loaded in the initialization of the logging functionality
305   //
306   // find the symbol
307   AliHLTMiscInitCDB_t pFunc=(AliHLTMiscInitCDB_t)pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_INIT_CDB);
308   if (pFunc) {
309     TString path;
310     if (cdbPath && cdbPath[0]!=0) {
311       path=cdbPath;
312       // very temporary fix, have to check for other formats
313       if (!path.BeginsWith("local://")) {
314         path="local://";
315         path+=cdbPath;
316       }
317     }
318     if ((iResult=(*pFunc)(path.Data()))>=0) {
319       if (!(fCDBSetRunNoFunc=pHandler->FindSymbol(ALIHLTMISC_LIBRARY, ALIHLTMISC_SET_CDB_RUNNO))) {
320         Message(NULL, kHLTLogWarning, "AliHLTComponent::InitCDB", "init CDB",
321                 "can not find function to set CDB run no");
322       }
323     }
324   } else {
325     Message(NULL, kHLTLogError, "AliHLTComponent::InitCDB", "init CDB",
326             "can not find initialization function");
327     iResult=-ENOSYS;
328   }
329   } else {
330     iResult=-EINVAL;
331   }
332   return iResult;
333 }
334
335 int AliHLTComponent::SetCDBRunNo(int runNo)
336 {
337   // see header file for function documentation
338   if (!fCDBSetRunNoFunc) return 0;
339   return (*((AliHLTMiscSetCDBRunNo_t)fCDBSetRunNoFunc))(runNo);
340 }
341
342 int AliHLTComponent::SetRunDescription(const AliHLTRunDesc* desc, const char* /*runType*/)
343 {
344   // see header file for function documentation
345   if (!desc) return -EINVAL;
346   if (desc->fStructSize!=sizeof(AliHLTRunDesc)) {
347     HLTError("invalid size of RunDesc struct (%ul)", desc->fStructSize);
348     return -EINVAL;
349   }
350
351   if (!fpRunDesc) {
352     fpRunDesc=new AliHLTRunDesc;
353     if (!fpRunDesc) return -ENOMEM;
354     *fpRunDesc=kAliHLTVoidRunDesc;
355   }
356
357   if (fpRunDesc->fRunNo!=kAliHLTVoidRunNo && fpRunDesc->fRunNo!=desc->fRunNo) {
358     HLTWarning("Run description has already been set");
359   }
360   *fpRunDesc=*desc;
361   SetCDBRunNo(fpRunDesc->fRunNo);
362   // TODO: we have to decide about the runType
363   return 0;
364 }
365
366 int AliHLTComponent::SetComponentDescription(const char* desc)
367 {
368   // see header file for function documentation
369   int iResult=0;
370   if (!desc) return 0;
371
372   TString descriptor=desc;
373   TObjArray* pTokens=descriptor.Tokenize(" ");
374   if (pTokens) {
375     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
376       TString argument=((TObjString*)pTokens->At(i++))->GetString();
377       if (!argument || argument.IsNull()) continue;
378
379       // chainid
380       if (argument.BeginsWith("chainid")) {
381         argument.ReplaceAll("chainid", "");
382         if (argument.BeginsWith("=")) {
383           fChainId=argument.Replace(0,1,"");
384           fChainIdCrc=CalculateChecksum((const AliHLTUInt8_t*)fChainId.c_str(), fChainId.length());
385           HLTDebug("setting component description: chain id %s crc 0x%8x", fChainId.c_str(), fChainIdCrc);
386         } else {
387           fChainId="";
388         }
389       } else {
390         HLTWarning("unknown component description %s", argument.Data());
391       }
392     }
393   }
394   
395   return iResult;
396 }
397
398 int AliHLTComponent::ConfigureFromArgumentString(int argc, const char** argv)
399 {
400   // see header file for function documentation
401   int iResult=0;
402   vector<const char*> array;
403   TObjArray choppedArguments;
404   TString argument="";
405   int i=0;
406   for (i=0; i<argc && iResult>=0; i++) {
407     argument=argv[i];
408     if (argument.IsNull()) continue;
409     TObjArray* pTokens=argument.Tokenize(" ");
410     if (pTokens) {
411       if (pTokens->GetEntriesFast()>0) {
412         for (int n=0; n<pTokens->GetEntriesFast(); n++) {
413           choppedArguments.AddLast(pTokens->At(n));
414           TString data=((TObjString*)pTokens->At(n))->GetString();
415           if (!data.IsNull()) {
416             array.push_back(data.Data());
417           }
418         }
419         pTokens->SetOwner(kFALSE);
420       }
421       delete pTokens;
422     }
423   }
424
425   for (i=0; (unsigned)i<array.size() && iResult>=0;) {
426     int result=ScanConfigurationArgument(array.size()-i, &array[i]);
427     if (result==0) {
428       HLTWarning("unknown component argument %s", array[i]);
429       i++;
430     } else if (result>0) {
431       i+=result;
432     } else {
433       iResult=result;
434       if (iResult==-EINVAL) {
435         HLTError("unknown argument %s", array[i]);
436       } else if (iResult==-EPROTO) {
437         HLTError("missing/wrong parameter for argument %s (%s)", array[i], (array.size()>(unsigned)i+1)?array[i+1]:"missing");
438       } else {
439         HLTError("scan of argument %s failed (%d)", array[i], iResult);
440       }
441     }
442   }
443
444   return iResult;
445 }
446
447 int AliHLTComponent::ConfigureFromCDBTObjString(const char* entries)
448 {
449   // see header file for function documentation
450   int iResult=0;
451   TString arguments;
452   TString confEntries=entries;
453   TObjArray* pTokens=confEntries.Tokenize(" ");
454   if (pTokens) {
455     for (int n=0; n<pTokens->GetEntriesFast(); n++) {
456       const char* path=((TObjString*)pTokens->At(n))->GetString().Data();
457       const char* chainId=GetChainId();
458       HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
459       TObject* pOCDBObject = LoadAndExtractOCDBObject(path);
460       if (pOCDBObject) {
461         TObjString* pString=dynamic_cast<TObjString*>(pOCDBObject);
462         if (pString) {
463           HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
464           arguments+=pString->GetString().Data();
465           arguments+=" ";
466         } else {
467           HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
468           iResult=-EINVAL;
469         }
470       } else {
471         HLTError("can not fetch object \"%s\" from OCDB", path);
472         iResult=-ENOENT;
473       }
474     }
475     delete pTokens;
476   }
477   if (iResult>=0 && !arguments.IsNull())  {
478     const char* array=arguments.Data();
479     iResult=ConfigureFromArgumentString(1, &array);
480   }
481   return iResult;
482 }
483
484 TObject* AliHLTComponent::LoadAndExtractOCDBObject(const char* path, int version, int subVersion)
485 {
486   // see header file for function documentation
487   AliCDBEntry* pEntry=AliHLTMisc::Instance().LoadOCDBEntry(path, GetRunNo(), version, subVersion);
488   if (!pEntry) return NULL;
489   return AliHLTMisc::Instance().ExtractObject(pEntry);
490 }
491
492 int AliHLTComponent::DoInit( int /*argc*/, const char** /*argv*/)
493 {
494   // default implementation, childs can overload
495   HLTLogKeyword("dummy");
496   return 0;
497 }
498
499 int AliHLTComponent::DoDeinit()
500 {
501   // default implementation, childs can overload
502   HLTLogKeyword("dummy");
503   return 0;
504 }
505
506 int AliHLTComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/)
507 {
508   // default implementation, childs can overload
509   HLTLogKeyword("dummy");
510   return 0;
511 }
512
513 int AliHLTComponent::ReadPreprocessorValues(const char* /*modules*/)
514 {
515   // default implementation, childs can overload
516   HLTLogKeyword("dummy");
517   return 0;
518 }
519
520 int AliHLTComponent::ScanConfigurationArgument(int /*argc*/, const char** /*argv*/)
521 {
522   // default implementation, childs can overload
523   HLTLogKeyword("dummy");
524   HLTWarning("The function needs to be implemented by the component");
525   return 0;
526 }
527
528 int AliHLTComponent::StartOfRun()
529 {
530   // default implementation, childs can overload
531   HLTLogKeyword("dummy");
532   return 0;
533 }
534
535 int AliHLTComponent::EndOfRun()
536 {
537   // default implementation, childs can overload
538   HLTLogKeyword("dummy");
539   return 0;
540 }
541
542
543 int AliHLTComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& /*tgtList*/)
544 {
545   // default implementation, childs can overload
546   HLTLogKeyword("dummy");
547   return 0;
548 }
549
550 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
551 {
552   // see header file for function documentation
553   memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
554   strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
555   strcat( output, ":" );
556   strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
557 }
558
559 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, int mode)
560 {
561   // see header file for function documentation
562   string out("");
563
564   if (mode==2) {
565     int i=0;
566     char tmp[8];
567     for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
568       sprintf(tmp, "'%d", type.fOrigin[i]);
569       out+=tmp;
570     }
571     out+="':'";
572     for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
573       sprintf(tmp, "%d'", type.fID[i]);
574       out+=tmp;
575     }
576     return out;
577   }
578
579   if (mode==1) {
580     int i=0;
581     char tmp[8];
582     for (i=0; i<kAliHLTComponentDataTypefOriginSize; i++) {
583       unsigned char* puc=(unsigned char*)type.fOrigin;
584       if ((puc[i])<32)
585         sprintf(tmp, "'\\%x", type.fOrigin[i]);
586       else
587         sprintf(tmp, "'%c", type.fOrigin[i]);
588       out+=tmp;
589     }
590     out+="':'";
591     for (i=0; i<kAliHLTComponentDataTypefIDsize; i++) {
592       unsigned char* puc=(unsigned char*)type.fID;
593       if (puc[i]<32)
594         sprintf(tmp, "\\%x'", type.fID[i]);
595       else
596         sprintf(tmp, "%c'", type.fID[i]);
597       out+=tmp;
598     }
599     return out;
600   }
601
602   if (type==kAliHLTVoidDataType) {
603     out="VOID:VOID";
604   } else {
605     // some gymnastics in order to avoid a '0' which is part of either or both
606     // ID and origin terminating the whole string. Unfortunately, string doesn't
607     // stop appending at the '0' if the number of elements to append was 
608     // explicitely specified
609     string tmp("");
610     tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
611     out.append(tmp.c_str());
612     out.append(":");
613     tmp="";
614     tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
615     out.append(tmp.c_str());
616   }
617   return out;
618 }
619
620
621 void* AliHLTComponent::AllocMemory( unsigned long size ) 
622 {
623   // see header file for function documentation
624   if (fEnvironment.fAllocMemoryFunc)
625     return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
626   HLTFatal("no memory allocation handler registered");
627   return NULL;
628 }
629
630 int AliHLTComponent::MakeOutputDataBlockList( const AliHLTComponentBlockDataList& blocks, AliHLTUInt32_t* blockCount,
631                                               AliHLTComponentBlockData** outputBlocks ) 
632 {
633   // see header file for function documentation
634     if ( blockCount==NULL || outputBlocks==NULL )
635         return -EFAULT;
636     AliHLTUInt32_t count = blocks.size();
637     if ( !count )
638         {
639         *blockCount = 0;
640         *outputBlocks = NULL;
641         return 0;
642         }
643     *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
644     if ( !*outputBlocks )
645         return -ENOMEM;
646     for ( unsigned long i = 0; i < count; i++ ) {
647         (*outputBlocks)[i] = blocks[i];
648         if (MatchExactly(blocks[i].fDataType, kAliHLTAnyDataType)) {
649           (*outputBlocks)[i].fDataType=GetOutputDataType();
650           /* data type was set to the output data type by the PubSub AliRoot
651              Wrapper component, if data type of the block was ********:****.
652              Now handled by the component base class in order to have same
653              behavior when running embedded in AliRoot
654           memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
655           memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
656           */
657         }
658     }
659     *blockCount = count;
660     return 0;
661
662 }
663
664 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) 
665 {
666   // see header file for function documentation
667   if (fEnvironment.fGetEventDoneDataFunc)
668     return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
669   return -ENOSYS;
670 }
671
672 int AliHLTComponent::ReserveEventDoneData( unsigned long size )
673 {
674   // see header file for function documentation
675   int iResult=0;
676
677   unsigned long capacity=fEventDoneDataSize;
678   if (fEventDoneData) capacity-=sizeof(AliHLTComponentEventDoneData)+fEventDoneData->fDataSize;
679   if (size>capacity) {
680     unsigned long newSize=sizeof(AliHLTComponentEventDoneData)+size+(fEventDoneDataSize-capacity);
681     AliHLTComponentEventDoneData* newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[newSize] );
682     if (!newEDD)
683       return -ENOMEM;
684     newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
685     newEDD->fDataSize = 0;
686     newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
687     if (fEventDoneData) {
688       memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
689       newEDD->fDataSize = fEventDoneData->fDataSize;
690       delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
691     }
692     fEventDoneData = newEDD;
693     fEventDoneDataSize = newSize;
694   }
695   return iResult;
696
697 }
698
699 int AliHLTComponent::PushEventDoneData( AliHLTUInt32_t eddDataWord )
700 {
701   if (!fEventDoneData)
702     return -ENOMEM;
703   if (fEventDoneData->fDataSize+sizeof(AliHLTUInt32_t)>fEventDoneDataSize)
704     return -ENOSPC;
705   *reinterpret_cast<AliHLTUInt32_t*>((reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize)) = eddDataWord;
706   fEventDoneData->fDataSize += sizeof(AliHLTUInt32_t);
707   return 0;
708 }
709
710 void AliHLTComponent::ReleaseEventDoneData()
711 {
712   if (fEventDoneData)
713     delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
714   fEventDoneData = NULL;
715   fEventDoneDataSize = 0;
716 }
717
718
719 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, AliHLTComponentDataTypeList* tgtList) 
720 {
721   // see header file for function documentation
722   int iResult=0;
723   if (pConsumer) {
724     AliHLTComponentDataTypeList itypes;
725     AliHLTComponentDataTypeList otypes;
726     otypes.push_back(GetOutputDataType());
727     if (MatchExactly(otypes[0],kAliHLTMultipleDataType)) {
728       otypes.clear();
729       int count=0;
730       if ((count=GetOutputDataTypes(otypes))>0) {
731       } else if (GetComponentType()!=kSink) {
732         HLTWarning("component %s indicates multiple output data types but GetOutputDataTypes returns %d", GetComponentID(), count);
733       }
734     }
735     ((AliHLTComponent*)pConsumer)->GetInputDataTypes(itypes);
736     AliHLTComponentDataTypeList::iterator otype=otypes.begin();
737     for (;otype!=otypes.end();otype++) {
738       //PrintDataTypeContent((*otype), "publisher \'%s\'");
739       if ((*otype)==(kAliHLTAnyDataType|kAliHLTDataOriginPrivate)) {
740         if (tgtList) tgtList->push_back(*otype);
741         iResult++;
742         continue;
743       }
744       
745       AliHLTComponentDataTypeList::iterator itype=itypes.begin();
746       for ( ; itype!=itypes.end() && (*itype)!=(*otype) ; itype++) {/* empty body */};
747       //if (itype!=itypes.end()) PrintDataTypeContent(*itype, "consumer \'%s\'");
748       if (itype!=itypes.end()) {
749         if (tgtList) tgtList->push_back(*otype);
750         iResult++;
751       }
752     }
753   } else {
754     iResult=-EINVAL;
755   }
756   return iResult;
757 }
758
759 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format)
760 {
761   // see header file for function documentation
762   const char* fmt="\'%s\'";
763   if (format) fmt=format;
764   AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, Form(fmt, (DataType2Text(dt)).c_str()));
765   AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, 
766                          Form("%x %x %x %x %x %x %x %x : %x %x %x %x", 
767                               dt.fID[0],
768                               dt.fID[1],
769                               dt.fID[2],
770                               dt.fID[3],
771                               dt.fID[4],
772                               dt.fID[5],
773                               dt.fID[6],
774                               dt.fID[7],
775                               dt.fOrigin[0],
776                               dt.fOrigin[1],
777                               dt.fOrigin[2],
778                               dt.fOrigin[3]));
779 }
780
781 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData )
782 {
783   // see header file for function documentation
784   blockData.fStructSize = sizeof(blockData);
785   FillShmData( blockData.fShmKey );
786   blockData.fOffset = ~(AliHLTUInt32_t)0;
787   blockData.fPtr = NULL;
788   blockData.fSize = 0;
789   FillDataType( blockData.fDataType );
790   blockData.fSpecification = kAliHLTVoidDataSpec;
791 }
792
793 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData )
794 {
795   // see header file for function documentation
796   shmData.fStructSize = sizeof(shmData);
797   shmData.fShmType = gkAliHLTComponentInvalidShmType;
798   shmData.fShmID = gkAliHLTComponentInvalidShmID;
799 }
800
801 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType )
802 {
803   // see header file for function documentation
804   dataType=kAliHLTAnyDataType;
805 }
806
807 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) 
808 {
809   // see header file for function documentation
810   memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
811   memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
812 }
813
814 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) 
815 {
816   // see header file for function documentation
817   tgtdt.fStructSize=sizeof(AliHLTComponentDataType);
818   if (id) {
819     memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
820     strncpy(&tgtdt.fID[0], id, strlen(id)<(size_t)kAliHLTComponentDataTypefIDsize?strlen(id):kAliHLTComponentDataTypefIDsize);
821   }
822   if (origin) {
823     memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
824     strncpy(&tgtdt.fOrigin[0], origin, strlen(origin)<(size_t)kAliHLTComponentDataTypefOriginSize?strlen(origin):kAliHLTComponentDataTypefOriginSize);
825   }
826 }
827
828 void AliHLTComponent::SetDataType(AliHLTComponentDataType& dt, AliHLTUInt64_t id, AliHLTUInt32_t origin)
829 {
830   // see header file for function documentation
831   dt.fStructSize=sizeof(AliHLTComponentDataType);
832   assert(kAliHLTComponentDataTypefIDsize==sizeof(id));
833   assert(kAliHLTComponentDataTypefOriginSize==sizeof(origin));
834   memcpy(&dt.fID, &id, kAliHLTComponentDataTypefIDsize);
835   memcpy(&dt.fOrigin, &origin, kAliHLTComponentDataTypefOriginSize);
836 }
837
838 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
839 {
840   // see header file for function documentation
841   memset(&evtData, 0, sizeof(AliHLTComponentEventData));
842   evtData.fStructSize=sizeof(AliHLTComponentEventData);
843   evtData.fEventID=kAliHLTVoidEventID;
844 }
845
846 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) 
847 {
848   // see header file for function documentation
849   TString msg;
850   msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
851   for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
852    if (dt.fID[i]!=0) msg+=dt.fID[i];
853    else msg+="\\0";
854   }
855   msg+="\" Origin=\"";
856   for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
857    if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
858    else msg+="\\0";
859   }
860   msg+="\"";
861   AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
862 }
863
864 int AliHLTComponent::GetEventCount() const
865 {
866   // see header file for function documentation
867   return fEventCount;
868 }
869
870 int AliHLTComponent::IncrementEventCounter()
871 {
872   // see header file for function documentation
873   if (fEventCount>=0) fEventCount++;
874   return fEventCount;
875 }
876
877 int AliHLTComponent::GetNumberOfInputBlocks() const
878 {
879   // see header file for function documentation
880   if (fpInputBlocks!=NULL) {
881     return fCurrentEventData.fBlockCnt;
882   }
883   return 0;
884 }
885
886 AliHLTEventID_t AliHLTComponent::GetEventId() const
887 {
888   // see header file for function documentation
889   if (fpInputBlocks!=NULL) {
890     return fCurrentEventData.fEventID;
891   }
892   return 0;
893 }
894
895 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
896                                                     const char* classname,
897                                                     int bForce)
898 {
899   // see header file for function documentation
900   ALIHLTCOMPONENT_BASE_STOPWATCH();
901   fSearchDataType=dt;
902   if (classname) fClassName=classname;
903   else fClassName.clear();
904   int idx=FindInputBlock(fSearchDataType, 0, 1);
905   TObject* pObj=NULL;
906   if (idx>=0) {
907     HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
908     if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
909       fCurrentInputBlock=idx;
910     } else {
911     }
912   }
913   return pObj;
914 }
915
916 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID, 
917                                                     const char* dtOrigin,
918                                                     const char* classname,
919                                                     int         bForce)
920 {
921   // see header file for function documentation
922   ALIHLTCOMPONENT_BASE_STOPWATCH();
923   AliHLTComponentDataType dt;
924   SetDataType(dt, dtID, dtOrigin);
925   return GetFirstInputObject(dt, classname, bForce);
926 }
927
928 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
929 {
930   // see header file for function documentation
931   ALIHLTCOMPONENT_BASE_STOPWATCH();
932   int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1, 1);
933   //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
934   TObject* pObj=NULL;
935   if (idx>=0) {
936     if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
937       fCurrentInputBlock=idx;
938     }
939   }
940   return pObj;
941 }
942
943 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx, int bObject) const
944 {
945   // see header file for function documentation
946   int iResult=-ENOENT;
947   if (fpInputBlocks!=NULL) {
948     int idx=startIdx<0?0:startIdx;
949     for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
950       if (dt!=fpInputBlocks[idx].fDataType) continue;
951
952       if (bObject!=0) {
953         if (fpInputBlocks[idx].fPtr==NULL) continue;
954         AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
955         if (firstWord!=fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) continue;
956       }
957       iResult=idx;
958     }
959   }
960   return iResult;
961 }
962
963 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
964 {
965   // see header file for function documentation
966   TObject* pObj=NULL;
967   if (fpInputBlocks!=NULL) {
968     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
969       if (fpInputBlocks[idx].fPtr) {
970         AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
971         if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
972           HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
973           AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
974           TClass* objclass=msg.GetClass();
975           pObj=msg.ReadObject(objclass);
976           if (pObj && objclass) {
977             HLTDebug("object %p type %s created", pObj, objclass->GetName());
978           } else {
979           }
980           //} else {
981         } else if (bForce!=0) {
982           HLTError("size mismatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
983         }
984       } else {
985         HLTFatal("block descriptor empty");
986       }
987     } else {
988       HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
989     }
990   } else {
991     HLTError("no input blocks available");
992   }
993   
994   return pObj;
995 }
996
997 TObject* AliHLTComponent::GetInputObject(int idx, const char* /*classname*/, int bForce)
998 {
999   // see header file for function documentation
1000   if (fpInputObjects==NULL) {
1001     fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
1002   }
1003   TObject* pObj=NULL;
1004   if (fpInputObjects) {
1005     pObj=fpInputObjects->At(idx);
1006     if (pObj==NULL) {
1007       pObj=CreateInputObject(idx, bForce);
1008       if (pObj) {
1009         fpInputObjects->AddAt(pObj, idx);
1010       }
1011     }
1012   } else {
1013     HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
1014   }
1015   return pObj;
1016 }
1017
1018 int AliHLTComponent::CleanupInputObjects()
1019 {
1020   // see header file for function documentation
1021   if (!fpInputObjects) return 0;
1022   TObjArray* array=fpInputObjects;
1023   fpInputObjects=NULL;
1024   for (int i=0; i<array->GetEntries(); i++) {
1025     TObject* pObj=array->At(i);
1026     // grrr, garbage collection strikes back: When read via AliHLTMessage
1027     // (CreateInputObject), and written to a TFile afterwards, the
1028     // TFile::Close calls ROOOT's garbage collection. No clue why the
1029     // object ended up in the key list and needs to be deleted
1030     //
1031     // Matthias 09.11.2008 follow up
1032     // This approach doesn't actually work in all cases: the object table
1033     // can be switched off globally, the flag needs to be checked here as
1034     // well in order to avoid memory leaks.
1035     // This means we have to find another solution for the problem if it
1036     // pops up again.
1037     if (pObj &&
1038         (!TObject::GetObjectStat() || gObjectTable->PtrIsValid(pObj))) {
1039       delete pObj;
1040     }
1041   }
1042   delete array;
1043   return 0;
1044 }
1045
1046 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
1047 {
1048   // see header file for function documentation
1049   ALIHLTCOMPONENT_BASE_STOPWATCH();
1050   AliHLTComponentDataType dt=kAliHLTVoidDataType;
1051   int idx=fCurrentInputBlock;
1052   if (pObject) {
1053     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1054     } else {
1055       HLTError("unknown object %p", pObject);
1056     }
1057   }
1058   if (idx>=0) {
1059     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1060       dt=fpInputBlocks[idx].fDataType;
1061     } else {
1062       HLTFatal("severe internal error, index out of range");
1063     }
1064   }
1065   return dt;
1066 }
1067
1068 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
1069 {
1070   // see header file for function documentation
1071   ALIHLTCOMPONENT_BASE_STOPWATCH();
1072   AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1073   int idx=fCurrentInputBlock;
1074   if (pObject) {
1075     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1076     } else {
1077       HLTError("unknown object %p", pObject);
1078     }
1079   }
1080   if (idx>=0) {
1081     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
1082       iSpec=fpInputBlocks[idx].fSpecification;
1083     } else {
1084       HLTFatal("severe internal error, index out of range");
1085     }
1086   }
1087   return iSpec;
1088 }
1089
1090 int AliHLTComponent::Forward(const TObject* pObject)
1091 {
1092   // see header file for function documentation
1093   int iResult=0;
1094   int idx=fCurrentInputBlock;
1095   if (pObject) {
1096     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
1097     } else {
1098       HLTError("unknown object %p", pObject);
1099       iResult=-ENOENT;
1100     }
1101   }
1102   if (idx>=0) {
1103     fOutputBlocks.push_back(fpInputBlocks[idx]);
1104   }
1105   return iResult;
1106 }
1107
1108 int AliHLTComponent::Forward(const AliHLTComponentBlockData* pBlock)
1109 {
1110   // see header file for function documentation
1111   int iResult=0;
1112   int idx=fCurrentInputBlock;
1113   if (pBlock) {
1114     if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1115     } else {
1116       HLTError("unknown Block %p", pBlock);
1117       iResult=-ENOENT;      
1118     }
1119   }
1120   if (idx>=0) {
1121     // check for fpInputBlocks pointer done in FindInputBlock
1122     fOutputBlocks.push_back(fpInputBlocks[idx]);
1123   }
1124   return iResult;
1125 }
1126
1127 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
1128 {
1129   // see header file for function documentation
1130   ALIHLTCOMPONENT_BASE_STOPWATCH();
1131   fSearchDataType=dt;
1132   fClassName.clear();
1133   int idx=FindInputBlock(fSearchDataType, 0);
1134   const AliHLTComponentBlockData* pBlock=NULL;
1135   if (idx>=0) {
1136     // check for fpInputBlocks pointer done in FindInputBlock
1137     pBlock=&fpInputBlocks[idx];
1138     fCurrentInputBlock=idx;
1139   }
1140   return pBlock;
1141 }
1142
1143 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID, 
1144                                                                     const char* dtOrigin)
1145 {
1146   // see header file for function documentation
1147   ALIHLTCOMPONENT_BASE_STOPWATCH();
1148   AliHLTComponentDataType dt;
1149   SetDataType(dt, dtID, dtOrigin);
1150   return GetFirstInputBlock(dt);
1151 }
1152
1153 const AliHLTComponentBlockData* AliHLTComponent::GetInputBlock(int index) const
1154 {
1155   // see header file for function documentation
1156   ALIHLTCOMPONENT_BASE_STOPWATCH();
1157   assert( 0 <= index and index < (int)fCurrentEventData.fBlockCnt );
1158   return &fpInputBlocks[index];
1159 }
1160
1161 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
1162 {
1163   // see header file for function documentation
1164   ALIHLTCOMPONENT_BASE_STOPWATCH();
1165   int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
1166   const AliHLTComponentBlockData* pBlock=NULL;
1167   if (idx>=0) {
1168     // check for fpInputBlocks pointer done in FindInputBlock
1169     pBlock=&fpInputBlocks[idx];
1170     fCurrentInputBlock=idx;
1171   }
1172   return pBlock;
1173 }
1174
1175 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock) const
1176 {
1177   // see header file for function documentation
1178   int iResult=-ENOENT;
1179   if (fpInputBlocks!=NULL) {
1180     if (pBlock) {
1181       if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
1182         iResult=(int)(pBlock-fpInputBlocks);
1183       }
1184     } else {
1185       iResult=-EINVAL;
1186     }
1187   }
1188   return iResult;
1189 }
1190
1191 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
1192 {
1193   // see header file for function documentation
1194   ALIHLTCOMPONENT_BASE_STOPWATCH();
1195   AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
1196   int idx=fCurrentInputBlock;
1197   if (pBlock) {
1198     if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
1199     } else {
1200       HLTError("unknown Block %p", pBlock);
1201     }
1202   }
1203   if (idx>=0) {
1204     // check for fpInputBlocks pointer done in FindInputBlock
1205     iSpec=fpInputBlocks[idx].fSpecification;
1206   }
1207   return iSpec;
1208 }
1209
1210 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec, 
1211                               void* pHeader, int headerSize)
1212 {
1213   // see header file for function documentation
1214   ALIHLTCOMPONENT_BASE_STOPWATCH();
1215   int iResult=0;
1216   fLastObjectSize=0;
1217   if (pObject) {
1218     AliHLTMessage msg(kMESS_OBJECT);
1219     msg.SetCompressionLevel(fCompressionLevel);
1220     msg.WriteObject(pObject);
1221     Int_t iMsgLength=msg.Length();
1222     if (iMsgLength>0) {
1223       // Matthias Sep 2008
1224       // NOTE: AliHLTMessage does implement it's own SetLength method
1225       // which is not architecture independent. The original SetLength
1226       // stores the size always in network byte order.
1227       // I'm trying to remember the rational for that, might be that
1228       // it was just some lack of knowledge. Want to change this, but
1229       // has to be done carefullt to be backward compatible.
1230       msg.SetLength(); // sets the length to the first (reserved) word
1231
1232       // does nothing if the level is 0
1233       msg.Compress();
1234
1235       char *mbuf = msg.Buffer();
1236       if (msg.CompBuffer()) {
1237         msg.SetLength(); // set once more to have to byte order
1238         mbuf = msg.CompBuffer();
1239         iMsgLength = msg.CompLength();
1240       }
1241       assert(mbuf!=NULL);
1242       iResult=InsertOutputBlock(mbuf, iMsgLength, dt, spec, pHeader, headerSize);
1243       if (iResult>=0) {
1244         HLTDebug("object %s (%p) size %d compression %d inserted to output", pObject->ClassName(), pObject, iMsgLength, msg.GetCompressionLevel());
1245       }
1246       fLastObjectSize=iMsgLength;
1247     } else {
1248       HLTError("object serialization failed for object %p", pObject);
1249       iResult=-ENOMSG;
1250     }
1251   } else {
1252     iResult=-EINVAL;
1253   }
1254   return iResult;
1255 }
1256
1257 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1258                               void* pHeader, int headerSize)
1259 {
1260   // see header file for function documentation
1261   ALIHLTCOMPONENT_BASE_STOPWATCH();
1262   AliHLTComponentDataType dt;
1263   SetDataType(dt, dtID, dtOrigin);
1264   return PushBack(pObject, dt, spec, pHeader, headerSize);
1265 }
1266
1267 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1268                               const void* pHeader, int headerSize)
1269 {
1270   // see header file for function documentation
1271   ALIHLTCOMPONENT_BASE_STOPWATCH();
1272   return InsertOutputBlock(pBuffer, iSize, dt, spec, pHeader, headerSize);
1273 }
1274
1275 int AliHLTComponent::PushBack(const void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec,
1276                               const void* pHeader, int headerSize)
1277 {
1278   // see header file for function documentation
1279   ALIHLTCOMPONENT_BASE_STOPWATCH();
1280   AliHLTComponentDataType dt;
1281   SetDataType(dt, dtID, dtOrigin);
1282   return PushBack(pBuffer, iSize, dt, spec, pHeader, headerSize);
1283 }
1284
1285 int AliHLTComponent::InsertOutputBlock(const void* pBuffer, int iBufferSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec,
1286                                        const void* pHeader, int iHeaderSize)
1287 {
1288   // see header file for function documentation
1289   int iResult=0;
1290   int iBlkSize = iBufferSize + iHeaderSize;
1291
1292   if ((pBuffer!=NULL && iBufferSize>0) || (pHeader!=NULL && iHeaderSize>0)) {
1293     if (fpOutputBuffer && iBlkSize<=(int)(fOutputBufferSize-fOutputBufferFilled)) {
1294       AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1295
1296       // copy header if provided but skip if the header is the target location
1297       // in that case it has already been copied
1298       if (pHeader!=NULL && pHeader!=pTgt) {
1299         memcpy(pTgt, pHeader, iHeaderSize);
1300       }
1301
1302       pTgt += (AliHLTUInt8_t) iHeaderSize;
1303
1304       // copy buffer if provided but skip if buffer is the target location
1305       // in that case it has already been copied
1306       if (pBuffer!=NULL && pBuffer!=pTgt) {
1307         memcpy(pTgt, pBuffer, iBufferSize);
1308         
1309         //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer); 
1310         //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iBufferSize, pBuffer, pTgt, firstWord);
1311       }
1312       //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iBlkSize, DataType2Text(dt).c_str(), spec);
1313     } else {
1314       if (fpOutputBuffer) {
1315         HLTError("too little space in output buffer: %d of %d, required %d", fOutputBufferSize-fOutputBufferFilled, fOutputBufferSize, iBlkSize);
1316       } else {
1317         HLTError("output buffer not available");
1318       }
1319       iResult=-ENOSPC;
1320     }
1321   }
1322   if (iResult>=0) {
1323     AliHLTComponentBlockData bd;
1324     FillBlockData( bd );
1325     bd.fOffset        = fOutputBufferFilled;
1326     bd.fSize          = iBlkSize;
1327     bd.fDataType      = dt;
1328     bd.fSpecification = spec;
1329     fOutputBlocks.push_back( bd );
1330     fOutputBufferFilled+=bd.fSize;
1331   }
1332
1333   return iResult;
1334 }
1335
1336 int AliHLTComponent::EstimateObjectSize(TObject* pObject) const
1337 {
1338   // see header file for function documentation
1339   if (!pObject) return -EINVAL;
1340     AliHLTMessage msg(kMESS_OBJECT);
1341     msg.WriteObject(pObject);
1342     return msg.Length();  
1343 }
1344
1345 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity, const char* dtID,
1346                                                     const char* dtOrigin,
1347                                                     AliHLTUInt32_t spec)
1348 {
1349   // see header file for function documentation
1350   ALIHLTCOMPONENT_BASE_STOPWATCH();
1351   AliHLTComponentDataType dt;
1352   SetDataType(dt, dtID, dtOrigin);
1353   return CreateMemoryFile(capacity, dt, spec);
1354 }
1355
1356 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(int capacity,
1357                                                     const AliHLTComponentDataType& dt,
1358                                                     AliHLTUInt32_t spec)
1359 {
1360   // see header file for function documentation
1361   ALIHLTCOMPONENT_BASE_STOPWATCH();
1362   AliHLTMemoryFile* pFile=NULL;
1363   if (capacity>=0 && static_cast<unsigned int>(capacity)<=fOutputBufferSize-fOutputBufferFilled){
1364     AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
1365     pFile=new AliHLTMemoryFile((char*)pTgt, capacity);
1366     if (pFile) {
1367       unsigned int nofBlocks=fOutputBlocks.size();
1368       if (nofBlocks+1>fMemFiles.size()) {
1369         fMemFiles.resize(nofBlocks+1, NULL);
1370       }
1371       if (nofBlocks<fMemFiles.size()) {
1372         fMemFiles[nofBlocks]=pFile;
1373         AliHLTComponentBlockData bd;
1374         FillBlockData( bd );
1375         bd.fOffset        = fOutputBufferFilled;
1376         bd.fSize          = capacity;
1377         bd.fDataType      = dt;
1378         bd.fSpecification = spec;
1379         fOutputBufferFilled+=bd.fSize;
1380         fOutputBlocks.push_back( bd );
1381       } else {
1382         HLTError("can not allocate/grow object array");
1383         pFile->CloseMemoryFile(0);
1384         delete pFile;
1385         pFile=NULL;
1386       }
1387     }
1388   } else {
1389     HLTError("can not create memory file of size %d (%d available)", capacity, fOutputBufferSize-fOutputBufferFilled);
1390   }
1391   return pFile;
1392 }
1393
1394 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const char* dtID,
1395                                                     const char* dtOrigin,
1396                                                     AliHLTUInt32_t spec,
1397                                                     float capacity)
1398 {
1399   // see header file for function documentation
1400   ALIHLTCOMPONENT_BASE_STOPWATCH();
1401   AliHLTComponentDataType dt;
1402   SetDataType(dt, dtID, dtOrigin);
1403   int size=fOutputBufferSize-fOutputBufferFilled;
1404   if (capacity<0 || capacity>1.0) {
1405     HLTError("invalid parameter: capacity %f", capacity);
1406     return NULL;
1407   }
1408   size=(int)(size*capacity);
1409   return CreateMemoryFile(size, dt, spec);
1410 }
1411
1412 AliHLTMemoryFile* AliHLTComponent::CreateMemoryFile(const AliHLTComponentDataType& dt,
1413                                                     AliHLTUInt32_t spec,
1414                                                     float capacity)
1415 {
1416   // see header file for function documentation
1417   ALIHLTCOMPONENT_BASE_STOPWATCH();
1418   int size=fOutputBufferSize-fOutputBufferFilled;
1419   if (capacity<0 || capacity>1.0) {
1420     HLTError("invalid parameter: capacity %f", capacity);
1421     return NULL;
1422   }
1423   size=(int)(size*capacity);
1424   return CreateMemoryFile(size, dt, spec);
1425 }
1426
1427 int AliHLTComponent::Write(AliHLTMemoryFile* pFile, const TObject* pObject,
1428                            const char* key, int option)
1429 {
1430   // see header file for function documentation
1431   int iResult=0;
1432   if (pFile && pObject) {
1433     pFile->cd();
1434     iResult=pObject->Write(key, option);
1435     if (iResult>0) {
1436       // success
1437     } else {
1438       iResult=-pFile->GetErrno();
1439       if (iResult==-ENOSPC) {
1440         HLTError("error writing memory file, buffer too small");
1441       }
1442     }
1443   } else {
1444     iResult=-EINVAL;
1445   }
1446   return iResult;
1447 }
1448
1449 int AliHLTComponent::CloseMemoryFile(AliHLTMemoryFile* pFile)
1450 {
1451   // see header file for function documentation
1452   int iResult=0;
1453   if (pFile) {
1454     AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1455     int i=0;
1456     while (element!=fMemFiles.end() && iResult>=0) {
1457       if (*element && *element==pFile) {
1458         iResult=pFile->CloseMemoryFile();
1459         
1460         // sync memory files and descriptors
1461         if (iResult>=0) {
1462           fOutputBlocks[i].fSize=(*element)->GetSize()+(*element)->GetHeaderSize();
1463         }
1464         delete *element;
1465         *element=NULL;
1466         return iResult;
1467       }
1468       element++; i++;
1469     }
1470     HLTError("can not find memory file %p", pFile);
1471     iResult=-ENOENT;
1472   } else {
1473     iResult=-EINVAL;
1474   }
1475   return iResult;
1476 }
1477
1478 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
1479 {
1480   // see header file for function documentation
1481   int iResult=0;
1482
1483   AliHLTComponentEventDoneData* newEDD = NULL;
1484   
1485   unsigned long newSize=edd.fDataSize;
1486   if (fEventDoneData)
1487     newSize += fEventDoneData->fDataSize;
1488
1489   if (newSize>fEventDoneDataSize) {
1490     newEDD = reinterpret_cast<AliHLTComponentEventDoneData*>( new AliHLTUInt8_t[ sizeof(AliHLTComponentEventDoneData)+newSize ] );
1491     if (!newEDD)
1492       return -ENOMEM;
1493     newEDD->fStructSize = sizeof(AliHLTComponentEventDoneData);
1494     newEDD->fDataSize = newSize;
1495     newEDD->fData = reinterpret_cast<AliHLTUInt8_t*>(newEDD)+newEDD->fStructSize;
1496     unsigned long long offset = 0;
1497     if (fEventDoneData) {
1498       memcpy( newEDD->fData, fEventDoneData->fData, fEventDoneData->fDataSize );
1499       offset += fEventDoneData->fDataSize;
1500     }
1501     memcpy( reinterpret_cast<AliHLTUInt8_t*>(newEDD->fData)+offset, edd.fData, edd.fDataSize );
1502     if (fEventDoneData)
1503       delete [] reinterpret_cast<AliHLTUInt8_t*>( fEventDoneData );
1504     fEventDoneData = newEDD;
1505     fEventDoneDataSize = newSize;
1506   }
1507   else {
1508     memcpy( reinterpret_cast<AliHLTUInt8_t*>(fEventDoneData->fData)+fEventDoneData->fDataSize, edd.fData, edd.fDataSize );
1509     fEventDoneData->fDataSize += edd.fDataSize;
1510   }
1511   return iResult;
1512 }
1513
1514 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
1515                                    const AliHLTComponentBlockData* blocks, 
1516                                    AliHLTComponentTriggerData& trigData,
1517                                    AliHLTUInt8_t* outputPtr, 
1518                                    AliHLTUInt32_t& size,
1519                                    AliHLTUInt32_t& outputBlockCnt, 
1520                                    AliHLTComponentBlockData*& outputBlocks,
1521                                    AliHLTComponentEventDoneData*& edd )
1522 {
1523   // see header file for function documentation
1524   HLTLogKeyword(fChainId.c_str());
1525   ALIHLTCOMPONENT_BASE_STOPWATCH();
1526   int iResult=0;
1527   fCurrentEvent=evtData.fEventID;
1528   fCurrentEventData=evtData;
1529   fpInputBlocks=blocks;
1530   fCurrentInputBlock=-1;
1531   fSearchDataType=kAliHLTAnyDataType;
1532   fpOutputBuffer=outputPtr;
1533   fOutputBufferSize=size;
1534   fOutputBufferFilled=0;
1535   fOutputBlocks.clear();
1536   outputBlockCnt=0;
1537   outputBlocks=NULL;
1538
1539   AliHLTComponentBlockDataList forwardedBlocks;
1540
1541   // optional component statistics
1542   AliHLTComponentStatisticsList compStats;
1543   bool bAddComponentTableEntry=false;
1544   vector<AliHLTUInt32_t> parentComponentTables;
1545 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1546   AliHLTComponentStatistics outputStat;
1547   memset(&outputStat, 0, sizeof(AliHLTComponentStatistics));
1548   outputStat.fStructSize=sizeof(AliHLTComponentStatistics);
1549   outputStat.fId=fChainIdCrc;
1550   if (fpBenchmark) {
1551     fpBenchmark->Stop();
1552     outputStat.fComponentCycleTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1553     fpBenchmark->Reset();
1554     fpBenchmark->Start();
1555   }
1556   compStats.push_back(outputStat);
1557 #endif
1558
1559   // data processing is skipped
1560   // -  if there are only steering events in the block list.
1561   //    For the sake of data source components data processing
1562   //    is not skipped if there is no block list at all or if it
1563   //    just contains the eventType block
1564   // - always skipped if the event is of type
1565   //   - gkAliEventTypeConfiguration
1566   //   - gkAliEventTypeReadPreprocessor
1567   const unsigned int skipModeDefault=0x1;
1568   const unsigned int skipModeForce=0x2;
1569   unsigned int bSkipDataProcessing=skipModeDefault;
1570
1571   // find special events
1572   if (fpInputBlocks && evtData.fBlockCnt>0) {
1573     // first look for all special events and execute in the appropriate
1574     // sequence afterwords
1575     int indexComConfEvent=-1;
1576     int indexUpdtDCSEvent=-1;
1577     int indexSOREvent=-1;
1578     int indexEOREvent=-1;
1579     int indexECSParamBlock=-1;
1580     for (unsigned int i=0; i<evtData.fBlockCnt && iResult>=0; i++) {
1581       if (fpInputBlocks[i].fDataType==kAliHLTDataTypeSOR) {
1582         indexSOREvent=i;
1583         // the AliHLTCalibrationProcessor relies on the SOR and EOR events
1584         bSkipDataProcessing&=~skipModeDefault;
1585       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeRunType) {
1586         // run type string
1587         // handling is not clear yet
1588         if (fpInputBlocks[i].fPtr) {
1589           HLTDebug("got run type \"%s\"\n", fpInputBlocks[i].fPtr);
1590         }
1591       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEOR) {
1592         indexEOREvent=i;
1593         // the calibration processor relies on the SOR and EOR events
1594         bSkipDataProcessing&=~skipModeDefault;
1595       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeDDL) {
1596         // DDL list
1597         // this event is most likely deprecated
1598       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComConf) {
1599         indexComConfEvent=i;
1600       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeUpdtDCS) {
1601         indexUpdtDCSEvent=i;
1602       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeEvent) {
1603         fEventType=fpInputBlocks[i].fSpecification;
1604
1605         // skip always in case of gkAliEventTypeConfiguration
1606         if (fpInputBlocks[i].fSpecification==gkAliEventTypeConfiguration) bSkipDataProcessing|=skipModeForce;
1607
1608         // skip always in case of gkAliEventTypeReadPreprocessor
1609         if (fpInputBlocks[i].fSpecification==gkAliEventTypeReadPreprocessor) bSkipDataProcessing|=skipModeForce;
1610
1611         // never skip if the event type block is the only block
1612         if (evtData.fBlockCnt==1) bSkipDataProcessing&=~skipModeDefault;
1613
1614       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentStatistics) {
1615         if (compStats.size()>0) {
1616           AliHLTUInt8_t* pData=reinterpret_cast<AliHLTUInt8_t*>(fpInputBlocks[i].fPtr);
1617           for (AliHLTUInt32_t offset=0;
1618                offset+sizeof(AliHLTComponentStatistics)<=fpInputBlocks[i].fSize;
1619                offset+=sizeof(AliHLTComponentStatistics)) {
1620             AliHLTComponentStatistics* pStat=reinterpret_cast<AliHLTComponentStatistics*>(pData+offset);
1621             if (pStat && compStats[0].fLevel<=pStat->fLevel) {
1622               compStats[0].fLevel=pStat->fLevel+1;
1623             }
1624             compStats.push_back(*pStat);
1625           }
1626         }
1627       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeComponentTable) {
1628         forwardedBlocks.push_back(fpInputBlocks[i]);
1629         parentComponentTables.push_back(fpInputBlocks[i].fSpecification);
1630       } else if (fpInputBlocks[i].fDataType==kAliHLTDataTypeECSParam) {
1631         indexECSParamBlock=i;
1632       } else {
1633         // the processing function is called if there is at least one
1634         // non-steering data block. Steering blocks are not filtered out
1635         // for sake of performance 
1636         bSkipDataProcessing&=~skipModeDefault;
1637         if (compStats.size()>0) {
1638           compStats[0].fInputBlockCount++;
1639           compStats[0].fTotalInputSize+=fpInputBlocks[i].fSize;
1640         }
1641       }
1642     }
1643
1644     if (indexSOREvent>=0) {
1645       // start of run
1646       bAddComponentTableEntry=true;
1647       if (fpRunDesc==NULL) {
1648         fpRunDesc=new AliHLTRunDesc;
1649         if (fpRunDesc) *fpRunDesc=kAliHLTVoidRunDesc;
1650       }
1651       if (fpRunDesc) {
1652         AliHLTRunDesc rundesc;
1653         if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexSOREvent, "AliHLTRunDesc", "SOR"))>0) {
1654           if (fpRunDesc->fRunNo==kAliHLTVoidRunNo) {
1655             *fpRunDesc=rundesc;
1656             HLTDebug("set run decriptor, run no %d", fpRunDesc->fRunNo);
1657             SetCDBRunNo(fpRunDesc->fRunNo);
1658           } else if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1659             HLTWarning("already set run properties run no %d, ignoring SOR with run no %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1660           }
1661         }
1662       } else {
1663         iResult=-ENOMEM;
1664       }
1665
1666       if (indexECSParamBlock>=0) {
1667         if (fpInputBlocks[indexECSParamBlock].fSize>0) {
1668           const char* param=reinterpret_cast<const char*>(fpInputBlocks[indexECSParamBlock].fPtr);
1669           TString paramString;
1670           if (param[fpInputBlocks[indexECSParamBlock].fSize-1]!=0) {
1671             HLTWarning("ECS parameter string not terminated");
1672             paramString.Insert(0, param, fpInputBlocks[indexECSParamBlock].fSize);
1673             paramString+="";
1674           } else {
1675             paramString=param;
1676           }
1677           ScanECSParam(paramString.Data());
1678         } else {
1679           HLTWarning("empty ECS parameter received");
1680         }
1681       } else {
1682         // TODO: later on we might throw a warning here since the CTP trigger classes
1683         // should be mandatory
1684       }
1685     }
1686     if (indexEOREvent>=0) {
1687       bAddComponentTableEntry=true;
1688       if (fpRunDesc!=NULL) {
1689         if (fpRunDesc) {
1690           AliHLTRunDesc rundesc;
1691           if ((iResult=CopyStruct(&rundesc, sizeof(AliHLTRunDesc), indexEOREvent, "AliHLTRunDesc", "SOR"))>0) {
1692             if (fpRunDesc->fRunNo!=rundesc.fRunNo) {
1693               HLTWarning("run no mismatch: SOR %d, EOR %d", fpRunDesc->fRunNo, rundesc.fRunNo);
1694             } else {
1695               HLTDebug("EOR run no %d", fpRunDesc->fRunNo);
1696             }
1697           }
1698           AliHLTRunDesc* pRunDesc=fpRunDesc;
1699           fpRunDesc=NULL;
1700           delete pRunDesc;
1701         }
1702       } else {
1703         HLTWarning("did not receive SOR, ignoring EOR");
1704       }
1705     }
1706     if (indexComConfEvent>=0 || fEventType==gkAliEventTypeConfiguration) {
1707       TString cdbEntry;
1708       if (indexComConfEvent>=0 && fpInputBlocks[indexComConfEvent].fPtr!=NULL && fpInputBlocks[indexComConfEvent].fSize>0) {
1709         cdbEntry.Append(reinterpret_cast<const char*>(fpInputBlocks[indexComConfEvent].fPtr), fpInputBlocks[indexComConfEvent].fSize);
1710       }
1711       HLTDebug("received component configuration command: entry %s", cdbEntry.IsNull()?"none":cdbEntry.Data());
1712       int tmpResult=Reconfigure(cdbEntry[0]==0?NULL:cdbEntry.Data(), fChainId.c_str());
1713       if (tmpResult<0) {
1714         HLTWarning("reconfiguration of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1715       }
1716     }
1717     if (indexUpdtDCSEvent>=0 || fEventType==gkAliEventTypeReadPreprocessor) {
1718       TString modules;
1719       if (fpInputBlocks[indexUpdtDCSEvent].fPtr!=NULL && fpInputBlocks[indexUpdtDCSEvent].fSize>0) {
1720         modules.Append(reinterpret_cast<const char*>(fpInputBlocks[indexUpdtDCSEvent].fPtr), fpInputBlocks[indexUpdtDCSEvent].fSize);
1721       }
1722       HLTDebug("received preprocessor update command: detectors %s", modules.IsNull()?"ALL":modules.Data());
1723       int tmpResult=ReadPreprocessorValues(modules[0]==0?"ALL":modules.Data());
1724       if (tmpResult<0) {
1725         HLTWarning("preprocessor update of component %p (%s) failed with error code %d", this, GetComponentID(), tmpResult);
1726       }
1727     }
1728   } else {
1729     // processing function needs to be called if there are no input data
1730     // blocks in order to make data source components working.
1731     bSkipDataProcessing&=~skipModeDefault;
1732   }
1733
1734   // data processing is not skipped if the component explicitly asks
1735   // for the private blocks
1736   if (fRequireSteeringBlocks) bSkipDataProcessing=0;
1737
1738   // increment CTP trigger counters if available
1739   if (fpCTPData && IsDataEvent()) fpCTPData->Increment(trigData);
1740
1741   AliHLTComponentBlockDataList blockData;
1742   if (iResult>=0 && !bSkipDataProcessing)
1743   { // dont delete, sets the scope for the stopwatch guard
1744     // do not use ALIHLTCOMPONENT_DA_STOPWATCH(); macro
1745     // in order to avoid 'shadowed variable' warning
1746     AliHLTStopwatchGuard swguard2(fpStopwatches!=NULL?reinterpret_cast<TStopwatch*>(fpStopwatches->At((int)kSWDA)):NULL);
1747     iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
1748   } // end of the scope of the stopwatch guard
1749   if (iResult>=0 && !bSkipDataProcessing) {
1750     if (fOutputBlocks.size()>0) {
1751       // High Level interface
1752
1753       //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());      
1754       // sync memory files and descriptors
1755       AliHLTMemoryFilePList::iterator element=fMemFiles.begin();
1756       int i=0;
1757       while (element!=fMemFiles.end() && iResult>=0) {
1758         if (*element) {
1759           if ((*element)->IsClosed()==0) {
1760             HLTWarning("memory file has not been closed, force flush");
1761             iResult=CloseMemoryFile(*element);
1762           }
1763         }
1764         element++; i++;
1765       }
1766
1767       if (iResult>=0) {
1768         // create the descriptor list
1769         if (blockData.size()>0) {
1770           HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
1771           iResult=-EFAULT;
1772         } else {
1773           if (compStats.size()>0 && IsDataEvent()) {
1774             int offset=AddComponentStatistics(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, compStats);
1775             if (offset>0) fOutputBufferFilled+=offset;
1776           }
1777           if (bAddComponentTableEntry) {
1778             int offset=AddComponentTableEntry(fOutputBlocks, fpOutputBuffer, fOutputBufferSize, fOutputBufferFilled, parentComponentTables);
1779             if (offset>0) size+=offset;
1780           }
1781           if (forwardedBlocks.size()>0) {
1782             fOutputBlocks.insert(fOutputBlocks.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1783           }
1784           iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
1785           size=fOutputBufferFilled;
1786         }
1787       }
1788     } else {
1789       // Low Level interface
1790       if (compStats.size()>0) {
1791         int offset=AddComponentStatistics(blockData, fpOutputBuffer, fOutputBufferSize, size, compStats);
1792         if (offset>0) size+=offset;
1793       }
1794       if (bAddComponentTableEntry) {
1795         int offset=AddComponentTableEntry(blockData, fpOutputBuffer, fOutputBufferSize, size, parentComponentTables);
1796         if (offset>0) size+=offset;
1797       }
1798       if (forwardedBlocks.size()>0) {
1799         blockData.insert(blockData.end(), forwardedBlocks.begin(), forwardedBlocks.end());
1800       }
1801       iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
1802     }
1803     if (iResult<0) {
1804       HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
1805     }
1806   }
1807   if (iResult<0 || bSkipDataProcessing) {
1808     outputBlockCnt=0;
1809     outputBlocks=NULL;
1810   }
1811   CleanupInputObjects();
1812   if (iResult>=0 && IsDataEvent()) {
1813     IncrementEventCounter();
1814   }
1815   if (outputBlockCnt==0) {
1816     // no output blocks, set size to 0
1817     size=0;
1818   }
1819
1820   // reset the internal EventData struct
1821   FillEventData(fCurrentEventData);
1822   return iResult;
1823 }
1824
1825 int  AliHLTComponent::AddComponentStatistics(AliHLTComponentBlockDataList& blocks, 
1826                                              AliHLTUInt8_t* buffer,
1827                                              AliHLTUInt32_t bufferSize,
1828                                              AliHLTUInt32_t offset,
1829                                              AliHLTComponentStatisticsList& stats) const
1830 {
1831   // see header file for function documentation
1832   int iResult=0;
1833 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1834   if (stats.size()==0) return -ENOENT;
1835   // check if there is space for at least one entry
1836   if (offset+sizeof(AliHLTComponentStatistics)>bufferSize) return 0;
1837   stats[0].fTotalOutputSize=offset;
1838   stats[0].fOutputBlockCount=blocks.size();
1839   if (fpBenchmark) {
1840     fpBenchmark->Stop();
1841     stats[0].fTime=(AliHLTUInt32_t)(fpBenchmark->RealTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1842     stats[0].fCTime=(AliHLTUInt32_t)(fpBenchmark->CpuTime()*ALIHLTCOMPONENT_STATTIME_SCALER);
1843     fpBenchmark->Continue();
1844   }
1845   if (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize) {
1846     AliHLTUInt32_t removedLevel=0;
1847     do {
1848       // remove all entries of the level of the last entry
1849       removedLevel=stats.back().fLevel;
1850       AliHLTComponentStatisticsList::iterator element=stats.begin();
1851       element++;
1852       while (element!=stats.end()) {
1853         if (element->fLevel<=removedLevel) {
1854           element=stats.erase(element);
1855         } else {
1856           element++;
1857         }
1858       }
1859     } while (stats.size()>1 && 
1860              (offset+stats.size()*sizeof(AliHLTComponentStatistics)>bufferSize));
1861   }
1862   assert(stats.size()>0);
1863   if (stats.size()==0) return 0;
1864
1865   if (offset+stats.size()*sizeof(AliHLTComponentStatistics)<=bufferSize) {
1866     AliHLTComponentBlockData bd;
1867     FillBlockData( bd );
1868     bd.fOffset        = offset;
1869     bd.fSize          = stats.size()*sizeof(AliHLTComponentStatistics);
1870     bd.fDataType      = kAliHLTDataTypeComponentStatistics;
1871     bd.fSpecification = kAliHLTVoidDataSpec;
1872     unsigned int master=0;
1873     for (unsigned int i=1; i<blocks.size(); i++) {
1874       if (blocks[i].fSize>blocks[master].fSize && 
1875           !MatchExactly(blocks[i].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate))
1876         master=i;
1877     }
1878     if (blocks.size()>0 && !MatchExactly(blocks[master].fDataType, kAliHLTVoidDataType|kAliHLTDataOriginPrivate)) {
1879       // take the data origin of the biggest block as specification
1880       // this is similar to the treatment in the HOMER interface. For traditional
1881       // reasons, the bytes are swapped there on a little endian architecture, so
1882       // we do it as well.
1883       memcpy(&bd.fSpecification, &blocks[master].fDataType.fOrigin, sizeof(bd.fSpecification));
1884 #ifdef R__BYTESWAP // set on little endian architectures
1885       bd.fSpecification=((bd.fSpecification & 0xFFULL) << 24) | 
1886         ((bd.fSpecification & 0xFF00ULL) << 8) | 
1887         ((bd.fSpecification & 0xFF0000ULL) >> 8) | 
1888         ((bd.fSpecification & 0xFF000000ULL) >> 24);
1889 #endif
1890     }
1891     memcpy(buffer+offset, &(stats[0]), bd.fSize);
1892     blocks.push_back(bd);
1893     iResult=bd.fSize;
1894   }
1895 #else
1896   if (blocks.size() && buffer && bufferSize && offset && stats.size()) {
1897     // get rid of warning
1898   }
1899 #endif
1900   return iResult;
1901 }
1902
1903 int  AliHLTComponent::AddComponentTableEntry(AliHLTComponentBlockDataList& blocks, 
1904                                              AliHLTUInt8_t* buffer,
1905                                              AliHLTUInt32_t bufferSize,
1906                                              AliHLTUInt32_t offset,
1907                                              const vector<AliHLTUInt32_t>& parents) const
1908 {
1909   // see header file for function documentation
1910   int iResult=0;
1911 #if defined(__DEBUG) || defined(HLT_COMPONENT_STATISTICS)
1912   // the payload consists of the AliHLTComponentTableEntry struct,
1913   // followed by a an array of 32bit crc chain ids and the component
1914   // description string
1915   unsigned int payloadSize=sizeof(AliHLTComponentTableEntry);
1916   payloadSize+=parents.size()*sizeof(AliHLTUInt32_t);
1917
1918   // the component description has the following format:
1919   // chain-id{component-id:arguments}
1920   const char* componentId=const_cast<AliHLTComponent*>(this)->GetComponentID();
1921   unsigned int descriptionSize=fChainId.size()+1;
1922   descriptionSize+=2; // the '{}' around the component id
1923   descriptionSize+=strlen(componentId);
1924   descriptionSize+=1; // the ':' between component id and arguments
1925   descriptionSize+=fComponentArgs.size();
1926
1927   payloadSize+=descriptionSize;
1928   if (buffer && (offset+payloadSize<=bufferSize)) {
1929     AliHLTUInt8_t* pTgt=buffer+offset;
1930     memset(pTgt, 0, payloadSize);
1931
1932     // write entry
1933     AliHLTComponentTableEntry* pEntry=reinterpret_cast<AliHLTComponentTableEntry*>(pTgt);
1934     pEntry->fStructSize=sizeof(AliHLTComponentTableEntry);
1935     pEntry->fNofParents=parents.size();
1936     pEntry->fSizeDescription=descriptionSize;
1937     pTgt=pEntry->fBuffer;
1938
1939     // write array of parents
1940     if (parents.size()>0) {
1941       unsigned int copy=parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type);
1942       memcpy(pTgt, &parents[0], parents.size()*sizeof(vector<AliHLTUInt32_t>::value_type));
1943       pTgt+=copy;
1944     }
1945
1946     // write component description
1947     memcpy(pTgt, fChainId.c_str(), fChainId.size());
1948     pTgt+=fChainId.size();
1949     *pTgt++='{';
1950     memcpy(pTgt, componentId, strlen(componentId));
1951     pTgt+=strlen(componentId);
1952     *pTgt++=':';
1953     memcpy(pTgt, fComponentArgs.c_str(), fComponentArgs.size());
1954     pTgt+=fComponentArgs.size();
1955     *pTgt++='}';
1956     *pTgt++=0;
1957
1958     AliHLTComponentBlockData bd;
1959     FillBlockData( bd );
1960     bd.fOffset        = offset;
1961     bd.fSize          = payloadSize;
1962     bd.fDataType      = kAliHLTDataTypeComponentTable;
1963     bd.fSpecification = fChainIdCrc;
1964     blocks.push_back(bd);
1965     iResult=bd.fSize;
1966   }
1967 #else
1968   if (blocks.size() && buffer && bufferSize && offset && parents.size()) {
1969     // get rid of warning
1970   }
1971  #endif
1972   return iResult;
1973 }
1974
1975 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard()
1976   :
1977   fpStopwatch(NULL),
1978   fpPrec(NULL)
1979 {
1980   // standard constructor (not for use)
1981 }
1982
1983 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(TStopwatch* pStopwatch)
1984   :
1985   fpStopwatch(pStopwatch),
1986   fpPrec(NULL)
1987 {
1988   // constructor
1989
1990   // check for already existing guard
1991   if (fgpCurrent) fpPrec=fgpCurrent;
1992   fgpCurrent=this;
1993
1994   // stop the preceeding guard if it controls a different stopwatch
1995   int bStart=1;
1996   if (fpPrec && fpPrec!=this) bStart=fpPrec->Hold(fpStopwatch);
1997
1998   // start the stopwatch if the current guard controls a different one
1999   if (fpStopwatch && bStart==1) fpStopwatch->Start(kFALSE);
2000 }
2001
2002 AliHLTComponent::AliHLTStopwatchGuard::AliHLTStopwatchGuard(const AliHLTStopwatchGuard&)
2003   :
2004   fpStopwatch(NULL),
2005   fpPrec(NULL)
2006 {
2007   //
2008   // copy constructor not for use
2009   //
2010 }
2011
2012 AliHLTComponent::AliHLTStopwatchGuard& AliHLTComponent::AliHLTStopwatchGuard::operator=(const AliHLTStopwatchGuard&)
2013 {
2014   //
2015   // assignment operator not for use
2016   //
2017   fpStopwatch=NULL;
2018   fpPrec=NULL;
2019   return *this;
2020 }
2021
2022 AliHLTComponent::AliHLTStopwatchGuard* AliHLTComponent::AliHLTStopwatchGuard::fgpCurrent=NULL;
2023
2024 AliHLTComponent::AliHLTStopwatchGuard::~AliHLTStopwatchGuard()
2025 {
2026   // destructor
2027
2028   // resume the preceeding guard if it controls a different stopwatch
2029   int bStop=1;
2030   if (fpPrec && fpPrec!=this) bStop=fpPrec->Resume(fpStopwatch);
2031
2032   // stop the stopwatch if the current guard controls a different one
2033   if (fpStopwatch && bStop==1) fpStopwatch->Stop();
2034
2035   // resume to the preceeding guard
2036   fgpCurrent=fpPrec;
2037 }
2038
2039 int AliHLTComponent::AliHLTStopwatchGuard::Hold(TStopwatch* pSucc)
2040 {
2041   // see header file for function documentation
2042   if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Stop();
2043   return fpStopwatch!=pSucc?1:0;
2044 }
2045
2046 int AliHLTComponent::AliHLTStopwatchGuard::Resume(TStopwatch* pSucc)
2047 {
2048   // see header file for function documentation
2049   if (fpStopwatch!=NULL && fpStopwatch!=pSucc) fpStopwatch->Start(kFALSE);
2050   return fpStopwatch!=pSucc?1:0;
2051 }
2052
2053 int AliHLTComponent::SetStopwatch(TObject* pSW, AliHLTStopwatchType type) 
2054 {
2055   // see header file for function documentation
2056   int iResult=0;
2057   if (pSW!=NULL && type<kSWTypeCount) {
2058     if (fpStopwatches) {
2059       TObject* pObj=fpStopwatches->At((int)type);
2060       if (pSW==NULL        // explicit reset
2061           || pObj==NULL) { // explicit set
2062         fpStopwatches->AddAt(pSW, (int)type);
2063       } else if (pObj!=pSW) {
2064         HLTWarning("stopwatch %d already set, reset first", (int)type);
2065         iResult=-EBUSY;
2066       }
2067     }
2068   } else {
2069     iResult=-EINVAL;
2070   }
2071   return iResult;
2072 }
2073
2074 int AliHLTComponent::SetStopwatches(TObjArray* pStopwatches)
2075 {
2076   // see header file for function documentation
2077   if (pStopwatches==NULL) return -EINVAL;
2078
2079   int iResult=0;
2080   for (int i=0 ; i<(int)kSWTypeCount && pStopwatches->GetEntries(); i++)
2081     SetStopwatch(pStopwatches->At(i), (AliHLTStopwatchType)i);
2082   return iResult;
2083 }
2084
2085 AliHLTUInt32_t AliHLTComponent::GetRunNo() const
2086 {
2087   // see header file for function documentation
2088   if (fpRunDesc==NULL) return kAliHLTVoidRunNo;
2089   return fpRunDesc->fRunNo;
2090 }
2091
2092 AliHLTUInt32_t AliHLTComponent::GetRunType() const
2093 {
2094   // see header file for function documentation
2095   if (fpRunDesc==NULL) return kAliHLTVoidRunType;
2096   return fpRunDesc->fRunType;
2097 }
2098
2099 AliHLTUInt32_t    AliHLTComponent::GetTimeStamp() const
2100 {
2101   // see header file for function documentation
2102   return fCurrentEventData.fEventCreation_s>0? fCurrentEventData.fEventCreation_s:1;
2103 }
2104
2105 AliHLTUInt32_t    AliHLTComponent::GetPeriodNumber() const
2106 {
2107   // see header file for function documentation
2108   return (GetEventId()>>36)&0xfffffff;
2109 }
2110
2111 AliHLTUInt32_t    AliHLTComponent::GetOrbitNumber() const
2112 {
2113   // see header file for function documentation
2114   return (GetEventId()>>12)&0xffffff;
2115 }
2116
2117 AliHLTUInt16_t    AliHLTComponent::GetBunchCrossNumber() const
2118 {
2119   // see header file for function documentation
2120   return GetEventId()&0xfff;
2121 }
2122
2123 bool AliHLTComponent::IsDataEvent(AliHLTUInt32_t* pTgt)
2124 {
2125   // see header file for function documentation
2126   if (pTgt) *pTgt=fEventType;
2127   return (fEventType==gkAliEventTypeData ||
2128           fEventType==gkAliEventTypeDataReplay ||
2129           fEventType==gkAliEventTypeCalibration);
2130 }
2131
2132 int AliHLTComponent::CopyStruct(void* pStruct, unsigned int iStructSize, unsigned int iBlockNo,
2133                                 const char* structname, const char* eventname)
2134 {
2135   // see header file for function documentation
2136   int iResult=0;
2137   if (pStruct!=NULL && iStructSize>sizeof(AliHLTUInt32_t)) {
2138     if (fpInputBlocks!=NULL && iBlockNo<fCurrentEventData.fBlockCnt) {
2139       AliHLTUInt32_t* pTgt=(AliHLTUInt32_t*)pStruct;
2140       if (fpInputBlocks[iBlockNo].fPtr && fpInputBlocks[iBlockNo].fSize) {
2141         AliHLTUInt32_t copy=*((AliHLTUInt32_t*)fpInputBlocks[iBlockNo].fPtr);
2142         if (fpInputBlocks[iBlockNo].fSize!=copy) {
2143           HLTWarning("%s event: mismatch of block size (%d) and structure size (%d)", eventname, fpInputBlocks[iBlockNo].fSize, copy);
2144           if (copy>fpInputBlocks[iBlockNo].fSize) copy=fpInputBlocks[iBlockNo].fSize;
2145         }
2146         if (copy!=iStructSize) {
2147           HLTWarning("%s event: mismatch in %s version (data type version %d)", eventname, structname, ALIHLT_DATA_TYPES_VERSION);
2148           if (copy>iStructSize) {
2149             copy=iStructSize;
2150           } else {
2151             memset(pTgt, 0, iStructSize);
2152           }
2153         }
2154         memcpy(pTgt, fpInputBlocks[iBlockNo].fPtr, copy);
2155         *pTgt=iStructSize;
2156         iResult=copy;
2157       } else {
2158         HLTWarning("%s event: missing data block", eventname);
2159       }
2160     } else {
2161       iResult=-ENODATA;
2162     }
2163   } else {
2164     HLTError("invalid struct");
2165     iResult=-EINVAL;
2166   }
2167   return iResult;
2168 }
2169
2170 void AliHLTComponent::SetDDLBit(AliHLTEventDDL &list, Int_t ddlId, Bool_t state ) const
2171 {
2172   // see header file for function documentation
2173   
2174   // -- Detector offset
2175   Int_t ddlIdBase =  TMath::FloorNint( (Double_t) ddlId / 256.0 );
2176   
2177   // -- Word Base = 1. word of detector ( TPC has 8 words, TOF 3 ) 
2178   Int_t wordBase = 0;
2179
2180   if ( ddlIdBase <= 3 )
2181     wordBase = ddlIdBase;
2182   else if ( ddlIdBase > 3 && ddlIdBase < 5 )
2183     wordBase = ddlIdBase + 7;
2184   else 
2185     wordBase = ddlIdBase + 9;
2186
2187   // -- Bit index in Word
2188   Int_t bitIdx = ddlId % 32;
2189
2190   // -- Index of word
2191   Int_t wordIdx = wordBase;
2192
2193   // -- if TPC (3) or TOD (5) add word idx
2194   if ( ( ddlIdBase == 3 ) || ( ddlIdBase == 5 ) ) {
2195     wordIdx += TMath::FloorNint( (Double_t) ( ddlId - ( ddlIdBase * 256 ) ) / 32.0 );
2196   }
2197
2198   // -- Set -- 'OR' word with bit mask;
2199   if ( state )
2200     list.fList[wordIdx] |= ( 0x00000001 << bitIdx );
2201   // -- Unset -- 'AND' word with bit mask;
2202   else
2203     list.fList[wordIdx] &= ( 0xFFFFFFFF ^ ( 0x00000001 << bitIdx ) );
2204 }
2205
2206 Int_t AliHLTComponent::GetFirstUsedDDLWord(AliHLTEventDDL &list) const
2207 {
2208   // see header file for function documentation
2209
2210   Int_t iResult = -1;
2211
2212   for ( Int_t wordNdx = 0 ; wordNdx < gkAliHLTDDLListSize ; wordNdx++ ) {
2213
2214     if ( list.fList[wordNdx] != 0 && iResult == -1 ) {
2215       // check for special cases TPC and TOF
2216       if ( wordNdx > 3 && wordNdx <= 10 ) {
2217         wordNdx = 10;
2218         iResult = 3;
2219       }
2220       else if ( wordNdx > 12 && wordNdx <= 14 ) {
2221         wordNdx = 14;
2222         iResult = 12;
2223       }
2224       else
2225         iResult = wordNdx;
2226     }
2227     else if ( list.fList[wordNdx] != 0 && iResult >= 0 ) {
2228       HLTError( "DDLIDs for minimum of TWO detectors ( %d, %d ) set, this function works only for ONE detector.", iResult, wordNdx );
2229       iResult = -1;
2230       break;
2231     }
2232   }
2233
2234   return iResult;
2235 }
2236
2237 AliHLTUInt32_t AliHLTComponent::CalculateChecksum(const AliHLTUInt8_t* buffer, int size)
2238 {
2239   // see header file for function documentation
2240   AliHLTUInt32_t  remainder = 0; 
2241   const AliHLTUInt8_t crcwidth=(8*sizeof(AliHLTUInt32_t));
2242   const AliHLTUInt32_t topbit=1 << (crcwidth-1);
2243   const AliHLTUInt32_t polynomial=0xD8;  /* 11011 followed by 0's */
2244
2245   // code from
2246   // http://www.netrino.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
2247
2248   /*
2249    * Perform modulo-2 division, a byte at a time.
2250    */
2251   for (int byte = 0; byte < size; ++byte)
2252     {
2253       /*
2254        * Bring the next byte into the remainder.
2255        */
2256       remainder ^= (buffer[byte] << (crcwidth - 8));
2257
2258       /*
2259        * Perform modulo-2 division, a bit at a time.
2260        */
2261       for (uint8_t bit = 8; bit > 0; --bit)
2262         {
2263           /*
2264            * Try to divide the current data bit.
2265            */
2266           if (remainder & topbit)
2267             {
2268               remainder = (remainder << 1) ^ polynomial;
2269             }
2270           else
2271             {
2272               remainder = (remainder << 1);
2273             }
2274         }
2275     }
2276
2277   /*
2278    * The final remainder is the CRC result.
2279    */
2280   return (remainder);
2281 }
2282
2283 int AliHLTComponent::ExtractComponentTableEntry(const AliHLTUInt8_t* pBuffer, AliHLTUInt32_t size,
2284                                                 string& retChainId, string& retCompId, string& retCompArgs,
2285                                                 vector<AliHLTUInt32_t>& parents)
2286 {
2287   // see header file for function documentation
2288   retChainId.clear();
2289   retCompId.clear();
2290   retCompArgs.clear();
2291   parents.clear();
2292   if (!pBuffer || size==0) return 0;
2293
2294   const AliHLTComponentTableEntry* pEntry=reinterpret_cast<const AliHLTComponentTableEntry*>(pBuffer);
2295   if (size<8/* the initial size of the structure*/ ||
2296       pEntry==NULL || pEntry->fStructSize<8) return -ENOMSG;
2297   const AliHLTUInt32_t* pParents=reinterpret_cast<const AliHLTUInt32_t*>(pEntry->fBuffer);
2298   const AliHLTUInt8_t* pEnd=pBuffer+size;
2299
2300   if (pParents+pEntry->fNofParents>=reinterpret_cast<const AliHLTUInt32_t*>(pEnd)) return -ENODEV;
2301   for (unsigned int i=0; i<pEntry->fNofParents; i++, pParents++) {
2302     parents.push_back(*pParents);
2303   }
2304
2305   const char* pDescription=reinterpret_cast<const char*>(pParents);
2306   if (pDescription+pEntry->fSizeDescription>=reinterpret_cast<const char*>(pEnd) ||
2307       *(pDescription+pEntry->fSizeDescription)!=0) {
2308     return -EBADF;
2309   }
2310
2311   TString descriptor=reinterpret_cast<const char*>(pDescription);
2312   TString chainId;
2313   TString compId;
2314   TString compArgs;
2315   TObjArray* pTokens=descriptor.Tokenize("{");
2316   if (pTokens) {
2317     int n=0;
2318     if (pTokens->GetEntries()>n) {
2319       retChainId=((TObjString*)pTokens->At(n++))->GetString();
2320     }
2321     if (pTokens->GetEntries()>n) {
2322       compId=((TObjString*)pTokens->At(n++))->GetString();
2323     }
2324     delete pTokens;
2325   }
2326   if (!compId.IsNull() && (pTokens=compId.Tokenize(":"))!=NULL) {
2327     int n=0;
2328     if (pTokens->GetEntries()>n) {
2329       compId=((TObjString*)pTokens->At(n++))->GetString();
2330     }
2331     if (pTokens->GetEntries()>n) {
2332       compArgs=((TObjString*)pTokens->At(n++))->GetString();
2333     }
2334     delete pTokens;
2335   }
2336   compId.ReplaceAll("}", "");
2337   compArgs.ReplaceAll("}", "");
2338
2339   retCompId=compId;
2340   retCompArgs=compArgs;
2341
2342   if (retChainId.size()==0) return -ENODATA;
2343
2344   return 1;
2345 }
2346
2347 int AliHLTComponent::LoggingVarargs(AliHLTComponentLogSeverity severity, 
2348                                     const char* originClass, const char* originFunc,
2349                                     const char* file, int line, ... ) const
2350 {
2351   // see header file for function documentation
2352   int iResult=0;
2353
2354   va_list args;
2355   va_start(args, line);
2356
2357   // logging function needs to be const in order to be called from const member functions
2358   // without problems. But at this point we face the problem with virtual members which
2359   // are not necessarily const.
2360   AliHLTComponent* nonconst=const_cast<AliHLTComponent*>(this);
2361   AliHLTLogging::SetLogString("%s (%s, %p): ", 
2362                               fChainId[0]!=0?fChainId.c_str():nonconst->GetComponentID(),
2363                               nonconst->GetComponentID(), this);
2364   iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args, true /*append*/));
2365   va_end(args);
2366
2367   return iResult;
2368 }
2369
2370 int AliHLTComponent::ScanECSParam(const char* ecsParam)
2371 {
2372   // see header file for function documentation
2373
2374   // format of the parameter string from ECS
2375   // <command>;<parameterkey>=<parametervalue>;<parameterkey>=<parametervalue>;...
2376   // search for a subset of the parameterkeys
2377   int iResult=0;
2378   TString string=ecsParam;
2379   TObjArray* parameter=string.Tokenize(";");
2380   if (parameter) {
2381     for (int i=0; i<parameter->GetEntries(); i++) {
2382       TString entry=((TObjString*)parameter->At(i))->GetString();
2383       HLTDebug("scanning ECS entry: %s", entry.Data());
2384       TObjArray* entryParams=entry.Tokenize("=");
2385       if (entryParams) {
2386         if (entryParams->GetEntries()>1) {
2387           if ((((TObjString*)entryParams->At(0))->GetString()).CompareTo("CTP_TRIGGER_CLASS")==0) {
2388             int result=InitCTPTriggerClasses((((TObjString*)entryParams->At(1))->GetString()).Data());
2389             if (iResult>=0 && result<0) iResult=result;
2390           } else {
2391             // TODO: scan the other parameters
2392             // e.g. consistency check of run number
2393           }
2394         }
2395         delete entryParams;
2396       }
2397     }
2398     delete parameter;
2399   }
2400
2401   return iResult;
2402 }
2403
2404 int AliHLTComponent::SetupCTPData()
2405 {
2406   // see header file for function documentation
2407   if (fpCTPData) delete fpCTPData;
2408   fpCTPData=new AliHLTCTPData;
2409   if (!fpCTPData) return -ENOMEM;
2410   return 0;
2411 }
2412
2413 int AliHLTComponent::InitCTPTriggerClasses(const char* ctpString)
2414 {
2415   // see header file for function documentation
2416   if (!fpCTPData) return 0; // silently accept as the component has to announce that it want's the CTP info
2417   return fpCTPData->InitCTPTriggerClasses(ctpString);
2418 }
2419
2420 bool AliHLTComponent::EvaluateCTPTriggerClass(const char* expression, AliHLTComponentTriggerData& trigData) const
2421 {
2422   // see header file for function documentation
2423   if (!fpCTPData) {
2424     static bool bWarningThrown=false;
2425     if (!bWarningThrown) HLTError("Trigger classes not initialized, use SetupCTPData from DoInit()");
2426     bWarningThrown=true;
2427     return false;
2428   }
2429
2430   return fpCTPData->EvaluateCTPTriggerClass(expression, trigData);
2431 }