CMS 3D CMS Logo

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
 
CacheHint cacheHint (void) const
 
bool check (const std::string &url, IOOffset *size=0) const
 
unsigned int debugLevel (void) const
 
bool enableAccounting (bool enabled)
 
std::unique_ptr< Storageopen (const std::string &url, int mode=IOFlags::OpenRead) const
 
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) const
 
std::string tempDir (void) const
 
double tempMinFree (void) const
 
std::string tempPath (void) const
 
unsigned int timeout (void) const
 
std::unique_ptr< StoragewrapNonLocalFile (std::unique_ptr< Storage > s, const std::string &proto, const std::string &path, int mode) const
 
 ~StorageFactory (void)
 

Static Public Member Functions

static const StorageFactoryget (void)
 
static StorageFactorygetToModify (void)
 

Private Types

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

Private Member Functions

StorageMakergetMaker (const std::string &proto) const
 
StorageMakergetMaker (const std::string &url, std::string &protocol, std::string &rest) const
 
 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
 
std::string m_unusableDirWarnings
 

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

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

Definition at line 13 of file StorageFactory.cc.

References m_tempfree, m_temppath, and setTempDir().

16  m_accounting (false),
17  m_tempfree (4.), // GB
18  m_temppath (".:$TMPDIR"),
19  m_timeout(0U),
20  m_debugLevel(0U)
21 {
23 }
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 46 of file StorageFactory.cc.

References m_accounting.

Referenced by wrapNonLocalFile().

47 { return m_accounting; }
StorageFactory::CacheHint StorageFactory::cacheHint ( void  ) const
bool StorageFactory::check ( const std::string &  url,
IOOffset size = 0 
) const

Definition at line 239 of file StorageFactory.cc.

References StorageAccount::check, StorageAccount::counter(), cms::Exception::explainSelf(), getMaker(), m_accounting, m_debugLevel, m_timeout, StorageMaker::AuxSettings::setDebugLevel(), StorageMaker::AuxSettings::setTimeout(), findQualityFiles::size, AlCaHLTBitMon_QueryRunRegistry::string, and StorageAccount::tokenForStorageClassName().

Referenced by TStorageFactorySystem::AccessPathName(), and MatacqProducer::loadOrbitOffset().

240 {
241  std::string protocol;
242  std::string rest;
243 
244  bool ret = false;
245  std::unique_ptr<StorageAccount::Stamp> stats;
246  if (StorageMaker *maker = getMaker (url, protocol, rest))
247  {
248  if (m_accounting) {
249  auto token = StorageAccount::tokenForStorageClassName(protocol);
251  }
252  try
253  {
254  ret = maker->check (protocol, rest, StorageMaker::AuxSettings{}.setDebugLevel(m_debugLevel).setTimeout(m_timeout), size);
255  if (stats) stats->tick();
256  }
257  catch (cms::Exception &err)
258  {
259  edm::LogWarning("StorageFactory::check()")
260  << "Existence or size check for the file '" << url << "' failed because:\n"
261  << err.explainSelf();
262  }
263  }
264 
265  return ret;
266 }
size
Write out results.
virtual std::string explainSelf() const
Definition: Exception.cc:146
unsigned int m_debugLevel
StorageMaker * getMaker(const std::string &proto) const
static StorageClassToken tokenForStorageClassName(std::string const &iName)
static Counter & counter(StorageClassToken token, Operation operation)
unsigned int m_timeout
AuxSettings & setDebugLevel(unsigned int iLevel)
Definition: StorageMaker.h:16
AuxSettings & setTimeout(unsigned int iTime)
Definition: StorageMaker.h:21
unsigned int StorageFactory::debugLevel ( void  ) const

Definition at line 78 of file StorageFactory.cc.

References m_debugLevel.

79 { return m_debugLevel; }
unsigned int m_debugLevel
bool StorageFactory::enableAccounting ( bool  enabled)
const StorageFactory * StorageFactory::get ( void  )
static
StorageMaker * StorageFactory::getMaker ( const std::string &  proto) const
private

Definition at line 134 of file StorageFactory.cc.

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

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

135 {
136  auto itFound = m_makers.find(proto);
137  if(itFound != m_makers.end()) {
138  return itFound->second.get();
139  }
142  }
143  std::shared_ptr<StorageMaker> instance{ StorageMakerFactory::get()->tryToCreate(proto)};
144  auto insertResult = m_makers.insert(MakerTable::value_type(proto,instance));
145  //Can't use instance since it is possible that another thread beat
146  // us to the insertion so the map contains a different instance.
147  return insertResult.first->second.get();
148 }
static PluginManager & configure(const Config &)
static PFTauRenderPlugin instance
PluginManager::Config config()
Definition: standard.cc:21
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 
) const
private

Definition at line 151 of file StorageFactory.cc.

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

