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

26 {
27  for (MakerTable::iterator i = m_makers.begin (); i != m_makers.end (); ++i)
28  delete i->second;
29 }
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 {
23 }
ReadHint m_readHint
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 44 of file StorageFactory.cc.

References m_accounting.

Referenced by wrapNonLocalFile().

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

267 {
268  std::string protocol;
269  std::string rest;
270 
271  if (StorageMaker *maker = getMaker (url, protocol, rest))
272  {
273  maker->setTimeout (m_timeout);
274  }
275 }
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 217 of file StorageFactory.cc.

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

Referenced by TStorageFactorySystem::AccessPathName().

218 {
219  std::string protocol;
220  std::string rest;
221 
222  bool ret = false;
223  boost::shared_ptr<StorageAccount::Stamp> stats;
224  if (StorageMaker *maker = getMaker (url, protocol, rest))
225  {
226  if (m_accounting)
227  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "check")));
228  try
229  {
230  ret = maker->check (protocol, rest, size);
231  if (stats) stats->tick();
232  }
233  catch (cms::Exception &err)
234  {
235  edm::LogWarning("StorageFactory::check()")
236  << "Existence or size check for the file '" << url << "' failed because:\n"
237  << err.explainSelf();
238  }
239  }
240 
241  return ret;
242 }
virtual std::string explainSelf() const
Definition: Exception.cc:56
StorageMaker * getMaker(const std::string &proto)
static Counter & counter(const std::string &storageClass, const std::string &operation)
tuple size
Write out results.
bool StorageFactory::enableAccounting ( bool  enabled)

Definition at line 36 of file StorageFactory.cc.

References m_accounting.

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

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

Definition at line 124 of file StorageFactory.cc.

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

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

125 {
126  StorageMaker *&instance = m_makers [proto];
129  if (! instance)
130  instance = StorageMakerFactory::get()->tryToCreate(proto);
131  return instance;
132 }
static PluginManager & configure(const Config &)
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 135 of file StorageFactory.cc.

References getMaker(), and L1TEmulatorMonitor_cff::p.

138 {
139  size_t p = url.find(':');
140  if (p != std::string::npos)
141  {
142  protocol = url.substr(0,p);
143  rest = url.substr(p+1);
144  }
145  else
146  {
147  protocol = "file";
148  rest = url;
149  }
150 
151  return getMaker (protocol);
152 }
StorageMaker * getMaker(const std::string &proto)
Storage * StorageFactory::open ( const std::string &  url,
int  mode = IOFlags::OpenRead 
)

Definition at line 155 of file StorageFactory.cc.

References StorageAccount::counter(), edm::hlt::Exception, getMaker(), m_accounting, and runTheMatrix::ret.

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

156 {
157  std::string protocol;
158  std::string rest;
159  Storage *ret = 0;
160  boost::shared_ptr<StorageAccount::Stamp> stats;
161  if (StorageMaker *maker = getMaker (url, protocol, rest))
162  {
163  if (m_accounting)
164  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "open")));
165  try
166  {
167  if (Storage *storage = maker->open (protocol, rest, mode))
168  {
169  if (dynamic_cast<LocalCacheFile *>(storage))
170  protocol = "local-cache";
171 
172  if (m_accounting)
173  ret = new StorageAccountProxy(protocol, storage);
174  else
175  ret = storage;
176 
177  if (stats)
178  stats->tick();
179  }
180  }
181  catch (cms::Exception &err)
182  {
183  throw cms::Exception("StorageFactory::open()")
184  << "Failed to open the file '" << url << "' because:\n"
185  << err;
186  }
187  }
188  return ret;
189 }
Definition: Storage.h:8
StorageMaker * getMaker(const std::string &proto)
static Counter & counter(const std::string &storageClass, const std::string &operation)
int mode
Definition: AMPTWrapper.h:139
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().

73 {
74 #if 0
75  std::cerr /* edm::LogInfo("StorageFactory") */
76  << "Considering path '" << s
77  << "', min free space " << minFreeSpace
78  << "GB for temp dir" << std::endl;
79 #endif
80 
81  size_t begin = 0;
82  std::vector<std::string> dirs;
83  dirs.reserve(std::count(s.begin(), s.end(), ':') + 1);
84 
85  while (true)
86  {
87  size_t end = s.find(':', begin);
88  if (end == std::string::npos)
89  {
90  dirs.push_back(s.substr(begin, end));
91  break;
92  }
93  else
94  {
95  dirs.push_back(s.substr(begin, end - begin));
96  begin = end+1;
97  }
98  }
99 
100  m_temppath = s;
101  m_tempfree = minFreeSpace;
102  m_tempdir = m_lfs.findCachePath(dirs, minFreeSpace);
103 
104 #if 0
105  std::cerr /* edm::LogInfo("StorageFactory") */
106  << "Using '" << m_tempdir << "' for temp dir"
107  << std::endl;
108 #endif
109 }
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
string s
Definition: asciidump.py:422
LocalFileSystem m_lfs
void StorageFactory::setTimeout ( unsigned int  timeout)

Definition at line 64 of file StorageFactory.cc.

References m_timeout, and timeout().

Referenced by TFileAdaptor::TFileAdaptor().

65 { m_timeout = timeout; }
unsigned int timeout(void) const
unsigned int m_timeout
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().

193 {
194  std::string protocol;
195  std::string rest;
196 
197  boost::shared_ptr<StorageAccount::Stamp> stats;
198  if (StorageMaker *maker = getMaker (url, protocol, rest))
199  {
200  if (m_accounting)
201  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "stagein")));
202  try
203  {
204  maker->stagein (protocol, rest);
205  if (stats) stats->tick();
206  }
207  catch (cms::Exception &err)
208  {
209  edm::LogWarning("StorageFactory::stagein()")
210  << "Failed to stage in file '" << url << "' because:\n"
211  << err.explainSelf();
212  }
213  }
214 }
virtual std::string explainSelf() const
Definition: Exception.cc:56
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 112 of file StorageFactory.cc.

References m_tempdir.

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

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

Definition at line 120 of file StorageFactory.cc.

References m_tempfree.

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 116 of file StorageFactory.cc.

References m_temppath.

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 68 of file StorageFactory.cc.

References m_timeout.

Referenced by setTimeout().

69 { 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 245 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 LocalStorageMaker::open(), DCacheStorageMaker::open(), StormStorageMaker::open(), StormLcgGtStorageMaker::open(), and RFIOStorageMaker::open().

249 {
253  && ! (mode & IOFlags::OpenWrite)
254  && ! m_tempdir.empty()
255  && (path.empty() || ! m_lfs.isLocalPath(path)))
256  {
257  if (accounting())
258  s = new StorageAccountProxy(proto, s);
259  s = new LocalCacheFile(s, m_tempdir);
260  }
261 
262  return s;
263 }
CacheHint cacheHint(void) const
std::string m_tempdir
bool isLocalPath(const std::string &path)
int path() const
Definition: HLTadd.h:3
int mode
Definition: AMPTWrapper.h:139
bool accounting(void) const
string s
Definition: asciidump.py:422
LocalFileSystem m_lfs

Member Data Documentation

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
staticprotected

Definition at line 83 of file StorageFactory.h.

Referenced by get().