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