Logo ROOT  
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 
31 class TSocket;
32 
33 
34 class TNetFile : public TFile {
35 
36 protected:
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);
58  Int_t SysClose(Int_t fd);
59  Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
60 
61 public:
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 
85 class TNetSystem : public TSystem {
86 
87 private:
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 
101 protected:
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 
108 public:
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
TNetSystem::fLocalPrefix
TString fLocalPrefix
Definition: TNetFile.h:103
TNetFile::SysStat
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:159
TNetFile::ReOpen
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:288
TNetSystem::OpenDirectory
void * OpenDirectory(const char *name)
Open a directory and return an opaque pointer to a dir structure.
Definition: TNetFile.cxx:989
TNetSystem::MakeDirectory
Int_t MakeDirectory(const char *name)
Make a directory via rootd.
Definition: TNetFile.cxx:967
TNetFile::Seek
void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TNetFile.cxx:565
TNetFile::SysOpen
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:112
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
Option_t
const char Option_t
Definition: RtypesCore.h:66
TNetFile::Print
void Print(Option_t *option) const
Print some info about the net file.
Definition: TNetFile.cxx:258
TNetFile::fErrorCode
Int_t fErrorCode
Definition: TNetFile.h:41
ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault
@ kUseCompiledDefault
Use the compile-time default setting.
Definition: Compression.h:50
TNetFile::ReadBuffer
Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via rootd daemon.
Definition: TNetFile.cxx:303
TFile::kBeg
@ kBeg
Definition: TFile.h:191
FileStat_t
Definition: TSystem.h:124
Long64_t
long long Long64_t
Definition: RtypesCore.h:73
TFile::ERelativeTo
ERelativeTo
Definition: TFile.h:191
TNetFile::Close
void Close(Option_t *option="")
Close remote file.
Definition: TNetFile.cxx:211
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:162
TNetSystem::fUser
TString fUser
Definition: TNetFile.h:93
TSystem
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:266
Int_t
int Int_t
Definition: RtypesCore.h:45
TNetFile::TNetFile
TNetFile(const TNetFile &)
TNetSystem::fDirp
void * fDirp
Definition: TNetFile.h:89
EMessageTypes
EMessageTypes
Definition: MessageTypes.h:27
MessageTypes.h
TNetFile::ReadBuffers
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:387
TNetFile::TNetFile
TNetFile()
Definition: TNetFile.h:64
TString
Basic string class.
Definition: TString.h:136
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TFile.h
TNetSystem::ConsistentWith
Bool_t ConsistentWith(const char *path, void *dirptr)
Check consistency of this helper with the one required by 'path' or 'dirptr'.
Definition: TNetFile.cxx:1118
bool
TNetFile::PrintError
void PrintError(const char *where, Int_t err)
Print error string depending on error code.
Definition: TNetFile.cxx:273
TNetSystem::~TNetSystem
virtual ~TNetSystem()
Destructor.
Definition: TNetFile.cxx:943
TNetFile::~TNetFile
virtual ~TNetFile()
TNetFile dtor. Send close message and close socket.
Definition: TNetFile.cxx:104
TNetSystem::FreeDirectory
void FreeDirectory(void *dirp=0)
Free directory via rootd.
Definition: TNetFile.cxx:1023
TSocket
Definition: TSocket.h:41
TNetFile::fNetopt
Int_t fNetopt
Definition: TNetFile.h:42
TNetFile::IsOpen
Bool_t IsOpen() const
Retruns kTRUE if file is open, kFALSE otherwise.
Definition: TNetFile.cxx:250
TNetSystem::AccessPathName
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
Definition: TNetFile.cxx:1096
TNetSystem::GetDirEntry
const char * GetDirEntry(void *dirp=0)
Get directory entry via rootd. Returns 0 in case no more entries.
Definition: TNetFile.cxx:1048
TNetFile::Flush
void Flush()
Flush file to disk.
Definition: TNetFile.cxx:228
TNetFile::GetEndpointUrl
const TUrl * GetEndpointUrl() const
Definition: TNetFile.h:79
TNetSystem::InitRemoteEntity
void InitRemoteEntity(const char *url)
Parse and save coordinates of the remote entity (user, host, port, ...)
Definition: TNetFile.cxx:841
TSystem.h
TNetFile::fEndpointUrl
TUrl fEndpointUrl
Definition: TNetFile.h:37
TNetSystem::fDir
Bool_t fDir
Definition: TNetFile.h:88
TNetFile::fProtocol
Int_t fProtocol
Definition: TNetFile.h:40
TNetFile::Create
virtual void Create(const char *url, Option_t *option, Int_t netopt)
Create a NetFile object.
Definition: TNetFile.cxx:662
TNetSystem::operator=
TNetSystem & operator=(const TNetSystem &)
TNetFile
Definition: TNetFile.h:34
Long_t
long Long_t
Definition: RtypesCore.h:54
TFTP.h
TNetSystem::fFTPOwner
Bool_t fFTPOwner
Definition: TNetFile.h:92
TUrl
This class represents a WWW compatible URL.
Definition: TUrl.h:33
TFile
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:54
TNetSystem
Definition: TNetFile.h:85
unsigned int
TNetSystem::fFTP
TFTP * fFTP
Definition: TNetFile.h:90
TNetFile::Init
void Init(Bool_t create)
Initialize a TNetFile object.
Definition: TNetFile.cxx:239
TNetSystem::fHost
TString fHost
Definition: TNetFile.h:91
TNetSystem::GetDirPtr
void * GetDirPtr() const
Definition: TNetFile.h:99
TNetFile::SysClose
Int_t SysClose(Int_t fd)
Close currently open file.
Definition: TNetFile.cxx:147
TNetSystem::fPort
Int_t fPort
Definition: TNetFile.h:94
EAccessMode
EAccessMode
Definition: TSystem.h:43
TNetSystem::GetPathInfo
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Definition: TNetFile.cxx:1072
TNetFile::WriteBuffer
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
Definition: TNetFile.cxx:491
TNetSystem::TNetSystem
TNetSystem(const TNetSystem &)
TNetFile::fSocket
TSocket * fSocket
Definition: TNetFile.h:39
TNetSystem::Create
void Create(const char *url, TSocket *sock=0)
Create a TNetSystem object.
Definition: TNetFile.cxx:865
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TNetSystem::Unlink
int Unlink(const char *path)
Remove a path.
Definition: TNetFile.cxx:1158
TFTP
Definition: TFTP.h:34
name
char name[80]
Definition: TGX11.cxx:110
TNetFile::GetErrorCode
Int_t GetErrorCode() const
Definition: TNetFile.h:69
TNetFile::operator=
TNetFile & operator=(const TNetFile &)
TNetFile::ConnectServer
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:573
TNetFile::Matches
Bool_t Matches(const char *url)
Return kTRUE if 'url' matches the coordinates of this file.
Definition: TNetFile.cxx:768
TUrl.h
TNetSystem::fIsLocal
Bool_t fIsLocal
Definition: TNetFile.h:102
TNetFile::Recv
Int_t Recv(Int_t &status, EMessageTypes &kind)
Return status from rootd server and message kind.
Definition: TNetFile.cxx:549
int
TNetFile::fUser
TString fUser
Definition: TNetFile.h:38