]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTComponent.h
Added a dummy component into the sample library.
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTComponent.h
1 // @(#) $Id$
2
3 #ifndef ALIHLTCOMPONENT_H
4 #define ALIHLTCOMPONENT_H
5 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6  * See cxx source for full Copyright notice                               */
7
8 /* AliHLTComponent
9    base class for HLT components
10  */
11
12 #include <errno.h>
13 #include "AliHLTDataTypes.h"
14 #include "AliHLTDefinitions.h"
15 #include "TObject.h"
16
17 class AliHLTComponentHandler;
18
19 class AliHLTComponent {
20  public:
21   AliHLTComponent();
22   virtual ~AliHLTComponent();
23
24   enum TComponentType { kUnknown=0, kSource=1, kProcessor=2, kSink=3 };
25   virtual int Init( AliHLTComponentEnvironment* environ, void* environ_param, int argc, const char** argv );
26   virtual int Deinit();
27   virtual int ProcessEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks, 
28                             AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr, 
29                             AliHLTUInt32_t& size, AliHLTUInt32_t& outputBlockCnt, 
30                             AliHLTComponent_BlockData*& outputBlocks,
31                             AliHLTComponent_EventDoneData*& edd ) = 0;
32
33   // Information member functions for registration.
34   virtual TComponentType GetComponentType() = 0; // Source, sink, or processor
35   virtual const char* GetComponentID() = 0;
36   virtual void GetInputDataTypes( vector<AliHLTComponent_DataType>& ) = 0;
37   virtual AliHLTComponent_DataType GetOutputDataType() = 0;
38   virtual void GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) = 0;
39
40   // Spawn function, return new class instance
41   virtual AliHLTComponent* Spawn() = 0;
42  
43   static int SetGlobalComponentHandler(AliHLTComponentHandler* pCH, int bOverwrite=0) {
44     int iResult=0;
45     if (fpComponentHandler==NULL || bOverwrite!=0)
46       fpComponentHandler=pCH;
47     else
48       iResult=-EPERM;
49     return iResult;
50   }
51   static int UnsetGlobalComponentHandler() {
52     return SetGlobalComponentHandler(NULL,1);
53   }
54  protected:
55
56   // Fill various structures with default values.
57   void FillBlockData( AliHLTComponent_BlockData& blockData ) {
58     blockData.fStructSize = sizeof(blockData);
59     FillShmData( blockData.fShmKey );
60     blockData.fOffset = ~(AliHLTUInt32_t)0;
61     blockData.fPtr = NULL;
62     blockData.fSize = 0;
63     FillDataType( blockData.fDataType );
64     blockData.fSpecification = ~(AliHLTUInt32_t)0;
65   }
66   void FillShmData( AliHLTComponent_ShmData& shmData ) {
67     shmData.fStructSize = sizeof(shmData);
68     shmData.fShmType = gkAliHLTComponent_InvalidShmType;
69     shmData.fShmID = gkAliHLTComponent_InvalidShmID;
70   }
71   void FillDataType( AliHLTComponent_DataType& dataType ) {
72     dataType.fStructSize = sizeof(dataType);
73     memset( dataType.fID, '*', 8 );
74     memset( dataType.fOrigin, '*', 4 );
75   }
76   
77   virtual int DoInit( int argc, const char** argv ){
78     return 0;
79   }
80
81   virtual int DoDeinit(){
82     return 0;
83   }
84
85   void* AllocMemory( unsigned long size ) {
86     if (fEnvironment.fAllocMemoryFunc)
87       return (*fEnvironment.fAllocMemoryFunc)(fEnvironment.fParam, size );
88     return NULL;
89   }
90
91   int MakeOutputDataBlockList( const vector<AliHLTComponent_BlockData>& blocks, AliHLTUInt32_t* blockCount,
92                                AliHLTComponent_BlockData** outputBlocks ) {
93     if (fEnvironment.fMakeOutputDataBlockListFunc)
94       return (*fEnvironment.fMakeOutputDataBlockListFunc)(fEnvironment.fParam, blocks, blockCount, outputBlocks );
95     return -ENOSYS;
96   }
97
98   int GetEventDoneData( unsigned long size, AliHLTComponent_EventDoneData** edd ) {
99     if (fEnvironment.fGetEventDoneDataFunc)
100       return (*fEnvironment.fGetEventDoneDataFunc)(fEnvironment.fParam, fCurrentEvent, size, edd );
101     return -ENOSYS;
102   }
103
104   int Logging( AliHLTComponent_LogSeverity severity, const char* origin, const char* keyword, const char* message, ... );
105
106  private:
107   static AliHLTComponentHandler* fpComponentHandler;
108   AliHLTComponentEnvironment fEnvironment;
109
110   AliHLTEventID_t fCurrentEvent; // Set by ProcessEvent before actual processing starts (e.g. before calling AliHLTProcessor::DoEvent)
111
112   ClassDef(AliHLTComponent, 0)
113 };
114 #endif