3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* Timm Steinbeck <timm@kip.uni-heidelberg.de> *
9 //* for The ALICE HLT Project. *
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 //**************************************************************************
20 /** @file AliHLT_C_Component_WrapperInterface.cxx
21 @author Matthias Richter, Timm Steinbeck
23 @brief Pure C interface to the AliRoot HLT component handler
30 #include "AliHLT_C_Component_WrapperInterface.h"
31 #include "AliHLTComponentHandler.h"
32 #include "AliHLTComponent.h"
35 static AliHLTComponentHandler *gComponentHandler_C = NULL;
36 static AliHLTRunDesc gRunDesc=kAliHLTVoidRunDesc;
37 static char* gRunType=NULL;
39 int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv )
41 if ( gComponentHandler_C )
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.
53 AliHLTAnalysisEnvironment mappedEnv;
54 memset(&mappedEnv, 0, sizeof(mappedEnv));
55 mappedEnv.fStructSize=sizeof(mappedEnv);
57 mappedEnv.fParam = comenv->fParam;
58 mappedEnv.fAllocMemoryFunc = comenv->fAllocMemoryFunc;
59 mappedEnv.fGetEventDoneDataFunc= comenv->fGetEventDoneDataFunc;
60 mappedEnv.fLoggingFunc = comenv->fLoggingFunc;
63 gComponentHandler_C = new AliHLTComponentHandler(&mappedEnv);
64 if ( !gComponentHandler_C )
66 gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
67 gComponentHandler_C->AnnounceVersion();
71 int AliHLT_C_Component_DeinitSystem()
73 if ( gComponentHandler_C )
75 delete gComponentHandler_C;
76 gComponentHandler_C = NULL;
81 int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
83 if ( !gComponentHandler_C )
85 return gComponentHandler_C->LoadLibrary( libraryPath );
88 int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
90 if ( !gComponentHandler_C )
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
101 //return gComponentHandler_C->UnloadLibrary( libraryPath );
105 int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
107 if ( !gComponentHandler_C )
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);
120 *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
125 void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
130 AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
135 int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
137 if (!desc) return -EINVAL;
138 if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
139 if (!gComponentHandler_C) return ENXIO;
141 memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc));
142 gRunDesc.fStructSize=sizeof(gRunDesc);
143 if (gRunType) delete [] gRunType;
146 gRunType=new char[strlen(runType)+1];
147 if (gRunType) strcpy(gRunType, runType);
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 )
160 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
161 return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
164 int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
168 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
169 *dataType = comp->GetOutputDataType();
173 int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
177 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
178 comp->GetOutputDataSize( *constBase, *inputMultiplier );