Logo ROOT  
Reference Guide
RRawFileNetXNG.cxx
Go to the documentation of this file.
1// @(#)root/io:$Id$
2// Author: Michal Simon
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
13
14#include <TError.h>
15
16#include <memory>
17#include <stdexcept>
18#include <vector>
19#include <XrdCl/XrdClFile.hh>
20#include <XrdCl/XrdClFileSystem.hh>
21
22
23namespace {
24constexpr int kDefaultBlockSize = 128 * 1024; // Read in relatively large 128k blocks for better network utilization
25} // anonymous namespace
26
27namespace ROOT {
28namespace Internal {
29
31 RRawFileNetXNGImpl() = default;
35
36 XrdCl::File file;
37};
38
39} // namespace Internal
40} // namespace ROOT
41
42
44 RRawFile::ROptions options )
45 : RRawFile( url, options ), pImpl( new RRawFileNetXNGImpl() )
46{
47}
48
50{
51}
52
53std::unique_ptr<ROOT::Internal::RRawFile> ROOT::Internal::RRawFileNetXNG::Clone() const
54{
55 return std::make_unique<RRawFileNetXNG>( fUrl, fOptions );
56}
57
59{
60 XrdCl::StatInfo *info = nullptr;
61 auto st = pImpl->file.Stat( true, info );
62 if( !st.IsOK() )
63 throw std::runtime_error( "Cannot determine size of '" + fUrl + "', " +
64 st.ToString() + "; " + st.GetErrorMessage() );
65 std::uint64_t ret = info->GetSize();
66 delete info; // XrdCl only allocates the object is the status was OK
67 return ret;
68}
69
71{
72 auto st = pImpl->file.Open( fUrl, XrdCl::OpenFlags::Read );
73 if( !st.IsOK() )
74 throw std::runtime_error( "Cannot open '" + fUrl + "', " +
75 st.ToString() + "; " + st.GetErrorMessage() );
76 if( fOptions.fBlockSize < 0 ) fOptions.fBlockSize = kDefaultBlockSize;
77}
78
79size_t ROOT::Internal::RRawFileNetXNG::ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset)
80{
81 std::uint32_t btsread = 0;
82 auto st = pImpl->file.Read( offset, nbytes, buffer, btsread );
83 if( !st.IsOK() )
84 throw std::runtime_error( "Cannot read from '" + fUrl + "', " +
85 st.ToString() + "; " + st.GetErrorMessage() );
86 return btsread;
87}
88
90{
91 XrdCl::ChunkList chunks;
92 chunks.reserve( nReq );
93 for( std::size_t i = 0; i < nReq; ++i )
94 chunks.emplace_back( ioVec[i].fOffset, ioVec[i].fSize, ioVec[i].fBuffer );
95
96 XrdCl::VectorReadInfo *info = nullptr;
97 auto st = pImpl->file.VectorRead( chunks, nullptr, info );
98 if( !st.IsOK() )
99 throw std::runtime_error( "Cannot do vector read from '" + fUrl + "', " +
100 st.ToString() + "; " + st.GetErrorMessage() );
101
102 XrdCl::ChunkList &rsp = info->GetChunks();
103 for( std::size_t i = 0; i < nReq; ++i )
104 ioVec[i].fOutBytes = rsp[i].length;
105 delete info;
106}
107
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
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 length
void OpenImpl() final
OpenImpl() is called at most once and before any call to either DoReadAt or DoGetSize.
void ReadVImpl(RIOVec *ioVec, unsigned int nReq) final
By default implemented as a loop of ReadAt calls but can be overwritten, e.g. XRootD or DAVIX impleme...
RRawFileNetXNG(std::string_view url, RRawFile::ROptions options)
std::unique_ptr< RRawFile > Clone() const final
Create a new RawFile that accesses the same resource. The file pointer is reset to zero.
size_t ReadAtImpl(void *buffer, size_t nbytes, std::uint64_t offset) final
Derived classes should implement low-level reading without buffering.
std::uint64_t GetSizeImpl() final
Derived classes should return the file size or kUnknownFileSize.
The RRawFile provides read-only access to local and remote files.
Definition: RRawFile.hxx:43
basic_string_view< char > string_view
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
RRawFileNetXNGImpl & operator=(const RRawFileNetXNGImpl &)=delete
RRawFileNetXNGImpl(const RRawFileNetXNGImpl &)=delete
Used for vector reads from multiple offsets into multiple buffers.
Definition: RRawFile.hxx:71
std::size_t fSize
The number of desired bytes.
Definition: RRawFile.hxx:77
void * fBuffer
The destination for reading.
Definition: RRawFile.hxx:73
std::uint64_t fOffset
The file offset.
Definition: RRawFile.hxx:75
On construction, an ROptions parameter can customize the RRawFile behavior.
Definition: RRawFile.hxx:59