]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/BASE/AliHLT_C_Component_WrapperInterface.cxx
ALIROOT-5600 - skip non-participating detector modules
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLT_C_Component_WrapperInterface.cxx
index 9f009c1285cea486edf8ce67e8391d86e4501059..628ac56a40b5235671daa0bd7da4f35c3152531a 100644 (file)
@@ -1,47 +1,67 @@
 // $Id$
 
-/**************************************************************************
- * This file is property of and copyright by the ALICE HLT Project        * 
- * ALICE Experiment at CERN, All rights reserved.                         *
- *                                                                        *
- * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
- *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
- *                  for The ALICE HLT Project.                            *
- *                                                                        *
- * Permission to use, copy, modify and distribute this software and its   *
- * documentation strictly for non-commercial purposes is hereby granted   *
- * without fee, provided that the above copyright notice appears in all   *
- * copies and that both the copyright notice and this permission notice   *
- * appear in the supporting documentation. The authors make no claims     *
- * about the suitability of this software for any purpose. It is          *
- * provided "as is" without express or implied warranty.                  *
- **************************************************************************/
-
-/** @file   AliHLT_C_Component_WrapperInterface.cxx
-    @author Matthias Richter, Timm Steinbeck
-    @date   
-    @brief  Pure C interface to the AliRoot HLT component handler
-*/
-
-#if __GNUC__>= 3
-using namespace std;
-#endif
+//**************************************************************************
+//* This file is property of and copyright by the ALICE HLT Project        * 
+//* ALICE Experiment at CERN, All rights reserved.                         *
+//*                                                                        *
+//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
+//*                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
+//*                  for The ALICE HLT Project.                            *
+//*                                                                        *
+//* Permission to use, copy, modify and distribute this software and its   *
+//* documentation strictly for non-commercial purposes is hereby granted   *
+//* without fee, provided that the above copyright notice appears in all   *
+//* copies and that both the copyright notice and this permission notice   *
+//* appear in the supporting documentation. The authors make no claims     *
+//* about the suitability of this software for any purpose. It is          *
+//* provided "as is" without express or implied warranty.                  *
+//**************************************************************************
+
+//  @file   AliHLT_C_Component_WrapperInterface.cxx
+//  @author Matthias Richter, Timm Steinbeck
+//  @date   
+//  @brief  Old C interface to the AliRoot HLT component handler
+//  @note   This interface is deprecated, the new interface is defined
+//          in HLT/BASE/AliHLTExternalInterface
 
 #include "AliHLT_C_Component_WrapperInterface.h"
 #include "AliHLTComponentHandler.h"
 #include "AliHLTComponent.h"
+#include "AliHLTMisc.h"
 #include <errno.h>
 
-static AliHLTComponentHandler *gComponentHandler_C = NULL;
+using namespace std;
 
+static AliHLTComponentHandler *gComponentHandler_C = NULL;
+static AliHLTRunDesc gRunDesc=kAliHLTVoidRunDesc;
+static char* gRunType=NULL;
 
