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