154 {
155  size_t p = url.find(':');
156  if (p != std::string::npos)
157  {
158  protocol = url.substr(0,p);
159  rest = url.substr(p+1);
160  }
161  else
162  {
163  protocol = "file";
164  rest = url;
165  }
166 
167  return getMaker (protocol);
168 }
StorageMaker * getMaker(const std::string &proto) const
StorageFactory * StorageFactory::getToModify ( void  )
static

Definition at line 34 of file StorageFactory.cc.

References s_instance.

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

35 { return &s_instance; }
static StorageFactory s_instance
std::unique_ptr< Storage > StorageFactory::open ( const std::string &  url,
int  mode = IOFlags::OpenRead 
) const

Definition at line 171 of file StorageFactory.cc.

References cms::Exception::addAdditionalInfo(), cms::Exception::addContext(), cms::Exception::clearMessage(), StorageAccount::counter(), getMaker(), m_accounting, m_debugLevel, m_timeout, cms::Exception::message(), eostools::move(), StorageAccount::open, StorageMaker::AuxSettings::setDebugLevel(), StorageMaker::AuxSettings::setTimeout(), AlCaHLTBitMon_QueryRunRegistry::string, and StorageAccount::tokenForStorageClassName().

Referenced by lhef::LHEReader::FileSource::FileSource(), MatacqProducer::loadOrbitOffset(), edm::StreamerInputFile::openStreamerFile(), and PixelSLinkDataInputSource::PixelSLinkDataInputSource().

172 {
173  std::string protocol;
174  std::string rest;
175  std::unique_ptr<Storage> ret;
176  std::unique_ptr<StorageAccount::Stamp> stats;
177  if (StorageMaker *maker = getMaker (url, protocol, rest))
178  {
179  if (m_accounting) {
180  auto token = StorageAccount::tokenForStorageClassName(protocol);
182  }
183  try
184  {
185  if (auto storage = maker->open (protocol, rest, mode, StorageMaker::AuxSettings{}.setDebugLevel(m_debugLevel).setTimeout(m_timeout)))
186  {
187  if (dynamic_cast<LocalCacheFile *>(storage.get()))
188  protocol = "local-cache";
189 
190  if (m_accounting)
191  ret = std::make_unique<StorageAccountProxy>(protocol, std::move(storage));
192  else
193  ret = std::move(storage);
194 
195  if (stats)
196  stats->tick();
197  }
198  }
199  catch (cms::Exception &err)
200  {
201  err.addContext("Calling StorageFactory::open()");
202  err.addAdditionalInfo(err.message());
203  err.clearMessage();
204  err << "Failed to open the file '" << url << "'";
205  throw;
206  }
207  }
208  return ret;
209 }
std::string message() const
Definition: Exception.cc:187
unsigned int m_debugLevel
StorageMaker * getMaker(const std::string &proto) const
static StorageClassToken tokenForStorageClassName(std::string const &iName)
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:235
void clearMessage()
Definition: Exception.cc:215
static Counter & counter(StorageClassToken token, Operation operation)
void addContext(std::string const &context)
Definition: Exception.cc:227
unsigned int m_timeout
AuxSettings & setDebugLevel(unsigned int iLevel)
Definition: StorageMaker.h:16
def move(src, dest)
Definition: eostools.py:510
AuxSettings & setTimeout(unsigned int iTime)
Definition: StorageMaker.h:21
StorageFactory::ReadHint StorageFactory::readHint ( void  ) const
void StorageFactory::setCacheHint ( CacheHint  value)
void StorageFactory::setDebugLevel ( unsigned int  level)

Definition at line 74 of file StorageFactory.cc.

References hcalDigis_cfi::level, and m_debugLevel.

Referenced by TFileAdaptor::TFileAdaptor().

75 { m_debugLevel = level; }
unsigned int m_debugLevel
void StorageFactory::setReadHint ( ReadHint  value)
void StorageFactory::setTempDir ( const std::string &  s,
double  minFreeSpace 
)

Definition at line 82 of file StorageFactory.cc.

References begin, MessageLogger_cfi::cerr, KineDebug3::count(), heppy_check::dirs, end, LocalFileSystem::findCachePath(), m_lfs, m_tempdir, m_tempfree, m_temppath, m_unusableDirWarnings, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 66 of file StorageFactory.cc.

References m_timeout, and timeout().

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 212 of file StorageFactory.cc.

References StorageAccount::counter(), cms::Exception::explainSelf(), getMaker(), m_accounting, m_debugLevel, m_timeout, StorageMaker::AuxSettings::setDebugLevel(), StorageMaker::AuxSettings::setTimeout(), StorageAccount::stagein, AlCaHLTBitMon_QueryRunRegistry::string, and StorageAccount::tokenForStorageClassName().

