CMS 3D CMS Logo

resolveMaker.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_interface_resolveMaker_h
2 #define FWCore_Framework_interface_resolveMaker_h
3 
8 
9 #include <memory>
10 #include <string>
11 
12 namespace edm::detail {
14  std::string const& modtype,
15  ModuleTypeResolverBase const* resolver);
16 
17  // Returns a non-owning pointer to the maker. Can be nullptr if
18  // failed to insert the maker to the cache
19  template <typename TFactory, typename TCache>
20  auto resolveMaker(std::string const& moduleType,
21  ModuleTypeResolverMaker const* resolverMaker,
22  edm::ParameterSet const& modulePSet,
23  TCache& makerCache) -> typename TCache::mapped_type::element_type const* {
24  if (resolverMaker) {
25  auto resolver = resolverMaker->makeResolver(modulePSet);
26  auto index = resolver->kInitialIndex;
27  auto newType = moduleType;
28  do {
29  auto [ttype, tindex] = resolver->resolveType(std::move(newType), index);
30  newType = std::move(ttype);
31  index = tindex;
32  // try the maker cache first
33  auto found = makerCache.find(newType);
34  if (found != makerCache.end()) {
35  return found->second.get();
36  }
37 
38  // if not in cache, then try to create
39  auto m = TFactory::get()->tryToCreate(newType);
40  if (m) {
41  //FDEBUG(1) << "Factory: created worker of type " << newType << std::endl;
42  auto [it, succeeded] = makerCache.emplace(newType, std::move(m));
43  if (not succeeded) {
44  return nullptr;
45  }
46  return it->second.get();
47  }
48  // not found, try next one
49  } while (index != resolver->kLastIndex);
50  try {
51  //failed to find a plugin
52  auto m = TFactory::get()->create(moduleType);
53  return nullptr; // dummy return, the create() call throws an exception
54  } catch (cms::Exception& iExcept) {
55  detail::annotateResolverMakerExceptionAndRethrow(iExcept, moduleType, resolver.get());
56  }
57  }
58  auto [it, succeeded] = makerCache.emplace(moduleType, TFactory::get()->create(moduleType));
59  //FDEBUG(1) << "Factory: created worker of type " << moduleType << std::endl;
60  if (not succeeded) {
61  return nullptr;
62  }
63  return it->second.get();
64  }
65 } // namespace edm::detail
66 
67 #endif
void annotateResolverMakerExceptionAndRethrow(cms::Exception &except, std::string const &modtype, ModuleTypeResolverBase const *resolver)
Definition: resolverMaker.cc:4
def create(alignables, pedeDump, additionalData, outputFile, config)
auto resolveMaker(std::string const &moduleType, ModuleTypeResolverMaker const *resolverMaker, edm::ParameterSet const &modulePSet, TCache &makerCache) -> typename TCache::mapped_type::element_type const *
Definition: resolveMaker.h:20
#define get
def move(src, dest)
Definition: eostools.py:511