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