CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DataFormats/Provenance/src/BranchMapper.cc

Go to the documentation of this file.
00001 #include "DataFormats/Provenance/interface/BranchMapper.h"
00002 #include "FWCore/Utilities/interface/EDMException.h"
00003 
00004 #include <cassert>
00005 #include <iostream>
00006 
00007 /*
00008   BranchMapper
00009 */
00010 
00011 namespace edm {
00012   BranchMapper::BranchMapper() :
00013       entryInfoSet_(),
00014       nextMapper_(),
00015       delayedRead_(false),
00016       provenanceReader_() {
00017   }
00018 
00019   BranchMapper::BranchMapper(std::unique_ptr<ProvenanceReaderBase> reader) :
00020       entryInfoSet_(),
00021       nextMapper_(),
00022       delayedRead_(true),
00023       provenanceReader_(reader.release()) {
00024     assert(provenanceReader_);
00025   }
00026 
00027   BranchMapper::~BranchMapper() {}
00028 
00029   void
00030   BranchMapper::readProvenance() const {
00031     if(delayedRead_ && provenanceReader_) {
00032       provenanceReader_->readProvenance(*this);
00033       delayedRead_ = false; // only read once
00034     }
00035   }
00036 
00037   void
00038   BranchMapper::reset() {
00039     entryInfoSet_.clear();
00040     delayedRead_ = true;
00041   }
00042 
00043   void
00044   BranchMapper::insertIntoSet(ProductProvenance const& entryInfo) const {
00045     //NOTE:do not read provenance here because we only need the full
00046     // provenance when someone tries to access it not when doing the insert
00047     // doing the delay saves 20% of time when doing an analysis job
00048     //readProvenance();
00049     entryInfoSet_.insert(entryInfo);
00050   }
00051  
00052   void
00053   BranchMapper::mergeMappers(boost::shared_ptr<BranchMapper> other) {
00054     nextMapper_ = other;
00055   }
00056 
00057   ProductProvenance const*
00058   BranchMapper::branchIDToProvenance(BranchID const& bid) const {
00059     readProvenance();
00060     ProductProvenance ei(bid);
00061     eiSet::const_iterator it = entryInfoSet_.find(ei);
00062     if(it == entryInfoSet_.end()) {
00063       if(nextMapper_) {
00064         return nextMapper_->branchIDToProvenance(bid);
00065       } else {
00066         return 0;
00067       }
00068     }
00069     return &*it;
00070   }
00071 
00072   ProvenanceReaderBase::~ProvenanceReaderBase() {
00073   }
00074 }