Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "ers/ers.h"
#include <fcntl.h>
#include "fReadXRootD.h"
#include "EventStorage/EventStorageIssues.h"
// external XRootD functions from ROOT net/xrootd/src/xrootd/src/XrdPosix/XrdPosixXrootd.hh
class XrdPosixCallBack;
class XrdPosixXrootd {
public:
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0);
static int Close(int fildes);
static size_t Read(int fildes, void *buf, size_t nbyte);
static off_t Lseek(int fildes, off_t offset, int whence);
};
fReadXRootD::fReadXRootD()
{
m_pfd = 0;
}
fReadXRootD::~fReadXRootD()
{
this->closeFile();
}
bool fReadXRootD::isOpen()
{
return m_pfd != 0;
}
bool fReadXRootD::isEoF()
{
//xrd eof??
return false;
}
bool fReadXRootD::fileExists(std::string fName) const
{
int pfd = XrdPosixXrootd::Open(fName.c_str(), O_RDONLY);
if(pfd == 0) return false;
XrdPosixXrootd::Close(pfd);
return true;
}
void fReadXRootD::openFile(std::string fName)
{
if(this->isOpen()) this->closeFile();
m_pfd = XrdPosixXrootd::Open(fName.c_str(), O_RDONLY);
}
void fReadXRootD::closeFile()
{
if(m_pfd != 0) XrdPosixXrootd::Close(m_pfd);
m_pfd = 0;
}
void fReadXRootD::readData(char *buffer, unsigned int sizeBytes)
{
if (sizeBytes==0) return;
if(this->isOpen())
{
unsigned int totalRead=0,ntry=0;
while(sizeBytes > totalRead)
{
int ret = XrdPosixXrootd::Read(m_pfd,buffer,sizeBytes);
totalRead += ret; ++ntry;
if(ntry>5) {
std::stringstream mystream;
mystream << "Problem reading from the data file. "
<<"fReadXRootD::readData asked to read "<<sizeBytes
<<" bytes and managed to read only "<<totalRead
<<" bytes.";
EventStorage::ReadingIssue ci(ERS_HERE, mystream.str().c_str());
ers::warning(ci);
return;
}
}
}
}
int64_t fReadXRootD::getPosition()
{
if(this->isOpen()) return XrdPosixXrootd::Lseek(m_pfd, 0, SEEK_CUR);
return -1;
}
void fReadXRootD::setPosition(int64_t p)
{
if(this->isOpen()) XrdPosixXrootd::Lseek(m_pfd, (long long)p, SEEK_SET);
}
void fReadXRootD::setPositionFromEnd(int64_t p)
{
if(this->isOpen()) XrdPosixXrootd::Lseek(m_pfd, (long long)p, SEEK_END);
}
fRead * fReadXRootD::newReader() const
{
fReadXRootD * nfr = new fReadXRootD();
return (fRead *)nfr;
}
extern "C" {
fRead * fReadFactory()
{
fReadXRootD * nfr = new fReadXRootD();
return (fRead *)nfr;
}
}