Go to the documentation of this file.00001 #ifndef DataFormats_Provenance_ProductRegistry_h
00002 #define DataFormats_Provenance_ProductRegistry_h
00003
00013 #include "DataFormats/Provenance/interface/BranchDescription.h"
00014 #include "DataFormats/Provenance/interface/BranchKey.h"
00015 #include "DataFormats/Provenance/interface/BranchListIndex.h"
00016 #include "DataFormats/Provenance/interface/BranchType.h"
00017 #include "DataFormats/Provenance/interface/ConstBranchDescription.h"
00018 #include "DataFormats/Provenance/interface/ProductTransientIndex.h"
00019 #include "DataFormats/Provenance/interface/TransientProductLookupMap.h"
00020
00021 #include "boost/array.hpp"
00022
00023 #include <iosfwd>
00024 #include <map>
00025 #include <set>
00026 #include <string>
00027 #include <vector>
00028
00029 namespace edm {
00030
00040 class ProductRegistry {
00041
00042 public:
00043 typedef std::map<BranchKey, BranchDescription> ProductList;
00044
00045 ProductRegistry();
00046
00047
00048
00049
00050 explicit ProductRegistry(ProductList const& productList, bool toBeFrozen = true);
00051
00052 virtual ~ProductRegistry() {}
00053
00054 typedef std::map<BranchKey, ConstBranchDescription> ConstProductList;
00055
00056 void addProduct(BranchDescription const& productdesc, bool iFromListener = false);
00057
00058 void copyProduct(BranchDescription const& productdesc);
00059
00060 void setFrozen(bool initializeLookupInfo = true) const;
00061
00062 std::string merge(ProductRegistry const& other,
00063 std::string const& fileName,
00064 BranchDescription::MatchMode parametersMustMatch = BranchDescription::Permissive,
00065 BranchDescription::MatchMode branchesMustMatch = BranchDescription::Permissive);
00066
00067 void updateFromInput(ProductList const& other);
00068
00069 void updateFromInput(std::vector<BranchDescription> const& other);
00070
00071 ProductList const& productList() const {
00072
00073 return productList_;
00074 }
00075
00076 ProductList& productListUpdator() {
00077 throwIfFrozen();
00078 return productList_;
00079 }
00080
00081
00082
00083
00084 std::vector<std::string> allBranchNames() const;
00085
00086
00087
00088
00089
00090 std::vector<BranchDescription const*> allBranchDescriptions() const;
00091
00092
00093
00094 template<typename T>
00095 void callForEachBranch(T const& iFunc) {
00096
00097
00098 for(ProductRegistry::ProductList::const_iterator itEntry = productList_.begin(),
00099 itEntryEnd = productList_.end();
00100 itEntry != itEntryEnd; ++itEntry) {
00101 iFunc(itEntry->second);
00102 }
00103 }
00104 ProductList::size_type size() const {return productList_.size();}
00105
00106 void print(std::ostream& os) const;
00107
00108 bool anyProducts(BranchType const brType) const;
00109
00110 ConstProductList& constProductList() const {
00111
00112 return transient_.constProductList_;
00113 }
00114
00115 TransientProductLookupMap& productLookup() const {return transient_.productLookup_;}
00116
00117 TransientProductLookupMap& elementLookup() const {return transient_.elementLookup_;}
00118
00119
00120 static ProductTransientIndex const kInvalidIndex = 0xFFFFFFFF;
00121 ProductTransientIndex indexFrom(BranchID const& iID) const;
00122
00123 bool productProduced(BranchType branchType) const {return transient_.productProduced_[branchType];}
00124 bool anyProductProduced() const {return transient_.anyProductProduced_;}
00125 BranchListIndex producedBranchListIndex() const {return transient_.producedBranchListIndex_;}
00126
00127 void setProducedBranchListIndex(BranchListIndex blix) const {
00128 transient_.producedBranchListIndex_ = blix;
00129 }
00130
00131 std::vector<std::string>& missingDictionaries() const {
00132 return transient_.missingDictionaries_;
00133 }
00134
00135 void initializeTransients() const {transient_.reset();}
00136
00137 struct Transients {
00138 Transients();
00139 void reset();
00140 bool frozen_;
00141 ConstProductList constProductList_;
00142
00143 boost::array<bool, NumBranchTypes> productProduced_;
00144 bool anyProductProduced_;
00145
00146
00147
00148
00149
00150 TransientProductLookupMap productLookup_;
00151 TransientProductLookupMap elementLookup_;
00152
00153 std::map<BranchID, ProductTransientIndex> branchIDToIndex_;
00154
00155 BranchListIndex producedBranchListIndex_;
00156
00157 std::vector<std::string> missingDictionaries_;
00158 };
00159
00160 private:
00161 void setProductProduced(BranchType branchType) const {
00162 transient_.productProduced_[branchType] = true;
00163 transient_.anyProductProduced_ = true;
00164 }
00165
00166 bool& frozen() const {return transient_.frozen_;}
00167
00168 void initializeLookupTables() const;
00169 virtual void addCalled(BranchDescription const&, bool iFromListener);
00170 void throwIfNotFrozen() const;
00171 void throwIfFrozen() const;
00172
00173 ProductList productList_;
00174 mutable Transients transient_;
00175 };
00176
00177 inline
00178 bool
00179 operator==(ProductRegistry const& a, ProductRegistry const& b) {
00180 return a.productList() == b.productList();
00181 }
00182
00183 inline
00184 bool
00185 operator!=(ProductRegistry const& a, ProductRegistry const& b) {
00186 return !(a == b);
00187 }
00188
00189 inline
00190 std::ostream&
00191 operator<<(std::ostream& os, ProductRegistry const& pr) {
00192 pr.print(os);
00193 return os;
00194 }
00195
00196 }
00197
00198 #endif