#include <StorageFactory.h>
Public Types | |
enum | CacheHint { CACHE_HINT_APPLICATION, CACHE_HINT_STORAGE, CACHE_HINT_LAZY_DOWNLOAD, CACHE_HINT_AUTO_DETECT } |
enum | ReadHint { READ_HINT_UNBUFFERED, READ_HINT_READAHEAD, READ_HINT_AUTO } |
Public Member Functions | |
bool | accounting (void) const |
void | activateTimeout (const std::string &url) |
CacheHint | cacheHint (void) const |
bool | check (const std::string &url, IOOffset *size=0) |
bool | enableAccounting (bool enabled) |
Storage * | open (const std::string &url, int mode=IOFlags::OpenRead) |
ReadHint | readHint (void) const |
void | setCacheHint (CacheHint value) |
void | setReadHint (ReadHint value) |
void | setTempDir (const std::string &s, double minFreeSpace) |
void | setTimeout (unsigned int timeout) |
void | stagein (const std::string &url) |
std::string | tempDir (void) const |
double | tempMinFree (void) const |
std::string | tempPath (void) const |
unsigned int | timeout (void) const |
Storage * | wrapNonLocalFile (Storage *s, const std::string &proto, const std::string &path, int mode) |
~StorageFactory (void) | |
Static Public Member Functions | |
static StorageFactory * | get (void) |
Protected Types | |
typedef std::map< std::string, StorageMaker * > | MakerTable |
Protected Member Functions | |
StorageMaker * | getMaker (const std::string &proto) |
StorageMaker * | getMaker (const std::string &url, std::string &protocol, std::string &rest) |
StorageFactory (void) | |
Protected Attributes | |
bool | m_accounting |
CacheHint | m_cacheHint |
LocalFileSystem | m_lfs |
MakerTable | m_makers |
ReadHint | m_readHint |
std::string | m_tempdir |
double | m_tempfree |
std::string | m_temppath |
unsigned int | m_timeout |
Static Protected Attributes | |
static StorageFactory | s_instance |
Definition at line 12 of file StorageFactory.h.
typedef std::map<std::string, StorageMaker *> StorageFactory::MakerTable [protected] |
Definition at line 66 of file StorageFactory.h.
CACHE_HINT_APPLICATION | |
CACHE_HINT_STORAGE | |
CACHE_HINT_LAZY_DOWNLOAD | |
CACHE_HINT_AUTO_DETECT |
Definition at line 15 of file StorageFactory.h.
Definition at line 23 of file StorageFactory.h.
StorageFactory::~StorageFactory | ( | void | ) |
StorageFactory::StorageFactory | ( | void | ) | [protected] |
Definition at line 14 of file StorageFactory.cc.
References m_tempfree, m_temppath, and setTempDir().
: m_cacheHint(CACHE_HINT_AUTO_DETECT), m_readHint(READ_HINT_AUTO), m_accounting (false), m_tempfree (4.), // GB m_temppath (".:$TMPDIR"), m_timeout(0U) { setTempDir(m_temppath, m_tempfree); }
bool StorageFactory::accounting | ( | void | ) | const |
Definition at line 44 of file StorageFactory.cc.
References m_accounting.
Referenced by wrapNonLocalFile().
{ return m_accounting; }
void StorageFactory::activateTimeout | ( | const std::string & | url | ) |
Definition at line 268 of file StorageFactory.cc.
References getMaker(), and m_timeout.
Referenced by edm::RootInputFileSequence::RootInputFileSequence().
{ std::string protocol; std::string rest; if (StorageMaker *maker = getMaker (url, protocol, rest)) { maker->setTimeout (m_timeout); } }
StorageFactory::CacheHint StorageFactory::cacheHint | ( | void | ) | const |
Definition at line 52 of file StorageFactory.cc.
References m_cacheHint.
Referenced by RFIOStorageMaker::open(), StormLcgGtStorageMaker::open(), StormStorageMaker::open(), LocalStorageMaker::open(), DCacheStorageMaker::open(), TStorageFactoryFile::ReadBufferAsync(), and wrapNonLocalFile().
{ return m_cacheHint; }
bool StorageFactory::check | ( | const std::string & | url, |
IOOffset * | size = 0 |
||
) |
Definition at line 219 of file StorageFactory.cc.
References StorageAccount::counter(), cms::Exception::explainSelf(), getMaker(), m_accounting, and runTheMatrix::ret.
{ std::string protocol; std::string rest; bool ret = false; boost::shared_ptr<StorageAccount::Stamp> stats; if (StorageMaker *maker = getMaker (url, protocol, rest)) { if (m_accounting) stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "check"))); try { ret = maker->check (protocol, rest, size); if (stats) stats->tick(); } catch (cms::Exception &err) { edm::LogWarning("StorageFactory::check()") << "Existence or size check for the file '" << url << "' failed because:\n" << err.explainSelf(); } } return ret; }
bool StorageFactory::enableAccounting | ( | bool | enabled | ) |
Definition at line 36 of file StorageFactory.cc.
References m_accounting.
Referenced by TFileAdaptor::TFileAdaptor().
{ bool old = m_accounting; m_accounting = enabled; return old; }
StorageFactory * StorageFactory::get | ( | void | ) | [static] |
Definition at line 32 of file StorageFactory.cc.
References s_instance.
Referenced by getMaker(), TStorageFactorySystem::GetPathInfo(), edm::StreamerInputFile::openStreamerFile(), PixelSLinkDataInputSource::PixelSLinkDataInputSource(), TStorageFactoryFile::SysOpen(), and TStorageFactoryFile::TStorageFactoryFile().
{ return &s_instance; }
StorageMaker * StorageFactory::getMaker | ( | const std::string & | proto | ) | [protected] |
Definition at line 124 of file StorageFactory.cc.
References edmplugin::standard::config(), edmplugin::PluginManager::configure(), get(), edmplugin::PluginManager::isAvailable(), and m_makers.
Referenced by activateTimeout(), check(), getMaker(), open(), and stagein().
{ StorageMaker *&instance = m_makers [proto]; if (! edmplugin::PluginManager::isAvailable()) edmplugin::PluginManager::configure(edmplugin::standard::config()); if (! instance) instance = StorageMakerFactory::get()->tryToCreate(proto); return instance; }
StorageMaker * StorageFactory::getMaker | ( | const std::string & | url, |
std::string & | protocol, | ||
std::string & | rest | ||
) | [protected] |
Definition at line 135 of file StorageFactory.cc.
References getMaker(), and AlCaHLTBitMon_ParallelJobs::p.
Storage * StorageFactory::open | ( | const std::string & | url, |
int | mode = IOFlags::OpenRead |
||
) |
Definition at line 155 of file StorageFactory.cc.
References cms::Exception::addAdditionalInfo(), cms::Exception::addContext(), cms::Exception::clearMessage(), StorageAccount::counter(), getMaker(), m_accounting, cms::Exception::message(), and runTheMatrix::ret.
{ std::string protocol; std::string rest; Storage *ret = 0; boost::shared_ptr<StorageAccount::Stamp> stats; if (StorageMaker *maker = getMaker (url, protocol, rest)) { if (m_accounting) stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "open"))); try { if (Storage *storage = maker->open (protocol, rest, mode)) { if (dynamic_cast<LocalCacheFile *>(storage)) protocol = "local-cache"; if (m_accounting) ret = new StorageAccountProxy(protocol, storage); else ret = storage; if (stats) stats->tick(); } } catch (cms::Exception &err) { err.addContext("Calling StorageFactory::open()"); err.addAdditionalInfo(err.message()); err.clearMessage(); err << "Failed to open the file '" << url << "'"; throw; } } return ret; }
StorageFactory::ReadHint StorageFactory::readHint | ( | void | ) | const |
Definition at line 60 of file StorageFactory.cc.
References m_readHint.
Referenced by RFIOStorageMaker::open(), StormLcgGtStorageMaker::open(), StormStorageMaker::open(), LocalStorageMaker::open(), and DCacheStorageMaker::open().
{ return m_readHint; }
void StorageFactory::setCacheHint | ( | CacheHint | value | ) |
Definition at line 48 of file StorageFactory.cc.
References m_cacheHint, and relativeConstraints::value.
Referenced by TFileAdaptor::TFileAdaptor().
{ m_cacheHint = value; }
void StorageFactory::setReadHint | ( | ReadHint | value | ) |
Definition at line 56 of file StorageFactory.cc.
References m_readHint, and relativeConstraints::value.
Referenced by TFileAdaptor::TFileAdaptor().
{ m_readHint = value; }
void StorageFactory::setTempDir | ( | const std::string & | s, |
double | minFreeSpace | ||
) |
Definition at line 72 of file StorageFactory.cc.
References begin, benchmark_cfg::cerr, prof2calltree::count, end, LocalFileSystem::findCachePath(), m_lfs, m_tempdir, m_tempfree, m_temppath, and asciidump::s.
Referenced by StorageFactory(), and TFileAdaptor::TFileAdaptor().
{ #if 0 std::cerr /* edm::LogInfo("StorageFactory") */ << "Considering path '" << s << "', min free space " << minFreeSpace << "GB for temp dir" << std::endl; #endif size_t begin = 0; std::vector<std::string> dirs; dirs.reserve(std::count(s.begin(), s.end(), ':') + 1); while (true) { size_t end = s.find(':', begin); if (end == std::string::npos) { dirs.push_back(s.substr(begin, end)); break; } else { dirs.push_back(s.substr(begin, end - begin)); begin = end+1; } } m_temppath = s; m_tempfree = minFreeSpace; m_tempdir = m_lfs.findCachePath(dirs, minFreeSpace); #if 0 std::cerr /* edm::LogInfo("StorageFactory") */ << "Using '" << m_tempdir << "' for temp dir" << std::endl; #endif }
void StorageFactory::setTimeout | ( | unsigned int | timeout | ) |
Definition at line 64 of file StorageFactory.cc.
References m_timeout, and timeout().
Referenced by TFileAdaptor::TFileAdaptor().
void StorageFactory::stagein | ( | const std::string & | url | ) |
Definition at line 194 of file StorageFactory.cc.
References StorageAccount::counter(), cms::Exception::explainSelf(), getMaker(), and m_accounting.
Referenced by edm::RootInputFileSequence::RootInputFileSequence().
{ std::string protocol; std::string rest; boost::shared_ptr<StorageAccount::Stamp> stats; if (StorageMaker *maker = getMaker (url, protocol, rest)) { if (m_accounting) stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "stagein"))); try { maker->stagein (protocol, rest); if (stats) stats->tick(); } catch (cms::Exception &err) { edm::LogWarning("StorageFactory::stagein()") << "Failed to stage in file '" << url << "' because:\n" << err.explainSelf(); } } }
std::string StorageFactory::tempDir | ( | void | ) | const |
Definition at line 112 of file StorageFactory.cc.
References m_tempdir.
Referenced by HttpStorageMaker::open(), and GsiFTPStorageMaker::open().
{ return m_tempdir; }
double StorageFactory::tempMinFree | ( | void | ) | const |
Definition at line 120 of file StorageFactory.cc.
References m_tempfree.
Referenced by TFileAdaptor::TFileAdaptor().
{ return m_tempfree; }
std::string StorageFactory::tempPath | ( | void | ) | const |
Definition at line 116 of file StorageFactory.cc.
References m_temppath.
Referenced by TFileAdaptor::TFileAdaptor().
{ return m_temppath; }
unsigned int StorageFactory::timeout | ( | void | ) | const |
Definition at line 68 of file StorageFactory.cc.
References m_timeout.
Referenced by setTimeout().
{ return m_timeout; }
Storage * StorageFactory::wrapNonLocalFile | ( | Storage * | s, |
const std::string & | proto, | ||
const std::string & | path, | ||
int | mode | ||
) |
Definition at line 247 of file StorageFactory.cc.
References accounting(), CACHE_HINT_AUTO_DETECT, CACHE_HINT_LAZY_DOWNLOAD, cacheHint(), LocalFileSystem::isLocalPath(), m_lfs, m_tempdir, IOFlags::OpenWrite, and asciidump::s.
Referenced by RFIOStorageMaker::open(), StormLcgGtStorageMaker::open(), StormStorageMaker::open(), LocalStorageMaker::open(), and DCacheStorageMaker::open().
{ StorageFactory::CacheHint hint = cacheHint(); if ((hint == StorageFactory::CACHE_HINT_LAZY_DOWNLOAD || hint == StorageFactory::CACHE_HINT_AUTO_DETECT) && ! (mode & IOFlags::OpenWrite) && ! m_tempdir.empty() && (path.empty() || ! m_lfs.isLocalPath(path))) { if (accounting()) s = new StorageAccountProxy(proto, s); s = new LocalCacheFile(s, m_tempdir); } return s; }
bool StorageFactory::m_accounting [protected] |
Definition at line 77 of file StorageFactory.h.
Referenced by accounting(), check(), enableAccounting(), open(), and stagein().
CacheHint StorageFactory::m_cacheHint [protected] |
Definition at line 75 of file StorageFactory.h.
Referenced by cacheHint(), and setCacheHint().
LocalFileSystem StorageFactory::m_lfs [protected] |
Definition at line 82 of file StorageFactory.h.
Referenced by setTempDir(), and wrapNonLocalFile().
MakerTable StorageFactory::m_makers [protected] |
Definition at line 74 of file StorageFactory.h.
Referenced by getMaker(), and ~StorageFactory().
ReadHint StorageFactory::m_readHint [protected] |
Definition at line 76 of file StorageFactory.h.
Referenced by readHint(), and setReadHint().
std::string StorageFactory::m_tempdir [protected] |
Definition at line 80 of file StorageFactory.h.
Referenced by setTempDir(), tempDir(), and wrapNonLocalFile().
double StorageFactory::m_tempfree [protected] |
Definition at line 78 of file StorageFactory.h.
Referenced by setTempDir(), StorageFactory(), and tempMinFree().
std::string StorageFactory::m_temppath [protected] |
Definition at line 79 of file StorageFactory.h.
Referenced by setTempDir(), StorageFactory(), and tempPath().
unsigned int StorageFactory::m_timeout [protected] |
Definition at line 81 of file StorageFactory.h.
Referenced by activateTimeout(), setTimeout(), and timeout().
StorageFactory StorageFactory::s_instance [static, protected] |
Definition at line 83 of file StorageFactory.h.
Referenced by get().