CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DataFormats/Provenance/src/BranchIDListHelper.cc

Go to the documentation of this file.
00001 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
00002 
00003 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00004 #include "FWCore/Utilities/interface/Algorithms.h"
00005 
00006 namespace edm {
00007 
00008   BranchIDListHelper::BranchIDListHelper() :
00009     branchIDLists_(),
00010     branchIDToIndexMap_(),
00011     branchListIndexMapper_() {}
00012 
00013   bool
00014   BranchIDListHelper:: updateFromInput(BranchIDLists const& bidlists) {
00015     bool unchanged = true;
00016     branchListIndexMapper_.clear();
00017     typedef BranchIDLists::const_iterator Iter;
00018     for(Iter it = bidlists.begin(), itEnd = bidlists.end(); it != itEnd; ++it) {
00019       BranchListIndex oldBlix = it - bidlists.begin();
00020       Iter j = find_in_all(branchIDLists_, *it);
00021       BranchListIndex blix = j - branchIDLists_.begin();
00022       if(j == branchIDLists_.end()) {
00023         branchIDLists_.push_back(*it);
00024         for(BranchIDList::const_iterator i = it->begin(), iEnd = it->end(); i != iEnd; ++i) {
00025           ProductIndex pix = i - it->begin();
00026           branchIDToIndexMap_.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
00027         }
00028       }
00029       branchListIndexMapper_.insert(std::make_pair(oldBlix, blix));
00030       if(oldBlix != blix) {
00031         unchanged = false;
00032       }
00033     }
00034     return unchanged;
00035   }
00036 
00037   void
00038   BranchIDListHelper::updateRegistries(ProductRegistry const& preg) {
00039     BranchIDList bidlist;
00040     // Add entries for current process for ProductID to BranchID mapping.
00041     for(ProductRegistry::ProductList::const_iterator it = preg.productList().begin(), itEnd = preg.productList().end();
00042         it != itEnd; ++it) {
00043       if(it->second.produced()) {
00044         if(it->second.branchType() == InEvent) {
00045           bidlist.push_back(it->second.branchID().id());
00046         }
00047       }
00048     }
00049     if(!bidlist.empty()) {
00050       BranchListIndex blix = branchIDLists_.size();
00051       preg.setProducedBranchListIndex(blix);
00052       branchIDLists_.push_back(bidlist);
00053       for(BranchIDList::const_iterator i = bidlist.begin(), iEnd = bidlist.end(); i != iEnd; ++i) {
00054         ProductIndex pix = i - bidlist.begin();
00055         branchIDToIndexMap_.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
00056       }
00057     }
00058   }
00059 
00060   void
00061   BranchIDListHelper::fixBranchListIndexes(BranchListIndexes& indexes) {
00062     for(BranchListIndex& i : indexes) {
00063       i = branchListIndexMapper_[i];
00064     }
00065   }
00066 }