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 
24  public:
25  virtual ~ProductRegistryHelper() noexcept(false);
27 
28  // has_donotrecordparents<T>::value is true if we should not
29  // record parentage for type T, and false otherwise.
30  template <typename T>
33  };
34 
35  struct TypeLabelItem {
36  enum class AliasType { kBranchAlias, kSwitchAlias };
37 
38  TypeLabelItem(Transition const& transition, TypeID const& tid, std::string pin)
39  : transition_(transition),
40  typeID_(tid),
41  productInstanceName_(std::move(pin)),
42  branchAlias_(),
43  aliasType_(AliasType::kBranchAlias) {}
49  };
50 
52  BranchAliasSetter(TypeLabelItem& iItem, EDPutToken iToken) : value_(iItem), token_(std::move(iToken)) {}
53 
55  value_.branchAlias_ = std::move(alias);
56  return *this;
57  }
59  value_.branchAlias_ = std::move(moduleLabel);
60  value_.aliasType_ = TypeLabelItem::AliasType::kSwitchAlias;
61  return *this;
62  }
65 
66  operator EDPutToken() { return token_; }
67  };
68 
69  template <typename T>
71  BranchAliasSetterT(TypeLabelItem& iItem, EDPutTokenT<T> iToken) : value_(iItem), token_(std::move(iToken)) {}
72 
73  BranchAliasSetterT(BranchAliasSetter&& iS) : value_(iS.value_), token_(iS.token_.index()) {}
74 
76  value_.branchAlias_ = std::move(alias);
77  return *this;
78  }
81 
82  operator EDPutTokenT<T>() { return token_; }
83  operator EDPutToken() { return EDPutToken(token_.index()); }
84  };
85 
86  typedef std::vector<TypeLabelItem> TypeLabelList;
87 
89  TypeLabelList const& typeLabelList() const;
90 
91  std::vector<bool> const& recordProvenanceList() const { return recordProvenanceList_; }
92 
93  static void addToRegistry(TypeLabelList::const_iterator const& iBegin,
94  TypeLabelList::const_iterator const& iEnd,
95  ModuleDescription const& iDesc,
96  ProductRegistry& iReg,
97  ProductRegistryHelper* iProd,
98  bool iIsListener = false);
99 
101 
107  template <class ProductType>
109  return produces<ProductType, InEvent>(std::string());
110  }
111 
112  template <class ProductType>
114  return produces<ProductType, InEvent>(std::move(instanceName));
115  }
116 
117  template <typename ProductType, BranchType B>
119  return produces<ProductType, B>(std::string());
120  }
121 
122  template <typename ProductType, BranchType B>
124  TypeID tid(typeid(ProductType));
126  produces<B>(tid, std::move(instanceName), (not has_donotrecordparents<ProductType>::value) and B == InEvent)};
127  }
128 
129  template <typename ProductType, Transition B>
131  return produces<ProductType, B>(std::string());
132  }
133 
134  template <typename ProductType, Transition B>
136  TypeID tid(typeid(ProductType));
137  return BranchAliasSetterT<ProductType>{produces<B>(
138  tid, std::move(instanceName), (not has_donotrecordparents<ProductType>::value) and B == Transition::Event)};
139  }
140 
143  bool recordProvenance = true) {
144  return produces<Transition::Event>(id, std::move(instanceName), recordProvenance);
145  }
146 
147  template <BranchType B>
150  bool recordProvenance = true) {
151  unsigned int index = typeLabelList_.size();
153  recordProvenanceList_.push_back(recordProvenance and B == InEvent);
154  return BranchAliasSetter{typeLabelList_.back(), EDPutToken{static_cast<unsigned int>(index)}};
155  }
156  template <Transition B>
159  bool recordProvenance = true) {
160  unsigned int index = typeLabelList_.size();
161  typeLabelList_.emplace_back(B, id, std::move(instanceName));
162  recordProvenanceList_.push_back(recordProvenance and B == Transition::Event);
163  return BranchAliasSetter{typeLabelList_.back(), EDPutToken{index}};
164  }
165 
166  virtual bool hasAbilityToProduceInRuns() const { return false; }
167 
168  virtual bool hasAbilityToProduceInLumis() const { return false; }
169 
170  private:
171  TypeLabelList typeLabelList_;
172  std::vector<bool> recordProvenanceList_;
173  };
174 
175 } // namespace edm
176 
177 #endif
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
value_type index() const
Definition: EDPutToken.h:77
std::vector< bool > const & recordProvenanceList() const
TypeLabelList const & typeLabelList() const
used by the fwk to register the list of products of this module
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)
BranchAliasSetterT< ProductType > produces(std::string instanceName)
BranchAliasSetterT(TypeLabelItem &iItem, EDPutTokenT< T > iToken)
BranchAliasSetter produces(const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
BranchAliasSetter & setSwitchAlias(std::string moduleLabel)
TypeLabelItem(Transition const &transition, TypeID const &tid, std::string pin)
virtual bool hasAbilityToProduceInRuns() const
std::vector< TypeLabelItem > TypeLabelList
Transition
Definition: Transition.h:12
Definition: value.py:1
BranchAliasSetterT< ProductType > produces(std::string instanceName)
static const std::string B
virtual bool hasAbilityToProduceInLumis() const
#define noexcept
BranchAliasSetter(TypeLabelItem &iItem, EDPutToken iToken)
constexpr Transition convertToTransition(BranchType iValue)
Definition: Transition.h:20
HLT enums.
BranchAliasSetterT< ProductType > produces()
BranchAliasSetter & setBranchAlias(std::string alias)
std::vector< bool > recordProvenanceList_
def move(src, dest)
Definition: eostools.py:511
#define constexpr
BranchAliasSetter produces(const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)