CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/DataFormats/Provenance/interface/ProductRegistry.h

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     // A constructor from the persistent data memebers from another product registry.
00048     // saves time by not copying the transient components.
00049     // The constructed registry will be frozen by default.
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       //throwIfNotFrozen();
00073       return productList_;
00074     }
00075 
00076     ProductList& productListUpdator() {
00077       throwIfFrozen();
00078       return productList_;
00079     }
00080 
00081     // Return all the branch names currently known to *this.  This
00082     // does a return-by-value of the vector so that it may be used in
00083     // a colon-initialization list.
00084     std::vector<std::string> allBranchNames() const;
00085 
00086     // Return pointers to (const) BranchDescriptions for all the
00087     // BranchDescriptions known to *this.  This does a
00088     // return-by-value of the vector so that it may be used in a
00089     // colon-initialization list.
00090     std::vector<BranchDescription const*> allBranchDescriptions() const;
00091 
00092     //NOTE: this is not const since we only want items that have non-const access to this class to be
00093     // able to call this internal iteration
00094     template<typename T>
00095     void callForEachBranch(T const& iFunc)  {
00096       //NOTE: If implementation changes from a map, need to check that iterators are still valid
00097       // after an insert with the new container, else need to copy the container and iterate over the copy
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        //throwIfNotFrozen();
00112        return transient_.constProductList_;
00113     }
00114 
00115     TransientProductLookupMap& productLookup() const {return transient_.productLookup_;}
00116 
00117     TransientProductLookupMap& elementLookup() const {return transient_.elementLookup_;}
00118 
00119     //returns the appropriate ProductTransientIndex else 0xFFFFFFFF if no BranchID is available
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       // Is at least one (run), (lumi), (event) product produced this process?
00143       boost::array<bool, NumBranchTypes> productProduced_;
00144       bool anyProductProduced_;
00145 
00146       // indices used to quickly find a group in the vector groups_
00147       // by type, first one by the type of the EDProduct and the
00148       // second by the type of object contained in a sequence in
00149       // an EDProduct
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 } // edm
00197 
00198 #endif