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=nullptr) 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

◆ MakerTable

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

Definition at line 57 of file StorageFactory.h.

Member Enumeration Documentation

◆ CacheHint

Enumerator
CACHE_HINT_APPLICATION 
CACHE_HINT_STORAGE 
CACHE_HINT_LAZY_DOWNLOAD 
CACHE_HINT_AUTO_DETECT 

Definition at line 15 of file StorageFactory.h.

◆ ReadHint

Enumerator
READ_HINT_UNBUFFERED 
READ_HINT_READAHEAD 
READ_HINT_AUTO 

Definition at line 17 of file StorageFactory.h.

Constructor & Destructor Documentation

◆ ~StorageFactory()

StorageFactory::~StorageFactory ( void  )

Definition at line 24 of file StorageFactory.cc.

24 {}

◆ StorageFactory()

StorageFactory::StorageFactory ( void  )
private

Definition at line 13 of file StorageFactory.cc.

16  m_accounting(false),
17  m_tempfree(4.), // GB
18  m_temppath(".:$TMPDIR"),
19  m_timeout(0U),
20  m_debugLevel(0U) {
22 }

References m_tempfree, m_temppath, and setTempDir().

Member Function Documentation

◆ accounting()

bool StorageFactory::accounting ( void  ) const

Definition at line 36 of file StorageFactory.cc.

36 { return m_accounting; }

References m_accounting.

Referenced by wrapNonLocalFile().

◆ cacheHint()

StorageFactory::CacheHint StorageFactory::cacheHint ( void  ) const

Definition at line 40 of file StorageFactory.cc.

40 { return m_cacheHint; }

References m_cacheHint.

Referenced by wrapNonLocalFile().

◆ check()

bool StorageFactory::check ( const std::string &  url,
IOOffset size = nullptr 
) const

Definition at line 178 of file StorageFactory.cc.

178  {
179  std::string protocol;
181 
182  bool ret = false;
183  std::unique_ptr<StorageAccount::Stamp> stats;
184  if (StorageMaker *maker = getMaker(url, protocol, rest)) {
185  if (m_accounting) {
188  }
189  try {
190  ret = maker->check(
192  if (stats)
193  stats->tick();
194  } catch (cms::Exception &err) {
195  edm::LogWarning("StorageFactory::check()")
196  << "Existence or size check for the file '" << url << "' failed because:\n"
197  << err.explainSelf();
198  }
199  }
200 
201  return ret;
202 }

References StorageAccount::check, StorageAccount::counter(), runTheMatrix::err, getMaker(), m_accounting, m_debugLevel, m_timeout, mergeAndRegister::rest, runTheMatrix::ret, StorageMaker::AuxSettings::setDebugLevel(), StorageMaker::AuxSettings::setTimeout(), findQualityFiles::size, dqmMemoryStats::stats, AlCaHLTBitMon_QueryRunRegistry::string, unpackBuffers-CaloStage2::token, StorageAccount::tokenForStorageClassName(), and relmon_authenticated_wget::url.

Referenced by TStorageFactorySystem::AccessPathName(), and PixelSLinkDataInputSource::PixelSLinkDataInputSource().

◆ debugLevel()

unsigned int StorageFactory::debugLevel ( void  ) const

Definition at line 52 of file StorageFactory.cc.

52 { return m_debugLevel; }

References m_debugLevel.

◆ enableAccounting()

bool StorageFactory::enableAccounting ( bool  enabled)

Definition at line 30 of file StorageFactory.cc.

30  {
31  bool old = m_accounting;
33  return old;
34 }

References pixel_dqm_sourceclient-live_cfg::enabled, and m_accounting.

Referenced by PixelSLinkDataInputSource::PixelSLinkDataInputSource().

◆ get()

const StorageFactory * StorageFactory::get ( void  )
static

◆ getMaker() [1/2]

StorageMaker * StorageFactory::getMaker ( const std::string &  proto) const
private

Definition at line 94 of file StorageFactory.cc.

94  {
95  auto itFound = m_makers.find(proto);
96  if (itFound != m_makers.end()) {
97  return itFound->second.get();
98  }
101  }
102  std::shared_ptr<StorageMaker> instance{StorageMakerFactory::get()->tryToCreate(proto)};
103  auto insertResult = m_makers.insert(MakerTable::value_type(proto, instance));
104  //Can't use instance since it is possible that another thread beat
105  // us to the insertion so the map contains a different instance.
106  return insertResult.first->second.get();
107 }

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

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

◆ getMaker() [2/2]

