CMS 3D CMS Logo

StorageFactory.cc
Go to the documentation of this file.
10 
12 
14  : m_cacheHint(CACHE_HINT_AUTO_DETECT),
15  m_readHint(READ_HINT_AUTO),
16  m_accounting(false),
17  m_tempfree(4.), // GB
18  m_temppath(".:$TMPDIR"),
19  m_timeout(0U),
20  m_debugLevel(0U) {
22 }
23 
25 
27 
29 
31  bool old = m_accounting;
33  return old;
34 }
35 
36 bool StorageFactory::accounting(void) const { return m_accounting; }
37 
39 
41 
43 
45 
47 
48 unsigned int StorageFactory::timeout(void) const { return m_timeout; }
49 
51 
52 unsigned int StorageFactory::debugLevel(void) const { return m_debugLevel; }
53 
54 void StorageFactory::setTempDir(const std::string &s, double minFreeSpace) {
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 }
87 
89 
91 
92 double StorageFactory::tempMinFree(void) const { return m_tempfree; }
93 
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 }
108 
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 }
121 
122 std::unique_ptr<Storage> StorageFactory::open(const std::string &url, int mode /* = IOFlags::OpenRead */) const {
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 }
156 
158  std::string protocol;
160 
161  std::unique_ptr<StorageAccount::Stamp> stats;
162  if (StorageMaker *maker = getMaker(url, protocol, rest)) {
163  if (m_accounting) {
166  }
167  try {
169  if (stats)
170  stats->tick();
171  } catch (cms::Exception &err) {
172  edm::LogWarning("StorageFactory::stagein()") << "Failed to stage in file '" << url << "' because:\n"
173  << err.explainSelf();
174  }
175  }
176 }
177 
178 bool StorageFactory::check(const std::string &url, IOOffset *size /* = 0 */) const {
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 }
203 
204 std::unique_ptr<Storage> StorageFactory::wrapNonLocalFile(std::unique_ptr<Storage> s,
205  const std::string &proto,
206  const std::string &path,
207  int mode) const {
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 }
personalPlayback.level
level
Definition: personalPlayback.py:22
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
StorageFactory::setCacheHint
void setCacheHint(CacheHint value)
Definition: StorageFactory.cc:38
StorageFactory::tempDir
std::string tempDir(void) const
Definition: StorageFactory.cc:88
relmon_authenticated_wget.url
url
Definition: relmon_authenticated_wget.py:22
StorageFactory::m_lfs
LocalFileSystem m_lfs
Definition: StorageFactory.h:73
MessageLogger.h
StorageFactory::~StorageFactory
~StorageFactory(void)
Definition: StorageFactory.cc:24
funct::false
false
Definition: Factorize.h:34
StorageFactory::wrapNonLocalFile
std::unique_ptr< Storage > wrapNonLocalFile(std::unique_ptr< Storage > s, const std::string &proto, const std::string &path, int mode) const
Definition: StorageFactory.cc:204
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::open
std::unique_ptr< Storage > open(const std::string &url, int mode=IOFlags::OpenRead) const
Definition: StorageFactory.cc:122
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
StorageFactory::StorageFactory
StorageFactory(void)
Definition: StorageFactory.cc:13
IOFlags::OpenWrap
Definition: IOFlags.h:35
IOFlags::OpenWrite
Definition: IOFlags.h:8
end
#define end
Definition: vmac.h:39
StorageFactory::getToModify
static StorageFactory * getToModify(void)
Definition: StorageFactory.cc:28
StorageFactory::tempPath
std::string tempPath(void) const
Definition: StorageFactory.cc:90
StorageFactory::setReadHint
void setReadHint(ReadHint value)
Definition: StorageFactory.cc:42
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
StorageFactory::setDebugLevel
void setDebugLevel(unsigned int level)
Definition: StorageFactory.cc:50
StorageFactory::get
static const StorageFactory * get(void)
Definition: StorageFactory.cc:26
StorageAccount::Operation::check
StorageAccount.h
StorageFactory::stagein
void stagein(const std::string &url) const
Definition: StorageFactory.cc:157
StorageFactory::m_debugLevel
unsigned int m_debugLevel
Definition: StorageFactory.h:72
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
StorageAccountProxy.h
StorageFactory::readHint
ReadHint readHint(void) const
Definition: StorageFactory.cc:44
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
standard.h
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
StorageFactory::check
bool check(const std::string &url, IOOffset *size=nullptr) const
Definition: StorageFactory.cc:178
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
StorageFactory.h
StorageFactory::debugLevel
unsigned int debugLevel(void) const
Definition: StorageFactory.cc:52
value
Definition: value.py:1
StorageAccount::tokenForStorageClassName
static StorageClassToken tokenForStorageClassName(std::string const &iName)
Definition: StorageAccount.cc:38
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
timeout
Definition: timeout.py:1
get
#define get
StorageAccount::Operation::stagein
StorageFactory
Definition: StorageFactory.h:13
instance
static PFTauRenderPlugin instance
Definition: PFTauRenderPlugin.cc:70
StorageMakerFactory.h
StorageFactory::m_timeout
unsigned int m_timeout
Definition: StorageFactory.h:71
LocalCacheFile.h
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
PluginManager.h
StorageFactory::setTimeout
void setTimeout(unsigned int timeout)
Definition: StorageFactory.cc:46
StorageFactory::tempMinFree
double tempMinFree(void) const
Definition: StorageFactory.cc:92
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
Exception.h
StorageFactory::enableAccounting
bool enableAccounting(bool enabled)
Definition: StorageFactory.cc:30
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::ReadHint
ReadHint
Definition: StorageFactory.h:17
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:137
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316