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