Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:22:39

0001 // Author: Jonas Hahnfeld
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2024, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOT_RRawFileTFile
0012 #define ROOT_RRawFileTFile
0013 
0014 #include <ROOT/RRawFile.hxx>
0015 
0016 #include <TFile.h>
0017 
0018 #include <stdexcept>
0019 
0020 namespace ROOT {
0021 namespace Internal {
0022 
0023 /**
0024  * \class RRawFileTFile RRawFileTFile.hxx
0025  * \ingroup IO
0026  *
0027  * The RRawFileTFile wraps an open TFile, but does not take ownership.
0028  */
0029 class RRawFileTFile : public RRawFile {
0030 private:
0031    TFile *fFile;
0032 
0033 protected:
0034    void OpenImpl() final { fOptions.fBlockSize = 0; }
0035 
0036    size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
0037    {
0038       if (fFile->ReadBuffer(static_cast<char *>(buffer), offset, nbytes)) {
0039          throw std::runtime_error("failed to read expected number of bytes");
0040       }
0041       return nbytes;
0042    }
0043 
0044    std::uint64_t GetSizeImpl() final { return fFile->GetSize(); }
0045 
0046 public:
0047    RRawFileTFile(TFile *file) : RRawFile(file->GetEndpointUrl()->GetFile(), {}), fFile(file) {}
0048 
0049    std::unique_ptr<ROOT::Internal::RRawFile> Clone() const final { return std::make_unique<RRawFileTFile>(fFile); }
0050 
0051    int GetFeatures() const final { return kFeatureHasSize; }
0052 };
0053 
0054 } // namespace Internal
0055 } // namespace ROOT
0056 
0057 #endif