CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/FWCore/Framework/src/RunPrincipal.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/RunPrincipal.h"
00002 
00003 #include "DataFormats/Common/interface/WrapperOwningHolder.h"
00004 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
00005 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00006 #include "FWCore/Framework/interface/DelayedReader.h"
00007 #include "FWCore/Framework/interface/Group.h"
00008 #include "FWCore/Utilities/interface/EDMException.h"
00009 
00010 namespace edm {
00011   RunPrincipal::RunPrincipal(
00012     boost::shared_ptr<RunAuxiliary> aux,
00013     boost::shared_ptr<ProductRegistry const> reg,
00014     ProcessConfiguration const& pc) :
00015       Base(reg, pc, InRun),
00016       aux_(aux) {
00017   }
00018 
00019   void
00020   RunPrincipal::fillRunPrincipal(
00021     boost::shared_ptr<BranchMapper> mapper,
00022     DelayedReader* reader) {
00023     if(productRegistry().anyProductProduced()) {
00024       checkProcessHistory();
00025     }
00026     fillPrincipal(aux_->processHistoryID(), mapper, reader);
00027     if(productRegistry().anyProductProduced()) {
00028       addToProcessHistory();
00029     }
00030     branchMapperPtr()->processHistoryID() = processHistoryID();
00031     for (const_iterator i = this->begin(), iEnd = this->end(); i != iEnd; ++i) {
00032       (*i)->setProvenance(branchMapperPtr());
00033     }
00034   }
00035 
00036   void
00037   RunPrincipal::put(
00038         ConstBranchDescription const& bd,
00039         WrapperOwningHolder const& edp,
00040         ProductProvenance& productProvenance) {
00041 
00042     assert(bd.produced());
00043     if(!edp.isValid()) {
00044       throw edm::Exception(edm::errors::InsertFailure,"Null Pointer")
00045         << "put: Cannot put because auto_ptr to product is null."
00046         << "\n";
00047     }
00048     branchMapperPtr()->insert(productProvenance);
00049     Group *g = getExistingGroup(bd.branchID());
00050     assert(g);
00051     // Group assumes ownership
00052     putOrMerge(edp, productProvenance, g);
00053   }
00054 
00055   void
00056   RunPrincipal::readImmediate() const {
00057     for (Principal::const_iterator i = begin(), iEnd = end(); i != iEnd; ++i) {
00058       Group const& g = **i;
00059       if(!g.branchDescription().produced()) {
00060         if(!g.productUnavailable()) {
00061           resolveProductImmediate(g);
00062         }
00063       }
00064     }
00065     branchMapperPtr()->setDelayedRead(false);
00066   }
00067 
00068   void
00069   RunPrincipal::resolveProductImmediate(Group const& g) const {
00070     if(g.branchDescription().produced()) return; // nothing to do.
00071     if(!reader()) return; // nothing to do.
00072 
00073     // must attempt to load from persistent store
00074     BranchKey const bk = BranchKey(g.branchDescription());
00075     WrapperOwningHolder edp(reader()->getProduct(bk, g.productData().getInterface(), this));
00076 
00077     // Now fix up the Group
00078     if(edp.isValid()) {
00079       putOrMerge(edp, &g);
00080     }
00081   }
00082 
00083   void
00084   RunPrincipal::checkProcessHistory() const {
00085     ProcessHistory ph;
00086     ProcessHistoryRegistry::instance()->getMapped(aux_->processHistoryID(), ph);
00087     std::string const& processName = processConfiguration().processName();
00088     for (ProcessHistory::const_iterator it = ph.begin(), itEnd = ph.end(); it != itEnd; ++it) {
00089       if(processName == it->processName()) {
00090         throw edm::Exception(errors::Configuration, "Duplicate Process")
00091           << "The process name " << processName << " was previously used on these products.\n"
00092           << "Please modify the configuration file to use a distinct process name.\n";
00093       }
00094     }
00095   }
00096 
00097   void
00098   RunPrincipal::addToProcessHistory() {
00099     ProcessHistory& ph = processHistoryUpdate();
00100     ph.push_back(processConfiguration());
00101     //OPTIMIZATION NOTE:  As of 0_9_0_pre3
00102     // For very simple Sources (e.g. EmptySource) this routine takes up nearly 50% of the time per event.
00103     // 96% of the time for this routine is being spent in computing the
00104     // ProcessHistory id which happens because we are reconstructing the ProcessHistory for each event.
00105     // (The process ID is first computed in the call to 'insertMapped(..)' below.)
00106     // It would probably be better to move the ProcessHistory construction out to somewhere
00107     // which persists for longer than one Event
00108 
00109     ProcessHistoryRegistry::instance()->insertMapped(ph);
00110     setProcessHistory(*this);
00111   }
00112 }