CMS 3D CMS Logo

LHESource.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <functional>
3 #include <iostream>
4 #include <string>
5 #include <memory>
6 
7 #include <boost/bind.hpp>
8 
17 
22 
26 
30 
31 #include "LHESource.h"
32 
33 using namespace lhef;
34 
36  : ProducerSourceFromFiles(params, desc, false),
37  reader_(new LHEReader(fileNames(0), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
38  lheProvenanceHelper_(
39  edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
40  phid_() {
41  nextEvent();
43  // Initialize metadata, and save the process history ID for use every event.
45 
46  // These calls are not wanted, because the principals are used for putting the products.
47  //produces<LHEEventProduct>();
48  //produces<LHERunInfoProduct, edm::InRun>();
49 }
50 
52 
53 void LHESource::endJob() { reader_.reset(); }
54 
56  if (partonLevel_) {
57  return;
58  }
59 
60  bool newFileOpened;
61  do {
62  newFileOpened = false;
63  partonLevel_ = reader_->next(&newFileOpened);
64  if (newFileOpened) {
66  }
67  } while (newFileOpened && !partonLevel_);
68 
69  if (!partonLevel_) {
70  return;
71  }
72 
73  auto runInfoThis = partonLevel_->getRunInfo();
74  if (runInfoThis != runInfoLast_) {
75  runInfoLast_ = runInfoThis;
76  std::unique_ptr<LHERunInfoProduct> product(new LHERunInfoProduct(*runInfoThis->getHEPRUP()));
77  fillRunInfoProduct(*runInfoThis, *product);
78 
79  if (runInfoProductLast_) {
80  if (!runInfoProductLast_->mergeProduct(*product)) {
81  //cannot be merged so must start new Run
82  runInfoProductLast_ = std::move(product);
83  lheProvenanceHelper_.lheAugment(runInfoThis.get());
84  // Initialize metadata, and save the process history ID for use every event.
87  }
88  } else {
89  runInfoProductLast_ = std::move(product);
90  }
91  }
92 }
93 
95  for (auto const& h : iInfo.getHeaders()) {
96  oProduct.addHeader(h);
97  }
98  for (auto const& c : iInfo.getComments()) {
99  oProduct.addComment(c);
100  }
101 }
102 
104  runAuxiliary()->setProcessHistoryID(phid_);
106 
107  putRunInfoProduct(runPrincipal);
108 }
109 
111  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
112  lumiPrincipal.fillLuminosityBlockPrincipal(
113  processHistoryRegistry().getMapped(lumiPrincipal.aux().processHistoryID()));
114 }
115 
117  if (runInfoProductLast_) {
118  auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
119  std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
121  }
122 }
123 
125  nextEvent();
126  if (!partonLevel_) {
127  // We just finished an input file. See if there is another.
128  nextEvent();
129  if (!partonLevel_) {
130  // No more input files.
131  return false;
132  }
133  }
134  return true;
135 }
136 
140  aux.setProcessHistoryID(phid_);
141  eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry().getMapped(aux.processHistoryID()));
142 
143  std::unique_ptr<LHEEventProduct> product(
144  new LHEEventProduct(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP()));
145  if (partonLevel_->getPDF()) {
146  product->setPDF(*partonLevel_->getPDF());
147  }
148  std::for_each(partonLevel_->weights().begin(),
149  partonLevel_->weights().end(),
150  boost::bind(&LHEEventProduct::addWeight, product.get(), _1));
151  product->setScales(partonLevel_->scales());
152  product->setNpLO(partonLevel_->npLO());
153  product->setNpNLO(partonLevel_->npNLO());
154  std::for_each(partonLevel_->getComments().begin(),
155  partonLevel_->getComments().end(),
156  boost::bind(&LHEEventProduct::addComment, product.get(), _1));
157 
158  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
160  std::move(edp),
162 
163  partonLevel_.reset();
164 
166 }
167 
168 std::shared_ptr<edm::RunAuxiliary> LHESource::readRunAuxiliary_() {
170  resetNewRun();
171  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
172  aux->setProcessHistoryID(phid_);
173  return aux;
174 }
175 
176 std::shared_ptr<edm::LuminosityBlockAuxiliary> LHESource::readLuminosityBlockAuxiliary_() {
177  if (processingMode() == Runs)
178  return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
180  resetNewLumi();
181  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(
183  aux->setProcessHistoryID(phid_);
184  return aux;
185 }
186 
189  desc.setComment("A source which reads LHE files.");
191  desc.addUntracked<unsigned int>("skipEvents", 0U)->setComment("Skip the first 'skipEvents' events.");
192  descriptions.add("source", desc);
193 }
194 
edm::InputSource::resetNewRun
void resetNewRun()
Definition: InputSource.h:352
LHESource::fillRunInfoProduct
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LHESource.cc:94
edm::FromFiles::incrementFileIndex
void incrementFileIndex()
Definition: FromFiles.h:27
MessageLogger.h
funct::false
false
Definition: Factorize.h:34
LHEEventProduct
Definition: LHEEventProduct.h:12
LHESource::partonLevel_
std::shared_ptr< lhef::LHEEvent > partonLevel_
Definition: LHESource.h:58
edm::InputSource::resetEventCached
void resetEventCached()
Definition: InputSource.h:359
LHESource::runInfoLast_
std::shared_ptr< lhef::LHERunInfo > runInfoLast_
Definition: LHESource.h:57
edm::IDGeneratorSourceBase< PuttableSourceBase >::run
RunNumber_t run() const
Definition: IDGeneratorSourceBase.h:37
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::LHEProvenanceHelper::lheInit
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
Definition: LHEProvenanceHelper.cc:117
edm::LuminosityBlockPrincipal
Definition: LuminosityBlockPrincipal.h:31
edm::InputSourceDescription
Definition: InputSourceDescription.h:20
cms::cuda::assert
assert(be >=bs)
TypeID.h
lhef::LHEReader
Definition: LHEReader.h:16
edm::IDGeneratorSourceBase< PuttableSourceBase >::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: IDGeneratorSourceBase.h:39
LHESource::readRun_
void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LHESource.cc:103
lhe2HepMCConverter_cff.LHERunInfoProduct
LHERunInfoProduct
Definition: lhe2HepMCConverter_cff.py:5
LHERunInfoProduct::addHeader
void addHeader(const Header &header)
Definition: LHERunInfoProduct.h:52
edm::InputSource::processHistoryRegistryForUpdate
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:327
LHESource::nextEvent
void nextEvent()
Definition: LHESource.cc:55
edm::Wrapper
Definition: Product.h:10
lhef::LHERunInfo::getComments
const std::vector< std::string > & getComments() const
Definition: LHERunInfo.h:57
edm::LuminosityBlockPrincipal::aux
LuminosityBlockAuxiliary const & aux() const
Definition: LuminosityBlockPrincipal.h:64
edm::RunPrincipal::put
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:36
lhe2HepMCConverter_cff.LHEEventProduct
LHEEventProduct
Definition: lhe2HepMCConverter_cff.py:4
LHERunInfoProduct.h
MakerMacros.h
LHERunInfoProduct
Definition: LHERunInfoProduct.h:13
LHEReader.h
h
edm::EventPrincipal
Definition: EventPrincipal.h:46
lhef::LHERunInfo::getHeaders
const std::vector< Header > & getHeaders() const
Definition: LHERunInfo.h:56
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
LHESource::phid_
edm::ProcessHistoryID phid_
Definition: LHESource.h:62
EventPrincipal.h
LHERunInfoProduct::addComment
void addComment(const std::string &line)
Definition: LHERunInfoProduct.h:53
DEFINE_FWK_INPUT_SOURCE
#define DEFINE_FWK_INPUT_SOURCE(type)
Definition: InputSourceMacros.h:8
OrphanHandle.h
edm::InputSource::luminosityBlockAuxiliary
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:242
edm::EventPrincipal::put
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
Definition: EventPrincipal.cc:178
LHESource::lheProvenanceHelper_
edm::LHEProvenanceHelper lheProvenanceHelper_
Definition: LHESource.h:61
LHESource::readLuminosityBlock_
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LHESource.cc:110
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::EventAuxiliary
Definition: EventAuxiliary.h:14
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
LHESource.h
edm::InputSource::processingMode
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:233
edm::InputSource::runAuxiliary
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:239
LuminosityBlockAuxiliary.h
edm::IDGeneratorSourceBase< PuttableSourceBase >::eventID
EventID const & eventID() const
Definition: IDGeneratorSourceBase.h:36
edm::LuminosityBlockAuxiliary::processHistoryID
ProcessHistoryID const & processHistoryID() const
Definition: LuminosityBlockAuxiliary.h:28
edm::ParameterSetDescription::addUntracked
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:100
edm::InputSource::processHistoryRegistry
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:155
lhef::LHERunInfo
Definition: LHERunInfo.h:25
edm::ParameterSet
Definition: ParameterSet.h:36
edm::ParameterSetDescription::setComment
void setComment(std::string const &value)
Definition: ParameterSetDescription.cc:33
Timestamp.h
edm::ProducerSourceFromFiles::fillDescription
static void fillDescription(ParameterSetDescription &desc)
Definition: ProducerSourceFromFiles.cc:13
LHESource::reader_
std::unique_ptr< lhef::LHEReader > reader_
Definition: LHESource.h:55
LHERunInfo.h
edm::LuminosityBlockPrincipal::fillLuminosityBlockPrincipal
void fillLuminosityBlockPrincipal(ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
Definition: LuminosityBlockPrincipal.cc:16
lhef
Definition: ExhumeHadronizer.h:12
LHESource::readLuminosityBlockAuxiliary_
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: LHESource.cc:176
RunPrincipal.h
LHESource::setRunAndEventInfo
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LHESource.cc:124
edm::LHEProvenanceHelper::lheAugment
void lheAugment(lhef::LHERunInfo const *runInfo)
Definition: LHEProvenanceHelper.cc:94
printConversionInfo.aux
aux
Definition: printConversionInfo.py:19
createfilelist.int
int
Definition: createfilelist.py:10
edm::LHEProvenanceHelper::eventProductProvenance_
ProductProvenance eventProductProvenance_
Definition: LHEProvenanceHelper.h:26
edm::InputSource::resetNewLumi
void resetNewLumi()
Definition: InputSource.h:355
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
LHESource::putRunInfoProduct
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LHESource.cc:116
LuminosityBlockPrincipal.h
LesHouches.h
LHESource::readEvent_
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:137
InputSourceMacros.h
LHESource::~LHESource
~LHESource() override
Definition: LHESource.cc:51
edm::InputSource::Runs
Definition: InputSource.h:80
edm::EventPrincipal::fillEventPrincipal
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
Definition: EventPrincipal.cc:103
edm::RunPrincipal::fillRunPrincipal
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:26
LHEEventProduct.h
edm::Timestamp::invalidTimestamp
static Timestamp invalidTimestamp()
Definition: Timestamp.h:82
edm::InputSource::eventCached
bool eventCached() const
Definition: InputSource.h:356
edm::IDGeneratorSourceBase< PuttableSourceBase >::presentTime
TimeValue_t presentTime() const
Definition: IDGeneratorSourceBase.h:31
eostools.move
def move(src, dest)
Definition: eostools.py:511
LHESource::readRunAuxiliary_
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LHESource.cc:168
LHESource::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LHESource.cc:187
LHESource
Definition: LHESource.h:33
edm::EventAuxiliary::ExperimentType
ExperimentType
Definition: EventAuxiliary.h:18
RunAuxiliary.h
LHESource::runInfoProductLast_
std::unique_ptr< LHERunInfoProduct > runInfoProductLast_
Definition: LHESource.h:60
LHEEvent.h
LHESource::endJob
void endJob() override
Definition: LHESource.cc:53
LaserTracksInput_cfi.fileNames
fileNames
Definition: LaserTracksInput_cfi.py:8
edm::InputSource::resetRunAuxiliary
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:337
LHESource::LHESource
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:35
ParameterSet.h
edm::LHEProvenanceHelper::eventProductBranchDescription_
const BranchDescription eventProductBranchDescription_
Definition: LHEProvenanceHelper.h:24
edm::RunPrincipal
Definition: RunPrincipal.h:34
edm::InputSource::processGUID
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:204
edm::EventID
Definition: EventID.h:31
edm::InputSource::RunsLumisAndEvents
Definition: InputSource.h:80
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
edm::LHEProvenanceHelper::runProductBranchDescription_
const BranchDescription runProductBranchDescription_
Definition: LHEProvenanceHelper.h:25
LHEEventProduct::addComment
void addComment(const std::string &line)
Definition: LHEEventProduct.h:32
edm::Timestamp
Definition: Timestamp.h:30
LHEEventProduct::addWeight
void addWeight(const WGT &wgt)
Definition: LHEEventProduct.h:31