diff --git a/Event/FaserEventPlugins/CMakeLists.txt b/Event/FaserEventPlugins/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..377c12e1553025d3ba3507b3811379852ea980e2 --- /dev/null +++ b/Event/FaserEventPlugins/CMakeLists.txt @@ -0,0 +1,43 @@ +################################################################################ +# Package: FaserEventsPlugins +################################################################################ + +# Declare the package name: +atlas_subdir( FaserEventsPlugins ) + +# External dependencies: +find_package( tdaq-common COMPONENTS ers EventStorage ) +find_package( Boost COMPONENTS system ) +find_package( Xrootd COMPONENTS Posix PosixPreload ) +find_package( Davix ) + +# Make sure that libraries are linked correctly: +atlas_disable_as_needed() + +atlas_add_library( fReadXRootD + src/fReadXRootD.h src/fReadXRootD.cxx + NO_PUBLIC_HEADERS + PRIVATE_INCLUDE_DIRS FaserEventStorage ${TDAQ-COMMON_INCLUDE_DIRS} + ${XROOTD_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} + PRIVATE_LINK_LIBRARIES FaserEventStorageLib ${TDAQ-COMMON_LIBRARIES} + ${XROOTD_LIBRARIES} ${Boost_LIBRARIES} + PRIVATE_DEFINITIONS -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE + -D_FILE_OFFSET_BITS=64 ) + +atlas_add_library( fReadPlain + src/fReadPlain.h src/fReadPlain.cxx + NO_PUBLIC_HEADERS + PRIVATE_INCLUDE_DIRS FaserEventStorage ${TDAQ-COMMON_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} + PRIVATE_LINK_LIBRARIES FaserEventStorageLib ${TDAQ-COMMON_LIBRARIES} + ${Boost_LIBRARIES}) + +atlas_add_library( fReadDavix + src/fReadDavix.h src/fReadDavix.cxx + NO_PUBLIC_HEADERS + PRIVATE_INCLUDE_DIRS FaserEventStorage ${TDAQ-COMMON_INCLUDE_DIRS} + ${DAVIX_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} + PRIVATE_LINK_LIBRARIES FaserEventStorageLib ${TDAQ-COMMON_LIBRARIES} + ${DAVIX_LIBRARIES} ${Boost_LIBRARIES} ) + + diff --git a/Event/FaserEventPlugins/src/fReadDavix.cxx b/Event/FaserEventPlugins/src/fReadDavix.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9d36e4780d3ec2022a4fb359c11b56f01784c6a2 --- /dev/null +++ b/Event/FaserEventPlugins/src/fReadDavix.cxx @@ -0,0 +1,163 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "ers/ers.h" +#include <fcntl.h> + +#include "fReadDavix.h" +#include "EventStorage/EventStorageIssues.h" + +// http://dmc-docs.web.cern.ch/dmc-docs/docs/davix-epel/html/lib-examples.html +// https://root.cern.ch/doc/master/TDavixFile_8cxx_source.html + +static int TDavixFile_http_authn_cert_X509(void *userdata, const Davix::SessionInfo &info, Davix::X509Credential *cert, Davix::DavixError **err) { + + (void) userdata; // keep quiete compilation warnings + (void) info; + // user proxy + std::string ucert, ukey; + if ( std::getenv("X509_USER_PROXY")) { + ucert = ukey = std::getenv("X509_USER_PROXY"); + } + + if (ucert.empty() || ukey.empty()) { + Davix::DavixError::setupError(err, "fReadDavix.cxx", + Davix::StatusCode::AuthentificationError, + "Could not set the user's proxy or certificate"); + return -1; + } + return cert->loadFromFilePEM(ukey, ucert, "", err); +} + +fReadDavix::fReadDavix() +{ + m_pfd = 0; + m_offset = 0; + m_fd = nullptr; + + m_davixParam = new Davix::RequestParams(); + m_err = NULL; + m_pos = new Davix::DavPosix(&m_c); + //m_pos = &m_c; + + + // enableGridMode + const char *env_var = NULL; + if( ( env_var = std::getenv("X509_CERT_DIR")) == NULL){ + env_var = "/etc/grid-security/certificates/"; + } + m_davixParam->addCertificateAuthorityPath(env_var); + m_davixParam->setTransparentRedirectionSupport(true); + m_cert = new Davix::X509Credential(); + m_davixParam->setClientCertCallbackX509(&TDavixFile_http_authn_cert_X509, NULL); + +} + +fReadDavix::~fReadDavix() +{ + this->closeFile(); +} + +bool fReadDavix::isOpen() +{ + return m_pfd != 0; +} + +bool fReadDavix::isEoF() +{ + + return false; +} + +bool fReadDavix::fileExists(std::string fName) const +{ + Davix::DavixError* err2 = NULL; + DAVIX_FD* pfd = m_pos->open(m_davixParam, fName.c_str(), O_RDONLY, &err2); + if(pfd == 0) return false; + m_pos->close(pfd, &err2); + return true; +} + +void fReadDavix::openFile(std::string fName) +{ + if(this->isOpen()) this->closeFile(); + m_fd = m_pos->open(m_davixParam, fName.c_str(), O_RDONLY, &m_err); + m_offset = 0; + m_pfd = 1; +} + +void fReadDavix::closeFile() +{ + if(m_pfd != 0) m_pos->close(m_fd, &m_err); + m_pfd = 0; +} + +void fReadDavix::readData(char *buffer, unsigned int sizeBytes) +{ + if (sizeBytes==0) return; + if(this->isOpen()) + { + unsigned int totalRead=0,ntry=0; + while(sizeBytes > totalRead) + { + ssize_t ret = m_pos->pread(m_fd, buffer, sizeBytes, m_offset, &m_err); + if (ret < 0) { + std::stringstream mystream; + mystream << "fReadDavix::readData: can not read data with davix " << m_err->getErrMsg().c_str() << " " << m_err->getStatus(); + Davix::DavixError::clearError(&m_err); + EventStorage::ReadingIssue ci(ERS_HERE, mystream.str().c_str()); + ers::warning(ci); + return; + } else { + m_offset += ret; + } + totalRead += ret; ++ntry; + if(ntry>5) { + std::stringstream mystream; + mystream << "Problem reading from the data file. " + <<"fReadDavix::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 fReadDavix::getPosition() +{ + if(this->isOpen()) return m_offset; + + return -1; +} + +void fReadDavix::setPosition(int64_t p) +{ + if(this->isOpen()) m_offset = p; +} + +void fReadDavix::setPositionFromEnd(int64_t p) +{ + dav_off_t ret; + if(this->isOpen()) { + ret = m_pos->lseek64(m_fd, p, SEEK_END, &m_err); + m_offset = ret; + } +} + +fRead * fReadDavix::newReader() const +{ + fReadDavix * nfr = new fReadDavix(); + return (fRead *)nfr; +} + +extern "C" { + fRead * fReadFactory() + { + fReadDavix * nfr = new fReadDavix(); + return (fRead *)nfr; + } +} diff --git a/Event/FaserEventPlugins/src/fReadDavix.h b/Event/FaserEventPlugins/src/fReadDavix.h new file mode 100644 index 0000000000000000000000000000000000000000..316d519ffc6a1504b267ba8a9d4d6d19b6b6a020 --- /dev/null +++ b/Event/FaserEventPlugins/src/fReadDavix.h @@ -0,0 +1,40 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef FREADDAVIX_H +#define FREADDAVIX_H + +#include "FaserEventStorage/fRead.h" +#include "davix.hpp" + +class fReadDavix : public fRead +{ + public: + fReadDavix(); + ~fReadDavix(); + + bool isOpen(); + bool isEoF(); + bool fileExists(std::string fName) const; + void openFile(std::string fName); + void closeFile(); + void readData(char *buffer, unsigned int sizeBytes); + int64_t getPosition(); + void setPosition(int64_t p); + void setPositionFromEnd(int64_t p); + fRead * newReader() const; + + private: + int m_pfd; // current file, used as bool to check if file is open + int64_t m_offset; + Davix::Context m_c; + Davix::RequestParams *m_davixParam; + Davix::DavixError* m_err; + Davix::DavPosix *m_pos; + Davix::X509Credential *m_cert; + DAVIX_FD* m_fd; // davix pointer to current file + +}; + +#endif diff --git a/Event/FaserEventStorage/src/fReadPlain.cxx b/Event/FaserEventPlugins/src/fReadPlain.cxx similarity index 100% rename from Event/FaserEventStorage/src/fReadPlain.cxx rename to Event/FaserEventPlugins/src/fReadPlain.cxx diff --git a/Event/FaserEventStorage/src/fReadPlain.h b/Event/FaserEventPlugins/src/fReadPlain.h similarity index 100% rename from Event/FaserEventStorage/src/fReadPlain.h rename to Event/FaserEventPlugins/src/fReadPlain.h diff --git a/Event/FaserEventPlugins/src/fReadXRootD.cxx b/Event/FaserEventPlugins/src/fReadXRootD.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f0e646127d3a27c8ed0f244cb42648326488b41d --- /dev/null +++ b/Event/FaserEventPlugins/src/fReadXRootD.cxx @@ -0,0 +1,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; + } +} diff --git a/Event/FaserEventPlugins/src/fReadXRootD.h b/Event/FaserEventPlugins/src/fReadXRootD.h new file mode 100644 index 0000000000000000000000000000000000000000..4d17ab197cfa4391711202d793a46853582da15b --- /dev/null +++ b/Event/FaserEventPlugins/src/fReadXRootD.h @@ -0,0 +1,31 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef FREADXROOTD_H +#define FREADXROOTD_H + +#include "FaserEventStorage/fRead.h" + +class fReadXRootD : public fRead +{ + public: + fReadXRootD(); + ~fReadXRootD(); + + bool isOpen(); + bool isEoF(); + bool fileExists(std::string fName) const; + void openFile(std::string fName); + void closeFile(); + void readData(char *buffer, unsigned int sizeBytes); + int64_t getPosition(); + void setPosition(int64_t p); + void setPositionFromEnd(int64_t p); + fRead * newReader() const; + + private: + int m_pfd; // current file +}; + +#endif diff --git a/Event/FaserEventStorage/CMakeLists.txt b/Event/FaserEventStorage/CMakeLists.txt index e2344ff4230053b5f3300d6a1784eb30497f2aca..f55d90c6efc96396ae41b40635f923c91a1d3792 100644 --- a/Event/FaserEventStorage/CMakeLists.txt +++ b/Event/FaserEventStorage/CMakeLists.txt @@ -16,11 +16,12 @@ atlas_add_library( FaserEventStorageLib LINK_LIBRARIES ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${TDAQ-COMMON_LIBRARIES} EventFormats ) + # atlas_add_library(fReadPlain -# src/fReadPlain.h src/fReadPlain.cxx -# PUBLIC_HEADERS src -# INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${TDAQ-COMMON_INCLUDE_DIRS} -# LINK_LIBRARIES ${Boost_LIBRARIES} ${TDAQ-COMMON_LIBRARIES} -rdynamic) +# src/fReadPlain.h src/fReadPlain.cxx +# NO_PUBLIC_HEADERS +# PRIVATE_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${TDAQ-COMMON_INCLUDE_DIRS} +# PRIVATE_LINK_LIBRARIES ${Boost_LIBRARIES} ${TDAQ-COMMON_LIBRARIES} -rdynamic) # Install files from the package: #atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) diff --git a/Event/FaserEventStorage/src/pickFaserDataReader.cxx b/Event/FaserEventStorage/src/pickFaserDataReader.cxx index e800e22aa88fe4358dfa4562d051747a12677769..72b95ec8b4e586a2243018e53a46e0f90a44858d 100644 --- a/Event/FaserEventStorage/src/pickFaserDataReader.cxx +++ b/Event/FaserEventStorage/src/pickFaserDataReader.cxx @@ -10,40 +10,28 @@ DataReader * pickFaserDataReader(std::string fileName) { ERS_DEBUG(1,"pickFaserDataReader(file) with file name "<<fileName); std::vector<std::string> fReadLibs; - fReadLibs.push_back("fReadPlain"); // Just use plain - /* // Control plugins libraries via file name prefixes. // Take the prefixes away from the name, in most cases anyway. - if(fileName.find("rfio:")==0) { - fileName.erase(0,std::string("rfio:").size()); - fReadLibs.push_back("fReadCastor"); - } else if(fileName.find("dcache:")==0) { - fileName.erase(0,std::string("dcache:").size()); - fReadLibs.push_back("fReaddCache"); - } else if(fileName.find("dcap:")==0) { - // Leave the prefix in the file name in this case. - fReadLibs.push_back("fReaddCache"); - } else if(fileName.find("root:")==0) { + + if(fileName.find("root:")==0) { // Leave the prefix in the file name in this case. fReadLibs.push_back("fReadXRootD"); + } else if(fileName.find("disk:")==0) { + fileName.erase(0,std::string("disk:").size()); + fReadLibs.push_back("fReadPlain"); } else if(fileName.find("https:")==0) { // Leave the prefix in the file name in this case. fReadLibs.push_back("fReadDavix"); } else if(fileName.find("davs:")==0) { // Leave the prefix in the file name in this case. fReadLibs.push_back("fReadDavix"); - } else if(fileName.find("disk:")==0) { - fileName.erase(0,std::string("disk:").size()); - fReadLibs.push_back("fReadPlain"); } else { // by defaul all will be tried fReadLibs.push_back("fReadPlain"); - fReadLibs.push_back("fReadCastor"); fReadLibs.push_back("fReadXRootD"); fReadLibs.push_back("fReadDavix"); - fReadLibs.push_back("fReaddCache"); } - */ + ERS_DEBUG(2,"After parsing the file name is "<<fileName); ERS_DEBUG(2,"Number of fRead plugins to try is "<<fReadLibs.size());