CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include "DataFormats/Provenance/interface/Provenance.h"
00002 #include "DataFormats/Provenance/interface/ProcessConfiguration.h"
00003 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00004 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
00005 #include "DataFormats/Provenance/interface/ProductProvenance.h"
00006 
00007 #include <algorithm>
00008 
00009 /*----------------------------------------------------------------------
00010 
00011 ----------------------------------------------------------------------*/
00012 
00013 namespace edm {
00014 
00015   Provenance::Provenance() : Provenance{boost::shared_ptr<ConstBranchDescription>(), ProductID()} {
00016   }
00017 
00018   Provenance::Provenance(boost::shared_ptr<ConstBranchDescription> const& p, ProductID const& pid) :
00019     branchDescription_(p),
00020     productID_(pid),
00021     processHistoryID_(),
00022     productProvenanceValid_(false),
00023     productProvenancePtr_(new ProductProvenance),
00024     store_() {
00025   }
00026 
00027   ProductProvenance*
00028   Provenance::resolve() const {
00029     if(!store_) {
00030       return 0;
00031     }
00032     if (!productProvenanceValid_) {
00033       ProductProvenance const* prov  = store_->branchIDToProvenance(branchDescription_->branchID());
00034       if (prov) {
00035         *productProvenancePtr_ = *prov;
00036         productProvenanceValid_ = true;
00037       }
00038     }
00039     return productProvenancePtr_.get();
00040   }
00041 
00042   ProcessConfigurationID
00043   Provenance::processConfigurationID() const {
00044     if (parameterSetIDs().size() == 1) {
00045       return parameterSetIDs().begin()->first;
00046     }
00047     if (moduleNames().size() == 1) {
00048       return moduleNames().begin()->first;
00049     }
00050     // Get the ProcessHistory for this event.
00051     ProcessHistoryRegistry* phr = ProcessHistoryRegistry::instance();
00052     ProcessHistory ph;
00053     if (!phr->getMapped(processHistoryID(), ph)) {
00054       return ProcessConfigurationID();
00055     }
00056 
00057     ProcessConfiguration config;
00058     if (!ph.getConfigurationForProcess(processName(), config)) {
00059       return ProcessConfigurationID();
00060     }
00061     return config.id();
00062   }
00063 
00064   ReleaseVersion
00065   Provenance::releaseVersion() const {
00066     ProcessConfiguration pc;
00067     ProcessConfigurationRegistry::instance()->getMapped(processConfigurationID(), pc);
00068     return pc.releaseVersion();
00069   }
00070 
00071   ParameterSetID
00072   Provenance::psetID() const {
00073     if (product().parameterSetID().isValid()) {
00074       return product().parameterSetID();
00075     }
00076     if (parameterSetIDs().size() == 1) {
00077       return parameterSetIDs().begin()->second;
00078     }
00079     std::map<ProcessConfigurationID, ParameterSetID>::const_iterator it =
00080         parameterSetIDs().find(processConfigurationID());
00081     if (it == parameterSetIDs().end()) {
00082       return ParameterSetID();
00083     }
00084     return it->second;
00085   }
00086 
00087   std::string
00088   Provenance::moduleName() const {
00089     if (!product().moduleName().empty()) {
00090       return product().moduleName();
00091     }
00092     if (moduleNames().size() == 1) {
00093       return moduleNames().begin()->second;
00094     }
00095     std::map<ProcessConfigurationID, std::string>::const_iterator it =
00096         moduleNames().find(processConfigurationID());
00097     if (it == moduleNames().end()) {
00098       return std::string();
00099     }
00100     return it->second;
00101   }
00102 
00103   void
00104   Provenance::write(std::ostream& os) const {
00105     // This is grossly inadequate, but it is not critical for the
00106     // first pass.
00107     product().write(os);
00108     ProductProvenance* pp = productProvenance();
00109     if (pp != 0) {
00110       pp->write(os);
00111     }
00112   }
00113 
00114   bool operator==(Provenance const& a, Provenance const& b) {
00115     return a.product() == b.product();
00116   }
00117 
00118   void
00119   Provenance::resetProductProvenance() const {
00120     *productProvenancePtr_ = ProductProvenance();
00121     productProvenanceValid_ = false;
00122   }
00123 
00124   void
00125   Provenance::setProductProvenance(ProductProvenance const& prov) const {
00126     *productProvenancePtr_ = prov;
00127     productProvenanceValid_ = true;
00128   }
00129 
00130   void
00131   Provenance::swap(Provenance& iOther) {
00132     branchDescription_.swap(iOther.branchDescription_);
00133     productID_.swap(iOther.productID_);
00134     std::swap(processHistoryID_, iOther.processHistoryID_);
00135     std::swap(productProvenanceValid_, iOther.productProvenanceValid_);
00136     productProvenancePtr_.swap(iOther.productProvenancePtr_);
00137     store_.swap(iOther.store_);
00138  }
00139 }