CMS 3D CMS Logo

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