CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | 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>

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)
 
unsigned int debugLevel (void) const
 
bool enableAccounting (bool enabled)
 
Storageopen (const std::string &url, int mode=IOFlags::OpenRead)
 
ReadHint readHint (void) const
 
void setCacheHint (CacheHint value)
 
void setDebugLevel (unsigned int level)
 
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
 
unsigned int m_debugLevel
 
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 69 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 26 of file StorageFactory.cc.

References i, and m_makers.

27 {
28  for (MakerTable::iterator i = m_makers.begin (); i != m_makers.end (); ++i)
29  delete i->second;
30 }
int i
Definition: DBlmapReader.cc:9
MakerTable m_makers
StorageFactory::StorageFactory ( void  )
protected

Definition at line 14 of file StorageFactory.cc.

References m_tempfree, m_temppath, and setTempDir().

17  m_accounting (false),
18  m_tempfree (4.), // GB
19  m_temppath (".:$TMPDIR"),
20  m_timeout(0U),
21  m_debugLevel(0U)
22 {
24 }
ReadHint m_readHint
unsigned int m_debugLevel
CacheHint m_cacheHint
std::string m_temppath
void setTempDir(const std::string &s, double minFreeSpace)
unsigned int m_timeout

Member Function Documentation

bool StorageFactory::accounting ( void  ) const

Definition at line 45 of file StorageFactory.cc.

References m_accounting.

Referenced by wrapNonLocalFile().

46 { return m_accounting; }
void StorageFactory::activateTimeout ( const std::string &  url)

Definition at line 278 of file StorageFactory.cc.

References getMaker(), and m_timeout.

Referenced by edm::RootInputFileSequence::RootInputFileSequence().

279 {
280  std::string protocol;
281  std::string rest;
282 
283  if (StorageMaker *maker = getMaker (url, protocol, rest))
284  {
285  maker->setTimeout (m_timeout);
286  }
287 }
StorageMaker * getMaker(const std::string &proto)
unsigned int m_timeout
StorageFactory::CacheHint StorageFactory::cacheHint ( void  ) const
bool StorageFactory::check ( const std::string &  url,
IOOffset size = 0 
)

Definition at line 229 of file StorageFactory.cc.

References StorageAccount::counter(), cms::Exception::explainSelf(), getMaker(), m_accounting, and run_regression::ret.

Referenced by TStorageFactorySystem::AccessPathName().

230 {
231  std::string protocol;
232  std::string rest;
233 
234  bool ret = false;
235  boost::shared_ptr<StorageAccount::Stamp> stats;
236  if (StorageMaker *maker = getMaker (url, protocol, rest))
237  {
238  if (m_accounting)
239  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "check")));
240  try
241  {
242  ret = maker->check (protocol, rest, size);
243  if (stats) stats->tick();
244  }
245  catch (cms::Exception &err)
246  {
247  edm::LogWarning("StorageFactory::check()")
248  << "Existence or size check for the file '" << url << "' failed because:\n"
249  << err.explainSelf();
250  }
251  }
252 
253  return ret;
254 }
virtual std::string explainSelf() const
Definition: Exception.cc:146
StorageMaker * getMaker(const std::string &proto)
static Counter & counter(const std::string &storageClass, const std::string &operation)
tuple size
Write out results.
unsigned int StorageFactory::debugLevel ( void  ) const

Definition at line 77 of file StorageFactory.cc.

References m_debugLevel.

78 { return m_debugLevel; }
unsigned int m_debugLevel
bool StorageFactory::enableAccounting ( bool  enabled)

Definition at line 37 of file StorageFactory.cc.

References m_accounting.

Referenced by PixelSLinkDataInputSource::PixelSLinkDataInputSource(), and TFileAdaptor::TFileAdaptor().

38 {
39  bool old = m_accounting;
40  m_accounting = enabled;
41  return old;
42 }
StorageFactory * StorageFactory::get ( void  )
static
StorageMaker * StorageFactory::getMaker ( const std::string &  proto)
protected

Definition at line 133 of file StorageFactory.cc.

References edmplugin::standard::config(), edmplugin::PluginManager::configure(), reco::get(), instance, edmplugin::PluginManager::isAvailable(), and m_makers.

Referenced by activateTimeout(), check(), getMaker(), open(), and stagein().

134 {
135  StorageMaker *&instance = m_makers [proto];
138  if (! instance)
139  instance = StorageMakerFactory::get()->tryToCreate(proto);
140  return instance;
141 }
static PluginManager & configure(const Config &)
static PFTauRenderPlugin instance
PluginManager::Config config()
Definition: standard.cc:22
MakerTable m_makers
T get(const Candidate &c)
Definition: component.h:56
StorageMaker * StorageFactory::getMaker ( const std::string &  url,
std::string &  protocol,
std::string &  rest 
)
protected

Definition at line 144 of file StorageFactory.cc.

References getMaker(), AlCaHLTBitMon_ParallelJobs::p, and relmon_authenticated_wget::url.

