// @(#)root/io:$Id$ // Author: Rene Brun 28/11/94 /************************************************************************* * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * * All rights reserved. * * * * For the licensing terms see $ROOTSYS/LICENSE. * * For the list of contributors see $ROOTSYS/README/CREDITS. * *************************************************************************/ #ifndef ROOT_TFile #define ROOT_TFile ////////////////////////////////////////////////////////////////////////// // // // TFile // // // // ROOT file. // // // ////////////////////////////////////////////////////////////////////////// #include #include "Compression.h" #include "TDirectoryFile.h" #include "TUrl.h" #include "ROOT/RConcurrentHashColl.hxx" // Not a part of TFile interface; provide a forward declaration instead of #include. // #ifndef R__LESS_INCLUDES // #include "TMap.h" // #endif #ifdef R__USE_IMT #include "ROOT/TRWSpinLock.hxx" #include #endif class TMap; class TFree; class TArrayC; class TArchiveFile; class TFileOpenHandle; class TFileCacheRead; class TFileCacheWrite; class TProcessID; class TStopwatch; class TFilePrefetch; class TFile : public TDirectoryFile { friend class TDirectoryFile; friend class TFilePrefetch; // TODO: We need to make sure only one TBasket is being written at a time // if we are writing multiple baskets in parallel. #ifdef R__USE_IMT friend class TBasket; #endif public: /// Asynchronous open request status enum EAsyncOpenStatus { kAOSNotAsync = -1, kAOSFailure = 0, kAOSInProgress = 1, kAOSSuccess = 2 }; /// Open timeout constants enum EOpenTimeOut { kInstantTimeout = 0, kEternalTimeout = 999999999 }; /// TTreeCache flushing semantics enum ECacheAction { kDisconnect = 0, kDoNotDisconnect = 1 }; protected: Double_t fSumBuffer{0}; /// fgBytesWrite; /// fgBytesRead; /// fgFileCounter; /// fgReadCalls; ///GetSize(); } virtual Int_t GetNProcessIDs() const { return fNProcessIDs; } Option_t *GetOption() const override { return fOption.Data(); } virtual Long64_t GetBytesRead() const { return fBytesRead; } virtual Long64_t GetBytesReadExtra() const { return fBytesReadExtra; } virtual Long64_t GetBytesWritten() const; virtual Int_t GetReadCalls() const { return fReadCalls; } Int_t GetVersion() const { return fVersion; } Int_t GetRecordHeader(char *buf, Long64_t first, Int_t maxbytes, Int_t &nbytes, Int_t &objlen, Int_t &keylen); virtual Int_t GetNbytesInfo() const {return fNbytesInfo;} virtual Int_t GetNbytesFree() const {return fNbytesFree;} virtual TString GetNewUrl() { return ""; } Long64_t GetRelOffset() const { return fOffset - fArchiveOffset; } virtual Long64_t GetSeekFree() const {return fSeekFree;} virtual Long64_t GetSeekInfo() const {return fSeekInfo;} virtual Long64_t GetSize() const; virtual TList *GetStreamerInfoList() final; // Note: to override behavior, please override GetStreamerInfoListImpl const TList *GetStreamerInfoCache(); virtual void IncrementProcessIDs() { fNProcessIDs++; } virtual Bool_t IsArchive() const { return fIsArchive; } Bool_t IsBinary() const { return TestBit(kBinaryFile); } Bool_t IsRaw() const { return !fIsRootFile; } virtual Bool_t IsOpen() const; void ls(Option_t *option="") const override; virtual void MakeFree(Long64_t first, Long64_t last); virtual void MakeProject(const char *dirname, const char *classes="*", Option_t *option="new"); // *MENU* virtual void Map(Option_t *opt); // *MENU* virtual void Map() { Map(""); }; // *MENU* virtual Bool_t Matches(const char *name); virtual Bool_t MustFlush() const {return fMustFlush;} void Paint(Option_t *option="") override; void Print(Option_t *option="") const override; virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len); virtual Bool_t ReadBuffer(char *buf, Int_t len); virtual Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len); virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf); virtual void ReadFree(); virtual TProcessID *ReadProcessID(UShort_t pidf); virtual void ReadStreamerInfo(); virtual Int_t Recover(); virtual Int_t ReOpen(Option_t *mode); virtual void Seek(Long64_t offset, ERelativeTo pos = kBeg); virtual void SetCacheRead(TFileCacheRead *cache, TObject* tree = 0, ECacheAction action = kDisconnect); virtual void SetCacheWrite(TFileCacheWrite *cache); virtual void SetCompressionAlgorithm(Int_t algorithm = ROOT::RCompressionSetting::EAlgorithm::kUseGlobal); virtual void SetCompressionLevel(Int_t level = ROOT::RCompressionSetting::ELevel::kUseMin); virtual void SetCompressionSettings(Int_t settings = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault); virtual void SetEND(Long64_t last) { fEND = last; } virtual void SetOffset(Long64_t offset, ERelativeTo pos = kBeg); virtual void SetOption(Option_t *option=">") { fOption = option; } virtual void SetReadCalls(Int_t readcalls = 0) { fReadCalls = readcalls; } virtual void ShowStreamerInfo(); Int_t Sizeof() const override; void SumBuffer(Int_t bufsize); virtual Bool_t WriteBuffer(const char *buf, Int_t len); Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) override; Int_t Write(const char *name=nullptr, Int_t opt=0, Int_t bufsiz=0) const override; virtual void WriteFree(); virtual void WriteHeader(); virtual UShort_t WriteProcessID(TProcessID *pid); virtual void WriteStreamerInfo(); static TFileOpenHandle *AsyncOpen(const char *name, Option_t *option = "", const char *ftitle = "", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt = 0); static TFile *Open(const char *name, Option_t *option = "", const char *ftitle = "", Int_t compress = ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt = 0); static TFile *Open(TFileOpenHandle *handle); static EFileType GetType(const char *name, Option_t *option = "", TString *prefix = nullptr); static EAsyncOpenStatus GetAsyncOpenStatus(const char *name); static EAsyncOpenStatus GetAsyncOpenStatus(TFileOpenHandle *handle); static const TUrl *GetEndpointUrl(const char *name); static Long64_t GetFileBytesRead(); static Long64_t GetFileBytesWritten(); static Int_t GetFileReadCalls(); static Int_t GetReadaheadSize(); static void SetFileBytesRead(Long64_t bytes = 0); static void SetFileBytesWritten(Long64_t bytes = 0); static void SetFileReadCalls(Int_t readcalls = 0); static void SetReadaheadSize(Int_t bufsize = 256000); static void SetReadStreamerInfo(Bool_t readinfo=kTRUE); static Bool_t GetReadStreamerInfo(); static Long64_t GetFileCounter(); static void IncrementFileCounter(); static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected = kTRUE, Bool_t forceCacheread = kFALSE) { return SetCacheFileDir(std::string_view(cacheDir), operateDisconnected, forceCacheread); } static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected = kTRUE, Bool_t forceCacheread = kFALSE); static const char *GetCacheFileDir(); static Bool_t ShrinkCacheFileDir(Long64_t shrinkSize, Long_t cleanupInteval = 0); static Bool_t Cp(const char *src, const char *dst, Bool_t progressbar = kTRUE, UInt_t buffersize = 1000000); static UInt_t SetOpenTimeout(UInt_t timeout); // in ms static UInt_t GetOpenTimeout(); // in ms static Bool_t SetOnlyStaged(Bool_t onlystaged); static Bool_t GetOnlyStaged(); ClassDefOverride(TFile,8) //ROOT file }; #ifndef __CINT__ #define gFile (TFile::CurrentFile()) #elif defined(__MAKECINT__) // To properly handle the use of gFile in header files (in static declarations) R__EXTERN TFile *gFile; #endif /** \class TFileOpenHandle \ingroup IO Class holding info about the file being opened */ class TFileOpenHandle : public TNamed { friend class TFile; friend class TAlienFile; private: TString fOpt; ///< Options Int_t fCompress{0}; ///< Compression level and algorithm Int_t fNetOpt{0}; ///< Network options TFile *fFile{nullptr}; ///< TFile instance of the file being opened TFileOpenHandle(TFile *f) : TNamed("",""), fOpt(""), fCompress(ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault), fNetOpt(0), fFile(f) { } TFileOpenHandle(const char *n, const char *o, const char *t, Int_t cmp, Int_t no) : TNamed(n,t), fOpt(o), fCompress(cmp), fNetOpt(no), fFile(nullptr) { } TFileOpenHandle(const TFileOpenHandle&) = delete; TFileOpenHandle& operator=(const TFileOpenHandle&) = delete; TFile *GetFile() const { return fFile; } public: ~TFileOpenHandle() { } Bool_t Matches(const char *name); const char *GetOpt() const { return fOpt; } Int_t GetCompress() const { return fCompress; } Int_t GetNetOpt() const { return fNetOpt; } }; //______________________________________________________________________________ inline Int_t TFile::GetCompressionAlgorithm() const { return (fCompress < 0) ? -1 : fCompress / 100; } //______________________________________________________________________________ inline Int_t TFile::GetCompressionLevel() const { return (fCompress < 0) ? -1 : fCompress % 100; } //______________________________________________________________________________ inline Int_t TFile::GetCompressionSettings() const { return (fCompress < 0) ? -1 : fCompress; } #endif