Logo ROOT   6.16/01
Reference Guide
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);
54 void Print(Option_t *option) const;
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);
59 Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
60
61public:
62 TNetFile(const char *url, Option_t *option = "", const char *ftitle = "",
65 virtual ~TNetFile();
66
67 void Close(Option_t *option=""); // *MENU*
68 void Flush();
69 Int_t GetErrorCode() const { return fErrorCode; }
70 Bool_t IsOpen() const;
71 Bool_t Matches(const char *url);
72 Int_t ReOpen(Option_t *mode);
73 Bool_t ReadBuffer(char *buf, Int_t len);
74 Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
75 Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
76 Bool_t WriteBuffer(const char *buf, Int_t len);
77 void Seek(Long64_t offset, ERelativeTo pos = kBeg);
78
79 const TUrl *GetEndpointUrl() const { return &fEndpointUrl; }
80
81 ClassDef(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&); // not implemented
97 TNetSystem& operator=(const TNetSystem&); // not implemented
98
99 void *GetDirPtr() const { 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 = 0);
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);
114 Int_t MakeDirectory(const char *name);
115 void *OpenDirectory(const char *name);
116 void FreeDirectory(void *dirp = 0);
117 const char *GetDirEntry(void *dirp = 0);
118 Int_t GetPathInfo(const char *path, FileStat_t &buf);
119 Bool_t AccessPathName(const char *path, EAccessMode mode);
120 int Unlink(const char *path);
121
122 ClassDef(TNetSystem,0) // Directory handler for NetSystem
123};
124
125#endif
EMessageTypes
Definition: MessageTypes.h:27
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
long long Long64_t
Definition: RtypesCore.h:69
const Bool_t kTRUE
Definition: RtypesCore.h:87
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:324
EAccessMode
Definition: TSystem.h:44
Definition: TFTP.h:34
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
ERelativeTo
Definition: TFile.h:184
@ kBeg
Definition: TFile.h:184
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Open a remote file. Requires fOption to be set correctly.
Definition: TNetFile.cxx:120
Int_t GetErrorCode() const
Definition: TNetFile.h:69
void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TNetFile.cxx:573
void Print(Option_t *option) const
Print some info about the net file.
Definition: TNetFile.cxx:266
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Return file stat information.
Definition: TNetFile.cxx:167
virtual void Create(const char *url, Option_t *option, Int_t netopt)
Create a NetFile object.
Definition: TNetFile.cxx:671
Int_t fProtocol
Definition: TNetFile.h:40
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:581
Int_t Recv(Int_t &status, EMessageTypes &kind)
Return status from rootd server and message kind.
Definition: TNetFile.cxx:557
Bool_t IsOpen() const
Retruns kTRUE if file is open, kFALSE otherwise.
Definition: TNetFile.cxx:258
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)
Read a list of buffers given in pos[] and len[] and return it in a single buffer.
Definition: TNetFile.cxx:395
TString fUser
Definition: TNetFile.h:38
Bool_t Matches(const char *url)
Return kTRUE if 'url' matches the coordinates of this file.
Definition: TNetFile.cxx:777
Int_t SysClose(Int_t fd)
Close currently open file.
Definition: TNetFile.cxx:155
void PrintError(const char *where, Int_t err)
Print error string depending on error code.
Definition: TNetFile.cxx:281
const TUrl * GetEndpointUrl() const
Definition: TNetFile.h:79
Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via rootd daemon.
Definition: TNetFile.cxx:311
void Init(Bool_t create)
Initialize a TNetFile object.
Definition: TNetFile.cxx:247
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
Definition: TNetFile.cxx:499
Int_t fNetopt
Definition: TNetFile.h:42
Int_t fErrorCode
Definition: TNetFile.h:41
void Close(Option_t *option="")
Close remote file.
Definition: TNetFile.cxx:219
virtual ~TNetFile()
TNetFile dtor. Send close message and close socket.
Definition: TNetFile.cxx:112
void Flush()
Flush file to disk.
Definition: TNetFile.cxx:236
TSocket * fSocket
Definition: TNetFile.h:39
TNetFile & operator=(const TNetFile &)
Int_t ReOpen(Option_t *mode)
Reopen a file with a different access mode, like from READ to UPDATE or from NEW, CREATE,...
Definition: TNetFile.cxx:296
const char * GetDirEntry(void *dirp=0)
Get directory entry via rootd. Returns 0 in case no more entries.
Definition: TNetFile.cxx:1057
TString fLocalPrefix
Definition: TNetFile.h:103
TString fHost
Definition: TNetFile.h:91
TString fUser
Definition: TNetFile.h:93
void InitRemoteEntity(const char *url)
Parse and save coordinates of the remote entity (user, host, port, ...)
Definition: TNetFile.cxx:850
Int_t MakeDirectory(const char *name)
Make a directory via rootd.
Definition: TNetFile.cxx:976
void Create(const char *url, TSocket *sock=0)
Create a TNetSystem object.
Definition: TNetFile.cxx:874
void FreeDirectory(void *dirp=0)
Free directory via rootd.
Definition: TNetFile.cxx:1032
Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by 'path' or 'dirptr'.
Definition: TNetFile.cxx:1127
Bool_t fDir
Definition: TNetFile.h:88
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
Definition: TNetFile.cxx:1105
TNetSystem & operator=(const TNetSystem &)
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Definition: TNetFile.cxx:1081
virtual ~TNetSystem()
Destructor.
Definition: TNetFile.cxx:952
void * fDirp
Definition: TNetFile.h:89
void * GetDirPtr() const
Definition: TNetFile.h:99
Bool_t fFTPOwner
Definition: TNetFile.h:92
TFTP * fFTP
Definition: TNetFile.h:90
TNetSystem(const TNetSystem &)
int Unlink(const char *path)
Remove a path.
Definition: TNetFile.cxx:1167
void * OpenDirectory(const char *name)
Open a directory via rfiod.
Definition: TNetFile.cxx:998
Int_t fPort
Definition: TNetFile.h:94
Bool_t fIsLocal
Definition: TNetFile.h:102
Basic string class.
Definition: TString.h:131
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:248
This class represents a WWW compatible URL.
Definition: TUrl.h:35
static constexpr double s
@ kUseGeneralPurpose
Use the recommended general-purpose setting; moderate read / write speed and compression ratio.
Definition: Compression.h:53