Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RRawFileTFile.hxx
Go to the documentation of this file.
1// Author: Jonas Hahnfeld
2
3/*************************************************************************
4 * Copyright (C) 1995-2024, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_RRawFileTFile
12#define ROOT_RRawFileTFile
13
14#include <ROOT/RRawFile.hxx>
15
16#include <TFile.h>
17
18#include <stdexcept>
19
20namespace ROOT {
21namespace Internal {
22
23/**
24 * \class RRawFileTFile RRawFileTFile.hxx
25 * \ingroup io_files
26 *
27 * The RRawFileTFile wraps an open TFile, but does not take ownership.
28 */
29class RRawFileTFile : public RRawFile {
30private:
32
33protected:
34 void OpenImpl() final { fOptions.fBlockSize = 0; }
35
36 size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
37 {
38 if (fFile->ReadBuffer(static_cast<char *>(buffer), offset, nbytes)) {
39 throw std::runtime_error("failed to read expected number of bytes");
40 }
41 return nbytes;
42 }
43
44 std::uint64_t GetSizeImpl() final { return fFile->GetSize(); }
45
46public:
47 RRawFileTFile(TFile *file) : RRawFile(file->GetEndpointUrl()->GetFile(), {}), fFile(file) {}
48
49 std::unique_ptr<ROOT::Internal::RRawFile> Clone() const final { return std::make_unique<RRawFileTFile>(fFile); }
50};
51
52} // namespace Internal
53} // namespace ROOT
54
55#endif
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
Derived classes should implement low-level reading without buffering.
std::unique_ptr< ROOT::Internal::RRawFile > Clone() const final
Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
std::uint64_t GetSizeImpl() final
Derived classes should return the file size.
RRawFile(std::string_view url, ROptions options)
Definition RRawFile.cxx:61
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130