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 AliHLTMemoryFile.cxx
20 @author Matthias Richter
22 @brief ROOT file in memory. */
24 #include "AliHLTMemoryFile.h"
27 /** ROOT macro for the implementation of ROOT specific class methods */
28 ClassImp(AliHLTMemoryFile);
30 AliHLTMemoryFile::AliHLTMemoryFile()
41 // see header file for class documentation
43 // refer to README to build package
45 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
48 AliHLTMemoryFile::AliHLTMemoryFile(void* pBuffer, int iSize)
50 TFile("/dev/null", "CREATE"),
52 fpBuffer((char*)pBuffer),
61 // see header file for class documentation
62 //HLTDebug("created memory file %p, capacity %d, ROOT version %d", this, fBufferSize, fVersion);
65 AliHLTMemoryFile::~AliHLTMemoryFile()
67 // see header file for function documentation
68 //HLTDebug("deleting file %p size %d", this, fSize);
70 HLTWarning("memory file not closed, possible data loss");
74 void AliHLTMemoryFile::Close(const Option_t*)
79 int AliHLTMemoryFile::CloseMemoryFile(int bFlush)
82 if (fbClosed) return 0;
87 fBufferSize=fPosition=0;
90 HLTError("error flushing memory file, buffer too small");
91 } else if (fErrno>0) {
92 HLTError("error flushing memory file");
97 Int_t AliHLTMemoryFile::SysOpen(const char* /*pathname*/, Int_t /*flags*/, UInt_t /*mode*/)
99 // see header file for function documentation
100 if (fpBuffer==NULL || fSize==0) return 1;
101 //HLTDebug("opening file %p capacity %d", this, fSize);
107 Int_t AliHLTMemoryFile::SysClose(Int_t /*fd*/)
109 // see header file for function documentation
110 //HLTDebug("closing file %p size %d", this, fSize);
114 Int_t AliHLTMemoryFile::SysRead(Int_t /*fd*/, void *buf, Int_t len)
116 // see header file for function documentation
117 if (buf==NULL) return 0;
119 //HLTDebug("reading buffer of size %d at position %d", len, fPosition);
120 if (fpBuffer==NULL || fBufferSize==0) return 0;
121 int read=len<fSize-fPosition?len:fSize-fPosition;
122 memcpy(buf, fpBuffer+fPosition, read);
124 if (fPosition>=fSize) fSize=fPosition+1;
128 Int_t AliHLTMemoryFile::SysWrite(Int_t /*fd*/, const void *buf, Int_t len)
130 // see header file for function documentation
131 if (buf==NULL) return 0;
133 //HLTDebug("writing buffer of size %d at position %d", len, fPosition);
134 if (len<fBufferSize-fPosition) {
135 memcpy(fpBuffer+fPosition, buf, len);
137 if (fPosition>=fSize) fSize=fPosition+1;
144 Long64_t AliHLTMemoryFile::SysSeek(Int_t /*fd*/, Long64_t offset, Int_t whence)
146 // see header file for function documentation
147 //HLTDebug("seek %d from %d", offset, whence);
149 int position=(int)offset;
164 if (position<fBufferSize) {
174 Int_t AliHLTMemoryFile::SysStat(Int_t /*fd*/, Long_t */*id*/, Long64_t *size, Long_t */*flags*/, Long_t */*modtime*/)
176 // see header file for function documentation
177 if (size) *size=fSize;
181 Int_t AliHLTMemoryFile::SysSync(Int_t /*fd*/)
183 // see header file for function documentation
187 int AliHLTMemoryFile::WriteHeaderBuffer(const char* pHeader, int size)
189 // see header file for function documentation
191 if (fHeaderSize==0) {
192 if (fSize+size<fBufferSize) {
195 memcpy(fpBuffer+size, fpBuffer, fSize);
197 memcpy(fpBuffer, pHeader, size);
203 HLTError("no space left in memory file");
207 HLTError("header exists");
213 // int AliHLTMemoryFile::WriteTrailerBuffer(const char* pTrailer, int size)
215 // // see header file for function documentation
218 // HLTError("file must be closed to write trailer");
221 // if (fSize+size<fBufferSize) {
222 // memcpy(fpBuffer+fSize, pTrailer, size);
224 // HLTError("no space left in memory file");