CMS 3D CMS Logo

StorageFactory.cc
Go to the documentation of this file.
1 #include <memory>
2 
12 
14 
16  : m_cacheHint(CACHE_HINT_AUTO_DETECT),
17  m_readHint(READ_HINT_AUTO),
18  m_accounting(false),
19  m_tempfree(4.), // GB
20  m_temppath(".:$TMPDIR"),
21  m_timeout(0U),
22  m_debugLevel(0U) {
24 }
25 
27 
29 
31 
33  bool old = m_accounting;
35  return old;
36 }
37 
38 bool StorageFactory::accounting(void) const { return m_accounting; }
39 
41 
43 
45 
47 
49 
50 unsigned int StorageFactory::timeout(void) const { return m_timeout; }
51 
53 
54 unsigned int StorageFactory::debugLevel(void) const { return m_debugLevel; }
55 
56 void StorageFactory::setTempDir(const std::string &s, double minFreeSpace) {
57 #if 0
58  std::cerr /* edm::LogInfo("StorageFactory") */
59  << "Considering path '" << s
60  << "', min free space " << minFreeSpace
61  << "GB for temp dir" << std::endl;
62 #endif
63 
64  size_t begin = 0;
65  std::vector<std::string> dirs;
66  dirs.reserve(std::count(s.begin(), s.end(), ':') + 1);
67 
68  while (true) {
69  size_t end = s.find(':', begin);
70  if (end == std::string::npos) {
71  dirs.push_back(s.substr(begin, end));
72  break;
73  } else {
74  dirs.push_back(s.substr(begin, end - begin));
75  begin = end + 1;
76  }
77  }
78 
79  m_temppath = s;
80  m_tempfree = minFreeSpace;
81  std::tie(m_tempdir, m_unusableDirWarnings) = m_lfs.findCachePath(dirs, minFreeSpace);
82 
83 #if 0
84  std::cerr /* edm::LogInfo("StorageFactory") */
85  << "Using '" << m_tempdir << "' for temp dir"
86  << std::endl;
87 #endif
88 }
89 
91 
93 
94 double StorageFactory::tempMinFree(void) const { return m_tempfree; }
95 
97  auto itFound = m_makers.find(proto);
98  if (itFound != m_makers.end()) {
99  return itFound->second.get();
100  }
103  }
104  std::shared_ptr<StorageMaker> instance{StorageMakerFactory::get()->tryToCreate(proto)};
105  auto insertResult = m_makers.insert(MakerTable::value_type(proto, instance));
106  //Can't use instance since it is possible that another thread beat
107  // us to the insertion so the map contains a different instance.
108  return insertResult.first->second.get();
109 }
110 
112  size_t p = url.find(':');
113  if (p != std::string::npos) {
114  protocol = url.substr(0, p);
115  rest = url.substr(p + 1);
116  } else {
117  protocol = "file";
118  rest = url;
119  }
120 
121  return getMaker(protocol);
122 }
123 
124 std::unique_ptr<Storage> StorageFactory::open(const std::string &url, int mode /* = IOFlags::OpenRead */) const {
125  std::string protocol;
127  std::unique_ptr<Storage> ret;
128  std::unique_ptr<StorageAccount::Stamp> stats;
129  if (StorageMaker *maker = getMaker(url, protocol, rest)) {
130  if (m_accounting) {
132  stats = std::make_unique<StorageAccount::Stamp>(StorageAccount::counter(token, StorageAccount::Operation::open));
133  }
134  try {
135  if (auto storage = maker->open(
137  if (dynamic_cast<LocalCacheFile *>(storage.get()))
138  protocol = "local-cache";
139 
140  if (m_accounting)
141  ret = std::make_unique<StorageAccountProxy>(protocol, std::move(storage));
142  else
143  ret = std::move(storage);
144 
145  if (stats)
146  stats->tick();
147  }
148  } catch (cms::Exception &err) {
149  err.addContext("Calling StorageFactory::open()");
150  err.addAdditionalInfo(err.message());
151  err.clearMessage();
152  err << "Failed to open the file '" << url << "'";
153  throw;
154  }
155  }
156  return ret;
157 }
158 
160  std::string protocol;
162 
163  std::unique_ptr<StorageAccount::Stamp> stats;
164  if (StorageMaker *maker = getMaker(url, protocol, rest)) {
165  if (m_accounting) {
167  stats =
168  std::make_unique<StorageAccount::Stamp>(StorageAccount::counter(token, StorageAccount::Operation::stagein));
169  }
170  try {
172  if (stats)
173  stats->tick();
174  } catch (cms::Exception &err) {
175  edm::LogWarning("StorageFactory::stagein()") << "Failed to stage in file '" << url << "' because:\n"
176  << err.explainSelf();
177  }
178  }
179 }
180 
181 bool StorageFactory::check(const std::string &url, IOOffset *size /* = 0 */) const {
182  std::string protocol;
184 
185  bool ret = false;
186  std::unique_ptr<StorageAccount::Stamp> stats;
187  if (StorageMaker *maker = getMaker(url, protocol, rest)) {
188  if (m_accounting) {
190  stats = std::make_unique<StorageAccount::Stamp>(StorageAccount::counter(token, StorageAccount::Operation::check));
191  }
192  try {
193  ret = maker->check(
195  if (stats)
196  stats->tick();
197  } catch (cms::Exception &err) {
198  edm::LogWarning("StorageFactory::check()")
199  << "Existence or size check for the file '" << url << "' failed because:\n"
200  << err.explainSelf();
201  }
202  }
203 
204  return ret;
205 }
206 
207 std::unique_ptr<Storage> StorageFactory::wrapNonLocalFile(std::unique_ptr<Storage> s,
208  const std::string &proto,
209  const std::string &path,
210  int mode) const {
213  if (mode & IOFlags::OpenWrite) {
214  // For now, issue no warning - otherwise, we'd always warn on output files.
215  } else if (m_tempdir.empty()) {
216  edm::LogWarning("StorageFactory") << m_unusableDirWarnings;
217  } else if ((not path.empty()) and m_lfs.isLocalPath(path)) {
218  // For now, issue no warning - otherwise, we'd always warn on local input files.
219  } else {
220  if (accounting()) {
221  s = std::make_unique<StorageAccountProxy>(proto, std::move(s));
222  }
223  s = std::make_unique<LocalCacheFile>(std::move(s), m_tempdir);
224  }
225  }
226 
227  return s;
228 }
personalPlayback.level
level
Definition: personalPlayback.py:22
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
StorageFactory::setCacheHint
void setCacheHint(CacheHint value)
Definition: StorageFactory.cc:40
StorageFactory::tempDir
std::string tempDir(void) const
Definition: StorageFactory.cc:90
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:26
funct::false
false
Definition: Factorize.h:29
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:207
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:124
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:15
IOFlags::OpenWrap
Definition: IOFlags.h:35
IOFlags::OpenWrite
Definition: IOFlags.h:8
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
StorageFactory::getToModify
static StorageFactory * getToModify(void)
Definition: StorageFactory.cc:30
StorageFactory::tempPath
std::string tempPath(void) const
Definition: StorageFactory.cc:92
StorageFactory::setReadHint
void setReadHint(ReadHint value)
Definition: StorageFactory.cc:44
StorageFactory::accounting
bool accounting(void) const
Definition: StorageFactory.cc:38
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:426
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:52
StorageFactory::get
static const StorageFactory * get(void)
Definition: StorageFactory.cc:28
mps_fire.end
end
Definition: mps_fire.py:242
StorageAccount::Operation::check
StorageAccount.h
StorageFactory::stagein
void stagein(const std::string &url) const
Definition: StorageFactory.cc:159
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
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:46
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
standard.h
StorageFactory::s_instance
static StorageFactory s_instance
Definition: StorageFactory.h:74
edmplugin::PluginManager::configure
static PluginManager & configure(const Config &)
Definition: PluginManager.cc:315
StorageFactory::m_accounting
bool m_accounting
Definition: StorageFactory.h:66
StorageAccount::Operation::open
StorageFactory::check
bool check(const std::string &url, IOOffset *size=nullptr) const
Definition: StorageFactory.cc:181
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
StorageFactory.h
StorageFactory::debugLevel
unsigned int debugLevel(void) const
Definition: StorageFactory.cc:54
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
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
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:96
mergeAndRegister.rest
rest
Definition: mergeAndRegister.py:121
StorageFactory::cacheHint
CacheHint cacheHint(void) const
Definition: StorageFactory.cc:42
PluginManager.h
StorageFactory::setTimeout
void setTimeout(unsigned int timeout)
Definition: StorageFactory.cc:48
StorageFactory::tempMinFree
double tempMinFree(void) const
Definition: StorageFactory.cc:94
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:32
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:377
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
StorageFactory::timeout
unsigned int timeout(void) const
Definition: StorageFactory.cc:50
edmplugin::PluginManager::isAvailable
static bool isAvailable()
Definition: PluginManager.cc:346
StorageFactory::setTempDir
void setTempDir(const std::string &s, double minFreeSpace)
Definition: StorageFactory.cc:56
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:136
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316