]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLT_C_Component_WrapperInterface.cxx
From Svein Lindal:
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLT_C_Component_WrapperInterface.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   AliHLT_C_Component_WrapperInterface.cxx
21     @author Matthias Richter, Timm Steinbeck
22     @date   
23     @brief  Pure C interface to the AliRoot HLT component handler
24 */
25
26 #if __GNUC__>= 3
27 using namespace std;
28 #endif
29
30 #include "AliHLT_C_Component_WrapperInterface.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTComponent.h"
33 #include <errno.h>
34
35 static AliHLTComponentHandler *gComponentHandler_C = NULL;
36 static AliHLTRunDesc gRunDesc=kAliHLTVoidRunDesc;
37 static char* gRunType=NULL;
38
39 int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv )
40 {
41   if ( gComponentHandler_C )
42     {
43       return EINPROGRESS;
44     }
45
46   // July 2008  
47   // Due to a bug in the SimpleComponentWrapper and AliRootWrapperSubscriber
48   // the fStructSize member was never initialized and we can not use this
49   // method of synchronizing different versions.
50   // This interface is now deprecated, only kept for backward compatibility.
51   // All function pointers are explicitely mapped to the new structure.
52
53   AliHLTAnalysisEnvironment mappedEnv;
54   memset(&mappedEnv, 0, sizeof(mappedEnv));
55   mappedEnv.fStructSize=sizeof(mappedEnv);
56   if (comenv) {
57     mappedEnv.fParam               = comenv->fParam;
58     mappedEnv.fAllocMemoryFunc     = comenv->fAllocMemoryFunc;
59     mappedEnv.fGetEventDoneDataFunc= comenv->fGetEventDoneDataFunc;
60     mappedEnv.fLoggingFunc         = comenv->fLoggingFunc;
61   }
62
63   gComponentHandler_C = new AliHLTComponentHandler(&mappedEnv);
64   if ( !gComponentHandler_C )
65     return EFAULT;
66   gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
67   gComponentHandler_C->AnnounceVersion();
68   return 0;
69 }
70
71 int AliHLT_C_Component_DeinitSystem()
72 {
73   if ( gComponentHandler_C )
74     {
75       delete gComponentHandler_C;
76       gComponentHandler_C = NULL;
77     }
78   return 0;
79 }
80
81 int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
82 {
83   if ( !gComponentHandler_C )
84     return ENXIO;
85   return gComponentHandler_C->LoadLibrary( libraryPath );
86 }
87
88 int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
89 {
90   if ( !gComponentHandler_C )
91     return ENXIO;
92   // Matthias 26.10.2007
93   // Unloading of libraries has to be re-worked. It has been commented out here
94   // since the libraries will be unloaded at the destruction of the component
95   // handler instance anyway. So it has no effect to the operation in PubSub.
96   // With the introduction of the dynamic component registration via module
97   // agents we run into trouble when cleaning up the samples managed by the
98   // component handler. Destruction of the sample objects is done AFTER
99   // unloading of the library and thus the destructor is not present any 
100   // more.
101   //return gComponentHandler_C->UnloadLibrary( libraryPath );
102   return 0;
103 }
104
105 int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
106 {
107   if ( !gComponentHandler_C )
108     return ENXIO;
109   if ( !handle ) return EINVAL;
110   AliHLTComponent* comp=NULL;
111   const char* cdbPath = getenv("ALIHLT_HCDBDIR");
112   if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
113   int ret = gComponentHandler_C->CreateComponent( componentType, comp);
114   if (ret>=0 && comp) {
115     comp->InitCDB(cdbPath, gComponentHandler_C);
116     comp->SetRunDescription(&gRunDesc, gRunType);
117     const AliHLTAnalysisEnvironment* comenv=gComponentHandler_C->GetEnvironment();
118     ret=comp->Init(comenv, environParam, argc, argv);
119   }
120   *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
121
122   return ret;
123 }
124
125 void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
126 {
127   if ( !handle )
128     return;
129   
130   AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
131   pComp->Deinit();
132   delete pComp;
133 }
134
135 int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
136 {
137   if (!desc) return -EINVAL;
138   if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
139   if (!gComponentHandler_C) return ENXIO;
140
141   memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc));
142   gRunDesc.fStructSize=sizeof(gRunDesc);
143   if (gRunType) delete [] gRunType;
144   gRunType=NULL;
145   if (runType) {
146     gRunType=new char[strlen(runType)+1];
147     if (gRunType) strcpy(gRunType, runType);
148   }
149   return 0;
150 }
151
152 int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks, 
153                            AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
154                            AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt, 
155                            AliHLTComponentBlockData** outputBlocks,
156                            AliHLTComponentEventDoneData** edd )
157 {
158   if ( !handle )
159     return ENXIO;
160   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
161   return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
162 }
163
164 int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
165 {
166   if ( !handle )
167     return ENXIO;
168   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
169   *dataType = comp->GetOutputDataType();
170   return 0;
171 }
172
173 int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
174 {
175   if ( !handle )
176     return ENXIO;
177   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
178   comp->GetOutputDataSize( *constBase, *inputMultiplier );
179   return 0;
180 }