Warning, file /include/root/TMemFile.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TMemFile
0013 #define ROOT_TMemFile
0014
0015 #include "TFile.h"
0016 #include <vector>
0017 #include <memory>
0018
0019 class TMemFile : public TFile {
0020 public:
0021 using ExternalDataPtr_t = std::shared_ptr<const std::vector<char>>;
0022
0023 struct ZeroCopyView_t {
0024 const char *fStart;
0025 const size_t fSize;
0026 explicit ZeroCopyView_t(const char * start, const size_t size) : fStart(start), fSize(size) {}
0027 };
0028
0029 protected:
0030 struct TMemBlock {
0031 private:
0032 TMemBlock(const TMemBlock&) = delete;
0033 TMemBlock &operator=(const TMemBlock&) = delete;
0034 public:
0035 TMemBlock() = default;
0036 TMemBlock(Long64_t size, TMemBlock *previous = nullptr);
0037 TMemBlock(UChar_t* externalBuffer, Long64_t size);
0038 ~TMemBlock();
0039
0040 void CreateNext(Long64_t size);
0041
0042 TMemBlock *fPrevious{nullptr};
0043 TMemBlock *fNext{nullptr};
0044 UChar_t *fBuffer{nullptr};
0045 Long64_t fSize{0};
0046 };
0047 TMemBlock fBlockList;
0048 ExternalDataPtr_t fExternalData;
0049 Bool_t fIsOwnedByROOT{kFALSE};
0050 Long64_t fSize{0};
0051 Long64_t fSysOffset{0};
0052 TMemBlock *fBlockSeek{nullptr};
0053 Long64_t fBlockOffset{0};
0054
0055 constexpr static Long64_t fgDefaultBlockSize = 2 * 1024 * 1024;
0056 Long64_t fDefaultBlockSize = fgDefaultBlockSize;
0057
0058 Bool_t IsExternalData() const { return !fIsOwnedByROOT; }
0059
0060 Long64_t MemRead(Int_t fd, void *buf, Long64_t len) const;
0061
0062
0063 Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override;
0064 Int_t SysClose(Int_t fd) override;
0065 Int_t SysReadImpl(Int_t fd, void *buf, Long64_t len);
0066 Int_t SysWriteImpl(Int_t fd, const void *buf, Long64_t len);
0067 Int_t SysRead(Int_t fd, void *buf, Int_t len) override;
0068 Int_t SysWrite(Int_t fd, const void *buf, Int_t len) override;
0069 Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence) override;
0070 Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) override;
0071 Int_t SysSync(Int_t fd) override;
0072
0073 void ResetObjects(TDirectoryFile *, TFileMergeInfo *) const;
0074
0075 enum class EMode {
0076 kCreate,
0077 kRecreate,
0078 kUpdate,
0079 kRead
0080 };
0081
0082 bool NeedsToWrite(EMode mode) const { return mode != EMode::kRead; }
0083 bool NeedsExistingFile(EMode mode) const { return mode == EMode::kUpdate || mode == EMode::kRead; }
0084
0085 EMode ParseOption(Option_t *option);
0086
0087 TMemFile &operator=(const TMemFile&) = delete;
0088
0089 public:
0090 TMemFile(const char *name, Option_t *option = "", const char *ftitle = "",
0091 Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Long64_t defBlockSize = 0LL);
0092 TMemFile(const char *name, char *buffer, Long64_t size, Option_t *option = "", const char *ftitle = "",
0093 Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Long64_t defBlockSize = 0LL);
0094 TMemFile(const char *name, ExternalDataPtr_t data);
0095 TMemFile(const char *name, const ZeroCopyView_t &datarange);
0096 TMemFile(const char *name, std::unique_ptr<TBufferFile> buffer);
0097 TMemFile(const TMemFile &orig);
0098 ~TMemFile() override;
0099
0100 virtual Long64_t CopyTo(void *to, Long64_t maxsize) const;
0101 virtual void CopyTo(TBuffer &tobuf) const;
0102 Long64_t GetSize() const override;
0103
0104 void ResetAfterMerge(TFileMergeInfo *) override;
0105 void ResetErrno() const override;
0106
0107 void Print(Option_t *option="") const override;
0108
0109 ClassDefOverride(TMemFile, 0)
0110 };
0111
0112 #endif