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 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
31 #include "AliHLT_C_Component_WrapperInterface.h"
32 #include "AliHLTComponentHandler.h"
33 #include "AliHLTComponent.h"
34 #include "AliHLTMisc.h"
37 static AliHLTComponentHandler *gComponentHandler_C = NULL;
38 static AliHLTRunDesc gRunDesc=kAliHLTVoidRunDesc;
39 static char* gRunType=NULL;
41 int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv )
43 // init the HLT system
44 if ( gComponentHandler_C )
50 // Due to a bug in the SimpleComponentWrapper and AliRootWrapperSubscriber
51 // the fStructSize member was never initialized and we can not use this
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.
56 AliHLTAnalysisEnvironment mappedEnv;
57 memset(&mappedEnv, 0, sizeof(mappedEnv));
58 mappedEnv.fStructSize=sizeof(mappedEnv);
60 mappedEnv.fParam = comenv->fParam;
61 mappedEnv.fAllocMemoryFunc = comenv->fAllocMemoryFunc;
62 mappedEnv.fGetEventDoneDataFunc= comenv->fGetEventDoneDataFunc;
63 mappedEnv.fLoggingFunc = comenv->fLoggingFunc;
66 gComponentHandler_C = new AliHLTComponentHandler(&mappedEnv);
67 if ( !gComponentHandler_C )
69 gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
70 gComponentHandler_C->AnnounceVersion();
74 int AliHLT_C_Component_DeinitSystem()
76 // De-init the HLT system and clean-up internal memory
77 if ( gComponentHandler_C )
79 delete gComponentHandler_C;
80 gComponentHandler_C = NULL;
85 int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
87 // load a component library
88 if ( !gComponentHandler_C )
90 return gComponentHandler_C->LoadLibrary( libraryPath );
93 int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
95 // unload a component library
96 if ( !gComponentHandler_C )
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
107 //return gComponentHandler_C->UnloadLibrary( libraryPath );
111 int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
113 // create a component
114 if ( !gComponentHandler_C )
116 if ( !handle ) return EINVAL;
117 AliHLTComponent* comp=NULL;
118 const char* cdbPath = getenv("ALIHLT_HCDBDIR");
119 if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
120 int ret = gComponentHandler_C->CreateComponent( componentType, comp);
121 if (ret>=0 && comp) {
122 AliHLTMisc::Instance().InitCDB(cdbPath);
123 AliHLTMisc::Instance().SetCDBRunNo(gRunDesc.fRunNo);
124 comp->SetRunDescription(&gRunDesc, gRunType);
125 const AliHLTAnalysisEnvironment* comenv=gComponentHandler_C->GetEnvironment();
126 ret=comp->Init(comenv, environParam, argc, argv);
128 *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
133 void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
135 // destroy a component
139 AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
144 int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
146 // set run description
147 if (!desc) return -EINVAL;
148 if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
149 if (!gComponentHandler_C) return ENXIO;
151 memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc));
152 gRunDesc.fStructSize=sizeof(gRunDesc);
153 if (gRunType) delete [] gRunType;
156 gRunType=new char[strlen(runType)+1];
157 if (gRunType) strcpy(gRunType, runType);
162 int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks,
163 AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
164 AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt,
165 AliHLTComponentBlockData** outputBlocks,
166 AliHLTComponentEventDoneData** edd )
171 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
172 return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
175 int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
177 // get output data type of a component
180 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
181 *dataType = comp->GetOutputDataType();
185 int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
187 // get output data size of a component
190 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
191 comp->GetOutputDataSize( *constBase, *inputMultiplier );