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 | Private Types | Private Member Functions | Private Attributes | Static Private 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)
 

Private Types

typedef
tbb::concurrent_unordered_map
< std::string, std::shared_ptr
< StorageMaker > > 
MakerTable
 

Private Member Functions

StorageMakergetMaker (const std::string &proto)
 
StorageMakergetMaker (const std::string &url, std::string &protocol, std::string &rest)
 
 StorageFactory (void)
 

Private 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 Private Attributes

static StorageFactory s_instance
 

Detailed Description

Definition at line 13 of file StorageFactory.h.

Member Typedef Documentation

typedef tbb::concurrent_unordered_map<std::string, std::shared_ptr<StorageMaker> > StorageFactory::MakerTable
private

Definition at line 70 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 16 of file StorageFactory.h.

Enumerator
READ_HINT_UNBUFFERED 
READ_HINT_READAHEAD 
READ_HINT_AUTO 

Definition at line 24 of file StorageFactory.h.

Constructor & Destructor Documentation

StorageFactory::~StorageFactory ( void  )

Definition at line 26 of file StorageFactory.cc.

27 {
28 }
StorageFactory::StorageFactory ( void  )
private

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 43 of file StorageFactory.cc.

References m_accounting.

Referenced by wrapNonLocalFile().

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

Definition at line 292 of file StorageFactory.cc.

References getMaker(), m_timeout, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by edm::RootInputFileSequence::initFile(), and edm::RootInputFileSequence::RootInputFileSequence().

293 {
294  std::string protocol;
295  std::string rest;
296 
297  if (StorageMaker *maker = getMaker (url, protocol, rest))
298  {
299  maker->setTimeout (m_timeout);
300  }
301 }
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 233 of file StorageFactory.cc.

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

Referenced by TStorageFactorySystem::AccessPathName().

234 {
235  std::string protocol;
236  std::string rest;
237 
238  bool ret = false;
239  boost::shared_ptr<StorageAccount::Stamp> stats;
240  if (StorageMaker *maker = getMaker (url, protocol, rest))
241  {
242  if (m_accounting)
243  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "check")));
244  try
245  {
246  ret = maker->check (protocol, rest, size);
247  if (stats) stats->tick();
248  }
249  catch (cms::Exception &err)
250  {
251  edm::LogWarning("StorageFactory::check()")
252  << "Existence or size check for the file '" << url << "' failed because:\n"
253  << err.explainSelf();
254  }
255  }
256 
257  return ret;
258 }
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 75 of file StorageFactory.cc.

References m_debugLevel.

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

Definition at line 35 of file StorageFactory.cc.

References m_accounting.

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

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

Definition at line 131 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().

132 {
133  auto itFound = m_makers.find(proto);
134  if(itFound != m_makers.end()) {
135  return itFound->second.get();
136  }
139  }
140  std::shared_ptr<StorageMaker> instance{ StorageMakerFactory::get()->tryToCreate(proto)};
141  auto insertResult = m_makers.insert(MakerTable::value_type(proto,instance));
142  //Can't use instance since it is possible that another thread beat
143  // us to the insertion so the map contains a different instance.
144  return insertResult.first->second.get();
145 }
static PluginManager & configure(const Config &)
static PFTauRenderPlugin instance
PluginManager::Config config()
Definition: standard.cc:21
Container::value_type value_type
MakerTable m_makers
T get(const Candidate &c)
Definition: component.h:55
StorageMaker * StorageFactory::getMaker ( const std::string &  url,
std::string &  protocol,
std::string &  rest 
)
private

Definition at line 148 of file StorageFactory.cc.

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

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

Definition at line 168 of file StorageFactory.cc.

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

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

169 {
170  std::string protocol;
171  std::string rest;
172  Storage *ret = 0;
173  boost::shared_ptr<StorageAccount::Stamp> stats;
174  if (StorageMaker *maker = getMaker (url, protocol, rest))
175  {
176  maker->setDebugLevel(m_debugLevel);
177  if (m_accounting)
178  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "open")));
179  try
180  {
181  if (Storage *storage = maker->open (protocol, rest, mode))
182  {
183  if (dynamic_cast<LocalCacheFile *>(storage))
184  protocol = "local-cache";
185 
186  if (m_accounting)
187  ret = new StorageAccountProxy(protocol, storage);
188  else
189  ret = storage;
190 
191  if (stats)
192  stats->tick();
193  }
194  }
195  catch (cms::Exception &err)
196  {
197  err.addContext("Calling StorageFactory::open()");
198  err.addAdditionalInfo(err.message());
199  err.clearMessage();
200  err << "Failed to open the file '" << url << "'";
201  throw;
202  }
203  }
204  return ret;
205 }
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 47 of file StorageFactory.cc.

