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 {
40 
41  TypeLabelItem(Transition const& transition, TypeID const& tid, std::string pin)
42  : transition_(transition),
43  typeID_(tid),
45  branchAlias_(),
46  aliasType_(AliasType::kBranchAlias) {}
52  };
53 
55  BranchAliasSetter(TypeLabelItem& iItem, EDPutToken iToken) : value_(iItem), token_(iToken) {}
56 
59  return *this;
60  }
64  return *this;
65  }
68 
69  operator EDPutToken() { return token_; }
70  };
71 
72  template <typename T>
74  BranchAliasSetterT(TypeLabelItem& iItem, EDPutTokenT<T> iToken) : value_(iItem), token_(std::move(iToken)) {}
75 
77 
80  return *this;
81  }
84 
85  template <typename U>
87  static_assert(std::is_same_v<T, U>);
88  return token_;
89  }
90 
91  operator EDPutTokenT<T>() { return token_; }
92  operator EDPutToken() { return EDPutToken(token_.index()); }
93  };
94 
95  typedef std::vector<TypeLabelItem> TypeLabelList;
96 
98  TypeLabelList const& typeLabelList() const;
99 
100  std::vector<bool> const& recordProvenanceList() const { return recordProvenanceList_; }
101 
102  static void addToRegistry(TypeLabelList::const_iterator const& iBegin,
103  TypeLabelList::const_iterator const& iEnd,
104  ModuleDescription const& iDesc,
105  ProductRegistry& iReg,
106  ProductRegistryHelper* iProd,
107  bool iIsListener = false);
108 
110 
116  template <Transition Tr = Transition::Event>
117  [[nodiscard]] auto produces(std::string instanceName) noexcept {
119  }
120  template <Transition Tr = Transition::Event>
121  [[nodiscard]] auto produces() noexcept {
122  return ProductRegistryHelperAdaptor<Tr>(*this);
123  }
124 
125  template <class ProductType>
127  return produces<ProductType, InEvent>(std::string());
128  }
129 
130  template <class ProductType>
132  return produces<ProductType, InEvent>(std::move(instanceName));
133  }
134 
135  template <typename ProductType, BranchType B>
137  return produces<ProductType, B>(std::string());
138  }
139 
140  template <typename ProductType, BranchType B>
142  TypeID tid(typeid(ProductType));
145  }
146 
147  template <typename ProductType, Transition B>
149  return produces<ProductType, B>(std::string());
150  }
151 
152  template <typename ProductType, Transition B>
154  TypeID tid(typeid(ProductType));
155  return BranchAliasSetterT<ProductType>{produces<B>(
157  }
158 
161  bool recordProvenance = true) {
162  return produces<Transition::Event>(id, std::move(instanceName), recordProvenance);
163  }
164 
165  template <BranchType B>
168  bool recordProvenance = true) {
169  unsigned int index = typeLabelList_.size();
171  recordProvenanceList_.push_back(recordProvenance and B == InEvent);
172  return BranchAliasSetter{typeLabelList_.back(), EDPutToken{static_cast<unsigned int>(index)}};
173  }
174  template <Transition B>
177  bool recordProvenance = true) {
178  unsigned int index = typeLabelList_.size();
179  typeLabelList_.emplace_back(B, id, std::move(instanceName));
180  recordProvenanceList_.push_back(recordProvenance and B == Transition::Event);
182  }
183 
184  virtual bool hasAbilityToProduceInBeginProcessBlocks() const { return false; }
185  virtual bool hasAbilityToProduceInEndProcessBlocks() const { return false; }
186 
187  virtual bool hasAbilityToProduceInBeginRuns() const { return false; }
188  virtual bool hasAbilityToProduceInEndRuns() const { return false; }
189 
190  virtual bool hasAbilityToProduceInBeginLumis() const { return false; }
191  virtual bool hasAbilityToProduceInEndLumis() const { return false; }
192 
193  private:
195  std::vector<bool> recordProvenanceList_;
196  };
197 
198  template <Transition B>
200  public:
201  template <typename TYPE>
203  return m_helper.template produces<TYPE, B>(m_label);
204  }
205 
206  private:
207  //only ProductRegistryHelper is allowed to make an instance of this class
208  friend class ProductRegistryHelper;
209 
211  : m_helper(iBase), m_label(std::move(iLabel)) {}
213 
216  };
217 
218 } // namespace edm
219 
220 #endif
BranchAliasSetterT< ProductType > produces()
Definition: APVGainStruct.h:7
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
BranchAliasSetterT< ProductType > produces(std::string instanceName)
virtual bool hasAbilityToProduceInBeginLumis() const
BranchAliasSetterT(TypeLabelItem &iItem, EDPutTokenT< T > iToken)
BranchAliasSetter produces(const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
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
BranchAliasSetterT< ProductType > produces(std::string instanceName)
auto produces(std::string instanceName) noexcept
declare what type of product will make and with which optional label
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
BranchAliasSetterT< ProductType > produces()
BranchAliasSetter & setBranchAlias(std::string alias)
std::vector< bool > recordProvenanceList_
virtual bool hasAbilityToProduceInEndLumis() const
def move(src, dest)
Definition: eostools.py:511
BranchAliasSetter produces(const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)