CMS 3D CMS Logo

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