Skip to content

Commit

Permalink
Merge pull request #43749 from Dr15Jones/branchIdListLHESource
Browse files Browse the repository at this point in the history
Properly setup meta data in LHESource
  • Loading branch information
cmsbuild authored Jan 23, 2024
2 parents f4341e4 + b055c4c commit 743099a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
21 changes: 13 additions & 8 deletions GeneratorInterface/LHEInterface/plugins/LH5Source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ LH5Source::LH5Source(const edm::ParameterSet& params, const edm::InputSourceDesc
: ProducerSourceFromFiles(params, desc, false),
// reader_(new LH5Reader(params)),
reader_(new LH5Reader(fileNames(0), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
lheProvenanceHelper_(
edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)),
edm::TypeID(typeid(LHERunInfoProduct)),
productRegistryUpdate(),
*branchIDListHelper()),
phid_() {
nextEvent();
lheProvenanceHelper_.lheAugment(nullptr);
Expand Down Expand Up @@ -72,7 +74,7 @@ void LH5Source::nextEvent() {
auto runInfoThis = partonLevel_->getRunInfo();
if (runInfoThis != runInfoLast_) {
runInfoLast_ = runInfoThis;
std::unique_ptr<LHERunInfoProduct> product(new LHERunInfoProduct(*runInfoThis->getHEPRUP()));
std::unique_ptr<LHERunInfoProduct> product = std::make_unique<LHERunInfoProduct>(*runInfoThis->getHEPRUP());
fillRunInfoProduct(*runInfoThis, *product);

if (runInfoProductLast_) {
Expand Down Expand Up @@ -115,7 +117,7 @@ void LH5Source::readLuminosityBlock_(edm::LuminosityBlockPrincipal& lumiPrincipa
void LH5Source::putRunInfoProduct(edm::RunPrincipal& iRunPrincipal) {
if (runInfoProductLast_) {
auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
std::unique_ptr<edm::WrapperBase> rdp = std::make_unique<edm::Wrapper<LHERunInfoProduct>>(std::move(product));
iRunPrincipal.put(lheProvenanceHelper_.runProductBranchDescription_, std::move(rdp));
}
}
Expand All @@ -137,10 +139,13 @@ void LH5Source::readEvent_(edm::EventPrincipal& eventPrincipal) {
assert(eventCached() || processingMode() != RunsLumisAndEvents);
edm::EventAuxiliary aux(eventID(), processGUID(), edm::Timestamp(presentTime()), false);
aux.setProcessHistoryID(phid_);
eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry().getMapped(aux.processHistoryID()));
eventPrincipal.fillEventPrincipal(aux,
processHistoryRegistry().getMapped(aux.processHistoryID()),
edm::EventSelectionIDVector(),
lheProvenanceHelper_.branchListIndexes_);

std::unique_ptr<LHEEventProduct> product(
new LHEEventProduct(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP()));
std::unique_ptr<LHEEventProduct> product =
std::make_unique<LHEEventProduct>(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP());
if (partonLevel_->getPDF()) {
product->setPDF(*partonLevel_->getPDF());
}
Expand All @@ -154,7 +159,7 @@ void LH5Source::readEvent_(edm::EventPrincipal& eventPrincipal) {
partonLevel_->getComments().end(),
std::bind(&LHEEventProduct::addComment, product.get(), std::placeholders::_1));

std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
std::unique_ptr<edm::WrapperBase> edp = std::make_unique<edm::Wrapper<LHEEventProduct>>(std::move(product));
eventPrincipal.put(lheProvenanceHelper_.eventProductBranchDescription_,
std::move(edp),
lheProvenanceHelper_.eventProductProvenance_);
Expand Down
10 changes: 8 additions & 2 deletions GeneratorInterface/LHEInterface/plugins/LHEProvenanceHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "DataFormats/Provenance/interface/ProcessHistory.h"
#include "DataFormats/Provenance/interface/ProcessHistoryRegistry.h"
#include "DataFormats/Provenance/interface/ProductRegistry.h"
#include "DataFormats/Provenance/interface/BranchIDList.h"
#include "DataFormats/Provenance/interface/BranchIDListHelper.h"
#include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"

#include "FWCore/Utilities/interface/GetPassID.h"
Expand All @@ -17,7 +19,8 @@
namespace edm {
LHEProvenanceHelper::LHEProvenanceHelper(TypeID const& eventProductType,
TypeID const& runProductType,
ProductRegistry& productRegistry)
ProductRegistry& productRegistry,
BranchIDListHelper& branchIDListHelper)
: eventProductBranchDescription_(BranchDescription(InEvent,
"source",
"LHEFile"
Expand All @@ -44,14 +47,17 @@ namespace edm {
false)),
eventProductProvenance_(eventProductBranchDescription_.branchID()),
commonProcessParameterSet_(fillCommonProcessParameterSet()),
processParameterSet_() {
processParameterSet_(),
branchListIndexes_(1, 0) {
// Add the products to the product registry
auto ep = eventProductBranchDescription_;
ep.setIsProvenanceSetOnRead();
productRegistry.copyProduct(ep);
auto rp = runProductBranchDescription_;
rp.setIsProvenanceSetOnRead();
productRegistry.copyProduct(rp);
BranchIDList bli(1UL, ep.branchID().id());
branchIDListHelper.updateFromInput({{bli}});
}

ParameterSet LHEProvenanceHelper::fillCommonProcessParameterSet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "DataFormats/Provenance/interface/BranchDescription.h"
#include "DataFormats/Provenance/interface/ProcessHistoryID.h"
#include "DataFormats/Provenance/interface/ProductProvenance.h"
#include "DataFormats/Provenance/interface/BranchListIndex.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

namespace lhef {
Expand All @@ -14,10 +15,12 @@ namespace edm {
class ProcessHistoryRegistry;
class ProductRegistry;
class TypeID;
class BranchIDListHelper;
struct LHEProvenanceHelper {
explicit LHEProvenanceHelper(TypeID const& eventProductType,
TypeID const& runProductType,
ProductRegistry& productRegistry);
ProductRegistry& productRegistry,
BranchIDListHelper& helper);
ParameterSet fillCommonProcessParameterSet();
void lheAugment(lhef::LHERunInfo const* runInfo);
ProcessHistoryID lheInit(ProcessHistoryRegistry& processHistoryRegistry);
Expand All @@ -26,6 +29,7 @@ namespace edm {
ProductProvenance eventProductProvenance_;
ParameterSet const commonProcessParameterSet_;
ParameterSet processParameterSet_;
BranchListIndexes branchListIndexes_;
};
} // namespace edm
#endif
21 changes: 13 additions & 8 deletions GeneratorInterface/LHEInterface/plugins/LHESource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ using namespace lhef;
LHESource::LHESource(const edm::ParameterSet& params, const edm::InputSourceDescription& desc)
: ProducerSourceFromFiles(params, desc, false),
reader_(new LHEReader(fileNames(0), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
lheProvenanceHelper_(
edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)),
edm::TypeID(typeid(LHERunInfoProduct)),
productRegistryUpdate(),
*branchIDListHelper()),
phid_() {
nextEvent();
lheProvenanceHelper_.lheAugment(nullptr);
Expand Down Expand Up @@ -71,7 +73,7 @@ void LHESource::nextEvent() {
auto runInfoThis = partonLevel_->getRunInfo();
if (runInfoThis != runInfoLast_) {
runInfoLast_ = runInfoThis;
std::unique_ptr<LHERunInfoProduct> product(new LHERunInfoProduct(*runInfoThis->getHEPRUP()));
std::unique_ptr<LHERunInfoProduct> product = std::make_unique<LHERunInfoProduct>(*runInfoThis->getHEPRUP());
fillRunInfoProduct(*runInfoThis, *product);

if (runInfoProductLast_) {
Expand Down Expand Up @@ -114,7 +116,7 @@ void LHESource::readLuminosityBlock_(edm::LuminosityBlockPrincipal& lumiPrincipa
void LHESource::putRunInfoProduct(edm::RunPrincipal& iRunPrincipal) {
if (runInfoProductLast_) {
auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
std::unique_ptr<edm::WrapperBase> rdp = std::make_unique<edm::Wrapper<LHERunInfoProduct>>(std::move(product));
iRunPrincipal.putOrMerge(lheProvenanceHelper_.runProductBranchDescription_, std::move(rdp));
}
}
Expand All @@ -136,10 +138,13 @@ void LHESource::readEvent_(edm::EventPrincipal& eventPrincipal) {
assert(eventCached() || processingMode() != RunsLumisAndEvents);
edm::EventAuxiliary aux(eventID(), processGUID(), edm::Timestamp(presentTime()), false);
aux.setProcessHistoryID(phid_);
eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry().getMapped(aux.processHistoryID()));
eventPrincipal.fillEventPrincipal(aux,
processHistoryRegistry().getMapped(aux.processHistoryID()),
edm::EventSelectionIDVector(),
lheProvenanceHelper_.branchListIndexes_);

std::unique_ptr<LHEEventProduct> product(
new LHEEventProduct(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP()));
std::unique_ptr<LHEEventProduct> product =
std::make_unique<LHEEventProduct>(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP());
if (partonLevel_->getPDF()) {
product->setPDF(*partonLevel_->getPDF());
}
Expand All @@ -153,7 +158,7 @@ void LHESource::readEvent_(edm::EventPrincipal& eventPrincipal) {
partonLevel_->getComments().end(),
std::bind(&LHEEventProduct::addComment, product.get(), std::placeholders::_1));

std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
std::unique_ptr<edm::WrapperBase> edp = std::make_unique<edm::Wrapper<LHEEventProduct>>(std::move(product));
eventPrincipal.put(lheProvenanceHelper_.eventProductBranchDescription_,
std::move(edp),
lheProvenanceHelper_.eventProductProvenance_);
Expand Down

0 comments on commit 743099a

Please sign in to comment.