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 
16 
17 #include "boost/array.hpp"
18 #include <memory>
19 
20 #include <iosfwd>
21 #include <map>
22 #include <string>
23 #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, BranchDescription const> 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);
52 
53  std::string merge(ProductRegistry const& other,
54  std::string const& fileName,
56 
57  void updateFromInput(ProductList const& other);
58 
59  void updateFromInput(std::vector<BranchDescription> const& other);
60 
61  ProductList const& productList() const {
62  //throwIfNotFrozen();
63  return productList_;
64  }
65 
67  throwIfFrozen();
68  return productList_;
69  }
70 
71  // Return all the branch names currently known to *this. This
72  // does a return-by-value of the vector so that it may be used in
73  // a colon-initialization list.
74  std::vector<std::string> allBranchNames() const;
75 
76  // Return pointers to (const) BranchDescriptions for all the
77  // BranchDescriptions known to *this. This does a
78  // return-by-value of the vector so that it may be used in a
79  // colon-initialization list.
80  std::vector<BranchDescription const*> allBranchDescriptions() const;
81 
82  //NOTE: this is not const since we only want items that have non-const access to this class to be
83  // able to call this internal iteration
84  template<typename T>
85  void callForEachBranch(T const& iFunc) {
86  //NOTE: If implementation changes from a map, need to check that iterators are still valid
87  // after an insert with the new container, else need to copy the container and iterate over the copy
88  for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
89  itEntryEnd = productList_.end();
90  itEntry != itEntryEnd; ++itEntry) {
91  iFunc(itEntry->second);
92  }
93  }
94  ProductList::size_type size() const {return productList_.size();}
95 
96  void print(std::ostream& os) const;
97 
98  bool anyProducts(BranchType const brType) const;
99 
101  //throwIfNotFrozen();
103  }
104 
105  std::shared_ptr<ProductHolderIndexHelper> const& productLookup(BranchType branchType) const;
106 
107  // returns the appropriate ProductHolderIndex else ProductHolderIndexInvalid if no BranchID is available
108  ProductHolderIndex indexFrom(BranchID const& iID) const;
109 
112 
113  std::vector<std::string> const& missingDictionaries() const {
115  }
116 
117  std::vector<std::string>& missingDictionariesForUpdate() {
119  }
120 
122 
124 
125  bool frozen() const {return transient_.frozen_;}
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  std::shared_ptr<ProductHolderIndexHelper> eventProductLookup_;
137  std::shared_ptr<ProductHolderIndexHelper> lumiProductLookup_;
138  std::shared_ptr<ProductHolderIndexHelper> runProductLookup_;
139 
143 
144  std::map<BranchID, ProductHolderIndex> branchIDToIndex_;
145 
146  std::vector<std::string> missingDictionaries_;
147  };
148 
149  private:
153  }
154 
155  void freezeIt(bool frozen = true) {transient_.frozen_ = frozen;}
156 
158  void initializeLookupTables();
159  virtual void addCalled(BranchDescription const&, bool iFromListener);
160  void throwIfNotFrozen() const;
161  void throwIfFrozen() const;
162 
164 
167  };
168 
169  inline
170  bool
172  return a.productList() == b.productList();
173  }
174 
175  inline
176  bool
178  return !(a == b);
179  }
180 
181  inline
182  std::ostream&
183  operator<<(std::ostream& os, ProductRegistry const& pr) {
184  pr.print(os);
185  return os;
186  }
187 
188 } // edm
189 
190 #endif
std::vector< std::string > missingDictionaries_
void setProductProduced(BranchType branchType)
std::shared_ptr< ProductHolderIndexHelper > eventProductLookup_
ProductHolderIndex & nextIndexValue(BranchType branchType)
void throwIfNotFrozen() const
std::vector< std::string > allBranchNames() const
std::map< BranchKey, BranchDescription const > ConstProductList
std::map< BranchKey, BranchDescription > ProductList
ProductHolderIndex indexFrom(BranchID const &iID) const
std::shared_ptr< ProductHolderIndexHelper > lumiProductLookup_
bool anyProducts(BranchType const brType) const
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
std::shared_ptr< ProductHolderIndexHelper > const & productLookup(BranchType branchType) const
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
std::shared_ptr< ProductHolderIndexHelper > runProductLookup_
virtual void addCalled(BranchDescription const &, bool iFromListener)
ProductList const & productList() const
ConstProductList & constProductList()
ProductHolderIndex lumiNextIndexValue_
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
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_
void setFrozen(bool initializeLookupInfo=true)
void freezeIt(bool frozen=true)
void callForEachBranch(T const &iFunc)
void print(std::ostream &os) const
bool productProduced(BranchType branchType) const
ProductHolderIndex runNextIndexValue_
std::vector< std::string > & missingDictionariesForUpdate()
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)
std::map< BranchID, ProductHolderIndex > branchIDToIndex_
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)
void copyProduct(BranchDescription const &productdesc)
std::vector< std::string > const & missingDictionaries() const