]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLT_C_Component_WrapperInterface.cxx
ALIROOT-5433 Transition to CDHv3 in HLT
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLT_C_Component_WrapperInterface.cxx
CommitLineData
f23a6e1a 1// $Id$
2
a3c9b745 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//**************************************************************************
f23a6e1a 19
f27cf33a 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
f23a6e1a 26
f23a6e1a 27#include "AliHLT_C_Component_WrapperInterface.h"
28#include "AliHLTComponentHandler.h"
29#include "AliHLTComponent.h"
cc484ed9 30#include "AliHLTMisc.h"
f23a6e1a 31#include <errno.h>
32
c515df4c 33using namespace std;
34
f23a6e1a 35static AliHLTComponentHandler *gComponentHandler_C = NULL;
9a0ef890 36static AliHLTRunDesc gRunDesc=kAliHLTVoidRunDesc;
37static char* gRunType=NULL;
f23a6e1a 38
f7561f8d 39int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv )
f23a6e1a 40{
f27cf33a 41 // init the HLT system
f23a6e1a 42 if ( gComponentHandler_C )
43 {
44 return EINPROGRESS;
45 }
9a0ef890 46
a3c9b745 47 // July 2008
3ff6ace7 48 // Due to a bug in the SimpleComponentWrapper and AliRootWrapperSubscriber
49 // the fStructSize member was never initialized and we can not use this
a3c9b745 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 AliHLTAnalysisEnvironment mappedEnv;
55 memset(&mappedEnv, 0, sizeof(mappedEnv));
56 mappedEnv.fStructSize=sizeof(mappedEnv);
57 if (comenv) {
58 mappedEnv.fParam = comenv->fParam;
59 mappedEnv.fAllocMemoryFunc = comenv->fAllocMemoryFunc;
60 mappedEnv.fGetEventDoneDataFunc= comenv->fGetEventDoneDataFunc;
61 mappedEnv.fLoggingFunc = comenv->fLoggingFunc;
62 }
63
64 gComponentHandler_C = new AliHLTComponentHandler(&mappedEnv);
f23a6e1a 65 if ( !gComponentHandler_C )
66 return EFAULT;
a742f6f8 67 gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
fa760045 68 gComponentHandler_C->AnnounceVersion();
f23a6e1a 69 return 0;
70}
71
72int AliHLT_C_Component_DeinitSystem()
73{
f27cf33a 74 // De-init the HLT system and clean-up internal memory
f23a6e1a 75 if ( gComponentHandler_C )
76 {
77 delete gComponentHandler_C;
78 gComponentHandler_C = NULL;
79 }
80 return 0;
81}
82
83int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
84{
f27cf33a 85 // load a component library
f23a6e1a 86 if ( !gComponentHandler_C )
87 return ENXIO;
88 return gComponentHandler_C->LoadLibrary( libraryPath );
89}
90
d76bc02a 91int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
f23a6e1a 92{
f27cf33a 93 // unload a component library
f23a6e1a 94 if ( !gComponentHandler_C )
95 return ENXIO;
cbd84228 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 return 0;
f23a6e1a 107}
108
f7561f8d 109int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
f23a6e1a 110{
f27cf33a 111 // create a component
f23a6e1a 112 if ( !gComponentHandler_C )
113 return ENXIO;
3294f81a 114 if ( !handle ) return EINVAL;
b2065764 115 AliHLTComponent* comp=NULL;
116 const char* cdbPath = getenv("ALIHLT_HCDBDIR");
117 if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
f323c990 118 int ret = gComponentHandler_C->CreateComponent( componentType, comp);
9a0ef890 119 if (ret>=0 && comp) {
cc484ed9 120 AliHLTMisc::Instance().InitCDB(cdbPath);
121 AliHLTMisc::Instance().SetCDBRunNo(gRunDesc.fRunNo);
9a0ef890 122 comp->SetRunDescription(&gRunDesc, gRunType);
a3c9b745 123 const AliHLTAnalysisEnvironment* comenv=gComponentHandler_C->GetEnvironment();
9a0ef890 124 ret=comp->Init(comenv, environParam, argc, argv);
125 }
f23a6e1a 126 *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
3294f81a 127
f23a6e1a 128 return ret;
129}
130
131void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
132{
f27cf33a 133 // destroy a component
f23a6e1a 134 if ( !handle )
135 return;
3cde846d 136
137 AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
138 pComp->Deinit();
139 delete pComp;
f23a6e1a 140}
141
45c0a780 142int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
143{
f27cf33a 144 // set run description
45c0a780 145 if (!desc) return -EINVAL;
146 if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
147 if (!gComponentHandler_C) return ENXIO;
148
9a0ef890 149 memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc));
150 gRunDesc.fStructSize=sizeof(gRunDesc);
151 if (gRunType) delete [] gRunType;
152 gRunType=NULL;
153 if (runType) {
154 gRunType=new char[strlen(runType)+1];
155 if (gRunType) strcpy(gRunType, runType);
156 }
157 return 0;
45c0a780 158}
159
f7561f8d 160int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks,
161 AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
f23a6e1a 162 AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt,
f7561f8d 163 AliHLTComponentBlockData** outputBlocks,
164 AliHLTComponentEventDoneData** edd )
f23a6e1a 165{
f27cf33a 166 // process one event
f23a6e1a 167 if ( !handle )
168 return ENXIO;
169 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
71d7c760 170 return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
171}
172
f7561f8d 173int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
71d7c760 174{
f27cf33a 175 // get output data type of a component
71d7c760 176 if ( !handle )
177 return ENXIO;
178 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
179 *dataType = comp->GetOutputDataType();
180 return 0;
181}
182
183int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
184{
f27cf33a 185 // get output data size of a component
71d7c760 186 if ( !handle )
187 return ENXIO;
188 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
189 comp->GetOutputDataSize( *constBase, *inputMultiplier );
190 return 0;
f23a6e1a 191}