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 
22  namespace {
23  void throwProducesWithoutAbility(const char* transitionName, std::string const& productTypeName) {
25  << "Module declares it can produce a product of type \'" << productTypeName << "\'\nin a " << transitionName
26  << ", but does not have the ability to produce in " << transitionName << "s.\n"
27  << "You must add a template parameter of type " << transitionName << "Producer\n"
28  << "or " << transitionName << "Producer to the EDProducer or EDFilter base class\n"
29  << "of the module. Or you could remove the call to the function \'produces\'\n"
30  << "(Note legacy modules are not ever allowed to produce in Runs or Lumis)\n";
31  }
32  } // namespace
33 
34  void ProductRegistryHelper::addToRegistry(TypeLabelList::const_iterator const& iBegin,
35  TypeLabelList::const_iterator const& iEnd,
36  ModuleDescription const& iDesc,
37  ProductRegistry& iReg,
38  ProductRegistryHelper* iProd,
39  bool iIsListener) {
40  std::vector<std::string> missingDictionaries;
41  std::vector<std::string> producedTypes;
42  std::set<std::tuple<BranchType, std::type_index, std::string>> registeredProducts;
43 
44  for (TypeLabelList::const_iterator p = iBegin; p != iEnd; ++p) {
45  if (p->transition_ == Transition::BeginRun && not iProd->hasAbilityToProduceInBeginRuns()) {
46  throwProducesWithoutAbility("BeginRun", p->typeID_.userClassName());
47  } else if (p->transition_ == Transition::EndRun && not iProd->hasAbilityToProduceInEndRuns()) {
48  throwProducesWithoutAbility("EndRun", p->typeID_.userClassName());
49  } else if (p->transition_ == Transition::BeginLuminosityBlock && not iProd->hasAbilityToProduceInBeginLumis()) {
50  throwProducesWithoutAbility("BeginLuminosityBlock", p->typeID_.userClassName());
51  } else if (p->transition_ == Transition::EndLuminosityBlock && not iProd->hasAbilityToProduceInEndLumis()) {
52  throwProducesWithoutAbility("EndLuminosityBlock", p->typeID_.userClassName());
53  } else if (p->transition_ == Transition::BeginProcessBlock &&
55  throwProducesWithoutAbility("BeginProcessBlock", p->typeID_.userClassName());
56  } else if (p->transition_ == Transition::EndProcessBlock && not iProd->hasAbilityToProduceInEndProcessBlocks()) {
57  throwProducesWithoutAbility("EndProcessBlock", p->typeID_.userClassName());
58  }
59  if (!checkDictionary(missingDictionaries, p->typeID_)) {
60  checkDictionaryOfWrappedType(missingDictionaries, p->typeID_);
61  producedTypes.emplace_back(p->typeID_.className());
62  continue;
63  }
64  auto branchType = convertToBranchType(p->transition_);
65  if (branchType != InEvent) {
66  std::tuple<BranchType, std::type_index, std::string> entry{
67  branchType, p->typeID_.typeInfo(), p->productInstanceName_};
68  if (registeredProducts.end() != registeredProducts.find(entry)) {
69  //ignore registration of items if in both begin and end transitions for now
70  // This is to work around ExternalLHEProducer
71  continue;
72  } else {
73  registeredProducts.insert(entry);
74  }
75  }
76 
77  TypeWithDict type(p->typeID_.typeInfo());
78  BranchDescription pdesc(branchType,
79  iDesc.moduleLabel(),
80  iDesc.processName(),
81  p->typeID_.userClassName(),
82  p->typeID_.friendlyClassName(),
83  p->productInstanceName_,
84  iDesc.moduleName(),
85  iDesc.parameterSetID(),
86  type,
87  true,
88  isEndTransition(p->transition_));
89  if (p->aliasType_ == TypeLabelItem::AliasType::kSwitchAlias) {
90  if (p->branchAlias_.empty()) {
92  << "Branch alias type has been set to SwitchAlias, but the alias content is empty.\n"
93  << "Please report this error to the FWCore developers";
94  }
95  pdesc.setSwitchAliasModuleLabel(p->branchAlias_);
96  }
97  setIsMergeable(pdesc);
98 
99  if (pdesc.transient()) {
100  if (!checkDictionary(missingDictionaries, pdesc.wrappedName(), pdesc.wrappedType())) {
101  // It is should be impossible to get here, because the only way to
102  // make it transient is in the line that causes the wrapped dictionary
103  // to be created. Just to be safe I leave this check here ...
104  producedTypes.emplace_back(pdesc.className());
105  continue;
106  }
107  } else {
108  // also check constituents of wrapped types if it is not transient
109  if (!checkClassDictionaries(missingDictionaries, pdesc.wrappedName(), pdesc.wrappedType())) {
110  producedTypes.emplace_back(pdesc.className());
111  continue;
112  }
113  }
114  if (!p->branchAlias_.empty())
115  pdesc.insertBranchAlias(p->branchAlias_);
116  iReg.addProduct(pdesc, iIsListener);
117  }
118 
119  if (!missingDictionaries.empty()) {
120  std::string context("Calling ProductRegistryHelper::addToRegistry, checking dictionaries for produced types");
121  throwMissingDictionariesException(missingDictionaries, context, producedTypes);
122  }
123  }
124 } // namespace edm
edm::Transition::EndProcessBlock
edm::ModuleDescription::moduleLabel
std::string const & moduleLabel() const
Definition: ModuleDescription.h:43
edm::throwMissingDictionariesException
void throwMissingDictionariesException(std::vector< std::string > &missingDictionaries, std::string const &context)
Definition: DictionaryTools.cc:193
funct::false
false
Definition: Factorize.h:29
edm::ProductRegistryHelper::hasAbilityToProduceInEndRuns
virtual bool hasAbilityToProduceInEndRuns() const
Definition: ProductRegistryHelper.h:170
edm::ProductRegistryHelper::hasAbilityToProduceInBeginRuns
virtual bool hasAbilityToProduceInBeginRuns() const
Definition: ProductRegistryHelper.h:169
edm::isEndTransition
constexpr bool isEndTransition(Transition iValue)
Definition: Transition.h:37
edm::setIsMergeable
void setIsMergeable(BranchDescription &)
Definition: setIsMergeable.cc:15
edm::errors::LogicError
Definition: EDMException.h:37
edm::ProductRegistryHelper::hasAbilityToProduceInBeginLumis
virtual bool hasAbilityToProduceInBeginLumis() const
Definition: ProductRegistryHelper.h:172
edm
HLT enums.
Definition: AlignableModifier.h:19
mps_splice.entry
entry
Definition: mps_splice.py:68
edm::ModuleDescription::moduleName
std::string const & moduleName() const
Definition: ModuleDescription.h:42
ProductRegistryHelper.h
TypeWithDict.h
edm::ModuleDescription::processName
std::string const & processName() const
Definition: ModuleDescription.cc:47
ProductRegistry.h
edm::checkDictionaryOfWrappedType
bool checkDictionaryOfWrappedType(std::vector< std::string > &missingDictionaries, TypeID const &unwrappedTypeID)
Definition: DictionaryTools.cc:80
edm::ModuleDescription
Definition: ModuleDescription.h:21
edm::checkClassDictionaries
bool checkClassDictionaries(std::vector< std::string > &missingDictionaries, TypeID const &typeID)
Definition: DictionaryTools.cc:102
edm::ProductRegistry
Definition: ProductRegistry.h:37
ModuleDescription.h
visDQMUpload.context
context
Definition: visDQMUpload.py:37
EDMException.h
edm::ProductRegistryHelper::hasAbilityToProduceInEndProcessBlocks
virtual bool hasAbilityToProduceInEndProcessBlocks() const
Definition: ProductRegistryHelper.h:167
edm::ProductRegistryHelper::hasAbilityToProduceInBeginProcessBlocks
virtual bool hasAbilityToProduceInBeginProcessBlocks() const
Definition: ProductRegistryHelper.h:166
edm::ProductRegistryHelper::~ProductRegistryHelper
virtual ~ProductRegistryHelper() noexcept(false)
Definition: ProductRegistryHelper.cc:18
edm::ProductRegistryHelper::hasAbilityToProduceInEndLumis
virtual bool hasAbilityToProduceInEndLumis() const
Definition: ProductRegistryHelper.h:173
edm::InEvent
Definition: BranchType.h:11
edm::Transition::BeginLuminosityBlock
edm::ProductRegistry::addProduct
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
Definition: ProductRegistry.cc:68
edm::ProductRegistryHelper::typeLabelList
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
Definition: ProductRegistryHelper.cc:20
edm::convertToBranchType
constexpr BranchType convertToBranchType(Transition iValue)
Definition: Transition.h:26
BranchDescription.h
edm::TypeWithDict
Definition: TypeWithDict.h:38
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
edm::ProductRegistryHelper::typeLabelList_
TypeLabelList typeLabelList_
Definition: ProductRegistryHelper.h:176
edm::ProductRegistryHelper::TypeLabelList
std::vector< TypeLabelItem > TypeLabelList
Definition: ProductRegistryHelper.h:86
edm::Transition::BeginProcessBlock
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ProductRegistryHelper::addToRegistry
static void addToRegistry(TypeLabelList::const_iterator const &iBegin, TypeLabelList::const_iterator const &iEnd, ModuleDescription const &iDesc, ProductRegistry &iReg, ProductRegistryHelper *iProd, bool iIsListener=false)
Definition: ProductRegistryHelper.cc:34
edm::Transition::EndLuminosityBlock
setIsMergeable.h
edm::Transition::BeginRun
Exception
Definition: hltDiff.cc:245
edm::BranchDescription
Definition: BranchDescription.h:32
edm::ProductRegistryHelper::TypeLabelItem::AliasType::kSwitchAlias
edm::checkDictionary
bool checkDictionary(std::vector< std::string > &missingDictionaries, TypeID const &typeID)
Definition: DictionaryTools.cc:67
edm::ModuleDescription::parameterSetID
ParameterSetID const & parameterSetID() const
Definition: ModuleDescription.h:41
DictionaryTools.h
edm::Transition::EndRun
edm::ProductRegistryHelper
Definition: ProductRegistryHelper.h:23