58 #define THDFSFile_TRACE
59 #ifndef THDFSFile_TRACE
61 Debug("THDFSFile", "%s", x);
72 const
char *ftitle,
Int_t compress):
73 TFile(path, "WEB", ftitle, compress)
87 if (!create && !recreate && !update && !read) {
97 fFS = hdfsConnectAsUser(
"default", 0, user);
100 fFS = hdfsConnect(
"default", 0);
104 SysError(
"THDFSFile",
"HDFS client for %s cannot open the filesystem",
109 if (create || update || recreate) {
110 Int_t mode = O_RDWR | O_CREAT;
111 if (recreate) mode |= O_TRUNC;
114 fD = SysOpen(path, mode, 0644);
116 fD = SysOpen(path, mode |
O_BINARY, S_IREAD | S_IWRITE);
119 SysError(
"THDFSFile",
"file %s can not be opened", path);
125 fD = SysOpen(path, O_RDONLY, 0644);
127 fD = SysOpen(path, O_RDONLY |
O_BINARY, S_IREAD | S_IWRITE);
130 SysError(
"THDFSFile",
"file %s can not be opened for reading", path);
136 Init(create || recreate);
185 if (whence == SEEK_SET)
187 else if (whence == SEEK_CUR)
189 else if (whence == SEEK_END) {
191 SysError(
"THDFSFile",
"Unable to seek past end of file");
195 hdfsFileInfo *info = hdfsGetPathInfo((hdfsFS)
fFS,
fPath);
200 SysError(
"THDFSFile",
"Unable to seek to end of file");
206 SysError(
"THDFSFile",
"Unknown whence!");
221 size_t path_size = strlen(file);
222 fPath =
new char[path_size+1];
224 SysError(
"THDFSFile",
"Unable to allocate memory for path.");
226 strlcpy(
fPath, file,path_size+1);
227 if ((
fHdfsFH = hdfsOpenFile((hdfsFS)
fFS,
fPath, flags, 0, 0, 0)) == 0) {
228 SysError(
"THDFSFile",
"Unable to open file %s in HDFS", pathname);
261 hdfsFileInfo *info = hdfsGetPathInfo((hdfsFS)
fFS,
fPath);
265 if (info->mKind == kObjectKindFile)
267 else if (info->mKind == kObjectKindDirectory)
269 *modtime = info->mLastMod;
317 fFH = hdfsConnectAsUser(
"default", 0, user);
320 fFH = hdfsConnect(
"default", 0);
324 SysError(
"THDFSSystem",
"HDFS client cannot open the filesystem");
345 Error(
"MakeDirectory",
"No filesystem handle (should never happen)");
350 return hdfsCreateDirectory((hdfsFS)
fFH, path);
364 Error(
"OpenDirectory",
"No filesystem handle (should never happen)");
376 hdfsFileInfo *
dir = 0;
377 if ((dir = hdfsGetPathInfo((hdfsFS)
fFH, path)) == 0) {
380 if (dir->mKind != kObjectKindDirectory) {
398 Error(
"FreeDirectory",
"No filesystem handle (should never happen)");
402 Error(
"FreeDirectory",
"invalid directory pointer (should never happen)");
419 Error(
"GetDirEntry",
"No filesystem handle (should never happen)");
423 Error(
"GetDirEntry",
"invalid directory pointer (should never happen)");
427 Error(
"GetDirEntry",
"Passed an invalid directory pointer.");
435 hdfsFileInfo *fileInfo = ((hdfsFileInfo *)dirp) +
fDirCtr;
439 tempUrl.
SetUrl(
"hdfs:///");
457 Error(
"GetPathInfo",
"No filesystem handle (should never happen)");
460 hdfsFileInfo *fileInfo = hdfsGetPathInfo((hdfsFS)
fFH, path);
467 buf.
fMode = fileInfo->mPermissions;
470 buf.
fSize = fileInfo->mSize;
471 buf.
fMtime = fileInfo->mLastAccess;
488 Error(
"AccessPathName",
"No filesystem handle (should never happen)");
492 if (hdfsExists((hdfsFS)
fFH, path) == 0)
505 Error(
"Unlink",
"No filesystem handle (should never happen)");
510 return hdfsDelete((hdfsFS)
fFH, path, 1);
void SetFile(const char *file)
void * fDirp
Pointer to the array of file information.
double read(const std::string &file_name)
reading
Int_t SysClose(Int_t fd)
Close the file in HDFS.
Int_t SysSync(Int_t fd)
Sync remaining data to disk; Not supported by HDFS.
Bool_t AccessPathName(const char *path, EAccessMode mode)
Returns FALSE if one can access a file using the specified access mode.
void * OpenDirectory(const char *name)
Open a directory via hdfs.
virtual ULong_t Hash() const
Return hash value for this object.
This class represents a WWW compatible URL.
static const Bool_t R__HDFS_ALLOW_CHANGES
void SetUrl(const char *url, Bool_t defaultIsFile=kFALSE)
Parse url character string and split in its different subcomponents.
void * fFS
HDFS user handle.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
virtual ~THDFSFile()
Close and clean-up HDFS file.
Int_t SysStat(Int_t fd, Long_t *id, Long64_t *size, Long_t *flags, Long_t *modtime)
Perform a stat on the HDFS file; see TFile::SysStat().
Int_t Unlink(const char *path)
Unlink, i.e.
void FreeDirectory(void *dirp)
Free directory via httpd.
void ResetErrno() const
ResetErrno; simply calls TSystem::ResetErrno().
void SysError(const char *location, const char *msgfmt,...)
ClassImp(THDFSFile) THDFSFile
Usual Constructor. See the TFile constructor for details.
void Init(TClassEdit::TInterpreterLookupHelper *helper)
Long64_t fSysOffset
Seek offset in file.
std::vector< std::vector< double > > Data
virtual UserGroup_t * GetUserInfo(Int_t uid)
Returns all user info in the UserGroup_t structure.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Reads and writes its data via the HDFS protocols.
R__EXTERN TSystem * gSystem
static void update(gsl_integration_workspace *workspace, double a1, double b1, double area1, double error1, double a2, double b2, double area2, double error2)
Directory handler for HDFS (THDFSFile).
Int_t fDirCtr
The current position in the fDirp array.
void * fHdfsFH
HDFS file handle.
Int_t SysOpen(const char *pathname, Int_t flags, UInt_t mode)
Open a file in HDFS.
HelperImpl< VC_IMPL > Helper
const char * GetUrl(Bool_t withDeflt=kFALSE) const
Return full URL.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Long64_t SysSeek(Int_t fd, Long64_t offset, Int_t whence)
Seek to a specified position in the file.
virtual Int_t GetGid(const char *group=0)
Returns the group's id. If group = 0, returns current user's group.
char * fPath
HDFS path name.
virtual Int_t GetUid(const char *user=0)
Returns the user's id. If user = 0, returns current user's id.
Int_t MakeDirectory(const char *name)
Make a directory.
Int_t GetPathInfo(const char *path, FileStat_t &buf)
Get info about a file.
TUrl * fUrlp
Pointer to the array of directory content URLs.
const char * GetDirEntry(void *dirp)
Get directory entry via httpd. Returns 0 in case no more entries.
Int_t SysRead(Int_t fd, void *buf, Int_t len)
Read specified number of bytes from current offset into the buffer.
void * fFH
HDFS filesystem handle.
static void ResetErrno()
Static function resetting system error number.
Int_t fDirEntries
The number of entries in the fDirp array.
void SetErrorStr(const char *errstr)
Set the system error string.
Abstract base class defining a generic interface to the underlying Operating System.
Int_t SysWrite(Int_t fd, const void *buf, Int_t len)
Write a buffer into the file; this is not supported currently.
const char * GetFile() const