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 <memory>
20 
21 #include <iosfwd>
22 #include <map>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 namespace edm {
28  class ProductHolderIndexHelper;
29 
31 
32  public:
33  typedef std::map<BranchKey, BranchDescription> ProductList;
34 
36 
37  // A constructor from the persistent data memebers from another product registry.
38  // saves time by not copying the transient components.
39  // The constructed registry will be frozen by default.
40  explicit ProductRegistry(ProductList const& productList, bool toBeFrozen = true);
41 
42  virtual ~ProductRegistry() {}
43 
44  typedef std::map<BranchKey, BranchDescription const> ConstProductList;
45 
46  void addProduct(BranchDescription const& productdesc, bool iFromListener = false);
47 
48  void addLabelAlias(BranchDescription const& productdesc, std::string const& labelAlias, std::string const& instanceAlias);
49 
50  void copyProduct(BranchDescription const& productdesc);
51 
52  void setFrozen(bool initializeLookupInfo = true);
53 
54  std::string merge(ProductRegistry const& other,
55  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  std::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 
113 
114  std::vector<TypeID> const& missingDictionaries() const {
116  }
117 
118  std::vector<TypeID>& missingDictionariesForUpdate() {
120  }
121 
122  std::vector<std::pair<std::string, std::string> > const& aliasToOriginal() const {
124  }
125 
127 
129 
130  bool frozen() const {return transient_.frozen_;}
131 
132  struct Transients {
133  Transients();
134  void reset();
135  bool frozen_;
137  // Is at least one (run), (lumi), (event) product produced this process?
138  boost::array<bool, NumBranchTypes> productProduced_;
140 
141  std::shared_ptr<ProductHolderIndexHelper> eventProductLookup_;
142  std::shared_ptr<ProductHolderIndexHelper> lumiProductLookup_;
143  std::shared_ptr<ProductHolderIndexHelper> runProductLookup_;
144 
148 
149  std::map<BranchID, ProductHolderIndex> branchIDToIndex_;
150 
151  std::vector<TypeID> missingDictionaries_;
152 
153  std::vector<std::pair<std::string, std::string> > aliasToOriginal_;
154  };
155 
156  private:
160  }
161 
162  void freezeIt(bool frozen = true) {transient_.frozen_ = frozen;}
163 
165  void initializeLookupTables();
166  virtual void addCalled(BranchDescription const&, bool iFromListener);
167  void throwIfNotFrozen() const;
168  void throwIfFrozen() const;
169 
171 
174  };
175 
176  inline
177  bool
179  return a.productList() == b.productList();
180  }
181 
182  inline
183  bool
185  return !(a == b);
186  }
187 
188  inline
189  std::ostream&
190  operator<<(std::ostream& os, ProductRegistry const& pr) {
191  pr.print(os);
192  return os;
193  }
194 
195 } // edm
196 
197 #endif
void setProductProduced(BranchType branchType)
std::shared_ptr< ProductHolderIndexHelper > eventProductLookup_
ProductHolderIndex & nextIndexValue(BranchType branchType)
std::vector< TypeID > & missingDictionariesForUpdate()
void throwIfNotFrozen() const
std::vector< std::string > allBranchNames() const
std::map< BranchKey, BranchDescription const > ConstProductList
std::vector< TypeID > missingDictionaries_
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)
std::vector< TypeID > const & missingDictionaries() const
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::pair< std::string, std::string > > const & aliasToOriginal() const
double b
Definition: hdecay.h:120
ProductList & productListUpdator()
std::vector< std::pair< std::string, std::string > > aliasToOriginal_
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)