ATLAS Offline Software
Loading...
Searching...
No Matches
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
12class XrdPosixCallBack;
14public:
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
25
30
32{
33 return m_pfd != 0;
34}
35
37{
38//xrd eof??
39 return false;
40}
41
42// cppcheck-suppress passedByValue; interface defined in EventStorage.
43bool fReadXRootD::fileExists(std::string fName) const
44{
45 int pfd = XrdPosixXrootd::Open(fName.c_str(), O_RDONLY);
46 if(pfd == 0) return false;
48 return true;
49}
50
51// cppcheck-suppress passedByValue; interface defined in EventStorage.
52void fReadXRootD::openFile(std::string fName)
53{
54 if(this->isOpen()) this->closeFile();
55 m_pfd = XrdPosixXrootd::Open(fName.c_str(), O_RDONLY);
56}
57
59{
61 m_pfd = 0;
62}
63
64void 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
89{
90 if(this->isOpen()) return XrdPosixXrootd::Lseek(m_pfd, 0, SEEK_CUR);
91 return -1;
92}
93
95{
96 if(this->isOpen()) XrdPosixXrootd::Lseek(m_pfd, (long long)p, SEEK_SET);
97}
98
100{
101 if(this->isOpen()) XrdPosixXrootd::Lseek(m_pfd, (long long)p, SEEK_END);
102}
103
105{
106 fReadXRootD * nfr = new fReadXRootD();
107 return nfr;
108}
109
110extern "C" {
111 fRead * fReadFactory()
112 {
113 fReadXRootD * nfr = new fReadXRootD();
114 return nfr;
115 }
116}
static size_t Read(int fildes, void *buf, size_t nbyte)
static int Close(int fildes)
static off_t Lseek(int fildes, off_t offset, int whence)
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
void openFile(std::string fName)
void closeFile()
bool fileExists(std::string fName) const
void readData(char *buffer, unsigned int sizeBytes)
void setPositionFromEnd(int64_t p)
fRead * newReader() const
int64_t getPosition()
void setPosition(int64_t p)
fRead * fReadFactory()