Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TNetFile.h
Go to the documentation of this file.
1// @(#)root/net:$Id$
2// Author: Fons Rademakers 14/08/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, 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#ifndef ROOT_TNetFile
13#define ROOT_TNetFile
14
15
16//////////////////////////////////////////////////////////////////////////
17// //
18// TNetFile //
19// //
20// A TNetFile is like a normal TFile except that it reads and writes //
21// its data via a rootd server. //
22// //
23//////////////////////////////////////////////////////////////////////////
24
25#include "TFile.h"
26#include "TUrl.h"
27#include "TFTP.h"
28#include "TSystem.h"
29#include "MessageTypes.h"
30
31class TSocket;
32
33
34class TNetFile : public TFile {
35
36protected:
37 TUrl fEndpointUrl; //URL of realfile (after possible redirection)
38 TString fUser; //remote user name
39 TSocket *fSocket; //connection to rootd server
40 Int_t fProtocol; //rootd protocol level
41 Int_t fErrorCode; //error code returned by rootd (matching gRootdErrStr)
42 Int_t fNetopt; //initial network options (used for ReOpen())
43
44 TNetFile(const TNetFile&); // NetFile cannot be copied
45 TNetFile& operator=(const TNetFile&); // NetFile cannot be copied
46
47 TNetFile(const char *url, const char *ftitle, Int_t comp, Bool_t);
48 virtual void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt,
49 Int_t tcpwindowsize, Bool_t forceOpen,
50 Bool_t forceRead);
51 virtual void Create(const char *url, Option_t *option, Int_t netopt);
52 virtual void Create(TSocket *s, Option_t *option, Int_t netopt);
53 void Init(Bool_t create) override;
54 void Print(Option_t *option) const override;
55 void PrintError(const char *where, Int_t err);
56 Int_t Recv(Int_t &status, EMessageTypes &kind);
57 Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override;
58 Int_t SysClose(Int_t fd) override;
59 Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) override;
60
61public:
62 TNetFile(const char *url, Option_t *option = "", const char *ftitle = "",
64 TNetFile() : fEndpointUrl(), fUser(), fSocket(nullptr), fProtocol(0), fErrorCode(0), fNetopt(0) { }
65 virtual ~TNetFile();
66
67 void Close(Option_t *option="") override; // *MENU*
68 void Flush() override;
69 Int_t GetErrorCode() const { return fErrorCode; }
70 Bool_t IsOpen() const override;
71 Bool_t Matches(const char *url) override;
72 Int_t ReOpen(Option_t *mode) override;
73 Bool_t ReadBuffer(char *buf, Int_t len) override;
74 Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len) override;
75 Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override;
76 Bool_t WriteBuffer(const char *buf, Int_t len) override;
77 void Seek(Long64_t offset, ERelativeTo pos = kBeg) override;
78
79 const TUrl *GetEndpointUrl() const override { return &fEndpointUrl; }
80
81 ClassDefOverride(TNetFile,1) //A ROOT file that reads/writes via a rootd server
82};
83
84
85class TNetSystem : public TSystem {
86
87private:
88 Bool_t fDir; // true if a directory is open remotely
89 void *fDirp; // directory handler
90 TFTP *fFTP; // Connection to rootd
91 TString fHost; // Remote host
92 Bool_t fFTPOwner; // True if owner of the FTP instance
93 TString fUser; // Remote user
94 Int_t fPort; // Remote port
95
96 TNetSystem(const TNetSystem&) = delete;
97 TNetSystem& operator=(const TNetSystem&) = delete;
98
99 void *GetDirPtr() const override { return fDirp; }
100
101protected:
102 Bool_t fIsLocal; // TRUE if the path points to this host
103 TString fLocalPrefix; // if fIsLocal, prefix to be prepend locally
104
105 void Create(const char *url, TSocket *sock = nullptr);
106 void InitRemoteEntity(const char *url);
107
108public:
109 TNetSystem(Bool_t ftpowner = kTRUE);
110 TNetSystem(const char *url, Bool_t ftpowner = kTRUE);
111 virtual ~TNetSystem();
112
113 Bool_t ConsistentWith(const char *path, void *dirptr) override;
114 Int_t MakeDirectory(const char *name) override;
115 void *OpenDirectory(const char *name) override;
116 void FreeDirectory(void *dirp = nullptr) override;
117 const char *GetDirEntry(void *dirp = nullptr) override;
118 Int_t GetPathInfo(const char *path, FileStat_t &buf) override;
119 Bool_t AccessPathName(const char *path, EAccessMode mode) override;
120 int Unlink(const char *path) override;
121
122 ClassDefOverride(TNetSystem,0) // Directory handler for NetSystem
123};
124
125#endif
EMessageTypes
virtual RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, Configuration const &cfg)=0
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
long Long_t
Definition RtypesCore.h:54
long long Long64_t
Definition RtypesCore.h:80
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
char name[80]
Definition TGX11.cxx:110
EAccessMode
Definition TSystem.h:41
Definition TFTP.h:34
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
ERelativeTo
Definition TFile.h:199
@ kBeg
Definition TFile.h:199
A TNetFile is like a normal TFile except that it reads and writes its data via a rootd server (for mo...
Definition TNetFile.h:34
void Init(Bool_t create) override
Initialize a TNetFile object.
Definition TNetFile.cxx:236
Int_t GetErrorCode() const
Definition TNetFile.h:69
Bool_t ReadBuffer(char *buf, Int_t len) override
Read specified byte range from remote file via rootd daemon.
Definition TNetFile.cxx:300
Bool_t WriteBuffer(const char *buf, Int_t len) override
Write specified byte range to remote file via rootd daemon.
Definition TNetFile.cxx:488
Bool_t Matches(const char *url) override
Return kTRUE if 'url' matches the coordinates of this file.
Definition TNetFile.cxx:761
virtual void Create(const char *url, Option_t *option, Int_t netopt)
Create a NetFile object.
Definition TNetFile.cxx:659
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime) override
Return file stat information.
Definition TNetFile.cxx:156
Int_t fProtocol
Definition TNetFile.h:40
Int_t SysClose(Int_t fd) override
Close currently open file.
Definition TNetFile.cxx:144
TNetFile(const TNetFile &)
virtual void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt, Int_t tcpwindowsize, Bool_t forceOpen, Bool_t forceRead)
Connect to remote rootd server.
Definition TNetFile.cxx:570
void Print(Option_t *option) const override
Print some info about the net file.
Definition TNetFile.cxx:255
Bool_t IsOpen() const override
Retruns kTRUE if file is open, kFALSE otherwise.
Definition TNetFile.cxx:247
const TUrl * GetEndpointUrl() const override
Definition TNetFile.h:79
Int_t Recv(Int_t &status, EMessageTypes &kind)
Return status from rootd server and message kind.
Definition TNetFile.cxx:546
Int_t ReOpen(Option_t *mode) override
Reopen a file with a different access mode, like from READ to UPDATE or from NEW, CREATE,...
Definition TNetFile.cxx:285
TNetFile()
Definition TNetFile.h:64
TUrl fEndpointUrl
Definition TNetFile.h:37
Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf) override
Read a list of buffers given in pos[] and len[] and return it in a single buffer.
Definition TNetFile.cxx:384
TString fUser
Definition TNetFile.h:38
void Flush() override
Flush file to disk.
Definition TNetFile.cxx:225
void PrintError(const char *where, Int_t err)
Print error string depending on error code.
Definition TNetFile.cxx:270
Int_t fNetopt
Definition TNetFile.h:42
void Seek(Long64_t offset, ERelativeTo pos=kBeg) override
Set position from where to start reading.
Definition TNetFile.cxx:562
Int_t fErrorCode
Definition TNetFile.h:41
void Close(Option_t *option="") override
Close remote file.
Definition TNetFile.cxx:208
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode) override
Open a remote file. Requires fOption to be set correctly.
Definition TNetFile.cxx:109
virtual ~TNetFile()
TNetFile dtor. Send close message and close socket.
Definition TNetFile.cxx:101
TSocket * fSocket
Definition TNetFile.h:39
TNetFile & operator=(const TNetFile &)
TString fLocalPrefix
Definition TNetFile.h:103
void Create(const char *url, TSocket *sock=nullptr)
Create a TNetSystem object.
Definition TNetFile.cxx:858
Int_t MakeDirectory(const char *name) override
Make a directory via rootd.
Definition TNetFile.cxx:960
TString fHost
Definition TNetFile.h:91
TString fUser
Definition TNetFile.h:93
TNetSystem(const TNetSystem &)=delete
void InitRemoteEntity(const char *url)
Parse and save coordinates of the remote entity (user, host, port, ...)
Definition TNetFile.cxx:834
Bool_t fDir
Definition TNetFile.h:88
int Unlink(const char *path) override
Remove a path.
virtual ~TNetSystem()
Destructor.
Definition TNetFile.cxx:936
void * GetDirPtr() const override
Definition TNetFile.h:99
void * fDirp
Definition TNetFile.h:89
Bool_t ConsistentWith(const char *path, void *dirptr) override
Check consistency of this helper with the one required by 'path' or 'dirptr'.
Bool_t fFTPOwner
Definition TNetFile.h:92
TFTP * fFTP
Definition TNetFile.h:90
Int_t GetPathInfo(const char *path, FileStat_t &buf) override
Get info about a file.
TNetSystem & operator=(const TNetSystem &)=delete
const char * GetDirEntry(void *dirp=nullptr) override
Get directory entry via rootd. Returns 0 in case no more entries.
Int_t fPort
Definition TNetFile.h:94
void FreeDirectory(void *dirp=nullptr) override
Free directory via rootd.
Bool_t AccessPathName(const char *path, EAccessMode mode) override
Returns FALSE if one can access a file using the specified access mode.
Bool_t fIsLocal
Definition TNetFile.h:102
void * OpenDirectory(const char *name) override
Open a directory and return an opaque pointer to a dir structure.
Definition TNetFile.cxx:982
Basic string class.
Definition TString.h:139
Abstract base class defining a generic interface to the underlying Operating System.
Definition TSystem.h:260
This class represents a WWW compatible URL.
Definition TUrl.h:33
@ kUseCompiledDefault
Use the compile-time default setting.
Definition Compression.h:52