Go to the documentation of this file.00001 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
00002
00003 #include "DataFormats/Provenance/interface/BranchIDListRegistry.h"
00004 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00005 #include "FWCore/Utilities/interface/Algorithms.h"
00006
00007 namespace edm {
00008
00009 BranchIDListHelper::BranchIDListHelper() :
00010 branchIDToIndexMap_(),
00011 branchListIndexMapper_() {}
00012
00013 bool
00014 BranchIDListHelper:: updateFromInput(BranchIDLists const& bidlists, std::string const& ) {
00015 bool unchanged = true;
00016 BranchIDListRegistry& breg = *BranchIDListRegistry::instance();
00017 BranchIDListRegistry::collection_type& bdata = breg.data();
00018 BranchIDToIndexMap& branchIDToIndexMap = breg.extra().branchIDToIndexMap_;
00019 BranchListIndexMapper& branchListIndexMapper = breg.extra().branchListIndexMapper_;
00020 branchListIndexMapper.clear();
00021 typedef BranchIDLists::const_iterator Iter;
00022 typedef BranchIDListRegistry::const_iterator RegIter;
00023 for(Iter it = bidlists.begin(), itEnd = bidlists.end(); it != itEnd; ++it) {
00024 BranchListIndex oldBlix = it - bidlists.begin();
00025 RegIter j = find_in_all(bdata, *it);
00026 BranchListIndex blix = j - bdata.begin();
00027 if(j == bdata.end()) {
00028 breg.insertMapped(*it);
00029 for(BranchIDList::const_iterator i = it->begin(), iEnd = it->end(); i != iEnd; ++i) {
00030 ProductIndex pix = i - it->begin();
00031 branchIDToIndexMap.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
00032 }
00033 }
00034 branchListIndexMapper.insert(std::make_pair(oldBlix, blix));
00035 if(oldBlix != blix) {
00036 unchanged = false;
00037 }
00038 }
00039 return unchanged;
00040 }
00041
00042 void
00043 BranchIDListHelper::updateRegistries(ProductRegistry const& preg) {
00044 BranchIDList bidlist;
00045
00046 for(ProductRegistry::ProductList::const_iterator it = preg.productList().begin(), itEnd = preg.productList().end();
00047 it != itEnd; ++it) {
00048 if(it->second.produced()) {
00049 if(it->second.branchType() == InEvent) {
00050 bidlist.push_back(it->second.branchID().id());
00051 }
00052 }
00053 }
00054 BranchIDListRegistry& breg = *BranchIDListRegistry::instance();
00055 BranchIDToIndexMap& branchIDToIndexMap = breg.extra().branchIDToIndexMap_;
00056 if(!bidlist.empty()) {
00057 BranchListIndex blix = breg.data().size();
00058 preg.setProducedBranchListIndex(blix);
00059 breg.insertMapped(bidlist);
00060 for(BranchIDList::const_iterator i = bidlist.begin(), iEnd = bidlist.end(); i != iEnd; ++i) {
00061 ProductIndex pix = i - bidlist.begin();
00062 branchIDToIndexMap.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
00063 }
00064 }
00065 }
00066
00067 void
00068 BranchIDListHelper::fixBranchListIndexes(BranchListIndexes& indexes) {
00069 BranchIDListRegistry& breg = *BranchIDListRegistry::instance();
00070 BranchListIndexMapper& branchListIndexMapper = breg.extra().branchListIndexMapper_;
00071 for(BranchListIndexes::iterator i = indexes.begin(), e = indexes.end(); i != e; ++i) {
00072 *i = branchListIndexMapper[*i];
00073 }
00074 }
00075
00076 void
00077 BranchIDListHelper::clearRegistries() {
00078 BranchIDListRegistry& breg = *BranchIDListRegistry::instance();
00079 breg.data().clear();
00080 breg.extra().branchIDToIndexMap_.clear();
00081 breg.extra().branchListIndexMapper_.clear();
00082 }
00083 }