33 #include <sys/types.h> 38 #if defined(R__SUN) || defined(R__HPUX) || \ 39 defined(R__AIX) || defined(R__LINUX) || defined(R__SOLARIS) || \ 40 defined(R__HIUX) || defined(R__FBSD) || defined(R__MACOSX) || \ 41 defined(R__HURD) || defined(R__OBSD) 72 const char *ftitle,
Int_t compress):
73 TFile(path,
"NET", ftitle, compress)
76 path = pathString.
Data();
89 if (!create && !recreate && !update && !read) {
97 const char *fnameWithPrefix;
100 fnameWithPrefix = fname = path;
110 fnameWithPrefix = stmp2;
112 Error(
"TDCacheFile",
"error expanding path %s", path);
125 Error(
"TDCacheFile",
"file %s already exists", fname);
134 Error(
"TDCacheFile",
"no write permission, could not open file %s", fname);
142 if (create || update) {
144 fD =
SysOpen(fname, O_RDWR | O_CREAT, 0644);
149 SysError(
"TDCacheFile",
"file %s can not be opened", fname);
161 Error(
"TDCacheFile",
"file %s does not exist", fname);
165 Error(
"TDCacheFile",
"no read permission, could not open file %s", fname);
168 SysError(
"TDCacheFile",
"file %s can not be opened for reading", fname);
179 const char *DCACHE_RA_BUFFER =
gSystem->
Getenv(
"DCACHE_RA_BUFFER");
180 if (DCACHE_RA_BUFFER) {
181 int ra_buffer = atoi(DCACHE_RA_BUFFER);
182 dcache_RAHEAD_SIZE = ra_buffer<=0 ? dcache_RAHEAD_SIZE : ra_buffer;
184 dc_setBufferSize(
fD, dcache_RAHEAD_SIZE);
253 vector = (iovec2 *)
malloc(
sizeof(iovec2)*nbuf);
256 for (
Int_t i = 0; i < nbuf; i++) {
257 vector[i].buf = &buf[total_len];
259 vector[i].len = len[i];
263 Int_t rc = dc_readv2(
fD, vector, nbuf);
282 Long64_t high = pos[nbuf-1] + len[nbuf-1] - pos[0];
285 for(
Int_t j=0; j < nbuf; j++) {
289 if ( total && high / total < 10 ) {
291 char *temp =
new char[high];
296 for (
Int_t i = 0; i < nbuf; i++) {
297 memcpy(&buf[k], &(temp[pos[i]-pos[0]]), len[i]);
306 for (
Int_t i = 0; i < nbuf; i++) {
343 path = pathString.
Data();
347 if (dc_stage(path, after, location) == 0)
364 path = pathString.
Data();
368 if (dc_check(path, location) == 0)
382 dc_setOpenTimeout(n);
398 dc_setReplyHostName((
char*)host_name);
406 return getDcapVersion();
419 dc_setClientActive();
423 Int_t rc = dc_open(pathname, flags, (
Int_t) mode);
440 Int_t rc = dc_close(fd);
457 Int_t rc = dc_read(fd, buf, len);
474 Int_t rc = dc_write(fd, (
char *)buf, len);
491 Long64_t rc = dc_lseek64(fd, offset, whence);
544 path = pathString.
Data();
546 if (path && (dc_stat64(path, &statbuf) >= 0)) {
553 *
id = (statbuf.st_dev << 24) + statbuf.st_ino;
555 *size = statbuf.st_size;
557 *modtime = statbuf.st_mtime;
560 if (statbuf.st_mode & ((S_IEXEC)|(S_IEXEC>>3)|(S_IEXEC>>6)))
562 if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
564 if ((statbuf.st_mode & S_IFMT) != S_IFREG &&
565 (statbuf.st_mode & S_IFMT) != S_IFDIR)
625 path = pathString.
Data();
627 rc = dc_mkdir(path, 0755);
643 path = pathString.
Data();
645 fDirp = dc_opendir(path);
662 rc = dc_closedir((DIR *)dirp);
680 ent = dc_readdir((DIR *)dirp);
686 return !ent ? 0 : ent->d_name;
697 path = pathString.
Data();
699 return dc_access(path, mode);
711 path = pathString.
Data();
715 if (path && (dc_stat64(path, &sbuf) >= 0)) {
717 buf.
fDev = sbuf.st_dev;
718 buf.
fIno = sbuf.st_ino;
719 buf.
fMode = sbuf.st_mode;
720 buf.
fUid = sbuf.st_uid;
721 buf.
fGid = sbuf.st_gid;
722 buf.
fSize = sbuf.st_size;
723 buf.
fMtime = sbuf.st_mtime;
virtual const char * GetName() const
Returns name of object.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
A TDCacheFile is like a normal TFile except that it may read and write its data via a dCache server (...
void FreeDirectory(void *dirp)
Close a directory.
TFileCacheRead * fCacheRead
!Pointer to the read cache (if any)
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence)
Interface to system seek. All arguments like in POSIX lseek.
static const char *const DCAP_PREFIX
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Get info about a file: id, size, flags, modification time.
Int_t SysSync(Int_t fd)
Interface to system sync.
A cache when reading files over the network.
virtual void SetOffset(Long64_t offset, ERelativeTo pos=kBeg)
Set position from where to start reading.
This class represents a WWW compatible URL.
const char * GetProtocol() const
virtual void SetName(const char *name)
Set the name of the TNamed.
virtual void Seek(Long64_t offset, ERelativeTo pos=kBeg)
Seek to a specific position in the file. Pos it either kBeg, kCur or kEnd.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual Bool_t ReadBuffer(char *buf, Int_t len)
Read a buffer from the file.
void ToUpper()
Change string to upper case.
Bool_t fStatCached
! (transient) is file status cached?
Int_t WriteBufferViaCache(const char *buf, Int_t len)
Write buffer via cache.
static void SetOnError(EOnErrorAction=kOnErrorDefault)
Set on error handler.
Int_t SysWrite(Int_t fd, const void *buf, Int_t len)
Interface to system write. All arguments like in POSIX write.
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
static void SetOpenTimeout(UInt_t secs)
Set file open timeout.
Bool_t WriteBuffer(const char *buf, Int_t len)
Write specified byte range to remote file via dCache daemon.
const char * GetFile() const
const char * GetHost() const
static const char * GetDcapVersion()
Return dCache version string.
TString fRealName
Effective real file name (not original url)
static Long64_t GetFileBytesRead()
Static function returning the total number of bytes read from all files.
void * OpenDirectory(const char *name)
Open a directory.
static const size_t DCACHE_PREFIX_LEN
virtual const char * Getenv(const char *env)
Get environment variable.
void * fDirp
directory handler
static Bool_t CheckFile(const char *path, const char *location=0)
CheckFile() returns kTRUE on success and kFALSE on failure.
Int_t SysRead(Int_t fd, void *buf, Int_t len)
Interface to system read. All arguments like in POSIX read.
R__EXTERN TSystem * gSystem
static TString GetDcapPath(const char *path)
Transform the input path into a path usuable by the dcap C library, i.e either dcap://nodename.org/where/filename.root or /pnfs/where/filename.root.
virtual Bool_t WriteBuffer(const char *buf, Int_t len)
Write a buffer to the file.
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
void ResetErrno() const
Method resetting the dc_errno and errno.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
static void SetReplyHostName(const char *host_name)
Set reply host name.
const char * GetDirEntry(void *dirp)
Get a directory entry.
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...
static const size_t DCAP_PREFIX_LEN
virtual void Init(Bool_t create)
Initialize a TFile object.
Int_t ReadBufferViaCache(char *buf, Int_t len)
Read buffer via cache.
Bool_t fWritable
True if directory is writable.
static unsigned int total
virtual Bool_t IsOpen() const
Returns kTRUE in case file is open and kFALSE if file is not open.
static const char *const DCACHE_PREFIX
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Interface to system open. All arguments like in POSIX open.
Int_t MakeDirectory(const char *name)
Create a directory.
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
TString fOption
File options.
struct stat64 fStatBuffer
! (transient) Cached file status buffer (for performance)
Bool_t ReadBuffer(char *buf, Int_t len)
Read specified byte range from remote file via dCache daemon.
Int_t SysClose(Int_t fd)
Interface to system close. All arguments like in POSIX close.
EOnErrorAction
Note: This must be kept in sync with values #defined in dcap.h.
#define RAHEAD_BUFFER_SIZE
Long64_t fArchiveOffset
!Offset at which file starts in archive
static void ResetErrno()
Static function resetting system error number.
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
TDCacheSystem()
Create helper class that allows directory access via dCache.
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
void SetErrorStr(const char *errstr)
Set the system error string.
static void SetFileBytesRead(Long64_t bytes=0)
Abstract base class defining a generic interface to the underlying Operating System.
~TDCacheFile()
Close and cleanup dCache file.
Long64_t fBytesRead
Number of bytes read from this file.
virtual void Close(Option_t *option="")
Close a file.
static Bool_t Stage(const char *path, UInt_t secs, const char *location=0)
Stage() returns kTRUE on success and kFALSE on failure.
const char * Data() const