References m_cacheHint, and relativeConstraints::value.

Referenced by TFileAdaptor::TFileAdaptor().

void StorageFactory::setDebugLevel ( unsigned int  level)

Definition at line 71 of file StorageFactory.cc.

References testEve_cfg::level, and m_debugLevel.

Referenced by TFileAdaptor::TFileAdaptor().

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

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

References begin, ecal_dqm_sourceclient-live_cfg::cerr, prof2calltree::count, heppy_check::dirs, end, LocalFileSystem::findCachePath(), m_lfs, m_tempdir, m_tempfree, m_temppath, and alignCSCRings::s.

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

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

Definition at line 63 of file StorageFactory.cc.

References m_timeout, and timeout().

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 208 of file StorageFactory.cc.

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

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

209 {
210  std::string protocol;
211  std::string rest;
212 
213  boost::shared_ptr<StorageAccount::Stamp> stats;
214  if (StorageMaker *maker = getMaker (url, protocol, rest))
215  {
216  if (m_accounting)
217  stats.reset(new StorageAccount::Stamp(StorageAccount::counter (protocol, "stagein")));
218  try
219  {
220  maker->stagein (protocol, rest);
221  if (stats) stats->tick();
222  }
223  catch (cms::Exception &err)
224  {
225  edm::LogWarning("StorageFactory::stagein()")
226  << "Failed to stage in file '" << url << "' because:\n"
227  << err.explainSelf();
228  }
229  }
230 }
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 119 of file StorageFactory.cc.

References m_tempdir.

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

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

Definition at line 127 of file StorageFactory.cc.

References m_tempfree.

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 123 of file StorageFactory.cc.

References m_temppath.

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 67 of file StorageFactory.cc.

References m_timeout.

Referenced by setTimeout().

68 { 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 261 of file StorageFactory.cc.

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

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

265 {
268  {
269  if (mode & IOFlags::OpenWrite)
270  {
271  // For now, issue no warning - otherwise, we'd always warn on output files.
272  }
273  else if (m_tempdir.empty())
274  {
276  }
277  else if ( (not path.empty()) and m_lfs.isLocalPath(path))
278  {
279  // For now, issue no warning - otherwise, we'd always warn on local input files.
280  }
281  else
282  {
283  if (accounting()) {s = new StorageAccountProxy(proto, s);}
284  s = new LocalCacheFile(s, m_tempdir);
285  }
286  }
287 
288  return s;
289 }
CacheHint cacheHint(void) const
std::string m_tempdir
bool isLocalPath(const std::string &path)
tuple path
else: Piece not in the list, fine.
bool accounting(void) const
LocalFileSystem m_lfs

Member Data Documentation

bool StorageFactory::m_accounting
private

Definition at line 81 of file StorageFactory.h.

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

CacheHint StorageFactory::m_cacheHint
private

Definition at line 79 of file StorageFactory.h.

Referenced by cacheHint(), and setCacheHint().

unsigned int StorageFactory::m_debugLevel
private

Definition at line 86 of file StorageFactory.h.

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

LocalFileSystem StorageFactory::m_lfs
private

Definition at line 87 of file StorageFactory.h.

Referenced by setTempDir(), and wrapNonLocalFile().

MakerTable StorageFactory::m_makers
private

Definition at line 78 of file StorageFactory.h.

Referenced by getMaker().

ReadHint StorageFactory::m_readHint
private

Definition at line 80 of file StorageFactory.h.

Referenced by readHint(), and setReadHint().

std::string StorageFactory::m_tempdir
private

Definition at line 84 of file StorageFactory.h.

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

double StorageFactory::m_tempfree
private

Definition at line 82 of file StorageFactory.h.

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

std::string StorageFactory::m_temppath
private

Definition at line 83 of file StorageFactory.h.

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

unsigned int StorageFactory::m_timeout
private

Definition at line 85 of file StorageFactory.h.

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

StorageFactory StorageFactory::s_instance
staticprivate

Definition at line 88 of file StorageFactory.h.

Referenced by get().