147 {
148  size_t p = url.find(':');
149  if (p != std::string::npos)
150  {
151  protocol = url.substr(0,p);
152  rest = url.substr(p+1);
153  }
154  else
155  {
156  protocol = "file";
157  rest = url;
158  }
159 
160  return getMaker (protocol);
161 }
StorageMaker * getMaker(const std::string &proto)
Storage * StorageFactory::open ( const std::string &  url,
int  mode = IOFlags::OpenRead 
)

Definition at line 164 of file StorageFactory.cc.

References cms::Exception::addAdditionalInfo(), cms::Exception::addContext(), cms::Exception::clearMessage(), StorageAccount::counter(), getMaker(), m_accounting, m_debugLevel, cms::Exception::message(), and run_regression::ret.

Referenced by lhef::LHEReader::FileSource::FileSource().

165 {
166  std::string protocol;
167  std::string rest;
168  Storage *ret = 0;
169  boost::shared_ptr<StorageAccount::Stamp> stats;
170  if (StorageMaker *maker = getMaker (url, protocol, rest))
171  {
172  maker->setDebugLevel(m_debugLevel);
173  if (m_accounting)
174  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "open")));
175  try
176  {
177  if (Storage *storage = maker->open (protocol, rest, mode))
178  {
179  if (dynamic_cast<LocalCacheFile *>(storage))
180  protocol = "local-cache";
181 
182  if (m_accounting)
183  ret = new StorageAccountProxy(protocol, storage);
184  else
185  ret = storage;
186 
187  if (stats)
188  stats->tick();
189  }
190  }
191  catch (cms::Exception &err)
192  {
193  err.addContext("Calling StorageFactory::open()");
194  err.addAdditionalInfo(err.message());
195  err.clearMessage();
196  err << "Failed to open the file '" << url << "'";
197  throw;
198  }
199  }
200  return ret;
201 }
Definition: Storage.h:8
std::string message() const
Definition: Exception.cc:187
unsigned int m_debugLevel
StorageMaker * getMaker(const std::string &proto)
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:235
void clearMessage()
Definition: Exception.cc:215
static Counter & counter(const std::string &storageClass, const std::string &operation)
void addContext(std::string const &context)
Definition: Exception.cc:227
StorageFactory::ReadHint StorageFactory::readHint ( void  ) const
void StorageFactory::setCacheHint ( CacheHint  value)

Definition at line 49 of file StorageFactory.cc.

References m_cacheHint, and relativeConstraints::value.

Referenced by TFileAdaptor::TFileAdaptor().

void StorageFactory::setDebugLevel ( unsigned int  level)

Definition at line 73 of file StorageFactory.cc.

References testEve_cfg::level, and m_debugLevel.

Referenced by TFileAdaptor::TFileAdaptor().

74 { m_debugLevel = level; }
unsigned int m_debugLevel
tuple level
Definition: testEve_cfg.py:34
void StorageFactory::setReadHint ( ReadHint  value)

Definition at line 57 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 81 of file StorageFactory.cc.

References begin, dtNoiseDBValidation_cfg::cerr, prof2calltree::count, end, LocalFileSystem::findCachePath(), m_lfs, m_tempdir, m_tempfree, m_temppath, and alignCSCRings::s.

Referenced by StorageFactory(), and TFileAdaptor::TFileAdaptor().

82 {
83 #if 0
84  std::cerr /* edm::LogInfo("StorageFactory") */
85  << "Considering path '" << s
86  << "', min free space " << minFreeSpace
87  << "GB for temp dir" << std::endl;
88 #endif
89 
90  size_t begin = 0;
91  std::vector<std::string> dirs;
92  dirs.reserve(std::count(s.begin(), s.end(), ':') + 1);
93 
94  while (true)
95  {
96  size_t end = s.find(':', begin);
97  if (end == std::string::npos)
98  {
99  dirs.push_back(s.substr(begin, end));
100  break;
101  }
102  else
103  {
104  dirs.push_back(s.substr(begin, end - begin));
105  begin = end+1;
106  }
107  }
108 
109  m_temppath = s;
110  m_tempfree = minFreeSpace;
111  m_tempdir = m_lfs.findCachePath(dirs, minFreeSpace);
112 
113 #if 0
114  std::cerr /* edm::LogInfo("StorageFactory") */
115  << "Using '" << m_tempdir << "' for temp dir"
116  << std::endl;
117 #endif
118 }
std::string m_tempdir
std::string findCachePath(const std::vector< std::string > &paths, double minFreeSpace)
#define end
Definition: vmac.h:38
std::string m_temppath
#define begin
Definition: vmac.h:31
LocalFileSystem m_lfs
void StorageFactory::setTimeout ( unsigned int  timeout)

Definition at line 65 of file StorageFactory.cc.

References m_timeout, and timeout().

Referenced by TFileAdaptor::TFileAdaptor().

66 { m_timeout = timeout; }
unsigned int timeout(void) const
unsigned int m_timeout
void StorageFactory::stagein ( const std::string &  url)

