]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLT_C_Component_WrapperInterface.cxx
corrected CDB and run number initialization for usage from external interface, AliHLT...
[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 <errno.h>
34
35 static AliHLTComponentHandler *gComponentHandler_C = NULL;
36
37 int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv )
38 {
39   if ( gComponentHandler_C )
40     {
41       return EINPROGRESS;
42     }
43   gComponentHandler_C = new AliHLTComponentHandler(comenv);
44   if ( !gComponentHandler_C )
45     return EFAULT;
46   gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
47   gComponentHandler_C->AnnounceVersion();
48   return 0;
49 }
50
51 int AliHLT_C_Component_DeinitSystem()
52 {
53   if ( gComponentHandler_C )
54     {
55       delete gComponentHandler_C;
56       gComponentHandler_C = NULL;
57     }
58   return 0;
59 }
60
61 int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
62 {
63   if ( !gComponentHandler_C )
64     return ENXIO;
65   return gComponentHandler_C->LoadLibrary( libraryPath );
66 }
67
68 int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
69 {
70   if ( !gComponentHandler_C )
71     return ENXIO;
72   // Matthias 26.10.2007
73   // Unloading of libraries has to be re-worked. It has been commented out here
74   // since the libraries will be unloaded at the destruction of the component
75   // handler instance anyway. So it has no effect to the operation in PubSub.
76   // With the introduction of the dynamic component registration via module
77   // agents we run into trouble when cleaning up the samples managed by the
78   // component handler. Destruction of the sample objects is done AFTER
79   // unloading of the library and thus the destructor is not present any 
80   // more.
81   //return gComponentHandler_C->UnloadLibrary( libraryPath );
82   return 0;
83 }
84
85 int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
86 {
87   if ( !gComponentHandler_C )
88     return ENXIO;
89   if ( !handle ) return EINVAL;
90   AliHLTComponent* comp=NULL;
91   const char* cdbPath = getenv("ALIHLT_HCDBDIR");
92   if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
93   int ret = gComponentHandler_C->CreateComponent( componentType, environParam, argc, argv, comp, cdbPath);
94   *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
95
96   return ret;
97 }
98
99 void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
100 {
101   if ( !handle )
102     return;
103   
104   AliHLTComponent* pComp=reinterpret_cast<AliHLTComponent*>( handle );
105   pComp->Deinit();
106   delete pComp;
107 }
108
109 int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
110 {
111   if (!desc) return -EINVAL;
112   if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
113   if (!gComponentHandler_C) return ENXIO;
114
115   AliHLTRunDesc internalDesc=kAliHLTVoidRunDesc;
116   memcpy(&internalDesc, desc, desc->fStructSize<sizeof(internalDesc)?desc->fStructSize:sizeof(internalDesc));
117   return gComponentHandler_C->SetRunDescription(&internalDesc, runType);
118 }
119
120 int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks, 
121                            AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
122                            AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt, 
123                            AliHLTComponentBlockData** outputBlocks,
124                            AliHLTComponentEventDoneData** edd )
125 {
126   if ( !handle )
127     return ENXIO;
128   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
129   return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
130 }
131
132 int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
133 {
134   if ( !handle )
135     return ENXIO;
136   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
137   *dataType = comp->GetOutputDataType();
138   return 0;
139 }
140
141 int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
142 {
143   if ( !handle )
144     return ENXIO;
145   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
146   comp->GetOutputDataSize( *constBase, *inputMultiplier );
147   return 0;
148 }