CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 "boost/shared_ptr.hpp"
20 
21 #include <iosfwd>
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 namespace edm {
27  class ProductHolderIndexHelper;
28 
30 
31  public:
32  typedef std::map<BranchKey, BranchDescription> ProductList;
33 
35 
36  // A constructor from the persistent data memebers from another product registry.
37  // saves time by not copying the transient components.
38  // The constructed registry will be frozen by default.
39  explicit ProductRegistry(ProductList const& productList, bool toBeFrozen = true);
40 
41  virtual ~ProductRegistry() {}
42 
43  typedef std::map<BranchKey, ConstBranchDescription> ConstProductList;
44 
45  void addProduct(BranchDescription const& productdesc, bool iFromListener = false);
46 
47  void addLabelAlias(BranchDescription const& productdesc, std::string const& labelAlias, std::string const& instanceAlias);
48 
49  void copyProduct(BranchDescription const& productdesc);
50 
51  void setFrozen(bool initializeLookupInfo = true) const;
52 
53  std::string merge(ProductRegistry const& other,
54  std::string const& fileName,
57 
58  void updateFromInput(ProductList const& other);
59 
60  void updateFromInput(std::vector<BranchDescription> const& other);
61 
62  ProductList const& productList() const {
63  //throwIfNotFrozen();
64  return productList_;
65  }
66 
68  throwIfFrozen();
69  return productList_;
70  }
71 
72  // Return all the branch names currently known to *this. This
73  // does a return-by-value of the vector so that it may be used in
74  // a colon-initialization list.
75  std::vector<std::string> allBranchNames() const;
76 
77  // Return pointers to (const) BranchDescriptions for all the
78  // BranchDescriptions known to *this. This does a
79  // return-by-value of the vector so that it may be used in a
80  // colon-initialization list.
81  std::vector<BranchDescription const*> allBranchDescriptions() const;
82 
83  //NOTE: this is not const since we only want items that have non-const access to this class to be
84  // able to call this internal iteration
85  template<typename T>
86  void callForEachBranch(T const& iFunc) {
87  //NOTE: If implementation changes from a map, need to check that iterators are still valid
88  // after an insert with the new container, else need to copy the container and iterate over the copy
89  for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
90  itEntryEnd = productList_.end();
91  itEntry != itEntryEnd; ++itEntry) {
92  iFunc(itEntry->second);
93  }
94  }
95  ProductList::size_type size() const {return productList_.size();}
96 
97  void print(std::ostream& os) const;
98 
99  bool anyProducts(BranchType const brType) const;
100 
102  //throwIfNotFrozen();
104  }
105 
106  boost::shared_ptr<ProductHolderIndexHelper> const& productLookup(BranchType branchType) const;
107 
108  // returns the appropriate ProductHolderIndex else ProductHolderIndexInvalid if no BranchID is available
109  ProductHolderIndex indexFrom(BranchID const& iID) const;
110 
114 
117  }
118 
119  std::vector<std::string>& missingDictionaries() const {
121  }
122 
124 
126 
127  struct Transients {
128  Transients();
129  void reset();
130  bool frozen_;
132  // Is at least one (run), (lumi), (event) product produced this process?
133  boost::array<bool, NumBranchTypes> productProduced_;
135 
136  boost::shared_ptr<ProductHolderIndexHelper> eventProductLookup_;
137  boost::shared_ptr<ProductHolderIndexHelper> lumiProductLookup_;
138  boost::shared_ptr<ProductHolderIndexHelper> runProductLookup_;
139 
143 
144  std::map<BranchID, ProductHolderIndex> branchIDToIndex_;
145 
147 
148  std::vector<std::string> missingDictionaries_;
149  };
150 
151  private:
155  }
156 
157  bool& frozen() const {return transient_.frozen_;}
158 
160  void initializeLookupTables() const;
161  virtual void addCalled(BranchDescription const&, bool iFromListener);
162  void throwIfNotFrozen() const;
163  void throwIfFrozen() const;
164 
166 
169  };
170 
171  inline
172  bool
174  return a.productList() == b.productList();
175  }
176 
177  inline
178  bool
180  return !(a == b);
181  }
182 
183  inline
184  std::ostream&
185  operator<<(std::ostream& os, ProductRegistry const& pr) {
186  pr.print(os);
187  return os;
188  }
189 
190 } // edm
191 
192 #endif
unsigned short BranchListIndex
std::vector< std::string > missingDictionaries_
boost::shared_ptr< ProductHolderIndexHelper > lumiProductLookup_
void setProductProduced(BranchType branchType) const
ConstProductList & constProductList() const
void throwIfNotFrozen() const
std::vector< std::string > allBranchNames() const
std::map< BranchKey, BranchDescription > ProductList
ProductHolderIndex indexFrom(BranchID const &iID) const
BranchListIndex producedBranchListIndex() const
bool anyProducts(BranchType const brType) const
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
std::string merge(ProductRegistry const &other, std::string const &fileName, BranchDescription::MatchMode parametersMustMatch=BranchDescription::Permissive, BranchDescription::MatchMode branchesMustMatch=BranchDescription::Permissive)
ProductHolderIndex eventNextIndexValue_
unsigned int ProductHolderIndex
ProductList::size_type size() const
ProductHolderIndex const & getNextIndexValue(BranchType branchType) const
void addLabelAlias(BranchDescription const &productdesc, std::string const &labelAlias, std::string const &instanceAlias)
uint16_t size_type
BranchType
Definition: BranchType.h:11
virtual void addCalled(BranchDescription const &, bool iFromListener)
boost::shared_ptr< ProductHolderIndexHelper > const & productLookup(BranchType branchType) const
ProductList const & productList() const
void setProducedBranchListIndex(BranchListIndex blix) const
std::vector< std::string > & missingDictionaries() const
ProductHolderIndex lumiNextIndexValue_
void initializeTransients() const
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
std::vector< BranchDescription const * > allBranchDescriptions() const
boost::array< bool, NumBranchTypes > productProduced_
void callForEachBranch(T const &iFunc)
void print(std::ostream &os) const
bool productProduced(BranchType branchType) const
ProductHolderIndex runNextIndexValue_
void setFrozen(bool initializeLookupInfo=true) const
void initializeLookupTables() const
boost::shared_ptr< ProductHolderIndexHelper > runProductLookup_
double b
Definition: hdecay.h:120
ProductList & productListUpdator()
bool anyProductProduced() const
double a
Definition: hdecay.h:121
void throwIfFrozen() const
void updateFromInput(ProductList const &other)
boost::shared_ptr< ProductHolderIndexHelper > eventProductLookup_
std::map< BranchID, ProductHolderIndex > branchIDToIndex_
bool & frozen() const
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger tbale.
long double T
void addProduct(BranchDescription const &productdesc, bool iFromListener=false)
ProductHolderIndex & nextIndexValue(BranchType branchType) const
void copyProduct(BranchDescription const &productdesc)
std::map< BranchKey, ConstBranchDescription > ConstProductList