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