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