ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 #ifndef ROOT_TFile
26 #include "TFile.h"
27 #endif
28 #ifndef ROOT_TUrl
29 #include "TUrl.h"
30 #endif
31 #ifndef ROOT_TFTP
32 #include "TFTP.h"
33 #endif
34 #ifndef ROOT_TSystem
35 #include "TSystem.h"
36 #endif
37 #ifndef ROOT_MessageTypes
38 #include "MessageTypes.h"
39 #endif
40 
41 class TSocket;
42 
43 
44 class TNetFile : public TFile {
45 
46 protected:
47  TUrl fEndpointUrl; //URL of realfile (after possible redirection)
48  TString fUser; //remote user name
49  TSocket *fSocket; //connection to rootd server
50  Int_t fProtocol; //rootd protocol level
51  Int_t fErrorCode; //error code returned by rootd (matching gRootdErrStr)
52  Int_t fNetopt; //initial network options (used for ReOpen())
53 
54  TNetFile(const TNetFile&); // NetFile cannot be copied
55  TNetFile& operator=(const TNetFile&); // NetFile cannot be copied
56 
57  TNetFile(const char *url, const char *ftitle, Int_t comp, Bool_t);
58  virtual void ConnectServer(Int_t *stat, EMessageTypes *kind, Int_t netopt,
59  Int_t tcpwindowsize, Bool_t forceOpen,
60  Bool_t forceRead);
61  virtual void Create(const char *url, Option_t *option, Int_t netopt);
62  virtual void Create(TSocket *s, Option_t *option, Int_t netopt);
63  void Init(Bool_t create);
64  void Print(Option_t *option) const;
65  void PrintError(const char *where, Int_t err);
67  Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode);
68  Int_t SysClose(Int_t fd);
69  Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime);
70 
71 public:
72  TNetFile(const char *url, Option_t *option = "", const char *ftitle = "",
73  Int_t compress = 1, Int_t netopt = 0);
75  virtual ~TNetFile();
76 
77  void Close(Option_t *option=""); // *MENU*
78  void Flush();
79  Int_t GetErrorCode() const { return fErrorCode; }
80  Bool_t IsOpen() const;
81  Bool_t Matches(const char *url);
82  Int_t ReOpen(Option_t *mode);
83  Bool_t ReadBuffer(char *buf, Int_t len);
84  Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
85  Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
86  Bool_t WriteBuffer(const char *buf, Int_t len);
87  void Seek(Long64_t offset, ERelativeTo pos = kBeg);
88 
89  const TUrl *GetEndpointUrl() const { return &fEndpointUrl; }
90 
91  ClassDef(TNetFile,1) //A ROOT file that reads/writes via a rootd server
92 };
93 
94 
95 class TNetSystem : public TSystem {
96 
97 private:
98  Bool_t fDir; // true if a directory is open remotely
99  void *fDirp; // directory handler
100  TFTP *fFTP; // Connection to rootd
101  TString fHost; // Remote host
102  Bool_t fFTPOwner; // True if owner of the FTP instance
103  TString fUser; // Remote user
104  Int_t fPort; // Remote port
105 
106  TNetSystem(const TNetSystem&); // not implemented
107  TNetSystem& operator=(const TNetSystem&); // not implemented
108 
109  void *GetDirPtr() const { return fDirp; }
110 
111 protected:
112  Bool_t fIsLocal; // TRUE if the path points to this host
113  TString fLocalPrefix; // if fIsLocal, prefix to be prepend locally
114 
115  void Create(const char *url, TSocket *sock = 0);
116  void InitRemoteEntity(const char *url);
117 
118 public:
119  TNetSystem(Bool_t ftpowner = kTRUE);
120  TNetSystem(const char *url, Bool_t ftpowner = kTRUE);
121  virtual ~TNetSystem();
122 
123  Bool_t ConsistentWith(const char *path, void *dirptr);
124  Int_t MakeDirectory(const char *name);
125  void *OpenDirectory(const char *name);
126  void FreeDirectory(void *dirp = 0);
127  const char *GetDirEntry(void *dirp = 0);
128  Int_t GetPathInfo(const char *path, FileStat_t &buf);
129  Bool_t AccessPathName(const char *path, EAccessMode mode);
130  int Unlink(const char *path);
131 
132  ClassDef(TNetSystem,0) // Directory handler for NetSystem
133 };
134 
135 #endif
const char * GetDirEntry(void *dirp=0)
Get directory entry via rootd. Returns 0 in case no more entries.
Definition: TNetFile.cxx:1057
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
TNetFile()
Definition: TNetFile.h:74
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 SysClose(Int_t fd)
Close currently open file.
Definition: TNetFile.cxx:155
Bool_t fDir
Definition: TNetFile.h:98
long long Long64_t
Definition: RtypesCore.h:69
TNetSystem & operator=(const TNetSystem &)
const char Option_t
Definition: RtypesCore.h:62
Bool_t fFTPOwner
Definition: TNetFile.h:102
TFTP * fFTP
Definition: TNetFile.h:100
tuple offset
Definition: tree.py:93
This class represents a WWW compatible URL.
Definition: TUrl.h:41
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Bool_t Matches(const char *url)
Return kTRUE if 'url' matches the coordinates of this file.
Definition: TNetFile.cxx:777
TNetFile & operator=(const TNetFile &)
void Flush()
Flush file to disk.
Definition: TNetFile.cxx:236
TNetSystem(const TNetSystem &)
Basic string class.
Definition: TString.h:137
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Definition: TFTP.h:42
void Create(const char *url, TSocket *sock=0)
Create a TNetSystem object.
Definition: TNetFile.cxx:874
ERelativeTo
Definition: TFile.h:160
TString fHost
Definition: TNetFile.h:101
int Unlink(const char *path)
Remove a path.
Definition: TNetFile.cxx:1167
Int_t fPort
Definition: TNetFile.h:104
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
Definition: TNetFile.cxx:1081
#define ClassDef(name, id)
Definition: Rtypes.h:254
Bool_t fIsLocal
Definition: TNetFile.h:112
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
Int_t GetErrorCode() const
Definition: TNetFile.h:79
void PrintError(const char *where, Int_t err)
Print error string depending on error code.
Definition: TNetFile.cxx:281
TString fUser
Definition: TNetFile.h:48
Int_t fProtocol
Definition: TNetFile.h:50
Int_t fNetopt
Definition: TNetFile.h:52
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
TString fLocalPrefix
Definition: TNetFile.h:113
void * GetDirPtr() const
Definition: TNetFile.h:109
unsigned int UInt_t
Definition: RtypesCore.h:42
void * OpenDirectory(const char *name)
Open a directory via rfiod.
Definition: TNetFile.cxx:998
Int_t MakeDirectory(const char *name)
Make a directory via rootd.
Definition: TNetFile.cxx:976
EMessageTypes
Definition: MessageTypes.h:27
Int_t Recv(Int_t &status, EMessageTypes &kind)
Return status from rootd server and message kind.
Definition: TNetFile.cxx:557
TUrl fEndpointUrl
Definition: TNetFile.h:47
void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
Definition: TNetFile.cxx:573
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via rootd daemon.
Definition: TNetFile.cxx:499
TSocket * fSocket
Definition: TNetFile.h:49
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:103
long Long_t
Definition: RtypesCore.h:50
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
virtual void Create(const char *url, Option_t *option, Int_t netopt)
Create a NetFile object.
Definition: TNetFile.cxx:671
void Close(Option_t *option="")
Close remote file.
Definition: TNetFile.cxx:219
Bool_t IsOpen() const
Retruns kTRUE if file is open, kFALSE otherwise.
Definition: TNetFile.cxx:258
virtual ~TNetFile()
TNetFile dtor. Send close message and close socket.
Definition: TNetFile.cxx:112
EAccessMode
Definition: TSystem.h:54
const TUrl * GetEndpointUrl() const
Definition: TNetFile.h:89
#define name(a, b)
Definition: linkTestLib0.cpp:5
void * fDirp
Definition: TNetFile.h:99
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
Int_t fErrorCode
Definition: TNetFile.h:51
Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via rootd daemon.
Definition: TNetFile.cxx:311
virtual ~TNetSystem()
Destructor.
Definition: TNetFile.cxx:952
void Print(Option_t *option) const
Print some info about the net file.
Definition: TNetFile.cxx:266
void Init(Bool_t create)
Initialize a TNetFile object.
Definition: TNetFile.cxx:247
Abstract base class defining a generic interface to the underlying Operating System.
Definition: TSystem.h:258
const Bool_t kTRUE
Definition: Rtypes.h:91
void InitRemoteEntity(const char *url)
Parse and save coordinates of the remote entity (user, host, port, ...)
Definition: TNetFile.cxx:850
void FreeDirectory(void *dirp=0)
Free directory via rootd.
Definition: TNetFile.cxx:1032