]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTHOMERLibManager.cxx
- HLT simulation writes digit data in addition to raw data
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTHOMERLibManager.cxx
CommitLineData
6580df1c 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 */
39ClassImp(AliHLTHOMERLibManager)
40
41AliHLTHOMERLibManager::AliHLTHOMERLibManager()
42 :
43 fLibraryStatus(0),
a183f221 44 fFctCreateReaderFromTCPPort(NULL),
45 fFctCreateReaderFromTCPPorts(NULL),
6580df1c 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
58AliHLTHOMERLibManager::~AliHLTHOMERLibManager()
59{
60 // see header file for class documentation
61}
62
a183f221 63AliHLTHOMERReader* 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) {
cef34fbe 74 //HLTError("can not create instance of HOMER reader (function %p)", fFctCreateReaderFromTCPPort);
a183f221 75 }
76
77 return pReader;
78}
79
80AliHLTHOMERReader* 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) {
cef34fbe 91 //HLTError("can not create instance of HOMER reader (function %p)", fFctCreateReaderFromTCPPorts);
a183f221 92 }
93
94 return pReader;
95}
96
18b56222 97AliHLTHOMERReader* AliHLTHOMERLibManager::OpenReaderBuffer(const AliHLTUInt8_t* pBuffer, int size)
6580df1c 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) {
cef34fbe 108 //HLTError("can not create instance of HOMER reader (function %p)", fFctCreateReaderFromBuffer);
6580df1c 109 }
110
111 return pReader;
112}
113
114int 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
130AliHLTHOMERWriter* 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;
77fe3666 140 if (fFctCreateWriter!=NULL && (pWriter=(((AliHLTHOMERWriterCreate_t)fFctCreateWriter)()))==NULL) {
6580df1c 141// HLTError("can not create instance of HOMER writer (function %p)", fFctCreateWriter);
77fe3666 142 }
6580df1c 143
144 return pWriter;
145}
146
147int 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
163int 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) ||
a183f221 172 (gSystem->Load(*library)) >= 0) {
6580df1c 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";
cef34fbe 188 //HLTInfo("%s build on %s (%s)", *library, date, time);
6580df1c 189 } else {
cef34fbe 190 //HLTInfo("no build info available for %s", *library);
6580df1c 191 }
192
a183f221 193 fFctCreateReaderFromTCPPort=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_CREATE_FROM_TCPPORT);
194 fFctCreateReaderFromTCPPorts=gSystem->DynFindSymbol(*library, ALIHLTHOMERREADER_CREATE_FROM_TCPPORTS);
6580df1c 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);
a183f221 199 if (fFctCreateReaderFromTCPPort==NULL ||
200 fFctCreateReaderFromTCPPorts==NULL ||
201 fFctCreateReaderFromBuffer==NULL ||
202 fFctDeleteReader==NULL ||
203 fFctCreateWriter==NULL ||
204 fFctDeleteWriter==NULL) {
6580df1c 205 iResult=-ENOSYS;
206 } else {
6580df1c 207 }
208 }
209 if (iResult<0 || *library==NULL) {
a183f221 210 fFctCreateReaderFromTCPPort=NULL;
211 fFctCreateReaderFromTCPPorts=NULL;
6580df1c 212 fFctCreateReaderFromBuffer=NULL;
213 fFctDeleteReader=NULL;
214 fFctCreateWriter=NULL;
215 fFctDeleteWriter=NULL;
216 }
217
218 return iResult;
219}