CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/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
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* pp = productProvenance();
00113     if (pp != 0) {
00114       pp->write(os);
00115     }
00116   }
00117 
00118   bool operator==(Provenance const& a, Provenance const& b) {
00119     return a.product() == b.product();
00120   }
00121 
00122   void
00123   Provenance::resetProductProvenance() const {
00124     *productProvenancePtr_ = ProductProvenance();
00125     productProvenanceValid_ = false;
00126   }
00127 
00128   void
00129   Provenance::setProductProvenance(ProductProvenance const& prov) const {
00130     *productProvenancePtr_ = prov;
00131     productProvenanceValid_ = true;
00132   }
00133 
00134   void
00135   Provenance::swap(Provenance& iOther) {
00136     branchDescription_.swap(iOther.branchDescription_);
00137     productID_.swap(iOther.productID_);
00138     productProvenancePtr_.swap(iOther.productProvenancePtr_);
00139     store_.swap(iOther.store_);
00140  }
00141 
00142 }
00143