]>
Commit | Line | Data |
---|---|---|
79c114b5 | 1 | //-*- Mode: C++ -*- |
2 | // @(#) $Id$ | |
3 | ||
4 | #ifndef ALIHLTMEMORYFILE_H | |
5 | #define ALIHLTMEMORYFILE_H | |
6 | /* This file is property of and copyright by the ALICE HLT Project * | |
7 | * ALICE Experiment at CERN, All rights reserved. * | |
8 | * See cxx source for full Copyright notice */ | |
9 | ||
10 | /** @file AliHLTMemoryFile.h | |
11 | @author Matthias Richter | |
12 | @date | |
13 | @brief Serialization of complete ROOT files. | |
14 | ||
15 | // see below for class documentation | |
16 | // or | |
17 | // refer to README to build package | |
18 | // or | |
19 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
20 | */ | |
21 | #include "TFile.h" | |
22 | #include "AliHLTLogging.h" | |
23 | ||
24 | /** | |
25 | * @class AliHLTMemoryFile | |
26 | * Serialization of ROOT files for transport in the Alice HLT analysis | |
27 | * chain. | |
28 | * | |
29 | * The file behaves like a normal ROOT file except that it is written to | |
30 | * a memory buffer instead of disk. | |
31 | */ | |
32 | class AliHLTMemoryFile : public TFile, public AliHLTLogging { | |
33 | public: | |
34 | /** standard constructor */ | |
35 | AliHLTMemoryFile(); | |
36 | ||
37 | /** constructor */ | |
38 | AliHLTMemoryFile(void* pBuffer, int iSize); | |
39 | ||
40 | /** standard destructor */ | |
41 | virtual ~AliHLTMemoryFile(); | |
42 | ||
43 | /** | |
44 | * Write a header at the beginning of the file. | |
45 | * The header is not part of the ROOT file. It should be written before any | |
46 | * other object in order to avoid data to be moved. | |
47 | * @param pHeader buffer to write | |
48 | * @param iSize size of the buffer | |
49 | * @return neg. error code if failed | |
50 | * - -ENOSPC buffer size too small | |
51 | */ | |
32db4144 | 52 | int WriteHeader(const char* pHeader, int iSize); |
79c114b5 | 53 | |
54 | /** | |
55 | * Write a header at the beginning of the file. | |
56 | * The trailer is not part of the ROOT file. It can only be written if the | |
57 | * file already has been closed. | |
58 | * @param pTrailer buffer to write | |
59 | * @param iSize size of the buffer | |
60 | * @return neg. error code if failed | |
61 | * - -ENOSPC buffer size too small | |
62 | */ | |
63 | // not yet stable | |
64 | //int WriteTrailer(const char* pTrailer, int size); | |
65 | ||
66 | /** | |
67 | * Close file and flush output. | |
68 | * @param bFlush write remaining data | |
69 | * @return neg. error code if failed | |
70 | * - -ENOSPC buffer size too small | |
71 | */ | |
72 | int Close(int bFlush=1); | |
73 | ||
74 | /** | |
75 | * Check if file has been closed. | |
76 | * @return 1 if closed | |
77 | */ | |
78 | int IsClosed() {return fbClosed;} | |
79 | ||
80 | /** | |
81 | * Get the last error code. | |
82 | * @return error code | |
83 | */ | |
84 | int GetErrno() {return fErrno;} | |
85 | ||
86 | /** | |
87 | * Get header size. | |
88 | */ | |
89 | int GetHeaderSize() {return fHeaderSize;} | |
90 | ||
91 | protected: | |
92 | // Interface to basic system I/O routines | |
93 | Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode); | |
94 | Int_t SysClose(Int_t fd); | |
95 | Int_t SysRead(Int_t fd, void *buf, Int_t len); | |
96 | Int_t SysWrite(Int_t fd, const void *buf, Int_t len); | |
97 | Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence); | |
98 | Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime); | |
99 | Int_t SysSync(Int_t fd); | |
100 | ||
101 | private: | |
102 | /** not a valid copy constructor, defined according to effective C++ style */ | |
103 | AliHLTMemoryFile(const AliHLTMemoryFile&); | |
104 | /** not a valid assignment op, but defined according to effective C++ style */ | |
105 | AliHLTMemoryFile& operator=(const AliHLTMemoryFile&); | |
106 | ||
107 | /** target buffer */ | |
108 | char* fpBuffer; //! transient | |
109 | ||
110 | /** size of buffer */ | |
111 | int fBufferSize; // see above | |
112 | ||
113 | /** position */ | |
114 | int fPosition; // see above | |
115 | ||
116 | /** filled posrtion of the buffer */ | |
117 | int fSize; // see above | |
118 | ||
119 | /** result of last operation */ | |
120 | int fErrno; // see above | |
121 | ||
122 | /** file closed */ | |
123 | int fbClosed; // see above | |
124 | ||
125 | /** size of header */ | |
126 | int fHeaderSize; // see above | |
127 | ||
128 | /** size of trailer */ | |
129 | int fTrailerSize; // see above | |
130 | ||
131 | ClassDef(AliHLTMemoryFile, 1) | |
132 | }; | |
133 | #endif // ALIHLTMEMORYFILE_H |