ROOT  6.06/09
Reference Guide
TXNetFile.h
Go to the documentation of this file.
1 // @(#)root/netx:$Id$
2 /*************************************************************************
3  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
4  * All rights reserved. *
5  * *
6  * For the licensing terms see $ROOTSYS/LICENSE. *
7  * For the list of contributors see $ROOTSYS/README/CREDITS. *
8  *************************************************************************/
9 
10 #ifndef ROOT_TXNetFile
11 #define ROOT_TXNetFile
12 
13 
14 //////////////////////////////////////////////////////////////////////////
15 // //
16 // TXNetFile //
17 // //
18 // Authors: Alvise Dorigo, Fabrizio Furano //
19 // INFN Padova, 2003 //
20 // Interfaced to the posix client: G. Ganis, CERN //
21 // //
22 // TXNetFile is an extension of TNetFile able to deal with new xrootd //
23 // server. Its new features are: //
24 // - Automatic server kind recognition (xrootd load balancer, xrootd //
25 // data server, old rootd) //
26 // - Backward compatibility with old rootd server (acts as an old //
27 // TNetFile) //
28 // - Fault tolerance for read/write operations (read/write timeouts //
29 // and retry) //
30 // - Internal connection timeout (tunable indipendently from the OS //
31 // one) handled by threads //
32 // - handling of redirections from server //
33 // - Single TCP physical channel for multiple TXNetFile's instances //
34 // inside the same application //
35 // So, each TXNetFile object client must send messages containing //
36 // its ID (streamid). The server, of course, will respond with //
37 // messages containing the client's ID, in order to make the client //
38 // able to recognize its message by matching its streamid with that //
39 // one contained in the server's response. //
40 // - Tunable log verbosity level (0 = nothing, 3 = dump read/write //
41 // buffers too!) //
42 // - Many parameters configurable via TEnv facility (see SetParm() //
43 // methods) //
44 // //
45 //////////////////////////////////////////////////////////////////////////
46 
47 #ifndef ROOT_TNetFile
48 #include "TNetFile.h"
49 #endif
50 #ifndef ROOT_TString
51 #include "TString.h"
52 #endif
53 #ifndef ROOT_TUrl
54 #include "TUrl.h"
55 #endif
56 
57 class TFileStager;
58 class TSocket;
59 class XrdClient;
60 
61 class TXNetFile : public TNetFile {
62 
63 friend class TXNetSystem;
64 
65 private:
66  // Members
67  XrdClient *fClient; // Handle to the client object
68  Bool_t fIsRootd; // Nature of remote file server
69 
70  // Static members
71  static Bool_t fgInitDone; // Avoid initializing more than once
72  static Bool_t fgRootdBC; // Control rootd backward compatibility
73  static TFileStager *fgFileStager; // Stager for IsStaged checks
74 
75  void *fInitMtx; // Protects fInitDone, serializes the
76  // attempts to Init() for this object only
77 
78  // Methods
79  TXNetFile(const TXNetFile&); // Not implemented
80  TXNetFile& operator=(const TXNetFile&); // Not implemented
81  void CreateXClient(const char *url, Option_t *option, Int_t netopt,
82  Bool_t parallelopen);
83 
84  Int_t ParseOptions(const char *opts, Int_t &cachesz, Int_t &readaheadsz,
85  Int_t &rmpolicy, Int_t &mxredir, Int_t &rastrategy, Int_t &readtrimblksz);
86 
87  // Synchronizes the cache size in XrdClient
88  // XrdClient cannot have a cache size smaller than the one in TFile
89  void SynchronizeCacheSize();
90 
91  void Init(Bool_t create);
92  Bool_t Open(Option_t *option, Bool_t parallelopen);
93  Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags,
94  Long_t *modtime);
95  Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode);
96  Int_t SysClose(Int_t fd);
97 
98  // Static methods
99  static void FormUrl(TUrl uut, TString &uu);
100  static Int_t GetRootdProtocol(TSocket *s);
101  static void SetEnv();
102 
103 public:
104  TXNetFile() : TNetFile(), fClient(0), fIsRootd(0), fInitMtx(0) {}
105  TXNetFile(const char *url, Option_t *option = "", const char *fTitle = "",
106  Int_t compress = 1, Int_t netopt = 0, Bool_t parallelopen = kFALSE,
107  const char *logicalurl = 0);
108 
109  virtual ~TXNetFile();
110 
111  virtual void Close(const Option_t *opt ="");
112  virtual void ResetCache();
113  virtual void Flush();
114  virtual Int_t GetBytesToPrefetch() const;
115  virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len);
117  virtual Bool_t IsOpen() const;
118 
119  virtual void Print(Option_t *option="") const;
120  virtual Bool_t ReadBuffer(char *buf, Int_t len);
121  virtual Bool_t ReadBuffer(char *buf, Long64_t pos, Int_t len);
122  virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf);
123  virtual Int_t ReOpen(const Option_t *mode);
124  virtual Bool_t WriteBuffer(const char *buffer, Int_t BufferLength);
125 
126  ClassDef(TXNetFile,0) // TFile implementation to deal with new xrootd server.
127 };
128 
129 #endif
TString fTitle
Definition: TNamed.h:37
virtual ~TXNetFile()
Destructor.
Definition: TXNetFile.cxx:156
Int_t ParseOptions(const char *opts, Int_t &cachesz, Int_t &readaheadsz, Int_t &rmpolicy, Int_t &mxredir, Int_t &rastrategy, Int_t &readtrimblksz)
Parse input options for cache parameters.
Definition: TXNetFile.cxx:199
void Init(Bool_t create)
Initialize the file.
Definition: TXNetFile.cxx:912
long long Long64_t
Definition: RtypesCore.h:69
EAsyncOpenStatus
Asynchronous open request status.
Definition: TFile.h:51
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Override TNetFile::SysStat (see parent's method for more details).
Definition: TXNetFile.cxx:1091
XrdClient * fClient
Definition: TXNetFile.h:67
const char Option_t
Definition: RtypesCore.h:62
This class represents a WWW compatible URL.
Definition: TUrl.h:41
virtual TFile::EAsyncOpenStatus GetAsyncOpenStatus()
Return status of asynchronous request.
Definition: TXNetFile.cxx:993
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
static Int_t GetRootdProtocol(TSocket *s)
Find out the remote rootd protocol version.
Definition: TXNetFile.cxx:421
static Bool_t fgRootdBC
Definition: TXNetFile.h:72
virtual Int_t ReOpen(const Option_t *mode)
Re-open the file (see TNetFile::ReOpen() or TFile::ReOpen() for more details).
Definition: TXNetFile.cxx:1014
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Override TNetFile::ReadBuffer to deal with the xrootd server.
Definition: TXNetFile.cxx:591
virtual void Print(Option_t *option="") const
Print the local statistics.
Definition: TXNetFile.cxx:1434
TXNetFile & operator=(const TXNetFile &)
#define ClassDef(name, id)
Definition: Rtypes.h:254
static Bool_t fgInitDone
Definition: TXNetFile.h:71
static TFileStager * fgFileStager
Definition: TXNetFile.h:73
virtual Bool_t ReadBufferAsync(Long64_t offs, Int_t len)
Implementation dealing with the xrootd server.
Definition: TXNetFile.cxx:693
static void SetEnv()
Set the relevant environment variables.
Definition: TXNetFile.cxx:1193
virtual void ResetCache()
Reset the cache.
Definition: TXNetFile.cxx:1408
virtual Int_t GetBytesToPrefetch() const
Max number of bytes to prefetch.
Definition: TXNetFile.cxx:1417
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Override TNetFile::SysOpen (see parent's method for more details).
Definition: TXNetFile.cxx:1162
static void FormUrl(TUrl uut, TString &uu)
Form url for rootd socket.
Definition: TXNetFile.cxx:170
unsigned int UInt_t
Definition: RtypesCore.h:42
virtual void Flush()
Flushes un-written data.
Definition: TXNetFile.cxx:1053
void * fInitMtx
Definition: TXNetFile.h:75
Bool_t fIsRootd
Definition: TXNetFile.h:68
long Long_t
Definition: RtypesCore.h:50
virtual Bool_t WriteBuffer(const char *buffer, Int_t BufferLength)
Override TNetFile::WriteBuffer to deal with the xrootd server.
Definition: TXNetFile.cxx:852
virtual void Close(const Option_t *opt="")
Close the file (see TNetFile::Close() or TFile::Close() for more details).
Definition: TXNetFile.cxx:1029
Bool_t Open(Option_t *option, Bool_t parallelopen)
The real creation work is done here.
Definition: TXNetFile.cxx:476
void CreateXClient(const char *url, Option_t *option, Int_t netopt, Bool_t parallelopen)
The real creation work is done here.
Definition: TXNetFile.cxx:251
Int_t SysClose(Int_t fd)
Override TNetFile::SysClose (see parent's method for more details).
Definition: TXNetFile.cxx:1138
virtual Bool_t IsOpen() const
Return kTRUE if the file is open, kFALSE otherwise.
Definition: TXNetFile.cxx:975
virtual Bool_t ReadBuffers(char *buf, Long64_t *pos, Int_t *len, Int_t nbuf)
Read the nbuf blocks described in arrays pos and len, where pos[i] is the seek position of block i of...
Definition: TXNetFile.cxx:760
void SynchronizeCacheSize()
Synchronize the cache size Alternative purging policy.
Definition: TXNetFile.cxx:1376