#include <LStoreFile.h>
Classes | |
class | MutexWrapper |
Public Member Functions | |
virtual void | abort (void) |
virtual void | close (void) |
virtual void | create (const std::string &name, bool exclusive=false, int perms=0666) |
virtual void | create (const char *name, bool exclusive=false, int perms=0666) |
LStoreFile (void *fd) | |
LStoreFile (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666) | |
LStoreFile (const char *name, int flags=IOFlags::OpenRead, int perms=0666) | |
LStoreFile (void) | |
virtual void | open (const char *name, int flags=IOFlags::OpenRead, int perms=0666) |
virtual void | open (const std::string &name, int flags=IOFlags::OpenRead, int perms=0666) |
virtual IOOffset | position (IOOffset offset, Relative whence=SET) |
virtual IOSize | read (void *into, IOSize n) |
virtual void | resize (IOOffset size) |
virtual IOSize | write (const void *from, IOSize n) |
~LStoreFile (void) | |
Static Public Attributes | |
static pthread_mutex_t | m_dlopen_lock = PTHREAD_MUTEX_INITIALIZER |
Private Member Functions | |
void | closeLibrary () |
void | loadLibrary () |
Private Attributes | |
bool | m_close |
void * | m_fd |
bool | m_is_loaded |
void * | m_library_handle |
std::string | m_name |
int32_t(* | redd_close )(void *) |
int32_t(* | redd_errno )() |
int32_t(* | redd_init )() |
int64_t(* | redd_lseek )(void *, int64_t, uint32_t) |
void *(* | redd_open )(const char *, int32_t, int32_t) |
int64_t(* | redd_read )(void *, char *, int64_t) |
const std::string &(* | redd_strerror )() |
int32_t(* | redd_term )() |
int64_t(* | redd_write )(void *, const char *, int64_t) |
Definition at line 8 of file LStoreFile.h.
LStoreFile::LStoreFile | ( | void | ) |
Definition at line 18 of file LStoreFile.cc.
References loadLibrary().
: m_fd (0), m_close (false), m_name(), m_library_handle(0), m_is_loaded(false), redd_init(0), redd_read(0), redd_close(0), redd_lseek(0), redd_open(0), redd_write(0), redd_term(0), redd_errno(0), redd_strerror(0) { loadLibrary(); }
LStoreFile::LStoreFile | ( | void * | fd | ) |
Definition at line 37 of file LStoreFile.cc.
References loadLibrary().
: m_fd (fd), m_close (true), m_name(), m_library_handle(0), m_is_loaded(false), redd_init(0), redd_read(0), redd_close(0), redd_lseek(0), redd_open(0), redd_write(0), redd_term(0), redd_errno(0), redd_strerror(0) { loadLibrary(); }
LStoreFile::LStoreFile | ( | const char * | name, |
int | flags = IOFlags::OpenRead , |
||
int | perms = 0666 |
||
) |
Definition at line 56 of file LStoreFile.cc.
References loadLibrary(), and open().
: m_fd (NULL), m_close (false), m_is_loaded(false) { loadLibrary(); open (name, flags, perms); }
LStoreFile::LStoreFile | ( | const std::string & | name, |
int | flags = IOFlags::OpenRead , |
||
int | perms = 0666 |
||
) |
Definition at line 65 of file LStoreFile.cc.
References flags, loadLibrary(), and open().
: m_fd (NULL), m_close (false), m_is_loaded(false) { loadLibrary(); open (name.c_str (), flags, perms); }
LStoreFile::~LStoreFile | ( | void | ) |
Definition at line 74 of file LStoreFile.cc.
References closeLibrary(), m_close, and m_name.
{ if (m_close) edm::LogError("LStoreFileError") << "Destructor called on LStore file '" << m_name << "' but the file is still open"; closeLibrary(); }
void LStoreFile::abort | ( | void | ) | [virtual] |
void LStoreFile::close | ( | void | ) | [virtual] |
Reimplemented from Storage.
Definition at line 253 of file LStoreFile.cc.
References m_close, m_fd, m_name, NULL, redd_close, and redd_errno.
Referenced by open().
{ if (m_fd == NULL) { edm::LogError("LStoreFileError") << "LStoreFile::close(name='" << m_name << "') called but the file is not open"; m_close = false; return; } edm::LogInfo("LStoreFile::close()") << "closing " << m_name << std::endl; if ((*redd_close) (m_fd) == -1) edm::LogWarning("LStoreFileWarning") << "redd_close(name='" << m_name << "') failed with error '" << (*redd_strerror) () << "' (redd_errno=" << (*redd_errno)() << ")"; m_close = false; m_fd = NULL; // Caused hang. Will be added back after problem is fixed. // edm::LogInfo("LStoreFileInfo") << "Closed " << m_name; }
void LStoreFile::closeLibrary | ( | ) | [private] |
Definition at line 135 of file LStoreFile.cc.
References alignCSCRings::e, Exception, m_dlopen_lock, m_is_loaded, m_library_handle, NULL, and redd_term.
Referenced by ~LStoreFile().
{ try { LStoreFile::MutexWrapper lockObj( & this->m_dlopen_lock ); // What is the correct idiom for propagating error messages // in functions that are exclusively called in destructors? // Seriously. I have no idea // melo if ( m_is_loaded ) { if ( (*redd_term)() ) { throw cms::Exception("LStoreFile::closeLibrary()") << "Error in redd_term: " << (*redd_strerror)(); } } if ( m_library_handle != NULL ) { if ( dlclose( m_library_handle ) ) { throw cms::Exception("LStoreFile::closeLibrary()") << "Error on dlclose(): " << dlerror(); } } } catch (cms::Exception & e) { edm::LogError("LStoreFileError") << "LStoreFile had an error in its destructor: " << e; } m_is_loaded = false; }
void LStoreFile::create | ( | const std::string & | name, |
bool | exclusive = false , |
||
int | perms = 0666 |
||
) | [virtual] |
Definition at line 176 of file LStoreFile.cc.
References open(), IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.
{ open (name.c_str (), (IOFlags::OpenCreate | IOFlags::OpenWrite | IOFlags::OpenTruncate | (exclusive ? IOFlags::OpenExclusive : 0)), perms); }
void LStoreFile::create | ( | const char * | name, |
bool | exclusive = false , |
||
int | perms = 0666 |
||
) | [virtual] |
Definition at line 165 of file LStoreFile.cc.
References open(), IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenTruncate, and IOFlags::OpenWrite.
{ open (name, (IOFlags::OpenCreate | IOFlags::OpenWrite | IOFlags::OpenTruncate | (exclusive ? IOFlags::OpenExclusive : 0)), perms); }
void LStoreFile::loadLibrary | ( | ) | [private] |
Definition at line 99 of file LStoreFile.cc.
References Exception, m_dlopen_lock, m_is_loaded, m_library_handle, NULL, redd_errno, redd_init, REDD_LOAD_SYMBOL, redd_lseek, redd_open, redd_read, redd_strerror, redd_term, and redd_write.
Referenced by LStoreFile().
{ edm::LogError("LStoreFile::loadLibrary()") << "Loading library\n"; LStoreFile::MutexWrapper lockObj( & this->m_dlopen_lock ); // until ACCRE removes the java dependency from their client libs, // we'll dlopen() them so they don't need to be brought along with cmssw // if you're running LStore at your site, you will have the libs anyway // TODO add wrappers to make this work in OSX as well (CMSSW's getting ported?) // TODO should be easy, just need to know the "proper" way to do #if OSX // -Melo m_library_handle = dlopen("libreddnet.so", RTLD_LAZY); if (m_library_handle == NULL) { throw cms::Exception("LStoreFile::loadLibrary()") << "Can't dlopen() LStore libraries: " << dlerror(); } char * retval = NULL; // Explicitly state the size of these values, keeps weird 64/32 bit stuff away REDD_LOAD_SYMBOL( redd_init, int32_t(*)()); REDD_LOAD_SYMBOL( redd_read, int64_t(*)(void *, char*, int64_t)); REDD_LOAD_SYMBOL( redd_lseek, int64_t(*)(void*, int64_t, uint32_t)); REDD_LOAD_SYMBOL( redd_open, void*(*)(const char*,int,int)); REDD_LOAD_SYMBOL( redd_write, int64_t(*)(void *, const char *, int64_t)); REDD_LOAD_SYMBOL( redd_term, int32_t(*)()); REDD_LOAD_SYMBOL( redd_errno, int32_t(*)()); REDD_LOAD_SYMBOL( redd_strerror, const std::string & (*)()); if ( (*redd_init)() ) { throw cms::Exception("LStoreFile::loadLibrary()") << "Error in redd_init: " << (*redd_strerror)(); } m_is_loaded = true; }
void LStoreFile::open | ( | const std::string & | name, |
int | flags = IOFlags::OpenRead , |
||
int | perms = 0666 |
||
) | [virtual] |
void LStoreFile::open | ( | const char * | name, |
int | flags = IOFlags::OpenRead , |
||
int | perms = 0666 |
||
) | [virtual] |
Definition at line 193 of file LStoreFile.cc.
References close(), Exception, m_close, m_fd, m_name, mergeVDriftHistosByStation::name, NULL, O_NONBLOCK, IOFlags::OpenAppend, IOFlags::OpenCreate, IOFlags::OpenExclusive, IOFlags::OpenNonBlock, IOFlags::OpenRead, IOFlags::OpenTruncate, IOFlags::OpenWrite, redd_errno, and redd_open.
Referenced by create(), LStoreFile(), and open().
{ // Actual open if ((name == 0) || (*name == 0)) throw cms::Exception("LStoreFile::open()") << "Cannot open a file without a name"; if ((flags & (IOFlags::OpenRead | IOFlags::OpenWrite)) == 0) throw cms::Exception("LStoreFile::open()") << "Must open file '" << name << "' at least for read or write"; // If I am already open, close old file first if (m_fd != NULL && m_close) close (); // Translate our flags to system flags int openflags = 0; if ((flags & IOFlags::OpenRead) && (flags & IOFlags::OpenWrite)) openflags |= O_RDWR; else if (flags & IOFlags::OpenRead) openflags |= O_RDONLY; else if (flags & IOFlags::OpenWrite) openflags |= O_WRONLY; if (flags & IOFlags::OpenNonBlock) openflags |= O_NONBLOCK; if (flags & IOFlags::OpenAppend) openflags |= O_APPEND; if (flags & IOFlags::OpenCreate) openflags |= O_CREAT; if (flags & IOFlags::OpenExclusive) openflags |= O_EXCL; if (flags & IOFlags::OpenTruncate) openflags |= O_TRUNC; void * newfd = NULL; if ((newfd = (*redd_open) (name, openflags, perms)) == NULL) throw cms::Exception("LStoreFile::open()") << "redd_open(name='" << name << "', flags=0x" << std::hex << openflags << ", permissions=0" << std::oct << perms << std::dec << ") => error '" << (*redd_strerror)() << "' (redd_errno=" << (*redd_errno)() << ")"; m_name = name; m_fd = newfd; m_close = true; edm::LogInfo("LStoreFileInfo") << "Opened " << m_name; }
Implements Storage.
Definition at line 326 of file LStoreFile.cc.
References Storage::CURRENT, Storage::END, Exception, m_fd, m_name, NULL, redd_errno, redd_lseek, query::result, and Storage::SET.
Referenced by LStoreStorageMaker::check().
{ if (m_fd == NULL) throw cms::Exception("LStoreFile::position()") << "LStoreFile::position() called on a closed file"; if (whence != CURRENT && whence != SET && whence != END) throw cms::Exception("LStoreFile::position()") << "LStoreFile::position() called with incorrect 'whence' parameter"; IOOffset result; uint32_t mywhence = (whence == SET ? SEEK_SET : whence == CURRENT ? SEEK_CUR : SEEK_END); if ((result = (*redd_lseek) (m_fd, (off_t) offset, (uint32_t)mywhence)) == -1) throw cms::Exception("LStoreFile::position()") << "redd_lseek64(name='" << m_name << "', offset=" << offset << ", whence=" << mywhence << ") failed with error '" << (*redd_strerror) () << "' (redd_errno=" << (*redd_errno)() << ")"; return result; }
Read into into at most n number of bytes.
If this is a blocking stream, the call will block until some data can be read, end of input is reached, or an exception is thrown. For a non-blocking stream the available input is returned. If none is available, an exception is thrown.
In | case of error, a #IOError exception is thrown. This includes the situation where the input stream is in non-blocking mode and no input is currently available (FIXME: make this simpler; clarify which exception). |
Implements IOInput.
Definition at line 289 of file LStoreFile.cc.
References run_regression::done, Exception, m_fd, m_name, redd_errno, redd_strerror, and alignCSCRings::s.
{ IOSize done = 0; while (done < n) { ssize_t s = (*redd_read) (m_fd, (char *) into + done, n - done); if (s == -1) throw cms::Exception("LStoreFile::read()") << "redd_read(name='" << m_name << "', n=" << (n-done) << ") failed with error '" << (*redd_strerror)() << "' (redd_errno=" << (*redd_errno)() << ")"; done += s; } return done; }
void LStoreFile::resize | ( | IOOffset | size | ) | [virtual] |
Implements Storage.
Definition at line 348 of file LStoreFile.cc.
References Exception, and m_name.
{ throw cms::Exception("LStoreFile::resize()") << "LStoreFile::resize(name='" << m_name << "') not implemented"; }
Write n bytes of data starting at address from.
In | case of error, an exception is thrown. However if the stream is in non-blocking mode and cannot accept output, it will not throw an exception -- the return value will be less than requested. |
Implements IOOutput.
Definition at line 306 of file LStoreFile.cc.
References run_regression::done, Exception, m_fd, m_name, redd_errno, redd_strerror, and alignCSCRings::s.
{ IOSize done = 0; while (done < n) { ssize_t s = (*redd_write) (m_fd, (const char *) from + done, n - done); if (s == -1) throw cms::Exception("LStoreFile::write()") << "redd_write(name='" << m_name << "', n=" << (n-done) << ") failed with error '" << (*redd_strerror)() << "' (redd_errno=" << (*redd_errno)() << ")"; done += s; } return done; }
bool LStoreFile::m_close [private] |
Definition at line 61 of file LStoreFile.h.
Referenced by abort(), close(), open(), and ~LStoreFile().
pthread_mutex_t LStoreFile::m_dlopen_lock = PTHREAD_MUTEX_INITIALIZER [static] |
Definition at line 50 of file LStoreFile.h.
Referenced by closeLibrary(), and loadLibrary().
void* LStoreFile::m_fd [private] |
Definition at line 60 of file LStoreFile.h.
Referenced by abort(), close(), open(), position(), read(), and write().
bool LStoreFile::m_is_loaded [private] |
Definition at line 64 of file LStoreFile.h.
Referenced by closeLibrary(), and loadLibrary().
void* LStoreFile::m_library_handle [private] |
Definition at line 63 of file LStoreFile.h.
Referenced by closeLibrary(), and loadLibrary().
std::string LStoreFile::m_name [private] |
Definition at line 62 of file LStoreFile.h.
Referenced by close(), open(), position(), read(), resize(), write(), and ~LStoreFile().
int32_t(* LStoreFile::redd_close)(void *) [private] |
Definition at line 71 of file LStoreFile.h.
Referenced by close().
int32_t(* LStoreFile::redd_errno)() [private] |
Definition at line 76 of file LStoreFile.h.
Referenced by close(), loadLibrary(), open(), position(), read(), and write().
int32_t(* LStoreFile::redd_init)() [private] |
Definition at line 69 of file LStoreFile.h.
Referenced by loadLibrary().
int64_t(* LStoreFile::redd_lseek)(void *, int64_t, uint32_t) [private] |
Definition at line 72 of file LStoreFile.h.
Referenced by loadLibrary(), and position().
void*(* LStoreFile::redd_open)(const char *, int32_t, int32_t) [private] |
Definition at line 73 of file LStoreFile.h.
Referenced by loadLibrary(), and open().
int64_t(* LStoreFile::redd_read)(void *, char *, int64_t) [private] |
Definition at line 70 of file LStoreFile.h.
Referenced by loadLibrary().
const std::string&(* LStoreFile::redd_strerror)() [private] |
Definition at line 77 of file LStoreFile.h.
Referenced by loadLibrary(), read(), and write().
int32_t(* LStoreFile::redd_term)() [private] |
Definition at line 75 of file LStoreFile.h.
Referenced by closeLibrary(), and loadLibrary().
int64_t(* LStoreFile::redd_write)(void *, const char *, int64_t) [private] |
Definition at line 74 of file LStoreFile.h.
Referenced by loadLibrary().