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 
17 
18 #include <array>
19 #include <memory>
20 
21 #include <iosfwd>
22 #include <map>
23 #include <set>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 namespace edm {
29 
30  class ProductResolverIndexHelper;
31  class TypeID;
32  class TypeWithDict;
33 
35 
36  public:
37  typedef std::map<BranchKey, BranchDescription> ProductList;
38 
40 
41  // A constructor from the persistent data memebers from another product registry.
42  // saves time by not copying the transient components.
43  // The constructed registry will be frozen by default.
44  explicit ProductRegistry(ProductList const& productList, bool toBeFrozen = true);
45 
46  virtual ~ProductRegistry() {}
47 
48  typedef std::map<BranchKey, BranchDescription const> ConstProductList;
49 
50  void addProduct(BranchDescription const& productdesc, bool iFromListener = false);
51 
52  void addLabelAlias(BranchDescription const& productdesc, std::string const& labelAlias, std::string const& instanceAlias);
53 
54  void copyProduct(BranchDescription const& productdesc);
55 
56  void setFrozen(bool initializeLookupInfo = true);
57 
58  void setFrozen(std::set<TypeID> const& productTypesConsumed,
59  std::set<TypeID> const& elementTypesConsumed,
60  std::string const& processName);
61 
62  void setUnscheduledProducts(std::set<std::string> const& unscheduledLabels);
63 
65  std::string const& fileName,
67 
68  void updateFromInput(ProductList const& other);
69 
70  void updateFromInput(std::vector<BranchDescription> const& other);
71 
72  ProductList const& productList() const {
73  //throwIfNotFrozen();
74  return productList_;
75  }
76 
77  ProductList& productListUpdator() {
78  throwIfFrozen();
79  return productList_;
80  }
81 
82  // Return all the branch names currently known to *this. This
83  // does a return-by-value of the vector so that it may be used in
84  // a colon-initialization list.
85  std::vector<std::string> allBranchNames() const;
86 
87  // Return pointers to (const) BranchDescriptions for all the
88  // BranchDescriptions known to *this. This does a
89  // return-by-value of the vector so that it may be used in a
90  // colon-initialization list.
91  std::vector<BranchDescription const*> allBranchDescriptions() const;
92 
93  //NOTE: this is not const since we only want items that have non-const access to this class to be
94  // able to call this internal iteration
95  template<typename T>
96  void callForEachBranch(T const& iFunc) {
97  //NOTE: If implementation changes from a map, need to check that iterators are still valid
98  // after an insert with the new container, else need to copy the container and iterate over the copy
99  for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
100  itEntryEnd = productList_.end();
101  itEntry != itEntryEnd; ++itEntry) {
102  iFunc(itEntry->second);
103  }
104  }
105  ProductList::size_type size() const {return productList_.size();}
106 
107  void print(std::ostream& os) const;
108 
109  bool anyProducts(BranchType const brType) const;
110 
111  std::shared_ptr<ProductResolverIndexHelper const> productLookup(BranchType branchType) const;
112  std::shared_ptr<ProductResolverIndexHelper> productLookup(BranchType branchType);
113 
114  // returns the appropriate ProductResolverIndex else ProductResolverIndexInvalid if no BranchID is available
115  ProductResolverIndex indexFrom(BranchID const& iID) const;
116 
119 
120  std::vector<std::pair<std::string, std::string> > const& aliasToOriginal() const {
122  }
123 
124  ProductResolverIndex const& getNextIndexValue(BranchType branchType) const;
125 
127 
128  bool frozen() const {return transient_.frozen_;}
129 
130  struct Transients {
131  Transients();
132  void reset();
133 
134  std::shared_ptr<ProductResolverIndexHelper const> eventProductLookup() const {return get_underlying_safe(eventProductLookup_);}
135  std::shared_ptr<ProductResolverIndexHelper>& eventProductLookup() {return get_underlying_safe(eventProductLookup_);}
136  std::shared_ptr<ProductResolverIndexHelper const> lumiProductLookup() const {return get_underlying_safe(lumiProductLookup_);}
137  std::shared_ptr<ProductResolverIndexHelper>& lumiProductLookup() {return get_underlying_safe(lumiProductLookup_);}
138  std::shared_ptr<ProductResolverIndexHelper const> runProductLookup() const {return get_underlying_safe(runProductLookup_);}
139  std::shared_ptr<ProductResolverIndexHelper>& runProductLookup() {return get_underlying_safe(runProductLookup_);}
140 
141  bool frozen_;
142  // Is at least one (run), (lumi), (event) persistent product produced this process?
143  std::array<bool, NumBranchTypes> productProduced_;
145 
149 
153 
154  std::map<BranchID, ProductResolverIndex> branchIDToIndex_;
155 
156  std::vector<std::pair<std::string, std::string> > aliasToOriginal_;
157  };
158 
159  private:
160  void setProductProduced(BranchType branchType) {
163  }
164 
165  void freezeIt(bool frozen = true) {transient_.frozen_ = frozen;}
166 
167  void initializeLookupTables(std::set<TypeID> const* productTypesConsumed,
168  std::set<TypeID> const* elementTypesConsumed,
169  std::string const* processName);
170 
171  void checkDictionariesOfConsumedTypes(std::set<TypeID> const* productTypesConsumed,
172  std::set<TypeID> const* elementTypesConsumed,
173  std::map<TypeID, TypeID> const& containedTypeMap,
174  std::map<TypeID, std::vector<TypeWithDict> >& containedTypeToBaseTypesMap);
175 
177  std::string const* processName) const;
178 
179  virtual void addCalled(BranchDescription const&, bool iFromListener);
180  void throwIfNotFrozen() const;
181  void throwIfFrozen() const;
182 
184 
185  ProductList productList_;
187  };
188 
189  inline
190  bool
192  return a.productList() == b.productList();
193  }
194 
195  inline
196  bool
198  return !(a == b);
199  }
200 
201  inline
202  std::ostream&
203  operator<<(std::ostream& os, ProductRegistry const& pr) {
204  pr.print(os);
205  return os;
206  }
207 
208 } // edm
209 
210 #endif
edm::propagate_const< std::shared_ptr< ProductResolverIndexHelper > > lumiProductLookup_
std::shared_ptr< ProductResolverIndexHelper > & eventProductLookup()
void setProductProduced(BranchType branchType)
unsigned int ProductResolverIndex
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
std::shared_ptr< ProductResolverIndexHelper const > lumiProductLookup() const
ProductList::size_type size() const
void addLabelAlias(BranchDescription const &productdesc, std::string const &labelAlias, std::string const &instanceAlias)
uint16_t size_type
std::shared_ptr< ProductResolverIndexHelper const > eventProductLookup() const
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)
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
ProductResolverIndex eventNextIndexValue_
std::shared_ptr< ProductResolverIndexHelper const > runProductLookup() const
ProductResolverIndex lumiNextIndexValue_
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)
std::shared_ptr< T > & get_underlying_safe(propagate_const< std::shared_ptr< T >> &iP)
void setFrozen(bool initializeLookupInfo=true)
void freezeIt(bool frozen=true)
void callForEachBranch(T const &iFunc)
std::shared_ptr< ProductResolverIndexHelper > & runProductLookup()
void print(std::ostream &os) const
bool productProduced(BranchType branchType) const
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
std::vector< std::pair< std::string, std::string > > const & aliasToOriginal() const
ProductResolverIndex runNextIndexValue_
double b
Definition: hdecay.h:120
ProductList & productListUpdator()
std::vector< std::pair< std::string, std::string > > aliasToOriginal_
std::shared_ptr< ProductResolverIndexHelper const > productLookup(BranchType branchType) const
bool anyProductProduced() const
ProductResolverIndex const & getNextIndexValue(BranchType branchType) const
HLT enums.
double a
Definition: hdecay.h:121
void throwIfFrozen() const
void updateFromInput(ProductList const &other)
std::array< bool, NumBranchTypes > productProduced_
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
long double T
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)
edm::propagate_const< std::shared_ptr< ProductResolverIndexHelper > > eventProductLookup_
ProductResolverIndex indexFrom(BranchID const &iID) const
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
std::map< BranchID, ProductResolverIndex > branchIDToIndex_
edm::propagate_const< std::shared_ptr< ProductResolverIndexHelper > > runProductLookup_
def branchType(schema, name)
Definition: revisionDML.py:114
void copyProduct(BranchDescription const &productdesc)
std::shared_ptr< ProductResolverIndexHelper > & lumiProductLookup()