ATLAS Offline Software
fReadXRootD.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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;
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 
22 {
23  m_pfd = 0;
24 }
25 
27 {
28  this->closeFile();
29 }
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.
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;
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 
59 {
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 
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 
104 fRead * fReadXRootD::newReader() const
105 {
106  fReadXRootD * nfr = new fReadXRootD();
107  return (fRead *)nfr;
108 }
109 
110 extern "C" {
111  fRead * fReadFactory()
112  {
113  fReadXRootD * nfr = new fReadXRootD();
114  return (fRead *)nfr;
115  }
116 }
XrdPosixXrootd::Lseek
static off_t Lseek(int fildes, off_t offset, int whence)
fReadXRootD::openFile
void openFile(std::string fName)
Definition: fReadXRootD.cxx:52
XrdPosixXrootd
Definition: fReadXRootD.cxx:13
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
fReadXRootD::isOpen
bool isOpen()
Definition: fReadXRootD.cxx:31
fReadXRootD::~fReadXRootD
~fReadXRootD()
Definition: fReadXRootD.cxx:26
rootconvert.fName
string fName
Definition: rootconvert.py:5
XrdPosixXrootd::Read
static size_t Read(int fildes, void *buf, size_t nbyte)
fReadFactory
fRead * fReadFactory()
Definition: fReadXRootD.cxx:111
fReadXRootD::setPosition
void setPosition(int64_t p)
Definition: fReadXRootD.cxx:94
XrdPosixXrootd::Open
static int Open(const char *path, int oflag, mode_t mode=0, XrdPosixCallBack *cbP=0)
fReadXRootD.h
fReadXRootD::readData
void readData(char *buffer, unsigned int sizeBytes)
Definition: fReadXRootD.cxx:64
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
fReadXRootD
Definition: fReadXRootD.h:11
Preparation.mode
mode
Definition: Preparation.py:94
fReadXRootD::newReader
fRead * newReader() const
Definition: fReadXRootD.cxx:104
fReadXRootD::setPositionFromEnd
void setPositionFromEnd(int64_t p)
Definition: fReadXRootD.cxx:99
fReadXRootD::getPosition
int64_t getPosition()
Definition: fReadXRootD.cxx:88
fReadXRootD::closeFile
void closeFile()
Definition: fReadXRootD.cxx:58
fReadXRootD::isEoF
bool isEoF()
Definition: fReadXRootD.cxx:36
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
XrdPosixXrootd::Close
static int Close(int fildes)
fReadXRootD::m_pfd
int m_pfd
Definition: fReadXRootD.h:28
fReadXRootD::fReadXRootD
fReadXRootD()
Definition: fReadXRootD.cxx:21
fReadXRootD::fileExists
bool fileExists(std::string fName) const
Definition: fReadXRootD.cxx:43