CMS 3D CMS Logo

Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes

StorageFactory Class Reference

#include <StorageFactory.h>

List of all members.

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)
Storageopen (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
StoragewrapNonLocalFile (Storage *s, const std::string &proto, const std::string &path, int mode)
 ~StorageFactory (void)

Static Public Member Functions

static StorageFactoryget (void)

Protected Types

typedef std::map< std::string,
StorageMaker * > 
MakerTable

Protected Member Functions

StorageMakergetMaker (const std::string &proto)
StorageMakergetMaker (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

Detailed Description

Definition at line 12 of file StorageFactory.h.


Member Typedef Documentation

typedef std::map<std::string, StorageMaker *> StorageFactory::MakerTable [protected]

Definition at line 66 of file StorageFactory.h.


Member Enumeration Documentation

Enumerator:
CACHE_HINT_APPLICATION 
CACHE_HINT_STORAGE 
CACHE_HINT_LAZY_DOWNLOAD 
CACHE_HINT_AUTO_DETECT 

Definition at line 15 of file StorageFactory.h.

Enumerator:
READ_HINT_UNBUFFERED 
READ_HINT_READAHEAD 
READ_HINT_AUTO 

Definition at line 23 of file StorageFactory.h.


Constructor & Destructor Documentation

StorageFactory::~StorageFactory ( void  )

Definition at line 25 of file StorageFactory.cc.

References i, and m_makers.

{
  for (MakerTable::iterator i = m_makers.begin (); i != m_makers.end (); ++i)
    delete i->second;
}
StorageFactory::StorageFactory ( void  ) [protected]

Member Function Documentation

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 266 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
bool StorageFactory::check ( const std::string &  url,
IOOffset size = 0 
)

Definition at line 217 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]
StorageMaker * StorageFactory::getMaker ( const std::string &  proto) [protected]
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 L1TEmulatorMonitor_cff::p.

{
  size_t p = url.find(':');
  if (p != std::string::npos)
  {
    protocol = url.substr(0,p);
    rest = url.substr(p+1);
  }
  else
  {
    protocol = "file"; 
    rest = url;
  }

  return getMaker (protocol);
}
Storage * StorageFactory::open ( const std::string &  url,
int  mode = IOFlags::OpenRead 
)

Definition at line 155 of file StorageFactory.cc.

References StorageAccount::counter(), Exception, getMaker(), m_accounting, 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)
    {
      throw cms::Exception("StorageFactory::open()")
        << "Failed to open the file '" << url << "' because:\n"
        << err;
    }
  } 
  return ret;
}
StorageFactory::ReadHint StorageFactory::readHint ( void  ) const
void StorageFactory::setCacheHint ( CacheHint  value)

Definition at line 48 of file StorageFactory.cc.

References m_cacheHint, and relativeConstraints::value.

Referenced by TFileAdaptor::TFileAdaptor().

void StorageFactory::setReadHint ( ReadHint  value)

Definition at line 56 of file StorageFactory.cc.

References m_readHint, and relativeConstraints::value.

Referenced by TFileAdaptor::TFileAdaptor().

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 192 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 
)

Member Data Documentation

bool StorageFactory::m_accounting [protected]

Definition at line 77 of file StorageFactory.h.

Referenced by accounting(), check(), enableAccounting(), open(), and stagein().

Definition at line 75 of file StorageFactory.h.

Referenced by cacheHint(), and setCacheHint().

Definition at line 82 of file StorageFactory.h.

Referenced by setTempDir(), and wrapNonLocalFile().

Definition at line 74 of file StorageFactory.h.

Referenced by getMaker(), and ~StorageFactory().

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().

Definition at line 83 of file StorageFactory.h.

Referenced by get().