File indexing completed on 2025-09-17 07:31:09
0001 #include <string>
0002 #include <vector>
0003 #include "GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.h"
0004 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h"
0005
0006 #include "DataFormats/Provenance/interface/ProcessHistory.h"
0007 #include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
0008 #include "DataFormats/Provenance/interface/ProductRegistry.h"
0009 #include "DataFormats/Provenance/interface/BranchIDList.h"
0010 #include "DataFormats/Provenance/interface/BranchIDListHelper.h"
0011 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
0012
0013 #include "FWCore/AbstractServices/interface/ResourceInformation.h"
0014 #include "FWCore/Utilities/interface/TypeID.h"
0015 #include "FWCore/Reflection/interface/TypeWithDict.h"
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 #include "FWCore/Version/interface/GetReleaseVersion.h"
0018
0019 namespace edm {
0020 LHEProvenanceHelper::LHEProvenanceHelper(TypeID const& eventProductType,
0021 TypeID const& runProductType,
0022 ProductRegistry& productRegistry,
0023 BranchIDListHelper& branchIDListHelper)
0024 : eventProductProductDescription_(ProductDescription(InEvent,
0025 "source",
0026 "LHEFile"
0027
0028 ,
0029 "",
0030 eventProductType,
0031 false)),
0032 runProductProductDescription_(ProductDescription(InRun,
0033 "source",
0034 "LHEFile"
0035
0036 ,
0037 "",
0038 runProductType,
0039 false)),
0040 eventProductProvenance_(eventProductProductDescription_.branchID()),
0041 commonProcessParameterSet_(fillCommonProcessParameterSet()),
0042 processParameterSet_(),
0043 branchListIndexes_(1, 0) {
0044
0045 auto ep = eventProductProductDescription_;
0046 ep.setIsProvenanceSetOnRead();
0047 productRegistry.copyProduct(ep);
0048 auto rp = runProductProductDescription_;
0049 rp.setIsProvenanceSetOnRead();
0050 productRegistry.copyProduct(rp);
0051 productRegistry.setProcessOrder({eventProductProductDescription_.processName()});
0052 BranchIDList bli(1UL, ep.branchID().id());
0053 branchIDListHelper.updateFromInput({{bli}});
0054 }
0055
0056 ParameterSet LHEProvenanceHelper::fillCommonProcessParameterSet() {
0057
0058
0059
0060 ParameterSet pset;
0061 std::string const& moduleLabel = eventProductProductDescription_.moduleLabel();
0062 std::string const& processName = eventProductProductDescription_.processName();
0063 std::string const moduleName = "LHESource";
0064 typedef std::vector<std::string> vstring;
0065 vstring empty;
0066
0067 vstring modlbl;
0068 modlbl.reserve(1);
0069 modlbl.push_back(moduleLabel);
0070 pset.addParameter("@all_sources", modlbl);
0071
0072 ParameterSet triggerPaths;
0073 triggerPaths.addParameter<vstring>("@trigger_paths", empty);
0074 pset.addParameter<ParameterSet>("@trigger_paths", triggerPaths);
0075
0076 ParameterSet pseudoInput;
0077 pseudoInput.addParameter<std::string>("@module_edm_type", "Source");
0078 pseudoInput.addParameter<std::string>("@module_label", moduleLabel);
0079 pseudoInput.addParameter<std::string>("@module_type", moduleName);
0080 pset.addParameter<ParameterSet>(moduleLabel, pseudoInput);
0081
0082 pset.addParameter<vstring>("@all_esmodules", empty);
0083 pset.addParameter<vstring>("@all_esprefers", empty);
0084 pset.addParameter<vstring>("@all_essources", empty);
0085 pset.addParameter<vstring>("@all_loopers", empty);
0086 pset.addParameter<vstring>("@all_modules", empty);
0087 pset.addParameter<vstring>("@end_paths", empty);
0088 pset.addParameter<vstring>("@paths", empty);
0089 pset.addParameter<std::string>("@process_name", processName);
0090 return pset;
0091 }
0092
0093 void LHEProvenanceHelper::lheAugment(lhef::LHERunInfo const* runInfo) {
0094 processParameterSet_ = commonProcessParameterSet_;
0095 if (runInfo == nullptr)
0096 return;
0097 typedef std::vector<std::string> vstring;
0098 auto const& heprup = *runInfo->getHEPRUP();
0099 processParameterSet_.addParameter<int>("IDBMUP1", heprup.IDBMUP.first);
0100 processParameterSet_.addParameter<int>("IDBMUP2", heprup.IDBMUP.second);
0101 processParameterSet_.addParameter<int>("EBMUP1", heprup.EBMUP.first);
0102 processParameterSet_.addParameter<int>("EBMUP2", heprup.EBMUP.second);
0103 processParameterSet_.addParameter<int>("PDFGUP1", heprup.PDFGUP.first);
0104 processParameterSet_.addParameter<int>("PDFGUP2", heprup.PDFGUP.second);
0105 processParameterSet_.addParameter<int>("PDFSUP1", heprup.PDFSUP.first);
0106 processParameterSet_.addParameter<int>("PDFSUP2", heprup.PDFSUP.second);
0107 processParameterSet_.addParameter<int>("IDWTUP", heprup.IDWTUP);
0108 for (auto const& header : runInfo->getHeaders()) {
0109 if (!LHERunInfoProduct::isTagComparedInMerge(header.tag())) {
0110 continue;
0111 }
0112 processParameterSet_.addParameter<vstring>(header.tag(), header.lines());
0113 }
0114 }
0115
0116 ProcessHistoryID LHEProvenanceHelper::lheInit(ProcessHistoryRegistry& processHistoryRegistry) {
0117
0118 processParameterSet_.registerIt();
0119
0120
0121
0122 ProcessHistory ph;
0123 edm::Service<edm::ResourceInformation> resourceInformationService;
0124 edm::HardwareResourcesDescription hwResources;
0125 if (resourceInformationService.isAvailable()) {
0126 hwResources = resourceInformationService->hardwareResourcesDescription();
0127 }
0128 ph.emplace_back(
0129 eventProductProductDescription_.processName(), processParameterSet_.id(), getReleaseVersion(), hwResources);
0130 processHistoryRegistry.registerProcessHistory(ph);
0131
0132
0133 return ph.id();
0134 }
0135
0136 }