3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTHOMERLibManager.cxx
20 @author Matthias Richter
22 @brief dynamic HLT HOMER reader/writer generation and destruction. */
24 // see header file for class documentation
26 // refer to README to build package
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
32 #include "AliHLTHOMERLibManager.h"
33 #include "AliHLTHOMERReader.h"
34 #include "AliHLTHOMERWriter.h"
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTHOMERLibManager)
41 AliHLTHOMERLibManager::AliHLTHOMERLibManager()
44 fFctCreateReaderFromTCPPort(NULL),
45 fFctCreateReaderFromTCPPorts(NULL),
46 fFctCreateReaderFromBuffer(NULL),
47 fFctDeleteReader(NULL),
48 fFctCreateWriter(NULL),
49 fFctDeleteWriter(NULL)
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58 AliHLTHOMERLibManager::~AliHLTHOMERLibManager()
60 // see header file for class documentation
63 AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReader(const char* hostname, unsigned short port )
65 // see header file for class documentation
66 if (fLibraryStatus<0) return NULL;
68 if (fLibraryStatus==0) {
69 fLibraryStatus=LoadHOMERLibrary();
72 AliHLTHOMERReader* pReader=NULL;
73 if (fFctCreateReaderFromTCPPort!=NULL && (pReader=(((AliHLTHOMERReaderCreateFromTCPPort_t)fFctCreateReaderFromTCPPort)(hostname, port)))==NULL) {
74 //HLTError("can not create instance of HOMER reader (function %p)", fFctCreateReaderFromTCPPort);
80 AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReader(unsigned int tcpCnt, const char** hostnames, unsigned short* ports)
82 // see header file for class documentation
83 if (fLibraryStatus<0) return NULL;
85 if (fLibraryStatus==0) {
86 fLibraryStatus=LoadHOMERLibrary();
89 AliHLTHOMERReader* pReader=NULL;
90 if (fFctCreateReaderFromTCPPorts!=NULL && (pReader=(((AliHLTHOMERReaderCreateFromTCPPorts_t)fFctCreateReaderFromTCPPorts)(tcpCnt, hostnames, ports)))==NULL) {
91 //HLTError("can not create instance of HOMER reader (function %p)", fFctCreateReaderFromTCPPorts);
97 AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReaderBuffer(const AliHLTUInt8_t* pBuffer, int size)
99 // see header file for class documentation
100 if (fLibraryStatus<0) return NULL;
102 if (fLibraryStatus==0) {
103 fLibraryStatus=LoadHOMERLibrary();
106 AliHLTHOMERReader* pReader=NULL;
107 if (fFctCreateReaderFromBuffer!=NULL && (pReader=(((AliHLTHOMERReaderCreateFromBuffer_t)fFctCreateReaderFromBuffer)(pBuffer, size)))==NULL) {
108 //HLTError("can not create instance of HOMER reader (function %p)", fFctCreateReaderFromBuffer);
114 int AliHLTHOMERLibManager::DeleteReader(AliHLTHOMERReader* pReader)
116 // see header file for class documentation
117 if (fLibraryStatus<0) return fLibraryStatus;
119 if (fLibraryStatus==0) {
120 fLibraryStatus=LoadHOMERLibrary();
123 if (fFctDeleteReader!=NULL) {
124 ((AliHLTHOMERReaderDelete_t)fFctDeleteReader)(pReader);
130 AliHLTHOMERWriter* AliHLTHOMERLibManager::OpenWriter()
132 // see header file for class documentation
133 if (fLibraryStatus<0) return NULL;
135 if (fLibraryStatus==0) {
136 fLibraryStatus=LoadHOMERLibrary();
139 AliHLTHOMERWriter* pWriter=NULL;
140 if (fFctCreateWriter!=NULL && (pWriter=(((AliHLTHOMERWriterCreate_t)fFctCreateWriter)()))==NULL) {
141 // HLTError("can not create instance of HOMER writer (function %p)", fFctCreateWriter);
147 int AliHLTHOMERLibManager::DeleteWriter(AliHLTHOMERWriter* pWriter)
149 // see header file for class documentation
150 if (fLibraryStatus<0) return fLibraryStatus;
152 if (fLibraryStatus==0) {
153 fLibraryStatus=LoadHOMERLibrary();
156 if (fFctDeleteWriter!=NULL) {
157 ((AliHLTHOMERWriterDelete_t)fFctDeleteWriter)(pWriter);
163 int AliHLTHOMERLibManager::LoadHOMERLibrary()
165 // see header file for class documentation
167 const char* libraries[]={"libAliHLTHOMER.so", "libHOMER.so", NULL};
168 const char** library=&libraries[0];
170 TString libs = gSystem->GetLibraries();
171 if (libs.Contains(*library) ||
172 (gSystem->Load(*library)) >= 0) {
176 } while (*(++library)!=NULL);
178 if (iResult>0 && *library!=NULL) {
179 // print compile info
180 typedef void (*CompileInfo)( char*& date, char*& time);
181 CompileInfo fctInfo=(CompileInfo)gSystem->DynFindSymbol(*library, "CompileInfo");
185 (*fctInfo)(date, time);
186 if (!date) date="unknown";
187 if (!time) time="unknown";
188 //HLTInfo("%s build on %s (%s)", *library, date, time);
190 //HLTInfo("no build info available for %s", *library);
193 fFctCreateReaderFromTCPPort=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_CREATE_FROM_TCPPORT);
194 fFctCreateReaderFromTCPPorts=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_CREATE_FROM_TCPPORTS);
195 fFctCreateReaderFromBuffer=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_CREATE_FROM_BUFFER);
196 fFctDeleteReader=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_DELETE);
197 fFctCreateWriter=gSystem->DynFindSymbol(*library, ALIHLTHOMERWRITER_CREATE);
198 fFctDeleteWriter=gSystem->DynFindSymbol(*library, ALIHLTHOMERWRITER_DELETE);
199 if (fFctCreateReaderFromTCPPort==NULL ||
200 fFctCreateReaderFromTCPPorts==NULL ||
201 fFctCreateReaderFromBuffer==NULL ||
202 fFctDeleteReader==NULL ||
203 fFctCreateWriter==NULL ||
204 fFctDeleteWriter==NULL) {
209 if (iResult<0 || *library==NULL) {
210 fFctCreateReaderFromTCPPort=NULL;
211 fFctCreateReaderFromTCPPorts=NULL;
212 fFctCreateReaderFromBuffer=NULL;
213 fFctDeleteReader=NULL;
214 fFctCreateWriter=NULL;
215 fFctDeleteWriter=NULL;