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 "boost/array.hpp"
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 
63  std::string const& fileName,
65 
66  void updateFromInput(ProductList const& other);
67 
68  void updateFromInput(std::vector<BranchDescription> const& other);
69 
70  ProductList const& productList() const {
71  //throwIfNotFrozen();
72  return productList_;
73  }
74 
75  ProductList& productListUpdator() {
76  throwIfFrozen();
77  return productList_;
78  }
79 
80  // Return all the branch names currently known to *this. This
81  // does a return-by-value of the vector so that it may be used in
82  // a colon-initialization list.
83  std::vector<std::string> allBranchNames() const;
84 
85  // Return pointers to (const) BranchDescriptions for all the
86  // BranchDescriptions known to *this. This does a
87  // return-by-value of the vector so that it may be used in a
88  // colon-initialization list.
89  std::vector<BranchDescription const*> allBranchDescriptions() const;
90 
91  //NOTE: this is not const since we only want items that have non-const access to this class to be
92  // able to call this internal iteration
93  template<typename T>
94  void callForEachBranch(T const& iFunc) {
95  //NOTE: If implementation changes from a map, need to check that iterators are still valid
96  // after an insert with the new container, else need to copy the container and iterate over the copy
97  for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
98  itEntryEnd = productList_.end();
99  itEntry != itEntryEnd; ++itEntry) {
100  iFunc(itEntry->second);
101  }
102  }
103  ProductList::size_type size() const {return productList_.size();}
104 
105  void print(std::ostream& os) const;
106 
107  bool anyProducts(BranchType const brType) const;
108 
109  std::shared_ptr<ProductResolverIndexHelper const> productLookup(BranchType branchType) const;
110  std::shared_ptr<ProductResolverIndexHelper> productLookup(BranchType branchType);
111 
112  // returns the appropriate ProductResolverIndex else ProductResolverIndexInvalid if no BranchID is available
113  ProductResolverIndex indexFrom(BranchID const& iID) const;
114 
117 
118  std::vector<std::pair<std::string, std::string> > const& aliasToOriginal() const {
120  }
121 
122  ProductResolverIndex const& getNextIndexValue(BranchType branchType) const;
123 
125 
126  bool frozen() const {return transient_.frozen_;}
127 
128  struct Transients {
129  Transients();
130  void reset();
131 
132  std::shared_ptr<ProductResolverIndexHelper const> eventProductLookup() const {return get_underlying_safe(eventProductLookup_);}
133  std::shared_ptr<ProductResolverIndexHelper>& eventProductLookup() {return get_underlying_safe(eventProductLookup_);}
134  std::shared_ptr<ProductResolverIndexHelper const> lumiProductLookup() const {return get_underlying_safe(lumiProductLookup_);}
135  std::shared_ptr<ProductResolverIndexHelper>& lumiProductLookup() {return get_underlying_safe(lumiProductLookup_);}
136  std::shared_ptr<ProductResolverIndexHelper const> runProductLookup() const {return get_underlying_safe(runProductLookup_);}
137  std::shared_ptr<ProductResolverIndexHelper>& runProductLookup() {return get_underlying_safe(runProductLookup_);}
138 
139  bool frozen_;
140  // Is at least one (run), (lumi), (event) product produced this process?
141  boost::array<bool, NumBranchTypes> productProduced_;
143 
147 
151 
152  std::map<BranchID, ProductResolverIndex> branchIDToIndex_;
153 
154  std::vector<std::pair<std::string, std::string> > aliasToOriginal_;
155  };
156 
157  private:
158  void setProductProduced(BranchType branchType) {
161  }
162 
163  void freezeIt(bool frozen = true) {transient_.frozen_ = frozen;}
164 
165  void initializeLookupTables(std::set<TypeID> const* productTypesConsumed,
166  std::set<TypeID> const* elementTypesConsumed,
167  std::string const* processName);
168 
169  void checkDictionariesOfConsumedTypes(std::set<TypeID> const* productTypesConsumed,
170  std::set<TypeID> const* elementTypesConsumed,
171  std::map<TypeID, TypeID> const& containedTypeMap,
172  std::map<TypeID, std::vector<TypeWithDict> >& containedTypeToBaseTypesMap);
173 
175  std::string const* processName) const;
176 
177  virtual void addCalled(BranchDescription const&, bool iFromListener);
178  void throwIfNotFrozen() const;
179  void throwIfFrozen() const;
180 
182 
183  ProductList productList_;
185  };
186 
187  inline
188  bool
190  return a.productList() == b.productList();
191  }
192 
193  inline
194  bool
196  return !(a == b);
197  }
198 
199  inline
200  std::ostream&
201  operator<<(std::ostream& os, ProductRegistry const& pr) {
202  pr.print(os);
203  return os;
204  }
205 
206 } // edm
207 
208 #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
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > 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)
ProductResolverIndex eventNextIndexValue_
std::shared_ptr< ProductResolverIndexHelper const > runProductLookup() const
ProductResolverIndex lumiNextIndexValue_
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
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)
boost::array< bool, NumBranchTypes > productProduced_
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
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::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:112
void copyProduct(BranchDescription const &productdesc)
std::shared_ptr< ProductResolverIndexHelper > & lumiProductLookup()