-int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* environ )
+int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* comenv )
 {
+  // init the HLT system
   if ( gComponentHandler_C )
     {
       return EINPROGRESS;
     }
-  gComponentHandler_C = new AliHLTComponentHandler(environ);
+
+  // July 2008  
+  // Due to a bug in the SimpleComponentWrapper and AliRootWrapperSubscriber
+  // the fStructSize member was never initialized and we can not use this
+  // method of synchronizing different versions.
+  // This interface is now deprecated, only kept for backward compatibility.
+  // All function pointers are explicitely mapped to the new structure.
+
+  AliHLTAnalysisEnvironment mappedEnv;
+  memset(&mappedEnv, 0, sizeof(mappedEnv));
+  mappedEnv.fStructSize=sizeof(mappedEnv);
+  if (comenv) {
+    mappedEnv.fParam               = comenv->fParam;
+    mappedEnv.fAllocMemoryFunc     = comenv->fAllocMemoryFunc;
+    mappedEnv.fGetEventDoneDataFunc= comenv->fGetEventDoneDataFunc;
+    mappedEnv.fLoggingFunc         = comenv->fLoggingFunc;
+  }
+
+  gComponentHandler_C = new AliHLTComponentHandler(&mappedEnv);
   if ( !gComponentHandler_C )
     return EFAULT;
   gComponentHandler_C->InitAliLogTrap(gComponentHandler_C);
@@ -51,6 +71,7 @@ int AliHLT_C_Component_InitSystem( AliHLTComponentEnvironment* environ )
 
 int AliHLT_C_Component_DeinitSystem()
 {
+  // De-init the HLT system and clean-up internal memory
   if ( gComponentHandler_C )
     {
       delete gComponentHandler_C;
@@ -61,6 +82,7 @@ int AliHLT_C_Component_DeinitSystem()
 
 int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
 {
+  // load a component library
   if ( !gComponentHandler_C )
     return ENXIO;
   return gComponentHandler_C->LoadLibrary( libraryPath );
@@ -68,6 +90,7 @@ int AliHLT_C_Component_LoadLibrary( const char* libraryPath )
 
 int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
 {
+  // unload a component library
   if ( !gComponentHandler_C )
     return ENXIO;
   // Matthias 26.10.2007
@@ -83,17 +106,22 @@ int AliHLT_C_Component_UnloadLibrary( const char* /*libraryPath*/ )
   return 0;
 }
 
-int AliHLT_C_CreateComponent( const char* componentType, void* environ_param, int argc, const char** argv, AliHLTComponentHandle* handle )
+int AliHLT_C_CreateComponent( const char* componentType, void* environParam, int argc, const char** argv, AliHLTComponentHandle* handle )
 {
+  // create a component
   if ( !gComponentHandler_C )
     return ENXIO;
   if ( !handle ) return EINVAL;
-  AliHLTComponent* comp;
-  int ret = gComponentHandler_C->CreateComponent( componentType, environ_param, argc, argv, comp );
-  if (comp) {
-    const char* cdbPath = getenv("ALIHLT_HCDBDIR");
-    if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
-    if (cdbPath) comp->InitCDB(cdbPath, gComponentHandler_C);
+  AliHLTComponent* comp=NULL;
+  const char* cdbPath = getenv("ALIHLT_HCDBDIR");
+  if (!cdbPath) cdbPath = getenv("ALICE_ROOT");
+  int ret = gComponentHandler_C->CreateComponent( componentType, comp);
+  if (ret>=0 && comp) {
+    AliHLTMisc::Instance().InitCDB(cdbPath);
+    AliHLTMisc::Instance().SetCDBRunNo(gRunDesc.fRunNo);
+    comp->SetRunDescription(&gRunDesc, gRunType);
+    const AliHLTAnalysisEnvironment* comenv=gComponentHandler_C->GetEnvironment();
+    ret=comp->Init(comenv, environParam, argc, argv);
   }
   *handle = reinterpret_cast<AliHLTComponentHandle>( comp );
 
@@ -102,6 +130,7 @@ int AliHLT_C_CreateComponent( const char* componentType, void* environ_param, in
 
 void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
 {
+  // destroy a component
   if ( !handle )
     return;
   
@@ -110,20 +139,40 @@ void AliHLT_C_DestroyComponent( AliHLTComponentHandle handle )
   delete pComp;
 }
 
-int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponent_EventData* evtData, const AliHLTComponent_BlockData* blocks, 
-                           AliHLTComponent_TriggerData* trigData, AliHLTUInt8_t* outputPtr,
+int AliHLT_C_SetRunDescription(const AliHLTRunDesc* desc, const char* runType)
+{
+  // set run description
+  if (!desc) return -EINVAL;
+  if (desc->fStructSize<sizeof(AliHLTUInt32_t)) return -EINVAL;
+  if (!gComponentHandler_C) return ENXIO;
+
+  memcpy(&gRunDesc, desc, desc->fStructSize<sizeof(gRunDesc)?desc->fStructSize:sizeof(gRunDesc));
+  gRunDesc.fStructSize=sizeof(gRunDesc);
+  if (gRunType) delete [] gRunType;
+  gRunType=NULL;
+  if (runType) {
+    gRunType=new char[strlen(runType)+1];
+    if (gRunType) strcpy(gRunType, runType);
+  }
+  return 0;
+}
+
+int AliHLT_C_ProcessEvent( AliHLTComponentHandle handle, const AliHLTComponentEventData* evtData, const AliHLTComponentBlockData* blocks, 
+                           AliHLTComponentTriggerData* trigData, AliHLTUInt8_t* outputPtr,
                            AliHLTUInt32_t* size, AliHLTUInt32_t* outputBlockCnt, 
-                           AliHLTComponent_BlockData** outputBlocks,
-                           AliHLTComponent_EventDoneData** edd )
+                           AliHLTComponentBlockData** outputBlocks,
+                           AliHLTComponentEventDoneData** edd )
 {
+  // process one event
   if ( !handle )
     return ENXIO;
   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
   return comp->ProcessEvent( *evtData, blocks, *trigData, outputPtr, *size, *outputBlockCnt, *outputBlocks, *edd );
 }
 
-int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponent_DataType* dataType )
+int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponentDataType* dataType )
 {
+  // get output data type of a component
   if ( !handle )
     return ENXIO;
   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );
@@ -133,6 +182,7 @@ int AliHLT_C_GetOutputDataType( AliHLTComponentHandle handle, AliHLTComponent_Da
 
 int AliHLT_C_GetOutputSize( AliHLTComponentHandle handle, unsigned long* constBase, double* inputMultiplier )
 {
+  // get output data size of a component
   if ( !handle )
     return ENXIO;
   AliHLTComponent* comp = reinterpret_cast<AliHLTComponent*>( handle );