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 
18 
19 #include "boost/array.hpp"
20 #include <memory>
21 
22 #include <iosfwd>
23 #include <map>
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
28 namespace edm {
29  class ProductHolderIndexHelper;
30 
32 
33  public:
34  typedef std::map<BranchKey, BranchDescription> ProductList;
35 
37 
38  // A constructor from the persistent data memebers from another product registry.
39  // saves time by not copying the transient components.
40  // The constructed registry will be frozen by default.
41  explicit ProductRegistry(ProductList const& productList, bool toBeFrozen = true);
42 
43  virtual ~ProductRegistry() {}
44 
45  typedef std::map<BranchKey, BranchDescription const> ConstProductList;
46 
47  void addProduct(BranchDescription const& productdesc, bool iFromListener = false);
48 
49  void addLabelAlias(BranchDescription const& productdesc, std::string const& labelAlias, std::string const& instanceAlias);
50 
51  void copyProduct(BranchDescription const& productdesc);
52 
53  void setFrozen(bool initializeLookupInfo = true);
54 
55  std::string merge(ProductRegistry const& other,
56  std::string const& fileName,
58 
59  void updateFromInput(ProductList const& other);
60 
61  void updateFromInput(std::vector<BranchDescription> const& other);
62 
63  ProductList const& productList() const {
64  //throwIfNotFrozen();
65  return productList_;
66  }
67 
69  throwIfFrozen();
70  return productList_;
71  }
72 
73  // Return all the branch names currently known to *this. This
74  // does a return-by-value of the vector so that it may be used in
75  // a colon-initialization list.
76  std::vector<std::string> allBranchNames() const;
77 
78  // Return pointers to (const) BranchDescriptions for all the
79  // BranchDescriptions known to *this. This does a
80  // return-by-value of the vector so that it may be used in a
81  // colon-initialization list.
82  std::vector<BranchDescription const*> allBranchDescriptions() const;
83 
84  //NOTE: this is not const since we only want items that have non-const access to this class to be
85  // able to call this internal iteration
86  template<typename T>
87  void callForEachBranch(T const& iFunc) {
88  //NOTE: If implementation changes from a map, need to check that iterators are still valid
89  // after an insert with the new container, else need to copy the container and iterate over the copy
90  for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
91  itEntryEnd = productList_.end();
92  itEntry != itEntryEnd; ++itEntry) {
93  iFunc(itEntry->second);
94  }
95  }
96  ProductList::size_type size() const {return productList_.size();}
97 
98  void print(std::ostream& os) const;
99 
100  bool anyProducts(BranchType const brType) const;
101 
102  std::shared_ptr<ProductHolderIndexHelper const> productLookup(BranchType branchType) const;
103  std::shared_ptr<ProductHolderIndexHelper> productLookup(BranchType branchType);
104 
105  // returns the appropriate ProductHolderIndex else ProductHolderIndexInvalid if no BranchID is available
106  ProductHolderIndex indexFrom(BranchID const& iID) const;
107 
110 
111  std::vector<TypeID> const& missingDictionaries() const {
113  }
114 
115  std::vector<TypeID>& missingDictionariesForUpdate() {
117  }
118 
119  std::vector<std::pair<std::string, std::string> > const& aliasToOriginal() const {
121  }
122 
124 
126 
127  bool frozen() const {return transient_.frozen_;}
128 
129  struct Transients {
130  Transients();
131  void reset();
132 
133  std::shared_ptr<ProductHolderIndexHelper const> eventProductLookup() const {return get_underlying_safe(eventProductLookup_);}
134  std::shared_ptr<ProductHolderIndexHelper>& eventProductLookup() {return get_underlying_safe(eventProductLookup_);}
135  std::shared_ptr<ProductHolderIndexHelper const> lumiProductLookup() const {return get_underlying_safe(lumiProductLookup_);}
136  std::shared_ptr<ProductHolderIndexHelper>& lumiProductLookup() {return get_underlying_safe(lumiProductLookup_);}
137  std::shared_ptr<ProductHolderIndexHelper const> runProductLookup() const {return get_underlying_safe(runProductLookup_);}
138  std::shared_ptr<ProductHolderIndexHelper>& runProductLookup() {return get_underlying_safe(runProductLookup_);}
139 
140  bool frozen_;
141  // Is at least one (run), (lumi), (event) product produced this process?
142  boost::array<bool, NumBranchTypes> productProduced_;
144 
148 
152 
153  std::map<BranchID, ProductHolderIndex> branchIDToIndex_;
154 
155  std::vector<TypeID> missingDictionaries_;
156 
157  std::vector<std::pair<std::string, std::string> > aliasToOriginal_;
158  };
159 
160  private:
164  }
165 
166  void freezeIt(bool frozen = true) {transient_.frozen_ = frozen;}
167 
168  void initializeLookupTables();
169  virtual void addCalled(BranchDescription const&, bool iFromListener);
170  void throwIfNotFrozen() const;
171  void throwIfFrozen() const;
172 
174 
177  };
178 
179  inline
180  bool
182  return a.productList() == b.productList();
183  }
184 
185  inline
186  bool
188  return !(a == b);
189  }
190 
191  inline
192  std::ostream&
193  operator<<(std::ostream& os, ProductRegistry const& pr) {
194  pr.print(os);
195  return os;
196  }
197 
198 } // edm
199 
200 #endif
void setProductProduced(BranchType branchType)
ProductHolderIndex & nextIndexValue(BranchType branchType)
std::vector< TypeID > & missingDictionariesForUpdate()
void throwIfNotFrozen() const
std::shared_ptr< ProductHolderIndexHelper const > runProductLookup() const
std::vector< std::string > allBranchNames() const
std::shared_ptr< ProductHolderIndexHelper > & runProductLookup()
std::map< BranchKey, BranchDescription const > ConstProductList
edm::propagate_const< std::shared_ptr< ProductHolderIndexHelper > > lumiProductLookup_
std::vector< TypeID > missingDictionaries_
edm::propagate_const< std::shared_ptr< ProductHolderIndexHelper > > runProductLookup_
std::map< BranchKey, BranchDescription > ProductList
ProductHolderIndex indexFrom(BranchID const &iID) const
bool anyProducts(BranchType const brType) const
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
ProductHolderIndex eventNextIndexValue_
std::shared_ptr< ProductHolderIndexHelper const > productLookup(BranchType branchType) const
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)
std::shared_ptr< ProductHolderIndexHelper > & lumiProductLookup()
std::vector< TypeID > const & missingDictionaries() const
ProductList const & productList() const
std::shared_ptr< ProductHolderIndexHelper const > lumiProductLookup() const
ProductHolderIndex lumiNextIndexValue_
std::shared_ptr< ProductHolderIndexHelper const > eventProductLookup() const
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_
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)
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
edm::propagate_const< std::shared_ptr< ProductHolderIndexHelper > > eventProductLookup_
double a
Definition: hdecay.h:121
void throwIfFrozen() const
void updateFromInput(ProductList const &other)
std::map< BranchID, ProductHolderIndex > branchIDToIndex_
std::shared_ptr< ProductHolderIndexHelper > & eventProductLookup()
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)