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  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 
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
edm::ProductRegistry::callForEachBranch
void callForEachBranch(T const &iFunc)
Definition: ProductRegistry.h:100
edm::ProductRegistry::Transients::productProduced_
std::array< bool, NumBranchTypes > productProduced_
Definition: ProductRegistry.h:148
edm::ProductRegistry::checkDictionariesOfConsumedTypes
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)
Definition: ProductRegistry.cc:515
edm::ProductResolverIndex
unsigned int ProductResolverIndex
Definition: ProductResolverIndex.h:8
edm::ProductRegistry::Transients::frozen_
bool frozen_
Definition: ProductRegistry.h:146
edm::ProductRegistry::indexFrom
ProductResolverIndex indexFrom(BranchID const &iID) const
Definition: ProductRegistry.cc:606
edm::ProductRegistry::allBranchNames
std::vector< std::string > allBranchNames() const
Definition: ProductRegistry.cc:189
edm::ProductRegistry::transient_
Transients transient_
Definition: ProductRegistry.h:191
edm::ProductRegistry::setFrozen
void setFrozen(bool initializeLookupInfo=true)
Definition: ProductRegistry.cc:153
edm::ProductRegistry::Transients::productLookups_
std::array< edm::propagate_const< std::shared_ptr< ProductResolverIndexHelper > >, NumBranchTypes > productLookups_
Definition: ProductRegistry.h:151
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ProductRegistry::size
ProductList::size_type size() const
Definition: ProductRegistry.h:109
edm::ProductRegistry::checkForDuplicateProcessName
void checkForDuplicateProcessName(BranchDescription const &desc, std::string const *processName) const
Definition: ProductRegistry.cc:595
edm::ProductRegistry::~ProductRegistry
virtual ~ProductRegistry()
Definition: ProductRegistry.h:48
ProductResolverIndex.h
edm::ProductRegistry::Transients::kProductInstanceName
Definition: ProductRegistry.h:157
edm::ProductRegistry::updateFromInput
void updateFromInput(ProductList const &other)
Definition: ProductRegistry.cc:209
edm::ProductRegistry::productLookup
std::shared_ptr< ProductResolverIndexHelper const > productLookup(BranchType branchType) const
Definition: ProductRegistry.cc:145
edm::ProductRegistry::Transients::nextIndexValues_
std::array< ProductResolverIndex, NumBranchTypes > nextIndexValues_
Definition: ProductRegistry.h:153
edm::ProductRegistry::Transients::kAliasForModuleLabel
Definition: ProductRegistry.h:157
edm::ProductRegistry::getNextIndexValue
ProductResolverIndex const & getNextIndexValue(BranchType branchType) const
Definition: ProductRegistry.cc:643
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
edm::ProductRegistry::print
void print(std::ostream &os) const
Definition: ProductRegistry.cc:637
edm::BranchType
BranchType
Definition: BranchType.h:11
edm::NumBranchTypes
Definition: BranchType.h:11
edm::ProductRegistry
Definition: ProductRegistry.h:37
edm::BranchDescription::Permissive
Definition: BranchDescription.h:36
edm::operator<<
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
Definition: HLTGlobalStatus.h:106
edm::ProductRegistry::Transients::kModuleLabel
Definition: ProductRegistry.h:157
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
edm::ProductRegistry::Transients::aliasToOriginal_
AliasToOriginalVector aliasToOriginal_
Definition: ProductRegistry.h:159
edm::ProductRegistry::anyProducts
bool anyProducts(BranchType const brType) const
Definition: ProductRegistry.cc:135
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
edm::ProductRegistry::productListUpdator
ProductList & productListUpdator()
Definition: ProductRegistry.h:81
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
BranchListIndex.h
edm::BranchID
Definition: BranchID.h:14
edm::ProductRegistry::Transients::Transients
Transients()
Definition: ProductRegistry.cc:34
edm::BranchDescription::MatchMode
MatchMode
Definition: BranchDescription.h:36
trackingPlots.other
other
Definition: trackingPlots.py:1464
edm::ProductRegistry::throwIfFrozen
void throwIfFrozen() const
Definition: ProductRegistry.cc:173
b
double b
Definition: hdecay.h:118
edm::ProductRegistry::addProduct
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
Definition: ProductRegistry.cc:68
edm::ProductRegistry::throwIfNotFrozen
void throwIfNotFrozen() const
Definition: ProductRegistry.cc:180
edm::ProductRegistry::copyProduct
void copyProduct(BranchDescription const &productdesc)
Definition: ProductRegistry.cc:122
edm::ProductRegistry::Transients::branchIDToIndex_
std::map< BranchID, ProductResolverIndex > branchIDToIndex_
Definition: ProductRegistry.h:155
edm::ProductRegistry::ProductList
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductRegistry.h:39
edm::ProductRegistry::Transients::reset
void reset()
Definition: ProductRegistry.cc:48
BranchDescription.h
a
double a
Definition: hdecay.h:119
sipixeldigitoraw
Definition: SiPixelDigiToRaw.cc:32
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
edm::ProductRegistry::Transients::kType
Definition: ProductRegistry.h:157
edm::ProductRegistry::ConstProductList
std::map< BranchKey, BranchDescription const > ConstProductList
Definition: ProductRegistry.h:50
edm::ProductRegistry::Transients::AliasToOriginalVector
std::vector< std::tuple< KindOfType, TypeID, std::string, std::string, std::string > > AliasToOriginalVector
Definition: ProductRegistry.h:158
edm::ProductRegistry::ProductRegistry
ProductRegistry()
Definition: ProductRegistry.cc:32
BranchType.h
edm::ProductRegistry::allBranchDescriptions
std::vector< BranchDescription const * > allBranchDescriptions() const
Definition: ProductRegistry.cc:199
edm::ProductRegistry::addLabelAlias
void addLabelAlias(BranchDescription const &productdesc, std::string const &labelAlias, std::string const &instanceAlias)
Definition: ProductRegistry.cc:108
edm::ProductRegistry::initializeTransients
void initializeTransients()
Definition: ProductRegistry.h:138
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ProductRegistry::productList_
ProductList productList_
Definition: ProductRegistry.h:190
edm::ProductRegistry::setProductProduced
void setProductProduced(BranchType branchType)
Definition: ProductRegistry.h:163
SimL1EmulatorRepack_CalouGT_cff.processName
processName
Definition: SimL1EmulatorRepack_CalouGT_cff.py:17
edm::ProductRegistry::Transients
Definition: ProductRegistry.h:142
edm::ProductRegistry::initializeLookupTables
void initializeLookupTables(std::set< TypeID > const *productTypesConsumed, std::set< TypeID > const *elementTypesConsumed, std::string const *processName)
Definition: ProductRegistry.cc:296
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
edm::TypeID
Definition: TypeID.h:22
edm::ProductRegistry::productList
ProductList const & productList() const
Definition: ProductRegistry.h:76
edm::KindOfType
KindOfType
Definition: ProductKindOfType.h:5
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ProductRegistry::addCalled
virtual void addCalled(BranchDescription const &, bool iFromListener)
Definition: ProductRegistry.cc:187
BranchKey.h
edm::ProductRegistry::productProduced
bool productProduced(BranchType branchType) const
Definition: ProductRegistry.h:121
edm::ProductRegistry::aliasToModules
std::vector< std::string > aliasToModules(KindOfType kindOfType, TypeID const &type, std::string_view moduleLabel, std::string_view productInstanceName) const
Definition: ProductRegistry.cc:614
edm::ProductRegistry::frozen
bool frozen() const
Definition: ProductRegistry.h:140
edm::BranchDescription
Definition: BranchDescription.h:32
edm::ProductRegistry::nextIndexValue
ProductResolverIndex & nextIndexValue(BranchType branchType)
Definition: ProductRegistry.cc:647
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::ProductRegistry::merge
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
Definition: ProductRegistry.cc:250
edm::ProductRegistry::addElementTypesForAliases
void addElementTypesForAliases(std::set< TypeID > const *elementTypesConsumed, std::map< TypeID, TypeID > const &containedTypeMap, std::map< TypeID, std::vector< TypeWithDict >> const &containedTypeToBaseTypesMap)
Definition: ProductRegistry.cc:466
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::ProductRegistry::anyProductProduced
bool anyProductProduced() const
Definition: ProductRegistry.h:122
get_underlying_safe.h
edm::ProductRegistry::freezeIt
void freezeIt(bool frozen=true)
Definition: ProductRegistry.h:168
edm::ProductRegistry::setUnscheduledProducts
void setUnscheduledProducts(std::set< std::string > const &unscheduledLabels)
Definition: ProductRegistry.cc:221
ProductKindOfType.h
edm::ProductRegistry::Transients::anyProductProduced_
bool anyProductProduced_
Definition: ProductRegistry.h:149
edm::ProductRegistry::Transients::kKind
Definition: ProductRegistry.h:157