Definition at line 204 of file StorageFactory.cc.

References StorageAccount::counter(), cms::Exception::explainSelf(), getMaker(), and m_accounting.

Referenced by edm::RootInputFileSequence::RootInputFileSequence().

205 {
206  std::string protocol;
207  std::string rest;
208 
209  boost::shared_ptr<StorageAccount::Stamp> stats;
210  if (StorageMaker *maker = getMaker (url, protocol, rest))
211  {
212  if (m_accounting)
213  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "stagein")));
214  try
215  {
216  maker->stagein (protocol, rest);
217  if (stats) stats->tick();
218  }
219  catch (cms::Exception &err)
220  {
221  edm::LogWarning("StorageFactory::stagein()")
222  << "Failed to stage in file '" << url << "' because:\n"
223  << err.explainSelf();
224  }
225  }
226 }
virtual std::string explainSelf() const
Definition: Exception.cc:146
StorageMaker * getMaker(const std::string &proto)
static Counter & counter(const std::string &storageClass, const std::string &operation)
std::string StorageFactory::tempDir ( void  ) const

Definition at line 121 of file StorageFactory.cc.

References m_tempdir.

Referenced by GsiFTPStorageMaker::open(), and HttpStorageMaker::open().

122 { return m_tempdir; }
std::string m_tempdir
double StorageFactory::tempMinFree ( void  ) const

Definition at line 129 of file StorageFactory.cc.

References m_tempfree.

Referenced by TFileAdaptor::TFileAdaptor().

130 { return m_tempfree; }
std::string StorageFactory::tempPath ( void  ) const

Definition at line 125 of file StorageFactory.cc.

References m_temppath.

Referenced by TFileAdaptor::TFileAdaptor().

126 { return m_temppath; }
std::string m_temppath
unsigned int StorageFactory::timeout ( void  ) const

Definition at line 69 of file StorageFactory.cc.

References m_timeout.

Referenced by setTimeout().

70 { return m_timeout; }
unsigned int m_timeout
Storage * StorageFactory::wrapNonLocalFile ( Storage s,
const std::string &  proto,
const std::string &  path,
int  mode 
)

Definition at line 257 of file StorageFactory.cc.

References accounting(), CACHE_HINT_AUTO_DETECT, CACHE_HINT_LAZY_DOWNLOAD, cacheHint(), LocalFileSystem::isLocalPath(), m_lfs, m_tempdir, IOFlags::OpenWrite, and alignCSCRings::s.

Referenced by LocalStorageMaker::open(), XrdStorageMaker::open(), DCacheStorageMaker::open(), StormStorageMaker::open(), StormLcgGtStorageMaker::open(), and RFIOStorageMaker::open().

261 {
265  && ! (mode & IOFlags::OpenWrite)
266  && ! m_tempdir.empty()
267  && (path.empty() || ! m_lfs.isLocalPath(path)))
268  {
269  if (accounting())
270  s = new StorageAccountProxy(proto, s);
271  s = new LocalCacheFile(s, m_tempdir);
272  }
273 
274  return s;
275 }
CacheHint cacheHint(void) const
std::string m_tempdir
bool isLocalPath(const std::string &path)
list path
Definition: scaleCards.py:51
bool accounting(void) const
LocalFileSystem m_lfs

Member Data Documentation

bool StorageFactory::m_accounting
protected

Definition at line 80 of file StorageFactory.h.

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

CacheHint StorageFactory::m_cacheHint
protected

Definition at line 78 of file StorageFactory.h.

Referenced by cacheHint(), and setCacheHint().

unsigned int StorageFactory::m_debugLevel
protected

Definition at line 85 of file StorageFactory.h.

Referenced by debugLevel(), open(), and setDebugLevel().

LocalFileSystem StorageFactory::m_lfs
protected

Definition at line 86 of file StorageFactory.h.

Referenced by setTempDir(), and wrapNonLocalFile().

MakerTable StorageFactory::m_makers
protected

Definition at line 77 of file StorageFactory.h.

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

ReadHint StorageFactory::m_readHint
protected

Definition at line 79 of file StorageFactory.h.

Referenced by readHint(), and setReadHint().

std::string StorageFactory::m_tempdir
protected

Definition at line 83 of file StorageFactory.h.

Referenced by setTempDir(), tempDir(), and wrapNonLocalFile().

double StorageFactory::m_tempfree
protected

Definition at line 81 of file StorageFactory.h.

Referenced by setTempDir(), StorageFactory(), and tempMinFree().

std::string StorageFactory::m_temppath
protected

Definition at line 82 of file StorageFactory.h.

Referenced by setTempDir(), StorageFactory(), and tempPath().

unsigned int StorageFactory::m_timeout
protected

Definition at line 84 of file StorageFactory.h.

Referenced by activateTimeout(), setTimeout(), and timeout().

StorageFactory StorageFactory::s_instance
staticprotected

Definition at line 87 of file StorageFactory.h.

Referenced by get().