--- /dev/null
+// $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> *
+ * 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 AliHLTHOMERLibManager.cxx
+ @author Matthias Richter
+ @date
+ @brief dynamic HLT HOMER reader/writer generation and destruction. */
+
+// see header file for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+
+#include <cerrno>
+#include <cassert>
+#include "AliHLTHOMERLibManager.h"
+#include "AliHLTHOMERReader.h"
+#include "AliHLTHOMERWriter.h"
+#include "TString.h"
+#include "TSystem.h"
+
+/** ROOT macro for the implementation of ROOT specific class methods */
+ClassImp(AliHLTHOMERLibManager)
+
+AliHLTHOMERLibManager::AliHLTHOMERLibManager()
+ :
+ fLibraryStatus(0),
+ fFctCreateReaderFromBuffer(NULL),
+ fFctDeleteReader(NULL),
+ fFctCreateWriter(NULL),
+ fFctDeleteWriter(NULL)
+{
+ // see header file for class documentation
+ // or
+ // refer to README to build package
+ // or
+ // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+}
+
+AliHLTHOMERLibManager::~AliHLTHOMERLibManager()
+{
+ // see header file for class documentation
+}
+
+AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReader(const AliHLTUInt8_t* pBuffer, int size)
+{
+ // see header file for class documentation
+ if (fLibraryStatus<0) return NULL;
+
+ if (fLibraryStatus==0) {
+ fLibraryStatus=LoadHOMERLibrary();
+ }
+
+ AliHLTHOMERReader* pReader=NULL;
+ if (fFctCreateReaderFromBuffer!=NULL && (pReader=(((AliHLTHOMERReaderCreateFromBuffer_t)fFctCreateReaderFromBuffer)(pBuffer, size)))==NULL) {
+ HLTError("can not create instance of HOMER reader (function %p)", fFctCreateReaderFromBuffer);
+ }
+
+ return pReader;
+}
+
+int AliHLTHOMERLibManager::DeleteReader(AliHLTHOMERReader* pReader)
+{
+ // see header file for class documentation
+ if (fLibraryStatus<0) return fLibraryStatus;
+
+ if (fLibraryStatus==0) {
+ fLibraryStatus=LoadHOMERLibrary();
+ }
+
+ if (fFctDeleteReader!=NULL) {
+ ((AliHLTHOMERReaderDelete_t)fFctDeleteReader)(pReader);
+ }
+
+ return 0;
+}
+
+AliHLTHOMERWriter* AliHLTHOMERLibManager::OpenWriter()
+{
+ // see header file for class documentation
+ if (fLibraryStatus<0) return NULL;
+
+ if (fLibraryStatus==0) {
+ fLibraryStatus=LoadHOMERLibrary();
+ }
+
+ AliHLTHOMERWriter* pWriter=NULL;
+// if (fFctCreateWriter!=NULL && (pWriter=(((AliHLTHOMERWriterCreate_t)fFctCreateWriter)()))==NULL) {
+// HLTError("can not create instance of HOMER writer (function %p)", fFctCreateWriter);
+// }
+
+ return pWriter;
+}
+
+int AliHLTHOMERLibManager::DeleteWriter(AliHLTHOMERWriter* pWriter)
+{
+ // see header file for class documentation
+ if (fLibraryStatus<0) return fLibraryStatus;
+
+ if (fLibraryStatus==0) {
+ fLibraryStatus=LoadHOMERLibrary();
+ }
+
+ if (fFctDeleteWriter!=NULL) {
+ ((AliHLTHOMERWriterDelete_t)fFctDeleteWriter)(pWriter);
+ }
+
+ return 0;
+}
+
+int AliHLTHOMERLibManager::LoadHOMERLibrary()
+{
+ // see header file for class documentation
+ int iResult=-EBADF;
+ const char* libraries[]={"libAliHLTHOMER.so", "libHOMER.so", NULL};
+ const char** library=&libraries[0];
+ do {
+ TString libs = gSystem->GetLibraries();
+ if (libs.Contains(*library) ||
+ (gSystem->Load(*library)) > 0) {
+ HLTDebug("%s (is) loaded", *library);
+ iResult=1;
+ break;
+ }
+ } while (*(++library)!=NULL);
+
+ if (iResult>0 && *library!=NULL) {
+ // print compile info
+ typedef void (*CompileInfo)( char*& date, char*& time);
+ CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(*library, "CompileInfo");
+ if (fctInfo) {
+ char* date="";
+ char* time="";
+ (*fctInfo)(date, time);
+ if (!date) date="unknown";
+ if (!time) time="unknown";
+ HLTInfo("%s build on %s (%s)", *library, date, time);
+ } else {
+ HLTInfo("no build info available for %s", *library);
+ }
+
+ fFctCreateReaderFromBuffer=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_CREATE_FROM_BUFFER);
+ fFctDeleteReader=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_DELETE);
+ fFctCreateWriter=gSystem->DynFindSymbol(*library, ALIHLTHOMERWRITER_CREATE);
+ fFctDeleteWriter=gSystem->DynFindSymbol(*library, ALIHLTHOMERWRITER_DELETE);
+ if (fFctCreateReaderFromBuffer==NULL || fFctDeleteReader==NULL ||
+ fFctCreateWriter==NULL || fFctDeleteWriter==NULL) {
+ iResult=-ENOSYS;
+ } else {
+ HLTDebug("%s: create fct %p, delete fct %p", *library, fFctCreateReaderFromBuffer, fFctDeleteReader);
+ }
+ }
+ if (iResult<0 || *library==NULL) {
+ fFctCreateReaderFromBuffer=NULL;
+ fFctDeleteReader=NULL;
+ fFctCreateWriter=NULL;
+ fFctDeleteWriter=NULL;
+ }
+
+ return iResult;
+}
--- /dev/null
+//-*- Mode: C++ -*-
+// @(#) $Id$
+
+#ifndef ALIHLTHOMERLIBMANAGER_H
+#define ALIHLTHOMERLIBMANAGER_H
+/* This file is property of and copyright by the ALICE HLT Project *
+ * ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice */
+
+/** @file AliHLTHOMERLibManager.h
+ @author Matthias Richter
+ @date
+ @brief dynamic HLT HOMER reader/writer generation and destruction
+
+// see below for class documentation
+// or
+// refer to README to build package
+// or
+// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
+ */
+
+#include "AliHLTLogging.h"
+
+class AliHLTHOMERReader;
+class AliHLTHOMERWriter;
+
+/**
+ * @class AliHLTHOMERLibManager
+ * Handler of HLTOUT data for buffer input.
+ */
+class AliHLTHOMERLibManager : public AliHLTLogging {
+ public:
+ /** standard constructor */
+ AliHLTHOMERLibManager();
+ /** destructor */
+ virtual ~AliHLTHOMERLibManager();
+
+ /**
+ * Open a HOMER reader.
+ * Load HOMER library dynamically and create object working on the provided
+ * buffer.
+ */
+ AliHLTHOMERReader* OpenReader(const AliHLTUInt8_t* pBuffer, int size);
+
+ /**
+ * Delete a HOMER reader.
+ * Clean-up of the object is done inside the HOMER library.
+ */
+ int DeleteReader(AliHLTHOMERReader* pReader);
+
+ /**
+ * Open a HOMER writer.
+ * Load HOMER library dynamically and create object working on the provided
+ * buffer.
+ */
+ AliHLTHOMERWriter* OpenWriter();
+
+ /**
+ * Delete a HOMER writer.
+ * Clean-up of the object is done inside the HOMER library.
+ */
+ int DeleteWriter(AliHLTHOMERWriter* pWriter);
+
+ protected:
+
+ private:
+ /** copy constructor prohibited */
+ AliHLTHOMERLibManager(const AliHLTHOMERLibManager&);
+ /** assignment operator prohibited */
+ AliHLTHOMERLibManager& operator=(const AliHLTHOMERLibManager&);
+
+ /**
+ * Load the HOMER library.
+ */
+ int LoadHOMERLibrary();
+
+ /** status of the loading of the HOMER library */
+ int fLibraryStatus; //!transient
+
+ /** entry in the HOMER library */
+ void* fFctCreateReaderFromBuffer; //!transient
+
+ /** entry in the HOMER library */
+ void* fFctDeleteReader; //!transient
+
+ /** entry in the HOMER library */
+ void* fFctCreateWriter; //!transient
+
+ /** entry in the HOMER library */
+ void* fFctDeleteWriter; //!transient
+
+ ClassDef(AliHLTHOMERLibManager, 0)
+};
+#endif