CMS 3D CMS Logo

ProductRegistryHelper.cc
Go to the documentation of this file.
1 /*----------------------------------------------------------------------
2 
3 ----------------------------------------------------------------------*/
4 
13 
14 #include <vector>
15 #include <typeindex>
16 
17 namespace edm {
19 
21  return typeLabelList_;
22  }
23 
24  namespace {
25  void throwProducesWithoutAbility(const char* runOrLumi,
26  std::string const& productTypeName) {
27 
29  << "Module declares it can produce a product of type \'" << productTypeName
30  << "\'\nin a " << runOrLumi << ", but does not have the ability to produce in "
31  << runOrLumi << "s.\n"
32  << "You must add a template parameter of type Begin" << runOrLumi << "Producer\n"
33  << "or End" << runOrLumi << "Producer to the EDProducer or EDFilter base class\n"
34  << "of the module. Or you could remove the call to the function \'produces\'\n"
35  << "(Note legacy modules are not ever allowed to produce in Runs or Lumis)\n";
36  }
37  }
38 
39  void
40  ProductRegistryHelper::addToRegistry(TypeLabelList::const_iterator const& iBegin,
41  TypeLabelList::const_iterator const& iEnd,
42  ModuleDescription const& iDesc,
43  ProductRegistry& iReg,
44  ProductRegistryHelper* iProd,
45  bool iIsListener) {
46 
47  std::vector<std::string> missingDictionaries;
48  std::vector<std::string> producedTypes;
49  std::set<std::tuple<BranchType,std::type_index,std::string>> registeredProducts;
50 
51  for(TypeLabelList::const_iterator p = iBegin; p != iEnd; ++p) {
52  if (p->transition_ == Transition::BeginRun ||
53  p->transition_ == Transition::EndRun) {
54  if (not iProd->hasAbilityToProduceInRuns()) {
55  throwProducesWithoutAbility("Run", p->typeID_.userClassName());
56  }
57  } else if (p->transition_ == Transition::BeginLuminosityBlock ||
58  p->transition_ == Transition::EndLuminosityBlock) {
59  if (not iProd->hasAbilityToProduceInLumis()) {
60  throwProducesWithoutAbility("LuminosityBlock", p->typeID_.userClassName());
61  }
62  }
63  if (!checkDictionary(missingDictionaries, p->typeID_)) {
64  checkDictionaryOfWrappedType(missingDictionaries, p->typeID_);
65  producedTypes.emplace_back(p->typeID_.className());
66  continue;
67  }
68  auto branchType = convertToBranchType(p->transition_);
69  if(branchType != InEvent) {
70  std::tuple<BranchType, std::type_index, std::string> entry{ branchType,p->typeID_.typeInfo(),p->productInstanceName_};
71  if(registeredProducts.end() != registeredProducts.find(entry) ) {
72  //ignore registration of items if in both begin and end transitions for now
73  // This is to work around ExternalLHEProducer
74  continue;
75  } else {
76  registeredProducts.insert(entry);
77  }
78  }
79 
80  TypeWithDict type(p->typeID_.typeInfo());
82  iDesc.moduleLabel(),
83  iDesc.processName(),
84  p->typeID_.userClassName(),
85  p->typeID_.friendlyClassName(),
86  p->productInstanceName_,
87  iDesc.moduleName(),
88  iDesc.parameterSetID(),
89  type,
90  true,
91  isEndTransition(p->transition_));
92  setIsMergeable(pdesc);
93 
94  if (pdesc.transient()) {
95  if (!checkDictionary(missingDictionaries, pdesc.wrappedName(), pdesc.wrappedType())) {
96  // It is should be impossible to get here, because the only way to
97  // make it transient is in the line that causes the wrapped dictionary
98  // to be created. Just to be safe I leave this check here ...
99  producedTypes.emplace_back(pdesc.className());
100  continue;
101  }
102  } else {
103  // also check constituents of wrapped types if it is not transient
104  if (!checkClassDictionaries(missingDictionaries, pdesc.wrappedName(), pdesc.wrappedType())) {
105  producedTypes.emplace_back(pdesc.className());
106  continue;
107  }
108  }
109  if (!p->branchAlias_.empty()) pdesc.insertBranchAlias(p->branchAlias_);
110  iReg.addProduct(pdesc, iIsListener);
111  }
112 
113  if (!missingDictionaries.empty()) {
114  std::string context("Calling ProductRegistryHelper::addToRegistry, checking dictionaries for produced types");
115  throwMissingDictionariesException(missingDictionaries, context, producedTypes);
116  }
117  }
118 }
type
Definition: HCALResponse.h:21
void throwMissingDictionariesException(std::vector< std::string > &missingDictionaries, std::string const &context)
std::string const & processName() const
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
#define noexcept
std::string const & moduleName() const
virtual ~ProductRegistryHelper() noexcept(false)
static void addToRegistry(TypeLabelList::const_iterator const &iBegin, TypeLabelList::const_iterator const &iEnd, ModuleDescription const &iDesc, ProductRegistry &iReg, ProductRegistryHelper *iProd, bool iIsListener=false)
std::string const & moduleLabel() const
constexpr bool isEndTransition(Transition iValue)
Definition: Transition.h:31
virtual bool hasAbilityToProduceInRuns() const
std::vector< TypeLabelItem > TypeLabelList
bool checkDictionary(std::vector< std::string > &missingDictionaries, TypeID const &typeID)
bool checkClassDictionaries(std::vector< std::string > &missingDictionaries, TypeID const &typeID)
virtual bool hasAbilityToProduceInLumis() const
HLT enums.
ParameterSetID const & parameterSetID() const
bool checkDictionaryOfWrappedType(std::vector< std::string > &missingDictionaries, TypeID const &unwrappedTypeID)
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
void setIsMergeable(BranchDescription &)
constexpr BranchType convertToBranchType(Transition iValue)
Definition: Transition.h:21
def branchType(schema, name)
Definition: revisionDML.py:113