Skip to content
Snippets Groups Projects
Commit e659e004 authored by Johannes Elmsheuser's avatar Johannes Elmsheuser Committed by Graeme Stewart
Browse files

Tagging ByteStreamStoragePlugins-00-01-03 (ByteStreamStoragePlugins-00-01-03)

	* Add fReadDavix.h, fReadDavix.cxx to support https bytestream reading
	  using the davix library.
	* Tagging as ByteStreamStoragePlugins-00-01-03
parent 52437012
No related branches found
No related tags found
No related merge requests found
# $Id: CMakeLists.txt 756879 2016-06-22 12:09:32Z krasznaa $
# $Id: CMakeLists.txt 780174 2016-10-25 07:53:15Z elmsheus $
################################################################################
# Package: ByteStreamStoragePlugins
################################################################################
......@@ -12,6 +12,7 @@ find_package( CASTOR COMPONENTS rfio )
find_package( Xrootd COMPONENTS Posix PosixPreload )
find_package( dcache_client )
find_package( tdaq-common COMPONENTS ers )
find_package( Davix )
# Make sure that libraries are linked correctly:
atlas_disable_as_needed()
......@@ -42,3 +43,11 @@ atlas_add_library( fReaddCache
${DCACHE_CLIENT_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
PRIVATE_LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} ${DCACHE_CLIENT_LIBRARIES}
${Boost_LIBRARIES} )
atlas_add_library( fReadDavix
src/fReadDavix.h src/fReadDavix.cxx
NO_PUBLIC_HEADERS
PRIVATE_INCLUDE_DIRS ${TDAQ-COMMON_INCLUDE_DIRS}
${DAVIX_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
PRIVATE_LINK_LIBRARIES ${TDAQ-COMMON_LIBRARIES} ${DAVIX_LIBRARIES}
${Boost_LIBRARIES} )
/*
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;
fOffset = 0;
davixParam = new Davix::RequestParams();
err = NULL;
pos = new Davix::DavPosix(&c);
//pos = &c;
// enableGridMode
const char *env_var = NULL;
if( ( env_var = std::getenv("X509_CERT_DIR")) == NULL){
env_var = "/etc/grid-security/certificates/";
}
davixParam->addCertificateAuthorityPath(env_var);
davixParam->setTransparentRedirectionSupport(true);
cert = new Davix::X509Credential();
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 = pos->open(davixParam, fName.c_str(), O_RDONLY, &err2);
if(pfd == 0) return false;
pos->close(pfd, &err2);
return true;
}
void fReadDavix::openFile(std::string fName)
{
if(this->isOpen()) this->closeFile();
fd = pos->open(davixParam, fName.c_str(), O_RDONLY, &err);
fOffset = 0;
m_pfd = 1;
}
void fReadDavix::closeFile()
{
if(m_pfd != 0) pos->close(fd, &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 = pos->pread(fd, buffer, sizeBytes, fOffset, &err);
if (ret < 0) {
std::stringstream mystream;
mystream << "fReadDavix::readData: can not read data with davix " << err->getErrMsg().c_str() << " " << err->getStatus();
Davix::DavixError::clearError(&err);
EventStorage::ReadingIssue ci(ERS_HERE, mystream.str().c_str());
ers::warning(ci);
return;
} else {
fOffset += 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 fOffset;
return -1;
}
void fReadDavix::setPosition(int64_t p)
{
if(this->isOpen()) fOffset = p;
}
void fReadDavix::setPositionFromEnd(int64_t p)
{
dav_off_t ret;
if(this->isOpen()) {
ret = pos->lseek64(fd, p, SEEK_END, &err);
fOffset = ret;
}
}
fRead * fReadDavix::newReader() const
{
fReadDavix * nfr = new fReadDavix();
return (fRead *)nfr;
}
extern "C" {
fRead * fReadFactory()
{
fReadDavix * nfr = new fReadDavix();
return (fRead *)nfr;
}
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef FREADDAVIX_H
#define FREADDAVIX_H
#include "EventStorage/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
int64_t fOffset;
Davix::Context c;
Davix::RequestParams *davixParam;
Davix::DavixError* err;
Davix::DavPosix *pos;
Davix::X509Credential *cert;
DAVIX_FD* fd;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment