Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RRawFileWin.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Jakob Blomer
3
4/*************************************************************************
5 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "ROOT/RRawFileWin.hxx"
13
14#include "TError.h"
15
16#include <cerrno>
17#include <cstddef>
18#include <cstdint>
19#include <cstdio>
20#include <cstring>
21#include <memory>
22#include <stdexcept>
23#include <string>
24
25namespace {
26constexpr int kDefaultBlockSize = 4096; // Read files in 4k pages unless told otherwise
27} // anonymous namespace
28
29ROOT::Internal::RRawFileWin::RRawFileWin(std::string_view url, ROptions options) : RRawFile(url, options) {}
30
32{
33 if (fFilePtr != nullptr)
34 fclose(fFilePtr);
35}
36
37std::unique_ptr<ROOT::Internal::RRawFile> ROOT::Internal::RRawFileWin::Clone() const
38{
39 return std::make_unique<RRawFileWin>(fUrl, fOptions);
40}
41
43{
44 Seek(0L, SEEK_END);
45 long size = ftell(fFilePtr);
46 if (size < 0)
47 throw std::runtime_error("Cannot tell position counter in '" + fUrl +
48 "', error: " + std::string(strerror(errno)));
49 Seek(fFilePos, SEEK_SET);
50 return size;
51}
52
54{
55 fFilePtr = fopen(GetLocation(fUrl).c_str(), "rb");
56 if (fFilePtr == nullptr)
57 throw std::runtime_error("Cannot open '" + fUrl + "', error: " + std::string(strerror(errno)));
58 // Prevent double buffering
59 int res = setvbuf(fFilePtr, nullptr, _IONBF, 0);
60 R__ASSERT(res == 0);
61 if (fOptions.fBlockSize == ROptions::kUseDefaultBlockSize)
62 fOptions.fBlockSize = kDefaultBlockSize;
63}
64
65size_t ROOT::Internal::RRawFileWin::ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset)
66{
67 Seek(offset, SEEK_SET);
68 size_t res = fread(buffer, 1, nbytes, fFilePtr);
69 if ((res < nbytes) && (ferror(fFilePtr) != 0)) {
70 clearerr(fFilePtr);
71 throw std::runtime_error("Cannot read from '" + fUrl + "', error: " + std::string(strerror(errno)));
72 }
73 return res;
74}
75
77{
78 int res = fseek(fFilePtr, offset, whence);
79 if (res != 0)
80 throw std::runtime_error("Cannot seek in '" + fUrl + "', error: " + std::string(strerror(errno)));
81}
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
RRawFileWin(std::string_view url, RRawFile::ROptions options)
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< 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.
void Seek(long offset, int whence)
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
The RRawFile provides read-only access to local and remote files.
Definition RRawFile.hxx:43
On construction, an ROptions parameter can customize the RRawFile behavior.
Definition RRawFile.hxx:49