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 )
46 AliHLTComponentEnvironment internalEnv;
47 memset(&internalEnv, 0, sizeof(internalEnv));
49 memcpy(&internalEnv, comenv, sizeof(internalEnv)<comenv->fStructSize?sizeof(internalEnv):comenv->fStructSize);
51 internalEnv.fStructSize=sizeof(internalEnv);
53 // Due to a bug in the SimpleComponentWrapper and AliRootWrapperSubscriber
54 // the fStructSize member was never initialized and we can not use this
55 // method of synchronizing different versions
56 //gComponentHandler_C = new AliHLTComponentHandler(&internalEnv);
57 gComponentHandler_C = new AliHLTComponentHandler(comenv);
58 if ( !gComponentHandler_C )
60 gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
61 gComponentHandler_C->AnnounceVersion();
65 int AliHLT_C_Component_DeinitSystem()
67 if ( gComponentHandler_C )
69 delete gComponentHandler_C;
70 gComponentHandler_C = NULL;
75 int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
77 if ( !gComponentHandler_C )
79 return gComponentHandler_C->LoadLibrary( libraryPath );
82 int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
84 if ( !gComponentHandler_C )
86 // Matthias 26.10.2007
87 // Unloading of libraries has to be re-worked. It has been commented out here
88 // since the libraries will be unloaded at the destruction of the component
89 // handler instance anyway. So it has no effect to the operation in PubSub.
90 // With the introduction of the dynamic component registration via module
91 // agents we run into trouble when cleaning up the samples managed by the
92 // component handler. Destruction of the sample objects is done AFTER
93 // unloading of the library and thus the destructor is not present any
95 //return gComponentHandler_C->UnloadLibrary( libraryPath );
99 int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
101 if ( !gComponentHandler_C )
103 if ( !handle ) return EINVAL;
104 AliHLTComponent* comp=NULL;
105 const char* cdbPath = getenv("ALIHLT_HCDBDIR");
106 if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
107 int ret = gComponentHandler_C->CreateComponent( componentType, environParam, argc, argv, comp);
108 if (ret>=0 && comp) {
109 comp->InitCDB(cdbPath, gComponentHandler_C);
110 comp->SetRunDescription(&gRunDesc, gRunType);
111 const AliHLTComponentEnvironment* comenv=gComponentHandler_C->GetEnvironment();
112 ret=comp->Init(comenv, environParam, argc, argv);
114 *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
119 void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
124 AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
129 int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
131 if (!desc) return -EINVAL;
132 if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
133 if (!gComponentHandler_C) return ENXIO;
135 memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc));
136 gRunDesc.fStructSize=sizeof(gRunDesc);
137 if (gRunType) delete [] gRunType;
140 gRunType=new char[strlen(runType)+1];
141 if (gRunType) strcpy(gRunType, runType);
146 int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks,
147 AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
148 AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt,
149 AliHLTComponentBlockData** outputBlocks,
150 AliHLTComponentEventDoneData** edd )
154 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
155 return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
158 int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
162 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
163 *dataType = comp->GetOutputDataType();
167 int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
171 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
172 comp->GetOutputDataSize( *constBase, *inputMultiplier );