]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLT_C_Component_WrapperInterface.cxx
handling of steering events
[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
b22e91eb 20/** @file AliHLT_C_Component_WrapperInterface.cxx
21 @author Matthias Richter, Timm Steinbeck
22 @date
23 @brief Pure C interface to the AliRoot HLT component handler
24*/
f23a6e1a 25
0c0c9d99 26#if __GNUC__>= 3
f23a6e1a 27using namespace std;
28#endif
29
30#include "AliHLT_C_Component_WrapperInterface.h"
31#include "AliHLTComponentHandler.h"
32#include "AliHLTComponent.h"
33#include <errno.h>
34
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{
41 if ( gComponentHandler_C )
42 {
43 return EINPROGRESS;
44 }
9a0ef890 45
a3c9b745 46 // July 2008
3ff6ace7 47 // Due to a bug in the SimpleComponentWrapper and AliRootWrapperSubscriber
48 // the fStructSize member was never initialized and we can not use this
a3c9b745 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.
52
53 AliHLTAnalysisEnvironment mappedEnv;
54 memset(&mappedEnv, 0, sizeof(mappedEnv));
55 mappedEnv.fStructSize=sizeof(mappedEnv);
56 if (comenv) {
57 mappedEnv.fParam = comenv->fParam;
58 mappedEnv.fAllocMemoryFunc = comenv->fAllocMemoryFunc;
59 mappedEnv.fGetEventDoneDataFunc= comenv->fGetEventDoneDataFunc;
60 mappedEnv.fLoggingFunc = comenv->fLoggingFunc;
61 }
62
63 gComponentHandler_C = new AliHLTComponentHandler(&mappedEnv);
f23a6e1a 64 if ( !gComponentHandler_C )
65 return EFAULT;
a742f6f8 66 gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
fa760045 67 gComponentHandler_C->AnnounceVersion();
f23a6e1a 68 return 0;
69}
70
71int AliHLT_C_Component_DeinitSystem()
72{
73 if ( gComponentHandler_C )
74 {
75 delete gComponentHandler_C;
76 gComponentHandler_C = NULL;
77 }
78 return 0;
79}
80
81int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
82{
83 if ( !gComponentHandler_C )
84 return ENXIO;
85 return gComponentHandler_C->LoadLibrary( libraryPath );
86}
87
d76bc02a 88int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
f23a6e1a 89{
90 if ( !gComponentHandler_C )
91 return ENXIO;
cbd84228 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
100 // more.
101 //return gComponentHandler_C->UnloadLibrary( libraryPath );
102 return 0;
f23a6e1a 103}
104
f7561f8d 105int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
f23a6e1a 106{
107 if ( !gComponentHandler_C )
108 return ENXIO;
3294f81a 109 if ( !handle ) return EINVAL;
b2065764 110 AliHLTComponent* comp=NULL;
111 const char* cdbPath = getenv("ALIHLT_HCDBDIR");
112 if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
f323c990 113 int ret = gComponentHandler_C->CreateComponent( componentType, comp);
9a0ef890 114 if (ret>=0 && comp) {
115 comp->InitCDB(cdbPath, gComponentHandler_C);
116 comp->SetRunDescription(&gRunDesc, gRunType);
a3c9b745 117 const AliHLTAnalysisEnvironment* comenv=gComponentHandler_C->GetEnvironment();
9a0ef890 118 ret=comp->Init(comenv, environParam, argc, argv);
119 }
f23a6e1a 120 *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
3294f81a 121
f23a6e1a 122 return ret;
123}
124
125void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
126{
127 if ( !handle )
128 return;
3cde846d 129
130 AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
131 pComp->Deinit();
132 delete pComp;
f23a6e1a 133}
134
45c0a780 135int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
136{
137 if (!desc) return -EINVAL;
138 if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
139 if (!gComponentHandler_C) return ENXIO;
140
9a0ef890 141 memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc));
142 gRunDesc.fStructSize=sizeof(gRunDesc);
143 if (gRunType) delete [] gRunType;
144 gRunType=NULL;
145 if (runType) {
146 gRunType=new char[strlen(runType)+1];
147 if (gRunType) strcpy(gRunType, runType);
148 }
149 return 0;
45c0a780 150}
151
f7561f8d 152int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks,
153 AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
f23a6e1a 154 AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt,
f7561f8d 155 AliHLTComponentBlockData** outputBlocks,
156 AliHLTComponentEventDoneData** edd )
f23a6e1a 157{
158 if ( !handle )
159 return ENXIO;
160 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
71d7c760 161 return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
162}
163
f7561f8d 164int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
71d7c760 165{
166 if ( !handle )
167 return ENXIO;
168 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
169 *dataType = comp->GetOutputDataType();
170 return 0;
171}
172
173int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
174{
175 if ( !handle )
176 return ENXIO;
177 AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
178 comp->GetOutputDataSize( *constBase, *inputMultiplier );
179 return 0;
f23a6e1a 180}