StorageMaker * StorageFactory::getMaker ( const std::string &  url,
std::string &  protocol,
std::string &  rest 
) const
private

Definition at line 109 of file StorageFactory.cc.

109  {
110  size_t p = url.find(':');
111  if (p != std::string::npos) {
112  protocol = url.substr(0, p);
113  rest = url.substr(p + 1);
114  } else {
115  protocol = "file";
116  rest = url;
117  }
118 
119  return getMaker(protocol);
120 }

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

◆ getToModify()

StorageFactory * StorageFactory::getToModify ( void  )
static

Definition at line 28 of file StorageFactory.cc.

28 { return &s_instance; }

References s_instance.

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

◆ open()

std::unique_ptr< Storage > StorageFactory::open ( const std::string &  url,
int  mode = IOFlags::OpenRead 
) const

Definition at line 122 of file StorageFactory.cc.

122  {
123  std::string protocol;
125  std::unique_ptr<Storage> ret;
126  std::unique_ptr<StorageAccount::Stamp> stats;
127  if (StorageMaker *maker = getMaker(url, protocol, rest)) {
128  if (m_accounting) {
131  }
132  try {
133  if (auto storage = maker->open(
135  if (dynamic_cast<LocalCacheFile *>(storage.get()))
136  protocol = "local-cache";
137 
138  if (m_accounting)
139  ret = std::make_unique<StorageAccountProxy>(protocol, std::move(storage));
140  else
141  ret = std::move(storage);
142 
143  if (stats)
144  stats->tick();
145  }
146  } catch (cms::Exception &err) {
147  err.addContext("Calling StorageFactory::open()");
148  err.addAdditionalInfo(err.message());
149  err.clearMessage();
150  err << "Failed to open the file '" << url << "'";
151  throw;
152  }
153  }
154  return ret;
155 }

References StorageAccount::counter(), runTheMatrix::err, getMaker(), m_accounting, m_debugLevel, m_timeout, ALCARECOPromptCalibProdSiPixelAli0T_cff::mode, eostools::move(), StorageAccount::open, mergeAndRegister::rest, runTheMatrix::ret, StorageMaker::AuxSettings::setDebugLevel(), StorageMaker::AuxSettings::setTimeout(), dqmMemoryStats::stats, AlCaHLTBitMon_QueryRunRegistry::string, unpackBuffers-CaloStage2::token, StorageAccount::tokenForStorageClassName(), and relmon_authenticated_wget::url.

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

◆ readHint()

StorageFactory::ReadHint StorageFactory::readHint ( void  ) const

Definition at line 44 of file StorageFactory.cc.

44 { return m_readHint; }

References m_readHint.

◆ setCacheHint()

void StorageFactory::setCacheHint ( CacheHint  value)

Definition at line 38 of file StorageFactory.cc.

38 { m_cacheHint = value; }

References m_cacheHint, and relativeConstraints::value.

◆ setDebugLevel()

void StorageFactory::setDebugLevel ( unsigned int  level)

Definition at line 50 of file StorageFactory.cc.

50 { m_debugLevel = level; }

References personalPlayback::level, and m_debugLevel.

◆ setReadHint()

void StorageFactory::setReadHint ( ReadHint  value)

Definition at line 42 of file StorageFactory.cc.

42 { m_readHint = value; }

References m_readHint, and relativeConstraints::value.

◆ setTempDir()

void StorageFactory::setTempDir ( const std::string &  s,
double  minFreeSpace 
)

Definition at line 54 of file StorageFactory.cc.

54  {
55 #if 0
56  std::cerr /* edm::LogInfo("StorageFactory") */
57  << "Considering path '" << s
58  << "', min free space " << minFreeSpace
59  << "GB for temp dir" << std::endl;
60 #endif
61 
62  size_t begin = 0;
63  std::vector<std::string> dirs;
64  dirs.reserve(std::count(s.begin(), s.end(), ':') + 1);
65 
66  while (true) {
67  size_t end = s.find(':', begin);
68  if (end == std::string::npos) {
69  dirs.push_back(s.substr(begin, end));
70  break;
71  } else {
72  dirs.push_back(s.substr(begin, end - begin));
73  begin = end + 1;
74  }
75  }
76 
77  m_temppath = s;
78  m_tempfree = minFreeSpace;
79  std::tie(m_tempdir, m_unusableDirWarnings) = m_lfs.findCachePath(dirs, minFreeSpace);
80 
81 #if 0
82  std::cerr /* edm::LogInfo("StorageFactory") */
83  << "Using '" << m_tempdir << "' for temp dir"
84  << std::endl;
85 #endif
86 }

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

Referenced by StorageFactory().

◆ setTimeout()

void StorageFactory::setTimeout ( unsigned int  timeout)

Definition at line 46 of file StorageFactory.cc.

46 { m_timeout = timeout; }

References m_timeout, and timeout().

◆ stagein()

void StorageFactory::stagein ( const std::string &  url) const

◆ tempDir()

std::string StorageFactory::tempDir ( void  ) const

Definition at line 88 of file StorageFactory.cc.

88 { return m_tempdir; }

References m_tempdir.

◆ tempMinFree()

double StorageFactory::tempMinFree ( void  ) const

Definition at line 92 of file StorageFactory.cc.

92 { return m_tempfree; }

References m_tempfree.

◆ tempPath()

std::string StorageFactory::tempPath ( void  ) const

Definition at line 90 of file StorageFactory.cc.

90 { return m_temppath; }

References m_temppath.

◆ timeout()

unsigned int StorageFactory::timeout ( void  ) const

Definition at line 48 of file StorageFactory.cc.

48 { return m_timeout; }

References m_timeout.

Referenced by setTimeout().

◆ wrapNonLocalFile()

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

207  {
210  if (mode & IOFlags::OpenWrite) {
211  // For now, issue no warning - otherwise, we'd always warn on output files.
212  } else if (m_tempdir.empty()) {
213  edm::LogWarning("StorageFactory") << m_unusableDirWarnings;
214  } else if ((not path.empty()) and m_lfs.isLocalPath(path)) {
215  // For now, issue no warning - otherwise, we'd always warn on local input files.
216  } else {
217  if (accounting()) {
218  s = std::make_unique<StorageAccountProxy>(proto, std::move(s));
219  }
220  s = std::make_unique<LocalCacheFile>(std::move(s), m_tempdir);
221  }
222  }
223 
224  return s;
225 }

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

