]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/BASE/AliHLTMemoryFile.cxx
minor fix: documentation/compilation warnings
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTMemoryFile.cxx
CommitLineData
79c114b5 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 AliHLTMemoryFile.cxx
20 @author Matthias Richter
21 @date
22 @brief ROOT file in memory. */
23
24#include "AliHLTMemoryFile.h"
25#include <cerrno>
26
27/** ROOT macro for the implementation of ROOT specific class methods */
28ClassImp(AliHLTMemoryFile);
29
30AliHLTMemoryFile::AliHLTMemoryFile()
31 :
32 fpBuffer(NULL),
33 fBufferSize(0),
34 fPosition(0),
35 fSize(0),
36 fErrno(0),
37 fbClosed(0),
38 fHeaderSize(0),
39 fTrailerSize(0)
40{
41 // see header file for class documentation
42 // or
43 // refer to README to build package
44 // or
45 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
46}
47
48AliHLTMemoryFile::AliHLTMemoryFile(void* pBuffer, int iSize)
49 :
50 TFile("/dev/null", "CREATE"),
51 AliHLTLogging(),
52 fpBuffer((char*)pBuffer),
53 fBufferSize(iSize),
54 fPosition(0),
55 fSize(0),
56 fErrno(0),
57 fbClosed(0),
58 fHeaderSize(0),
59 fTrailerSize(0)
60{
61 // see header file for class documentation
62 //HLTDebug("created memory file %p, capacity %d, ROOT version %d", this, fBufferSize, fVersion);
63}
64
65AliHLTMemoryFile::AliHLTMemoryFile(const AliHLTMemoryFile&)
66 :
67 fpBuffer(NULL),
68 fBufferSize(0),
69 fPosition(0),
70 fSize(0),
71 fErrno(0),
72 fbClosed(0),
73 fHeaderSize(0),
74 fTrailerSize(0)
75{
76 // see header file for class documentation
77}
78
79AliHLTMemoryFile& AliHLTMemoryFile::operator=(const AliHLTMemoryFile&)
80{
81 // see header file for class documentation
82 return *this;
83}
84
85AliHLTMemoryFile::~AliHLTMemoryFile()
86{
87 // see header file for function documentation
88 //HLTDebug("deleting file %p size %d", this, fSize);
89 if (!fbClosed) {
90 HLTWarning("memory file not closed, possible data loss");
91 }
92}
93
94int AliHLTMemoryFile::Close(int bFlush)
95{
96 fErrno=0;
97 if (fbClosed) return 0;
98 if (bFlush) {
99 TFile::Close();
100 }
101 fpBuffer=NULL;
102 fBufferSize=fPosition=0;
103 fbClosed=1;
104 if (fErrno==ENOSPC) {
105 HLTError("error flushing memory file, buffer too small");
106 } else if (fErrno>0) {
107 HLTError("error flushing memory file");
108 }
109 return -fErrno;
110}
111
112Int_t AliHLTMemoryFile::SysOpen(const char *pathname, Int_t flags, UInt_t mode)
113{
114 // see header file for function documentation
115 if (fpBuffer==NULL || fSize==0) return 1;
116 //HLTDebug("opening file %p capacity %d", this, fSize);
117 fErrno=0;
118 errno=fErrno=ENOSPC;
119 return -1;
120}
121
122Int_t AliHLTMemoryFile::SysClose(Int_t fd)
123{
124 // see header file for function documentation
125 //HLTDebug("closing file %p size %d", this, fSize);
126 return 0;
127}
128
129Int_t AliHLTMemoryFile::SysRead(Int_t fd, void *buf, Int_t len)
130{
131 // see header file for function documentation
132 if (buf==NULL) return 0;
133 fErrno=0;
134 //HLTDebug("reading buffer of size %d at position %d", len, fPosition);
135 if (fpBuffer==NULL || fBufferSize==0) return 0;
136 int read=len<fSize-fPosition?len:fSize-fPosition;
137 memcpy(buf, fpBuffer+fPosition, read);
138 fPosition+=read;
139 if (fPosition>=fSize) fSize=fPosition+1;
140 return read;
141}
142
143Int_t AliHLTMemoryFile::SysWrite(Int_t fd, const void *buf, Int_t len)
144{
145 // see header file for function documentation
146 if (buf==NULL) return 0;
147 fErrno=0;
148 //HLTDebug("writing buffer of size %d at position %d", len, fPosition);
149 if (len<fBufferSize-fPosition) {
150 memcpy(fpBuffer+fPosition, buf, len);
151 fPosition+=len;
152 if (fPosition>=fSize) fSize=fPosition+1;
153 return len;
154 }
155 errno=fErrno=ENOSPC;
156 return -1;
157}
158
159Long64_t AliHLTMemoryFile::SysSeek(Int_t fd, Long64_t offset, Int_t whence)
160{
161 // see header file for function documentation
162 //HLTDebug("seek %d from %d", offset, whence);
163 fErrno=0;
164 int position=(int)offset;
165 switch (whence) {
166 case SEEK_SET:
167 // nothing to do
168 break;
169 case SEEK_CUR:
170 position+=fPosition;
171 break;
172 case SEEK_END:
173 position+=fSize;
174 default:
175 position=-1;
176 errno=EINVAL;
177 }
178 if (position>=0) {
179 if (position<fBufferSize) {
180 fPosition=position;
181 } else {
182 position=-1;
183 errno=fErrno=ENOSPC;
184 }
185 }
186 return position;
187}
188
189Int_t AliHLTMemoryFile::SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
190{
191 // see header file for function documentation
192 if (size) *size=fSize;
193 return 0;
194}
195
196Int_t AliHLTMemoryFile::SysSync(Int_t fd)
197{
198 // see header file for function documentation
199 return 0;
200}
201
202int AliHLTMemoryFile::WriteHeader(const char* pHeader, int size)
203{
204 // see header file for function documentation
205 fErrno=0;
206 if (fHeaderSize==0) {
207 if (fSize+size<fBufferSize) {
208 if (fSize>0) {
209 // move exiting data
210 memcpy(fpBuffer+size, fpBuffer, fSize);
211 }
212 memcpy(fpBuffer, pHeader, size);
213 fpBuffer+=size;
214 fPosition+=size;
215 fBufferSize-=size;
216 fHeaderSize=size;
217 } else {
218 HLTError("no space left in memory file");
219 fErrno=ENOSPC;
220 }
221 } else {
222 HLTError("header exists");
223 fErrno=EEXIST;
224 }
225 return -fErrno;
226}
227
228// int AliHLTMemoryFile::WriteTrailer(const char* pTrailer, int size)
229// {
230// // see header file for function documentation
231// fErrno=0;
232// if (fD>0) {
233// HLTError("file must be closed to write trailer");
234// return EPERM;
235// }
236// if (fSize+size<fBufferSize) {
237// memcpy(fpBuffer+fSize, pTrailer, size);
238// } else {
239// HLTError("no space left in memory file");
240// fErrno=ENOSPC;
241// }
242// return fErrno;
243// }