Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-19 04:32:58

0001 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
0002 
0003 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0004 #include "FWCore/Utilities/interface/Algorithms.h"
0005 
0006 #include <cassert>
0007 
0008 namespace edm {
0009 
0010   BranchIDListHelper::BranchIDListHelper()
0011       : branchIDLists_(),
0012         branchIDToIndexMap_(),
0013         inputIndexToJobIndex_(),
0014         producedBranchListIndex_(std::numeric_limits<BranchListIndex>::max()),
0015         nAlreadyCopied_(0) {}
0016 
0017   bool BranchIDListHelper::updateFromInput(BranchIDLists const& bidlists) {
0018     //The BranchIDLists is a list of lists
0019     // this routine compares bidlists to branchIDLists_ to see if a list
0020     // in branchIDLists_ is already in bidlist and if it isn't we insert
0021     // that new list into branchIDLists_
0022     bool unchanged = true;
0023     inputIndexToJobIndex_.clear();
0024     inputIndexToJobIndex_.resize(bidlists.size());
0025     for (auto it = bidlists.begin(), itEnd = bidlists.end(); it != itEnd; ++it) {
0026       BranchListIndex oldBlix = it - bidlists.begin();
0027       auto j = find_in_all(branchIDLists_, *it);
0028       BranchListIndex blix = j - branchIDLists_.begin();
0029       if (j == branchIDLists_.end()) {
0030         branchIDLists_.push_back(*it);
0031         for (BranchIDList::const_iterator i = it->begin(), iEnd = it->end(); i != iEnd; ++i) {
0032           ProductIndex pix = i - it->begin();
0033           branchIDToIndexMap_.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
0034         }
0035       }
0036       inputIndexToJobIndex_[oldBlix] = blix;
0037       if (oldBlix != blix) {
0038         unchanged = false;
0039       }
0040     }
0041     return unchanged;
0042   }
0043 
0044   void BranchIDListHelper::updateFromParent(BranchIDLists const& bidlists) {
0045     inputIndexToJobIndex_.resize(bidlists.size());
0046     for (auto it = bidlists.begin() + nAlreadyCopied_, itEnd = bidlists.end(); it != itEnd; ++it) {
0047       BranchListIndex oldBlix = it - bidlists.begin();
0048       BranchListIndex blix = branchIDLists_.size();
0049       branchIDLists_.push_back(*it);
0050       for (BranchIDList::const_iterator i = it->begin(), iEnd = it->end(); i != iEnd; ++i) {
0051         ProductIndex pix = i - it->begin();
0052         branchIDToIndexMap_.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
0053       }
0054       inputIndexToJobIndex_[oldBlix] = blix;
0055     }
0056     nAlreadyCopied_ = bidlists.size();
0057   }
0058 
0059   void BranchIDListHelper::updateFromRegistry(ProductRegistry const& preg) {
0060     BranchIDList bidlist;
0061     // Add entries for current process for ProductID to BranchID mapping.
0062     for (ProductRegistry::ProductList::const_iterator it = preg.productList().begin(), itEnd = preg.productList().end();
0063          it != itEnd;
0064          ++it) {
0065       //In the case of the alias, we always use the original branches BranchID
0066       if (it->second.produced() and not it->second.isAlias()) {
0067         if (it->second.branchType() == InEvent) {
0068           bidlist.push_back(it->second.branchID().id());
0069         }
0070       }
0071     }
0072     if (!bidlist.empty()) {
0073       BranchListIndex blix = branchIDLists_.size();
0074       producedBranchListIndex_ = blix;
0075       //preg.setProducedBranchListIndex(blix);
0076       branchIDLists_.push_back(bidlist);
0077       for (BranchIDList::const_iterator i = bidlist.begin(), iEnd = bidlist.end(); i != iEnd; ++i) {
0078         ProductIndex pix = i - bidlist.begin();
0079         branchIDToIndexMap_.insert(std::make_pair(BranchID(*i), std::make_pair(blix, pix)));
0080       }
0081     }
0082   }
0083 
0084   bool BranchIDListHelper::fixBranchListIndexes(BranchListIndexes& indexes, bool assertOnFailure) const {
0085     for (BranchListIndex& i : indexes) {
0086       bool indexInRange = i < inputIndexToJobIndex_.size();
0087       if (!indexInRange) {
0088         if (assertOnFailure) {
0089           assert(indexInRange);
0090         }
0091         return false;
0092       }
0093       i = inputIndexToJobIndex_[i];
0094     }
0095     return true;
0096   }
0097 }  // namespace edm