Referenced by edm::RootPrimaryFileSequence::RootPrimaryFileSequence(), and edm::RootSecondaryFileSequence::RootSecondaryFileSequence().

213 {
214  std::string protocol;
215  std::string rest;
216 
217  std::unique_ptr<StorageAccount::Stamp> stats;
218  if (StorageMaker *maker = getMaker (url, protocol, rest))
219  {
220  if (m_accounting) {
221  auto token = StorageAccount::tokenForStorageClassName(protocol);
223  }
224  try
225  {
226  maker->stagein (protocol, rest,StorageMaker::AuxSettings{}.setDebugLevel(m_debugLevel).setTimeout(m_timeout));
227  if (stats) stats->tick();
228  }
229  catch (cms::Exception &err)
230  {
231  edm::LogWarning("StorageFactory::stagein()")
232  << "Failed to stage in file '" << url << "' because:\n"
233  << err.explainSelf();
234  }
235  }
236 }
virtual std::string explainSelf() const
Definition: Exception.cc:146
unsigned int m_debugLevel
StorageMaker * getMaker(const std::string &proto) const
static StorageClassToken tokenForStorageClassName(std::string const &iName)
static Counter & counter(StorageClassToken token, Operation operation)
unsigned int m_timeout
AuxSettings & setDebugLevel(unsigned int iLevel)
Definition: StorageMaker.h:16
AuxSettings & setTimeout(unsigned int iTime)
Definition: StorageMaker.h:21
std::string StorageFactory::tempDir ( void  ) const

Definition at line 122 of file StorageFactory.cc.

References m_tempdir, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Definition at line 130 of file StorageFactory.cc.

References m_tempfree.

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 126 of file StorageFactory.cc.

References m_temppath.

Referenced by TFileAdaptor::TFileAdaptor().

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

Definition at line 70 of file StorageFactory.cc.

References m_timeout.

Referenced by setTimeout().

71 { return m_timeout; }
unsigned int m_timeout
std::unique_ptr< Storage > StorageFactory::wrapNonLocalFile ( std::unique_ptr< Storage s,
const std::string &  proto,
const std::string &  path,
int  mode 
) const

Definition at line 269 of file StorageFactory.cc.

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

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

273 {
276  {
277  if (mode & IOFlags::OpenWrite)
278  {
279  // For now, issue no warning - otherwise, we'd always warn on output files.
280  }
281  else if (m_tempdir.empty())
282  {
283  edm::LogWarning("StorageFactory") << m_unusableDirWarnings;
284  }
285  else if ( (not path.empty()) and m_lfs.isLocalPath(path))
286  {
287  // For now, issue no warning - otherwise, we'd always warn on local input files.
288  }
289  else
290  {
291  if (accounting()) {s = std::make_unique<StorageAccountProxy>(proto, std::move(s));}
292  s = std::make_unique<LocalCacheFile>(std::move(s), m_tempdir);
293  }
294  }
295 
296  return s;
297 }
CacheHint cacheHint(void) const
std::string m_tempdir
bool isLocalPath(const std::string &path) const
bool accounting(void) const
LocalFileSystem m_lfs
std::string m_unusableDirWarnings
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

bool StorageFactory::m_accounting
private

Definition at line 82 of file StorageFactory.h.

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

CacheHint StorageFactory::m_cacheHint
private

Definition at line 80 of file StorageFactory.h.

Referenced by cacheHint(), and setCacheHint().

unsigned int StorageFactory::m_debugLevel
private

Definition at line 88 of file StorageFactory.h.

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

LocalFileSystem StorageFactory::m_lfs
private

Definition at line 89 of file StorageFactory.h.

Referenced by setTempDir(), and wrapNonLocalFile().

MakerTable StorageFactory::m_makers
mutableprivate

Definition at line 79 of file StorageFactory.h.

Referenced by getMaker().

ReadHint StorageFactory::m_readHint
private

Definition at line 81 of file StorageFactory.h.

Referenced by readHint(), and setReadHint().

std::string StorageFactory::m_tempdir
private

Definition at line 85 of file StorageFactory.h.

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

double StorageFactory::m_tempfree
private

Definition at line 83 of file StorageFactory.h.

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

std::string StorageFactory::m_temppath
private

Definition at line 84 of file StorageFactory.h.

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

unsigned int StorageFactory::m_timeout
private

Definition at line 87 of file StorageFactory.h.

Referenced by check(), open(), setTimeout(), stagein(), and timeout().

std::string StorageFactory::m_unusableDirWarnings
private

Definition at line 86 of file StorageFactory.h.

Referenced by setTempDir(), and wrapNonLocalFile().

StorageFactory StorageFactory::s_instance
staticprivate

Definition at line 90 of file StorageFactory.h.

Referenced by get(), and getToModify().