Member Data Documentation

◆ m_accounting

bool StorageFactory::m_accounting
private

Definition at line 66 of file StorageFactory.h.

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

◆ m_cacheHint

CacheHint StorageFactory::m_cacheHint
private

Definition at line 64 of file StorageFactory.h.

Referenced by cacheHint(), and setCacheHint().

◆ m_debugLevel

unsigned int StorageFactory::m_debugLevel
private

Definition at line 72 of file StorageFactory.h.

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

◆ m_lfs

LocalFileSystem StorageFactory::m_lfs
private

Definition at line 73 of file StorageFactory.h.

Referenced by setTempDir(), and wrapNonLocalFile().

◆ m_makers

MakerTable StorageFactory::m_makers
mutableprivate

Definition at line 63 of file StorageFactory.h.

Referenced by getMaker().

◆ m_readHint

ReadHint StorageFactory::m_readHint
private

Definition at line 65 of file StorageFactory.h.

Referenced by readHint(), and setReadHint().

◆ m_tempdir

std::string StorageFactory::m_tempdir
private

Definition at line 69 of file StorageFactory.h.

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

◆ m_tempfree

double StorageFactory::m_tempfree
private

Definition at line 67 of file StorageFactory.h.

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

◆ m_temppath

std::string StorageFactory::m_temppath
private

Definition at line 68 of file StorageFactory.h.

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

◆ m_timeout

unsigned int StorageFactory::m_timeout
private

Definition at line 71 of file StorageFactory.h.

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

◆ m_unusableDirWarnings

std::string StorageFactory::m_unusableDirWarnings
private

Definition at line 70 of file StorageFactory.h.

Referenced by setTempDir(), and wrapNonLocalFile().

◆ s_instance

StorageFactory StorageFactory::s_instance
staticprivate

Definition at line 74 of file StorageFactory.h.

Referenced by get(), and getToModify().

