CMS 3D CMS Logo

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