CMS 3D CMS Logo

ProductRegistryHelper.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ProductRegistryHelper_h
2 #define FWCore_Framework_ProductRegistryHelper_h
3 
4 /*----------------------------------------------------------------------
5 
6 ProductRegistryHelper:
7 
8 ----------------------------------------------------------------------*/
9 
14 #include <string>
15 #include <vector>
16 #include <type_traits>
17 
18 namespace edm {
19  class ModuleDescription;
20  class ProductRegistry;
21  struct DoNotRecordParents;
22 
23  template <Transition B>
25 
27  public:
28  virtual ~ProductRegistryHelper() noexcept(false);
30 
31  // has_donotrecordparents<T>::value is true if we should not
32  // record parentage for type T, and false otherwise.
33  template <typename T>
36  };
37 
38  struct TypeLabelItem {
39  enum class AliasType : char { kBranchAlias, kSwitchAlias };
40 
41  TypeLabelItem(Transition const& transition, TypeID const& tid, std::string pin)
42  : transition_(transition),
43  typeID_(tid),
45  branchAlias_(),
46  aliasType_(AliasType::kBranchAlias),
54  };
55 
57  BranchAliasSetter(TypeLabelItem& iItem, EDPutToken iToken) : value_(iItem), token_(iToken) {}
58 
61  return *this;
62  }
66  return *this;
67  }
70 
71  operator EDPutToken() { return token_; }
72  };
73 
74  template <typename T>
76  BranchAliasSetterT(TypeLabelItem& iItem, EDPutTokenT<T> iToken) : value_(iItem), token_(std::move(iToken)) {}
77 
79 
82  return *this;
83  }
86 
87  template <typename U>
89  static_assert(std::is_same_v<T, U>);
90  return token_;
91  }
92 
93  operator EDPutTokenT<T>() { return token_; }
94  operator EDPutToken() { return EDPutToken(token_.index()); }
95  };
96 
97  typedef std::vector<TypeLabelItem> TypeLabelList;
98 
100  TypeLabelList const& typeLabelList() const;
101 
102  std::vector<bool> const& recordProvenanceList() const { return recordProvenanceList_; }
103 
104  static void addToRegistry(TypeLabelList::const_iterator const& iBegin,
105  TypeLabelList::const_iterator const& iEnd,
106  ModuleDescription const& iDesc,
107  ProductRegistry& iReg,
108  ProductRegistryHelper* iProd,
109  bool iIsListener = false);
110 
112 
118  template <Transition Tr = Transition::Event>
119  [[nodiscard]] auto produces(std::string instanceName) noexcept {
120  return ProductRegistryHelperAdaptor<Tr>(*this, std::move(instanceName));
121  }
122  template <Transition Tr = Transition::Event>
123  [[nodiscard]] auto produces() noexcept {
124  return ProductRegistryHelperAdaptor<Tr>(*this);
125  }
126 
127  template <class ProductType>
129  return produces<ProductType, InEvent>(std::string());
130  }
131 
132  template <class ProductType>
134  return produces<ProductType, InEvent>(std::move(instanceName));
135  }
136 
137  template <typename ProductType, BranchType B>
139  return produces<ProductType, B>(std::string());
140  }
141 
142  template <typename ProductType, BranchType B>
144  TypeID tid(typeid(ProductType));
146  produces<B>(tid, std::move(instanceName), (not has_donotrecordparents<ProductType>::value) and B == InEvent)};
147  }
148 
149  template <typename ProductType, Transition B>
151  return produces<ProductType, B>(std::string());
152  }
153 
154  template <typename ProductType, Transition B>
156  TypeID tid(typeid(ProductType));
157  return BranchAliasSetterT<ProductType>{produces<B>(
158  tid, std::move(instanceName), (not has_donotrecordparents<ProductType>::value) and B == Transition::Event)};
159  }
160 
161  BranchAliasSetter produces(const TypeID& id,
162  std::string instanceName = std::string(),
163  bool recordProvenance = true) {
164  return produces<Transition::Event>(id, std::move(instanceName), recordProvenance);
165  }
166 
167  template <BranchType B>
168  BranchAliasSetter produces(const TypeID& id,
169  std::string instanceName = std::string(),
170  bool recordProvenance = true) {
171  unsigned int index = typeLabelList_.size();
172  typeLabelList_.emplace_back(convertToTransition(B), id, std::move(instanceName));
173  recordProvenanceList_.push_back(recordProvenance and B == InEvent);
174  return BranchAliasSetter{typeLabelList_.back(), EDPutToken{static_cast<unsigned int>(index)}};
175  }
176  template <Transition B>
177  BranchAliasSetter produces(const TypeID& id,
178  std::string instanceName = std::string(),
179  bool recordProvenance = true) {
180  unsigned int index = typeLabelList_.size();
181  typeLabelList_.emplace_back(B, id, std::move(instanceName));
182  recordProvenanceList_.push_back(recordProvenance and B == Transition::Event);
183  return BranchAliasSetter{typeLabelList_.back(), EDPutToken{index}};
184  }
185 
186  EDPutToken transforms(const TypeID& id, std::string instanceName) {
187  unsigned int index = typeLabelList_.size();
188  typeLabelList_.emplace_back(Transition::Event, id, std::move(instanceName));
189  typeLabelList_.back().isTransform_ = true;
190  recordProvenanceList_.push_back(true);
191  return EDPutToken{index};
192  }
193 
194  virtual bool hasAbilityToProduceInBeginProcessBlocks() const { return false; }
195  virtual bool hasAbilityToProduceInEndProcessBlocks() const { return false; }
196 
197  virtual bool hasAbilityToProduceInBeginRuns() const { return false; }
198  virtual bool hasAbilityToProduceInEndRuns() const { return false; }
199 
200  virtual bool hasAbilityToProduceInBeginLumis() const { return false; }
201  virtual bool hasAbilityToProduceInEndLumis() const { return false; }
202 
203  private:
205  std::vector<bool> recordProvenanceList_;
206  };
207 
208  template <Transition B>
210  public:
211  template <typename TYPE>
213  return m_helper.template produces<TYPE, B>(m_label);
214  }
215 
216  private:
217  //only ProductRegistryHelper is allowed to make an instance of this class
218  friend class ProductRegistryHelper;
219 
221  : m_helper(iBase), m_label(std::move(iLabel)) {}
223 
226  };
227 
228 } // namespace edm
229 
230 #endif
Definition: APVGainStruct.h:7
EDPutToken transforms(const TypeID &id, std::string instanceName)
std::vector< bool > const & recordProvenanceList() const
BranchAliasSetterT< T > & setBranchAlias(std::string alias)
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)
virtual bool hasAbilityToProduceInEndRuns() const
virtual bool hasAbilityToProduceInBeginLumis() const
BranchAliasSetterT(TypeLabelItem &iItem, EDPutTokenT< T > iToken)
ProductRegistryHelperAdaptor(ProductRegistryHelper &iBase, std::string iLabel)
BranchAliasSetter & setSwitchAlias(std::string moduleLabel)
TypeLabelItem(Transition const &transition, TypeID const &tid, std::string pin)
std::vector< TypeLabelItem > TypeLabelList
virtual bool hasAbilityToProduceInEndProcessBlocks() const
ProductRegistryHelperAdaptor(ProductRegistryHelper &iBase)
Transition
Definition: Transition.h:12
Definition: value.py:1
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
BranchAliasSetter(TypeLabelItem &iItem, EDPutToken iToken)
constexpr Transition convertToTransition(BranchType iValue)
Definition: Transition.h:31
HLT enums.
virtual bool hasAbilityToProduceInBeginProcessBlocks() const
virtual bool hasAbilityToProduceInBeginRuns() const
BranchAliasSetter & setBranchAlias(std::string alias)
std::vector< bool > recordProvenanceList_
virtual bool hasAbilityToProduceInEndLumis() const
def move(src, dest)
Definition: eostools.py:511