personalPlayback.level
level
Definition: personalPlayback.py:22
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
relmon_authenticated_wget.url
url
Definition: relmon_authenticated_wget.py:22
StorageFactory::m_lfs
LocalFileSystem m_lfs
Definition: StorageFactory.h:73
StorageFactory::CacheHint
CacheHint
Definition: StorageFactory.h:15
heppy_check.dirs
dirs
Definition: heppy_check.py:26
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
StorageFactory::READ_HINT_UNBUFFERED
Definition: StorageFactory.h:17
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
StorageMaker
Definition: StorageMaker.h:9
StorageMaker::AuxSettings::setTimeout
AuxSettings & setTimeout(unsigned int iTime)
Definition: StorageMaker.h:20
IOFlags::OpenWrap
Definition: IOFlags.h:35
IOFlags::OpenWrite
Definition: IOFlags.h:8
end
#define end
Definition: vmac.h:39
StorageFactory::READ_HINT_READAHEAD
Definition: StorageFactory.h:17
StorageFactory::accounting
bool accounting(void) const
Definition: StorageFactory.cc:36
alignCSCRings.s
s
Definition: alignCSCRings.py:92
LocalFileSystem::findCachePath
std::pair< std::string, std::string > findCachePath(const std::vector< std::string > &paths, double minFreeSpace) const
Definition: LocalFileSystem.cc:431
StorageFactory::m_tempdir
std::string m_tempdir
Definition: StorageFactory.h:69
StorageFactory::CACHE_HINT_LAZY_DOWNLOAD
Definition: StorageFactory.h:15
StorageAccount::Operation::check
StorageFactory::READ_HINT_AUTO
Definition: StorageFactory.h:17
StorageFactory::m_debugLevel
unsigned int m_debugLevel
Definition: StorageFactory.h:72
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
StorageAccount::Stamp
Definition: StorageAccount.h:93
StorageFactory::s_instance
static StorageFactory s_instance
Definition: StorageFactory.h:74
edmplugin::PluginManager::configure
static PluginManager & configure(const Config &)
Definition: PluginManager.cc:316
runTheMatrix.err
err
Definition: runTheMatrix.py:288
StorageFactory::m_accounting
bool m_accounting
Definition: StorageFactory.h:66
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
StorageAccount::Operation::open
beam_dqm_sourceclient-live_cfg.cerr
cerr
Definition: beam_dqm_sourceclient-live_cfg.py:17
StorageAccount::tokenForStorageClassName
static StorageClassToken tokenForStorageClassName(std::string const &iName)
Definition: StorageAccount.cc:38
StorageFactory::CACHE_HINT_AUTO_DETECT
Definition: StorageFactory.h:15
StorageFactory::m_cacheHint
CacheHint m_cacheHint
Definition: StorageFactory.h:64
StorageMaker::AuxSettings::setDebugLevel
AuxSettings & setDebugLevel(unsigned int iLevel)
Definition: StorageMaker.h:15
dqmMemoryStats.stats
stats
Definition: dqmMemoryStats.py:134
edmplugin::standard::config
PluginManager::Config config()
Definition: standard.cc:21
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
get
#define get
StorageAccount::Operation::stagein
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
StorageFactory::m_timeout
unsigned int m_timeout
Definition: StorageFactory.h:71
eostools.move
def move(src, dest)
Definition: eostools.py:511
StorageFactory::getMaker
StorageMaker * getMaker(const std::string &proto) const
Definition: StorageFactory.cc:94
mergeAndRegister.rest
rest
Definition: mergeAndRegister.py:121
StorageFactory::cacheHint
CacheHint cacheHint(void) const
Definition: StorageFactory.cc:40
StorageFactory::CACHE_HINT_APPLICATION
Definition: StorageFactory.h:15
relativeConstraints.value
value
Definition: relativeConstraints.py:53
StorageAccount::counter
static Counter & counter(StorageClassToken token, Operation operation)
Definition: StorageAccount.cc:97
StorageFactory::m_tempfree
double m_tempfree
Definition: StorageFactory.h:67
StorageFactory::CACHE_HINT_STORAGE
Definition: StorageFactory.h:15
cms::Exception
Definition: Exception.h:70
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
StorageFactory::m_readHint
ReadHint m_readHint
Definition: StorageFactory.h:65
StorageFactory::m_makers
MakerTable m_makers
Definition: StorageFactory.h:63
StorageFactory::m_temppath
std::string m_temppath
Definition: StorageFactory.h:68
StorageMaker::AuxSettings
Definition: StorageMaker.h:11
LocalFileSystem::isLocalPath
bool isLocalPath(const std::string &path) const
Definition: LocalFileSystem.cc:382
StorageFactory::timeout
unsigned int timeout(void) const
Definition: StorageFactory.cc:48
begin
#define begin
Definition: vmac.h:32
edmplugin::PluginManager::isAvailable
static bool isAvailable()
Definition: PluginManager.cc:347
StorageFactory::setTempDir
void setTempDir(const std::string &s, double minFreeSpace)
Definition: StorageFactory.cc:54
StorageFactory::m_unusableDirWarnings
std::string m_unusableDirWarnings
Definition: StorageFactory.h:70
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
pixel_dqm_sourceclient-live_cfg.enabled
enabled
Definition: pixel_dqm_sourceclient-live_cfg.py:131
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316