]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponent.cxx
- default logging severity set to 0x3d (all but debug)
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5  *                                                                        *
6  * Authors: Matthias Richter <Matthias.Richter@ift.uib.no>                *
7  *          Timm Steinbeck <timm@kip.uni-heidelberg.de>                   *
8  *          for The ALICE Off-line Project.                               *
9  *                                                                        *
10  * Permission to use, copy, modify and distribute this software and its   *
11  * documentation strictly for non-commercial purposes is hereby granted   *
12  * without fee, provided that the above copyright notice appears in all   *
13  * copies and that both the copyright notice and this permission notice   *
14  * appear in the supporting documentation. The authors make no claims     *
15  * about the suitability of this software for any purpose. It is          *
16  * provided "as is" without express or implied warranty.                  *
17  **************************************************************************/
18
19 /** @file   AliHLTComponent.cxx
20     @author Matthias Richter, Timm Steinbeck
21     @date   
22     @brief  Base class implementation for HLT components. */
23
24 #if __GNUC__>= 3
25 using namespace std;
26 #endif
27
28 #include "AliHLTStdIncludes.h"
29 #include "AliHLTComponent.h"
30 #include "AliHLTComponentHandler.h"
31 #include "AliHLTMessage.h"
32 #include "TString.h"
33 #include "TObjArray.h"
34 #include "TClass.h"
35
36 /** ROOT macro for the implementation of ROOT specific class methods */
37 ClassImp(AliHLTComponent)
38
39 AliHLTComponent::AliHLTComponent()
40   :
41   fEnvironment(),
42   fCurrentEvent(0),
43   fEventCount(-1),
44   fFailedEvents(0),
45   fCurrentEventData(),
46   fpInputBlocks(NULL),
47   fCurrentInputBlock(-1),
48   fSearchDataType(kAliHLTVoidDataType),
49   fClassName(),
50   fpInputObjects(NULL),
51   fpOutputBuffer(NULL),
52   fOutputBufferSize(0),
53   fOutputBufferFilled(0),
54   fOutputBlocks()
55 {
56   // see header file for class documentation
57   // or
58   // refer to README to build package
59   // or
60   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
61   memset(&fEnvironment, 0, sizeof(AliHLTComponentEnvironment));
62   if (fgpComponentHandler)
63     fgpComponentHandler->ScheduleRegister(this);
64 }
65
66 AliHLTComponent::AliHLTComponent(const AliHLTComponent&)
67   :
68   fEnvironment(),
69   fCurrentEvent(0),
70   fEventCount(-1),
71   fFailedEvents(0),
72   fCurrentEventData(),
73   fpInputBlocks(NULL),
74   fCurrentInputBlock(-1),
75   fSearchDataType(kAliHLTVoidDataType),
76   fClassName(),
77   fpInputObjects(NULL),
78   fpOutputBuffer(NULL),
79   fOutputBufferSize(0),
80   fOutputBufferFilled(0),
81   fOutputBlocks()
82 {
83   // see header file for class documentation
84   HLTFatal("copy constructor untested");
85 }
86
87 AliHLTComponent& AliHLTComponent::operator=(const AliHLTComponent&)
88
89   // see header file for class documentation
90   HLTFatal("assignment operator untested");
91   return *this;
92 }
93
94 AliHLTComponent::~AliHLTComponent()
95 {
96   // see header file for function documentation
97 }
98
99 AliHLTComponentHandler* AliHLTComponent::fgpComponentHandler=NULL;
100
101 int AliHLTComponent::SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite) 
102 {
103   // see header file for function documentation
104   int iResult=0;
105   if (fgpComponentHandler==NULL || bOverwrite!=0)
106     fgpComponentHandler=pCH;
107   else
108     iResult=-EPERM;
109   return iResult;
110 }
111
112 int AliHLTComponent::UnsetGlobalComponentHandler() 
113 {
114   // see header file for function documentation
115   return SetGlobalComponentHandler(NULL,1);
116 }
117
118 int AliHLTComponent::Init( AliHLTComponentEnvironment* environ, void* environParam, int argc, const char** argv )
119 {
120   // see header file for function documentation
121   int iResult=0;
122   if (environ) {
123     memcpy(&fEnvironment, environ, sizeof(AliHLTComponentEnvironment));
124     fEnvironment.fParam=environParam;
125   }
126   iResult=DoInit(argc, argv);
127   if (iResult>=0) fEventCount=0;
128   return iResult;
129 }
130
131 int AliHLTComponent::Deinit()
132 {
133   // see header file for function documentation
134   int iResult=0;
135   iResult=DoDeinit();
136   return iResult;
137 }
138
139 int AliHLTComponent::DoInit( int argc, const char** argv )
140 {
141   // see header file for function documentation
142   if (argc==0 && argv==NULL) {
143     // this is currently just to get rid of the warning "unused parameter"
144   }
145   return 0;
146 }
147
148 int AliHLTComponent::DoDeinit()
149 {
150   // see header file for function documentation
151   return 0;
152 }
153
154 void AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type, char output[kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2] ) const
155 {
156   // see header file for function documentation
157   memset( output, 0, kAliHLTComponentDataTypefIDsize+kAliHLTComponentDataTypefOriginSize+2 );
158   strncat( output, type.fOrigin, kAliHLTComponentDataTypefOriginSize );
159   strcat( output, ":" );
160   strncat( output, type.fID, kAliHLTComponentDataTypefIDsize );
161 }
162
163 string AliHLTComponent::DataType2Text( const AliHLTComponentDataType& type )
164 {
165   // see header file for function documentation
166   string out("");
167   
168   if (type==kAliHLTVoidDataType) {
169     out="VOID:VOID";
170   } else {
171     // some gymnastics in order to avoid a '0' which is part of either or both
172     // ID and origin terminating the whole string. Unfortunately, string doesn't
173     // stop appending at the '0' if the number of elements to append was 
174     // explicitely specified
175     string tmp("");
176     tmp.append(type.fOrigin, kAliHLTComponentDataTypefOriginSize);
177     out.append(tmp.c_str());
178     out.append(":");
179     tmp="";
180     tmp.append(type.fID, kAliHLTComponentDataTypefIDsize);
181     out.append(tmp.c_str());
182   }
183   return out;
184 }
185
186
187 void* AliHLTComponent::AllocMemory( unsigned long size ) 
188 {
189   // see header file for function documentation
190   if (fEnvironment.fAllocMemoryFunc)
191     return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
192   HLTFatal("no memory allocation handler registered");
193   return NULL;
194 }
195
196 int AliHLTComponent::MakeOutputDataBlockList( const vector<AliHLTComponentBlockData>& blocks, AliHLTUInt32_t* blockCount,
197                                               AliHLTComponentBlockData** outputBlocks ) 
198 {
199   // see header file for function documentation
200     if ( blockCount==NULL || outputBlocks==NULL )
201         return -EFAULT;
202     AliHLTUInt32_t count = blocks.size();
203     if ( !count )
204         {
205         *blockCount = 0;
206         *outputBlocks = NULL;
207         return 0;
208         }
209     *outputBlocks = reinterpret_cast<AliHLTComponentBlockData*>( AllocMemory( sizeof(AliHLTComponentBlockData)*count ) );
210     if ( !*outputBlocks )
211         return -ENOMEM;
212     for ( unsigned long i = 0; i < count; i++ ) {
213         (*outputBlocks)[i] = blocks[i];
214         if (blocks[i].fDataType==kAliHLTAnyDataType) {
215           (*outputBlocks)[i].fDataType=GetOutputDataType();
216           /* data type was set to the output data type by the PubSub AliRoot
217              Wrapper component, if data type of the block was ********:****.
218              Now handled by the component base class in order to have same
219              behavior when running embedded in AliRoot
220           memset((*outputBlocks)[i].fDataType.fID, '*', kAliHLTComponentDataTypefIDsize);
221           memset((*outputBlocks)[i].fDataType.fOrigin, '*', kAliHLTComponentDataTypefOriginSize);
222           */
223         }
224     }
225     *blockCount = count;
226     return 0;
227
228 }
229
230 int AliHLTComponent::GetEventDoneData( unsigned long size, AliHLTComponentEventDoneData** edd ) 
231 {
232   // see header file for function documentation
233   if (fEnvironment.fGetEventDoneDataFunc)
234     return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
235   return -ENOSYS;
236 }
237
238 int AliHLTComponent::FindMatchingDataTypes(AliHLTComponent* pConsumer, vector<AliHLTComponentDataType>* tgtList) 
239 {
240   // see header file for function documentation
241   int iResult=0;
242   if (pConsumer) {
243     vector<AliHLTComponentDataType> ctlist;
244     ((AliHLTComponent*)pConsumer)->GetInputDataTypes(ctlist);
245     vector<AliHLTComponentDataType>::iterator type=ctlist.begin();
246     //AliHLTComponentDataType ouptdt=GetOutputDataType();
247     //PrintDataTypeContent(ouptdt, "publisher \'%s\'");
248     while (type!=ctlist.end() && iResult==0) {
249       //PrintDataTypeContent((*type), "consumer \'%s\'");
250       if ((*type)==GetOutputDataType() ||
251           (*type)==kAliHLTAnyDataType) {
252         if (tgtList) tgtList->push_back(*type);
253         iResult++;
254         // this loop has to be changed in case of multiple output types
255         break;
256       }
257       type++;
258     }
259   } else {
260     iResult=-EINVAL;
261   }
262   return iResult;
263 }
264
265 void AliHLTComponent::PrintDataTypeContent(AliHLTComponentDataType& dt, const char* format) const
266 {
267   const char* fmt="publisher \'%s\'";
268   if (format) fmt=format;
269   HLTMessage(fmt, (DataType2Text(dt)).c_str());
270   HLTMessage("%x %x %x %x %x %x %x %x : %x %x %x %x", 
271              dt.fID[0],
272              dt.fID[1],
273              dt.fID[2],
274              dt.fID[3],
275              dt.fID[4],
276              dt.fID[5],
277              dt.fID[6],
278              dt.fID[7],
279              dt.fOrigin[0],
280              dt.fOrigin[1],
281              dt.fOrigin[2],
282              dt.fOrigin[3]);
283 }
284
285 void AliHLTComponent::FillBlockData( AliHLTComponentBlockData& blockData ) const
286 {
287   // see header file for function documentation
288   blockData.fStructSize = sizeof(blockData);
289   FillShmData( blockData.fShmKey );
290   blockData.fOffset = ~(AliHLTUInt32_t)0;
291   blockData.fPtr = NULL;
292   blockData.fSize = 0;
293   FillDataType( blockData.fDataType );
294   blockData.fSpecification = kAliHLTVoidDataSpec;
295 }
296
297 void AliHLTComponent::FillShmData( AliHLTComponentShmData& shmData ) const
298 {
299   // see header file for function documentation
300   shmData.fStructSize = sizeof(shmData);
301   shmData.fShmType = gkAliHLTComponentInvalidShmType;
302   shmData.fShmID = gkAliHLTComponentInvalidShmID;
303 }
304
305 void AliHLTComponent::FillDataType( AliHLTComponentDataType& dataType ) const
306 {
307   // see header file for function documentation
308   dataType=kAliHLTAnyDataType;
309 }
310
311 void AliHLTComponent::CopyDataType(AliHLTComponentDataType& tgtdt, const AliHLTComponentDataType& srcdt) 
312 {
313   // see header file for function documentation
314   memcpy(&tgtdt.fID[0], &srcdt.fID[0], kAliHLTComponentDataTypefIDsize);
315   memcpy(&tgtdt.fOrigin[0], &srcdt.fOrigin[0], kAliHLTComponentDataTypefOriginSize);
316 }
317
318 void AliHLTComponent::SetDataType(AliHLTComponentDataType& tgtdt, const char* id, const char* origin) 
319 {
320   // see header file for function documentation
321   tgtdt.fStructSize = sizeof(AliHLTComponentDataType);
322   memset(&tgtdt.fID[0], 0, kAliHLTComponentDataTypefIDsize);
323   memset(&tgtdt.fOrigin[0], 0, kAliHLTComponentDataTypefOriginSize);
324
325   if ((int)strlen(id)>kAliHLTComponentDataTypefIDsize) {
326     HLTWarning("data type id %s is too long, truncated to %d", id, kAliHLTComponentDataTypefIDsize);
327   }
328   strncpy(&tgtdt.fID[0], id, kAliHLTComponentDataTypefIDsize);
329
330   if ((int)strlen(origin)>kAliHLTComponentDataTypefOriginSize) {
331     HLTWarning("data type origin %s is too long, truncated to %d", origin, kAliHLTComponentDataTypefOriginSize);
332   }
333   strncpy(&tgtdt.fOrigin[0], origin, kAliHLTComponentDataTypefOriginSize);
334 }
335
336 void AliHLTComponent::FillEventData(AliHLTComponentEventData& evtData)
337 {
338   // see header file for function documentation
339   memset(&evtData, 0, sizeof(AliHLTComponentEventData));
340   evtData.fStructSize=sizeof(AliHLTComponentEventData);
341 }
342
343 void AliHLTComponent::PrintComponentDataTypeInfo(const AliHLTComponentDataType& dt) 
344 {
345   // see header file for function documentation
346   TString msg;
347   msg.Form("AliHLTComponentDataType(%d): ID=\"", dt.fStructSize);
348   for ( int i = 0; i < kAliHLTComponentDataTypefIDsize; i++ ) {
349    if (dt.fID[i]!=0) msg+=dt.fID[i];
350    else msg+="\\0";
351   }
352   msg+="\" Origin=\"";
353   for ( int i = 0; i < kAliHLTComponentDataTypefOriginSize; i++ ) {
354    if (dt.fOrigin[i]!=0) msg+=dt.fOrigin[i];
355    else msg+="\\0";
356   }
357   msg+="\"";
358   AliHLTLogging::Message(NULL, kHLTLogNone, NULL , NULL, msg.Data());
359 }
360
361 int AliHLTComponent::GetEventCount() const
362 {
363   // see header file for function documentation
364   return fEventCount;
365 }
366
367 int AliHLTComponent::IncrementEventCounter()
368 {
369   // see header file for function documentation
370   if (fEventCount>=0) fEventCount++;
371   return fEventCount;
372 }
373
374 int AliHLTComponent::GetNumberOfInputBlocks()
375 {
376   // see header file for function documentation
377   if (fpInputBlocks!=NULL) {
378     return fCurrentEventData.fBlockCnt;
379   }
380   return 0;
381 }
382
383 const TObject* AliHLTComponent::GetFirstInputObject(const AliHLTComponentDataType& dt,
384                                                     const char* classname,
385                                                     int bForce)
386 {
387   // see header file for function documentation
388   fSearchDataType=dt;
389   if (classname) fClassName=classname;
390   else fClassName.clear();
391   int idx=FindInputBlock(fSearchDataType, 0);
392   //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(dt).c_str());
393   TObject* pObj=NULL;
394   if (idx>=0) {
395     if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
396       fCurrentInputBlock=idx;
397     } else {
398     }
399   }
400   return pObj;
401 }
402
403 const TObject* AliHLTComponent::GetFirstInputObject(const char* dtID, 
404                                                     const char* dtOrigin,
405                                                     const char* classname,
406                                                     int         bForce)
407 {
408   // see header file for function documentation
409   AliHLTComponentDataType dt;
410   SetDataType(dt, dtID, dtOrigin);
411   return GetFirstInputObject(dt, classname, bForce);
412 }
413
414 const TObject* AliHLTComponent::GetNextInputObject(int bForce)
415 {
416   // see header file for function documentation
417   int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
418   //HLTDebug("found block %d when searching for data type %s", idx, DataType2Text(fSearchDataType).c_str());
419   TObject* pObj=NULL;
420   if (idx>=0) {
421     if ((pObj=GetInputObject(idx, fClassName.c_str(), bForce))!=NULL) {
422       fCurrentInputBlock=idx;
423     }
424   }
425   return pObj;
426 }
427
428 int AliHLTComponent::FindInputBlock(const AliHLTComponentDataType& dt, int startIdx)
429 {
430   // see header file for function documentation
431   int iResult=-ENOENT;
432   if (fpInputBlocks!=NULL) {
433     int idx=startIdx<0?0:startIdx;
434     for ( ; (UInt_t)idx<fCurrentEventData.fBlockCnt && iResult==-ENOENT; idx++) {
435       if (dt == kAliHLTAnyDataType || fpInputBlocks[idx].fDataType == dt) {
436         iResult=idx;
437       }
438     }
439   }
440   return iResult;
441 }
442
443 TObject* AliHLTComponent::CreateInputObject(int idx, int bForce)
444 {
445   // see header file for function documentation
446   TObject* pObj=NULL;
447   if (fpInputBlocks!=NULL) {
448     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
449       if (fpInputBlocks[idx].fPtr) {
450         AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)fpInputBlocks[idx].fPtr);
451         if (firstWord==fpInputBlocks[idx].fSize-sizeof(AliHLTUInt32_t)) {
452           //HLTDebug("create object from block %d size %d", idx, fpInputBlocks[idx].fSize);
453           AliHLTMessage msg(fpInputBlocks[idx].fPtr, fpInputBlocks[idx].fSize);
454           pObj=msg.ReadObject(msg.GetClass());
455           if (pObj && msg.GetClass()) {
456             //HLTDebug("object %p type %s created", pObj, msg.GetClass()->GetName());
457           } else {
458           }
459         } else {
460           //    } else if (bForce!=0) {
461           HLTError("size missmatch: block size %d, indicated %d", fpInputBlocks[idx].fSize, firstWord+sizeof(AliHLTUInt32_t));
462         }
463       } else {
464         HLTFatal("block descriptor empty");
465       }
466     } else {
467       HLTError("index %d out of range %d", idx, fCurrentEventData.fBlockCnt);
468     }
469   } else {
470     HLTError("no input blocks available");
471   }
472   
473   return pObj;
474 }
475
476 TObject* AliHLTComponent::GetInputObject(int idx, const char* classname, int bForce)
477 {
478   // see header file for function documentation
479   if (fpInputObjects==NULL) {
480     fpInputObjects=new TObjArray(fCurrentEventData.fBlockCnt);
481   }
482   TObject* pObj=NULL;
483   if (fpInputObjects) {
484     pObj=fpInputObjects->At(idx);
485     if (pObj==NULL) {
486       pObj=CreateInputObject(idx, bForce);
487       if (pObj) {
488         fpInputObjects->AddAt(pObj, idx);
489       }
490     }
491   } else {
492     HLTFatal("memory allocation failed: TObjArray of size %d", fCurrentEventData.fBlockCnt);
493   }
494   return pObj;
495 }
496
497 AliHLTComponentDataType AliHLTComponent::GetDataType(const TObject* pObject)
498 {
499   // see header file for function documentation
500   AliHLTComponentDataType dt=kAliHLTVoidDataType;
501   int idx=fCurrentInputBlock;
502   if (pObject) {
503     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
504     } else {
505       HLTError("unknown object %p", pObject);
506     }
507   }
508   if (idx>=0) {
509     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
510       dt=fpInputBlocks[idx].fDataType;
511     } else {
512       HLTFatal("severe internal error, index out of range");
513     }
514   }
515   return dt;
516 }
517
518 AliHLTUInt32_t AliHLTComponent::GetSpecification(const TObject* pObject)
519 {
520   // see header file for function documentation
521   AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
522   int idx=fCurrentInputBlock;
523   if (pObject) {
524     if (fpInputObjects==NULL || (idx=fpInputObjects->IndexOf(pObject))>=0) {
525     } else {
526       HLTError("unknown object %p", pObject);
527     }
528   }
529   if (idx>=0) {
530     if ((UInt_t)idx<fCurrentEventData.fBlockCnt) {
531       iSpec=fpInputBlocks[idx].fSpecification;
532     } else {
533       HLTFatal("severe internal error, index out of range");
534     }
535   }
536   return iSpec;
537 }
538
539 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const AliHLTComponentDataType& dt)
540 {
541   // see header file for function documentation
542   fSearchDataType=dt;
543   fClassName.clear();
544   int idx=FindInputBlock(fSearchDataType, 0);
545   const AliHLTComponentBlockData* pBlock=NULL;
546   if (idx>=0) {
547     // check for fpInputBlocks pointer done in FindInputBlock
548     pBlock=&fpInputBlocks[idx];
549   }
550   return pBlock;
551 }
552
553 const AliHLTComponentBlockData* AliHLTComponent::GetFirstInputBlock(const char* dtID, 
554                                                                     const char* dtOrigin)
555 {
556   // see header file for function documentation
557   AliHLTComponentDataType dt;
558   SetDataType(dt, dtID, dtOrigin);
559   return GetFirstInputBlock(dt);
560 }
561
562 const AliHLTComponentBlockData* AliHLTComponent::GetNextInputBlock()
563 {
564   // see header file for function documentation
565   int idx=FindInputBlock(fSearchDataType, fCurrentInputBlock+1);
566   const AliHLTComponentBlockData* pBlock=NULL;
567   if (idx>=0) {
568     // check for fpInputBlocks pointer done in FindInputBlock
569     pBlock=&fpInputBlocks[idx];
570   }
571   return pBlock;
572 }
573
574 int AliHLTComponent::FindInputBlock(const AliHLTComponentBlockData* pBlock)
575 {
576   // see header file for function documentation
577   int iResult=-ENOENT;
578   if (fpInputBlocks!=NULL) {
579     if (pBlock) {
580       if (pBlock>=fpInputBlocks && pBlock<fpInputBlocks+fCurrentEventData.fBlockCnt) {
581         iResult=(int)(pBlock-fpInputBlocks);
582       }
583     } else {
584       iResult=-EINVAL;
585     }
586   }
587   return iResult;
588 }
589
590 AliHLTUInt32_t AliHLTComponent::GetSpecification(const AliHLTComponentBlockData* pBlock)
591 {
592   // see header file for function documentation
593   AliHLTUInt32_t iSpec=kAliHLTVoidDataSpec;
594   int idx=fCurrentInputBlock;
595   if (pBlock) {
596     if (fpInputObjects==NULL || (idx=FindInputBlock(pBlock))>=0) {
597     } else {
598       HLTError("unknown Block %p", pBlock);
599     }
600   }
601   if (idx>=0) {
602     // check for fpInputBlocks pointer done in FindInputBlock
603     iSpec=fpInputBlocks[idx].fSpecification;
604   }
605   return iSpec;
606 }
607
608 int AliHLTComponent::PushBack(TObject* pObject, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
609 {
610   // see header file for function documentation
611   int iResult=0;
612   if (pObject) {
613     AliHLTMessage msg(kMESS_OBJECT);
614     msg.WriteObject(pObject);
615     Int_t iMsgLength=msg.Length();
616     if (iMsgLength>0) {
617       msg.SetLength(); // sets the length to the first (reserved) word
618       iResult=InsertOutputBlock(msg.Buffer(), iMsgLength, dt, spec);
619       if (iResult>=0) {
620         //HLTDebug("object %s (%p) inserted to output", pObject->ClassName(), pObject);
621       }
622     } else {
623       HLTError("object serialization failed for object %p", pObject);
624       iResult=-ENOMSG;
625     }
626   } else {
627     iResult=-EINVAL;
628   }
629   return iResult;
630 }
631
632 int AliHLTComponent::PushBack(TObject* pObject, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
633 {
634   // see header file for function documentation
635   AliHLTComponentDataType dt;
636   SetDataType(dt, dtID, dtOrigin);
637   return PushBack(pObject, dt, spec);
638 }
639
640 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
641 {
642   // see header file for function documentation
643   return InsertOutputBlock(pBuffer, iSize, dt, spec);
644 }
645
646 int AliHLTComponent::PushBack(void* pBuffer, int iSize, const char* dtID, const char* dtOrigin, AliHLTUInt32_t spec)
647 {
648   // see header file for function documentation
649   AliHLTComponentDataType dt;
650   SetDataType(dt, dtID, dtOrigin);
651   return PushBack(pBuffer, iSize, dt, spec);
652 }
653
654 int AliHLTComponent::InsertOutputBlock(void* pBuffer, int iSize, const AliHLTComponentDataType& dt, AliHLTUInt32_t spec)
655 {
656   // see header file for function documentation
657   int iResult=0;
658   if (pBuffer) {
659     if (fpOutputBuffer && (fOutputBufferSize-fOutputBufferFilled)) {
660       AliHLTUInt8_t* pTgt=fpOutputBuffer+fOutputBufferFilled;
661       AliHLTComponentBlockData bd;
662       FillBlockData( bd );
663       bd.fOffset        = fOutputBufferFilled;
664       bd.fPtr           = pTgt;
665       bd.fSize          = iSize;
666       bd.fDataType      = dt;
667       bd.fSpecification = spec;
668       if (pBuffer!=NULL && pBuffer!=pTgt) {
669         memcpy(pTgt, pBuffer, iSize);
670         //AliHLTUInt32_t firstWord=*((AliHLTUInt32_t*)pBuffer); 
671         //HLTDebug("copy %d bytes from %p to output buffer %p, first word %#x", iSize, pBuffer, pTgt, firstWord);
672       }
673       fOutputBufferFilled+=bd.fSize;
674       fOutputBlocks.push_back( bd );
675       //HLTDebug("buffer inserted to output: size %d data type %s spec %#x", iSize, DataType2Text(dt).c_str(), spec);
676     } else {
677       if (fpOutputBuffer) {
678         HLTError("too little space in output buffer: %d, required %d", fOutputBufferSize-fOutputBufferFilled, iSize);
679       } else {
680         HLTError("output buffer not available");
681       }
682       iResult=-ENOSPC;
683     }
684   } else {
685     iResult=-EINVAL;
686   }
687   return iResult;
688 }
689
690 int AliHLTComponent::CreateEventDoneData(AliHLTComponentEventDoneData edd)
691 {
692   // see header file for function documentation
693   int iResult=-ENOSYS;
694   //#warning  function not yet implemented
695   HLTWarning("function not yet implemented");
696   return iResult;
697 }
698
699 int AliHLTComponent::ProcessEvent( const AliHLTComponentEventData& evtData,
700                                    const AliHLTComponentBlockData* blocks, 
701                                    AliHLTComponentTriggerData& trigData,
702                                    AliHLTUInt8_t* outputPtr, 
703                                    AliHLTUInt32_t& size,
704                                    AliHLTUInt32_t& outputBlockCnt, 
705                                    AliHLTComponentBlockData*& outputBlocks,
706                                    AliHLTComponentEventDoneData*& edd )
707 {
708   // see header file for function documentation
709   int iResult=0;
710   fCurrentEvent=evtData.fEventID;
711   fCurrentEventData=evtData;
712   fpInputBlocks=blocks;
713   fCurrentInputBlock=-1;
714   fSearchDataType=kAliHLTAnyDataType;
715   fpOutputBuffer=outputPtr;
716   fOutputBufferSize=size;
717   fOutputBufferFilled=0;
718   fOutputBlocks.clear();
719   
720   vector<AliHLTComponentBlockData> blockData;
721   iResult=DoProcessing(evtData, blocks, trigData, outputPtr, size, blockData, edd);
722   if (iResult>=0) {
723     if (fOutputBlocks.size()>0) {
724       //HLTDebug("got %d block(s) via high level interface", fOutputBlocks.size());
725       if (blockData.size()>0) {
726         HLTError("low level and high interface must not be mixed; use PushBack methods to insert data blocks");
727         iResult=-EFAULT;
728       } else {
729         iResult=MakeOutputDataBlockList(fOutputBlocks, &outputBlockCnt, &outputBlocks);
730         size=fOutputBufferFilled;
731       }
732     } else {
733       iResult=MakeOutputDataBlockList(blockData, &outputBlockCnt, &outputBlocks);
734     }
735     if (iResult<0) {
736       HLTFatal("component %s (%p): can not convert output block descriptor list", GetComponentID(), this);
737     }
738   }
739   if (iResult<0) {
740     outputBlockCnt=0;
741     outputBlocks=NULL;
742   }
743   IncrementEventCounter();
744   return iResult;
745 }
746