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