CMS 3D CMS Logo

ProductRegistry.h
Go to the documentation of this file.
1 #ifndef DataFormats_Provenance_ProductRegistry_h
2 #define DataFormats_Provenance_ProductRegistry_h
3 
18 
19 #include <array>
20 #include <memory>
21 
22 #include <iosfwd>
23 #include <map>
24 #include <set>
25 #include <string>
26 #include <string_view>
27 #include <tuple>
28 #include <utility>
29 #include <vector>
30 
31 namespace edm {
32 
33  class ProductResolverIndexHelper;
34  class TypeID;
35 
37  public:
38  typedef std::map<BranchKey, BranchDescription> ProductList;
39 
41 
42  // A constructor from the persistent data members from another product registry.
43  // saves time by not copying the transient components.
44  // The constructed registry will be frozen by default.
45  explicit ProductRegistry(ProductList const& productList, bool toBeFrozen = true);
46 
47  virtual ~ProductRegistry() {}
48 
49  typedef std::map<BranchKey, BranchDescription const> ConstProductList;
50 
51  void addProduct(BranchDescription const& productdesc, bool iFromListener = false);
52 
53  void addLabelAlias(BranchDescription const& productdesc,
54  std::string const& labelAlias,
55  std::string const& instanceAlias);
56 
57  void copyProduct(BranchDescription const& productdesc);
58 
59  void setFrozen(bool initializeLookupInfo = true);
60 
61  void setFrozen(std::set<TypeID> const& productTypesConsumed,
62  std::set<TypeID> const& elementTypesConsumed,
63  std::string const& processName);
64 
65  void setUnscheduledProducts(std::set<std::string> const& unscheduledLabels);
66 
68  std::string const& fileName,
70 
71  void updateFromInput(ProductList const& other);
72  // triggers callbacks for modules watching registration
74 
75  void updateFromInput(std::vector<BranchDescription> const& other);
76 
77  ProductList const& productList() const {
78  //throwIfNotFrozen();
79  return productList_;
80  }
81 
83  throwIfFrozen();
84  return productList_;
85  }
86 
87  // Return all the branch names currently known to *this. This
88  // does a return-by-value of the vector so that it may be used in
89  // a colon-initialization list.
90  std::vector<std::string> allBranchNames() const;
91 
92  // Return pointers to (const) BranchDescriptions for all the
93  // BranchDescriptions known to *this. This does a
94  // return-by-value of the vector so that it may be used in a
95  // colon-initialization list.
96  std::vector<BranchDescription const*> allBranchDescriptions() const;
97 
98  //NOTE: this is not const since we only want items that have non-const access to this class to be
99  // able to call this internal iteration
100  // Called only for branches that are present (part of avoiding creating type information for dropped branches)
101  template <typename T>
102  void callForEachBranch(T const& iFunc) {
103  //NOTE: If implementation changes from a map, need to check that iterators are still valid
104  // after an insert with the new container, else need to copy the container and iterate over the copy
105  for (ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(), itEntryEnd = productList_.end();
106  itEntry != itEntryEnd;
107  ++itEntry) {
108  if (itEntry->second.present()) {
109  iFunc(itEntry->second);
110  }
111  }
112  }
113  ProductList::size_type size() const { return productList_.size(); }
114 
115  void print(std::ostream& os) const;
116 
117  bool anyProducts(BranchType const brType) const;
118 
119  std::shared_ptr<ProductResolverIndexHelper const> productLookup(BranchType branchType) const;
120  std::shared_ptr<ProductResolverIndexHelper> productLookup(BranchType branchType);
121 
122  // returns the appropriate ProductResolverIndex else ProductResolverIndexInvalid if no BranchID is available
123  ProductResolverIndex indexFrom(BranchID const& iID) const;
124 
125  bool productProduced(BranchType branchType) const { return transient_.productProduced_[branchType]; }
127 
128  // Looks if a (type, moduleLabel, productInstanceName) is an alias to some other branch
129  //
130  // Can return multiple modules if kindOfType is ELEMENT_TYPE (i.e.
131  // the product is consumed via edm::View) and there is ambiguity
132  // (in which case actual Event::get() would eventually lead to an
133  // exception). In that case all possible modules whose product
134  // could be consumed are returned.
135  std::vector<std::string> aliasToModules(KindOfType kindOfType,
136  TypeID const& type,
137  std::string_view moduleLabel,
138  std::string_view productInstanceName) const;
139 
140  ProductResolverIndex const& getNextIndexValue(BranchType branchType) const;
141 
143 
144  bool frozen() const { return transient_.frozen_; }
145 
146  struct Transients {
147  Transients();
148  void reset();
149 
150  bool frozen_;
151  // Is at least one (run), (lumi), (event) persistent product produced this process?
152  std::array<bool, NumBranchTypes> productProduced_;
154 
155  std::array<edm::propagate_const<std::shared_ptr<ProductResolverIndexHelper>>, NumBranchTypes> productLookups_;
156 
157  std::array<ProductResolverIndex, NumBranchTypes> nextIndexValues_;
158 
159  std::map<BranchID, ProductResolverIndex> branchIDToIndex_;
160 
162  using AliasToOriginalVector = std::vector<std::tuple<KindOfType, TypeID, std::string, std::string, std::string>>;
164  };
165 
166  private:
167  void setProductProduced(BranchType branchType) {
168  transient_.productProduced_[branchType] = true;
170  }
171 
172  void freezeIt(bool frozen = true) { transient_.frozen_ = frozen; }
173 
174  void initializeLookupTables(std::set<TypeID> const* productTypesConsumed,
175  std::set<TypeID> const* elementTypesConsumed,
176  std::string const* processName);
177  void addElementTypesForAliases(std::set<TypeID> const* elementTypesConsumed,
178  std::map<TypeID, TypeID> const& containedTypeMap,
179  std::map<TypeID, std::vector<TypeID>> const& containedTypeToBaseTypesMap);
180 
181  void checkDictionariesOfConsumedTypes(std::set<TypeID> const* productTypesConsumed,
182  std::set<TypeID> const* elementTypesConsumed,
183  std::map<TypeID, TypeID> const& containedTypeMap,
184  std::map<TypeID, std::vector<TypeID>>& containedTypeToBaseTypesMap);
185 
187 
188  virtual void addCalled(BranchDescription const&, bool iFromListener);
189  void throwIfNotFrozen() const;
190  void throwIfFrozen() const;
191 
193 
196  };
197 
198  inline bool operator==(ProductRegistry const& a, ProductRegistry const& b) {
199  return a.productList() == b.productList();
200  }
201 
202  inline bool operator!=(ProductRegistry const& a, ProductRegistry const& b) { return !(a == b); }
203 
204  inline std::ostream& operator<<(std::ostream& os, ProductRegistry const& pr) {
205  pr.print(os);
206  return os;
207  }
208 
209 } // namespace edm
210 
211 #endif
constexpr bool operator==(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
std::vector< BranchDescription const * > allBranchDescriptions() const
void setProductProduced(BranchType branchType)
unsigned int ProductResolverIndex
ProductList const & productList() const
std::map< BranchKey, BranchDescription const > ConstProductList
std::map< BranchKey, BranchDescription > ProductList
std::vector< std::string > aliasToModules(KindOfType kindOfType, TypeID const &type, std::string_view moduleLabel, std::string_view productInstanceName) const
void addElementTypesForAliases(std::set< TypeID > const *elementTypesConsumed, std::map< TypeID, TypeID > const &containedTypeMap, std::map< TypeID, std::vector< TypeID >> const &containedTypeToBaseTypesMap)
void addLabelAlias(BranchDescription const &productdesc, std::string const &labelAlias, std::string const &instanceAlias)
uint16_t size_type
AliasToOriginalVector aliasToOriginal_
BranchType
Definition: BranchType.h:11
virtual void addCalled(BranchDescription const &, bool iFromListener)
bool anyProductProduced() const
void initializeLookupTables(std::set< TypeID > const *productTypesConsumed, std::set< TypeID > const *elementTypesConsumed, std::string const *processName)
bool productProduced(BranchType branchType) const
void setUnscheduledProducts(std::set< std::string > const &unscheduledLabels)
std::vector< std::string > allBranchNames() const
ProductResolverIndex & nextIndexValue(BranchType branchType)
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
void addFromInput(edm::ProductRegistry const &)
void setFrozen(bool initializeLookupInfo=true)
constexpr bool operator!=(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
void freezeIt(bool frozen=true)
void callForEachBranch(T const &iFunc)
std::vector< std::tuple< KindOfType, TypeID, std::string, std::string, std::string > > AliasToOriginalVector
ProductResolverIndex const & getNextIndexValue(BranchType branchType) const
std::array< ProductResolverIndex, NumBranchTypes > nextIndexValues_
std::shared_ptr< ProductResolverIndexHelper const > productLookup(BranchType branchType) const
ProductList::size_type size() const
std::array< edm::propagate_const< std::shared_ptr< ProductResolverIndexHelper > >, NumBranchTypes > productLookups_
ProductResolverIndex indexFrom(BranchID const &iID) const
void print(std::ostream &os) const
double b
Definition: hdecay.h:120
ProductList & productListUpdator()
HLT enums.
bool anyProducts(BranchType const brType) const
void checkForDuplicateProcessName(BranchDescription const &desc, std::string const *processName) const
double a
Definition: hdecay.h:121
void updateFromInput(ProductList const &other)
void throwIfNotFrozen() const
std::array< bool, NumBranchTypes > productProduced_
void checkDictionariesOfConsumedTypes(std::set< TypeID > const *productTypesConsumed, std::set< TypeID > const *elementTypesConsumed, std::map< TypeID, TypeID > const &containedTypeMap, std::map< TypeID, std::vector< TypeID >> &containedTypeToBaseTypesMap)
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger table.
long double T
void throwIfFrozen() const
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
std::map< BranchID, ProductResolverIndex > branchIDToIndex_
void copyProduct(BranchDescription const &productdesc)