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