]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTHOMERLibManager.cxx
bugfixes for HOMER reader working on data buffer; minor changes in documentation
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERLibManager.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  *                  for The ALICE HLT Project.                            *
9  *                                                                        *
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  **************************************************************************/
18
19 /** @file   AliHLTHOMERLibManager.cxx
20     @author Matthias Richter
21     @date   
22     @brief  dynamic HLT HOMER reader/writer generation and destruction.   */
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30 #include <cerrno>
31 #include <cassert>
32 #include "AliHLTHOMERLibManager.h"
33 #include "AliHLTHOMERReader.h"
34 #include "AliHLTHOMERWriter.h"
35 #include "TString.h"
36 #include "TSystem.h"
37
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTHOMERLibManager)
40
41 AliHLTHOMERLibManager::AliHLTHOMERLibManager()
42   :
43   fLibraryStatus(0),
44   fFctCreateReaderFromTCPPort(NULL),
45   fFctCreateReaderFromTCPPorts(NULL),
46   fFctCreateReaderFromBuffer(NULL),
47   fFctDeleteReader(NULL),
48   fFctCreateWriter(NULL),
49   fFctDeleteWriter(NULL)
50 {
51   // see header file for class documentation
52   // or
53   // refer to README to build package
54   // or
55   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 }
57
58 AliHLTHOMERLibManager::~AliHLTHOMERLibManager()
59 {
60   // see header file for class documentation
61 }
62
63 AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReader(const char* hostname, unsigned short port )
64 {
65   // see header file for class documentation
66   if (fLibraryStatus<0) return NULL;
67
68   if (fLibraryStatus==0) {
69     fLibraryStatus=LoadHOMERLibrary();
70   }
71   
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);
75   }
76   
77   return pReader;
78 }
79
80 AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReader(unsigned int tcpCnt, const char** hostnames, unsigned short* ports)
81 {
82   // see header file for class documentation
83   if (fLibraryStatus<0) return NULL;
84
85   if (fLibraryStatus==0) {
86     fLibraryStatus=LoadHOMERLibrary();
87   }
88   
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);
92   }
93   
94   return pReader;
95 }
96
97 AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReader(const AliHLTUInt8_t* pBuffer, int size)
98 {
99   // see header file for class documentation
100   if (fLibraryStatus<0) return NULL;
101
102   if (fLibraryStatus==0) {
103     fLibraryStatus=LoadHOMERLibrary();
104   }
105   
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);
109   }
110   
111   return pReader;
112 }
113
114 int AliHLTHOMERLibManager::DeleteReader(AliHLTHOMERReader* pReader)
115 {
116   // see header file for class documentation
117   if (fLibraryStatus<0) return fLibraryStatus;
118
119   if (fLibraryStatus==0) {
120     fLibraryStatus=LoadHOMERLibrary();
121   }
122   
123   if (fFctDeleteReader!=NULL) {
124     ((AliHLTHOMERReaderDelete_t)fFctDeleteReader)(pReader);
125   }
126   
127   return 0;
128 }
129
130 AliHLTHOMERWriter* AliHLTHOMERLibManager::OpenWriter()
131 {
132   // see header file for class documentation
133   if (fLibraryStatus<0) return NULL;
134
135   if (fLibraryStatus==0) {
136     fLibraryStatus=LoadHOMERLibrary();
137   }
138   
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);
142   }
143   
144   return pWriter;
145 }
146
147 int AliHLTHOMERLibManager::DeleteWriter(AliHLTHOMERWriter* pWriter)
148 {
149   // see header file for class documentation
150   if (fLibraryStatus<0) return fLibraryStatus;
151
152   if (fLibraryStatus==0) {
153     fLibraryStatus=LoadHOMERLibrary();
154   }
155   
156   if (fFctDeleteWriter!=NULL) {
157     ((AliHLTHOMERWriterDelete_t)fFctDeleteWriter)(pWriter);
158   }
159   
160   return 0;
161 }
162
163 int AliHLTHOMERLibManager::LoadHOMERLibrary()
164 {
165   // see header file for class documentation
166   int iResult=-EBADF;
167   const char* libraries[]={"libAliHLTHOMER.so", "libHOMER.so", NULL};
168   const char** library=&libraries[0];
169   do {
170     TString libs = gSystem->GetLibraries();
171     if (libs.Contains(*library) ||
172         (gSystem->Load(*library)) >= 0) {
173       iResult=1;
174       break;
175     }
176   } while (*(++library)!=NULL);
177
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");
182     if (fctInfo) {
183       char* date="";
184       char* time="";
185       (*fctInfo)(date, time);
186       if (!date) date="unknown";
187       if (!time) time="unknown";
188       //HLTInfo("%s build on %s (%s)", *library, date, time);
189     } else {
190       //HLTInfo("no build info available for %s", *library);
191     }
192
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) {
205       iResult=-ENOSYS;
206     } else {
207     }
208   }
209   if (iResult<0 || *library==NULL) {
210     fFctCreateReaderFromTCPPort=NULL;
211     fFctCreateReaderFromTCPPorts=NULL;
212     fFctCreateReaderFromBuffer=NULL;
213     fFctDeleteReader=NULL;
214     fFctCreateWriter=NULL;
215     fFctDeleteWriter=NULL;
216   }
217
218   return iResult;
219 }