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 
15 
20 
24 
28 
29 #include "LHESource.h"
30 
31 using namespace lhef;
32 
34  : ProducerSourceFromFiles(params, desc, false),
35  reader_(new LHEReader(fileNames(0), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
36  lheProvenanceHelper_(
37  edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
38  phid_() {
39  nextEvent();
41  // Initialize metadata, and save the process history ID for use every event.
43 
44  // These calls are not wanted, because the principals are used for putting the products.
45  //produces<LHEEventProduct>();
46  //produces<LHERunInfoProduct, edm::InRun>();
47 }
48 
50 
51 void LHESource::endJob() { reader_.reset(); }
52 
54  if (partonLevel_) {
55  return;
56  }
57 
58  bool newFileOpened;
59  do {
60  newFileOpened = false;
61  partonLevel_ = reader_->next(&newFileOpened);
62  if (newFileOpened) {
64  }
65  } while (newFileOpened && !partonLevel_);
66 
67  if (!partonLevel_) {
68  return;
69  }
70 
71  auto runInfoThis = partonLevel_->getRunInfo();
72  if (runInfoThis != runInfoLast_) {
73  runInfoLast_ = runInfoThis;
74  std::unique_ptr<LHERunInfoProduct> product(new LHERunInfoProduct(*runInfoThis->getHEPRUP()));
75  fillRunInfoProduct(*runInfoThis, *product);
76 
77  if (runInfoProductLast_) {
78  if (!runInfoProductLast_->mergeProduct(*product)) {
79  //cannot be merged so must start new Run
80  runInfoProductLast_ = std::move(product);
81  lheProvenanceHelper_.lheAugment(runInfoThis.get());
82  // Initialize metadata, and save the process history ID for use every event.
85  }
86  } else {
87  runInfoProductLast_ = std::move(product);
88  }
89  }
90 }
91 
93  for (auto const& h : iInfo.getHeaders()) {
94  oProduct.addHeader(h);
95  }
96  for (auto const& c : iInfo.getComments()) {
97  oProduct.addComment(c);
98  }
99 }
100 
102  runAuxiliary()->setProcessHistoryID(phid_);
104 
105  putRunInfoProduct(runPrincipal);
106 }
107 
109  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
110  lumiPrincipal.fillLuminosityBlockPrincipal(
111  processHistoryRegistry().getMapped(lumiPrincipal.aux().processHistoryID()));
112 }
113 
115  if (runInfoProductLast_) {
116  auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
117  std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
119  }
120 }
121 
123  nextEvent();
124  if (!partonLevel_) {
125  // We just finished an input file. See if there is another.
126  nextEvent();
127  if (!partonLevel_) {
128  // No more input files.
129  return false;
130  }
131  }
132  return true;
133 }
134 
138  aux.setProcessHistoryID(phid_);
139  eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry().getMapped(aux.processHistoryID()));
140 
141  std::unique_ptr<LHEEventProduct> product(
142  new LHEEventProduct(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP()));
143  if (partonLevel_->getPDF()) {
144  product->setPDF(*partonLevel_->getPDF());
145  }
146  std::for_each(partonLevel_->weights().begin(),
147  partonLevel_->weights().end(),
148  std::bind(&LHEEventProduct::addWeight, product.get(), std::placeholders::_1));
149  product->setScales(partonLevel_->scales());
150  product->setNpLO(partonLevel_->npLO());
151  product->setNpNLO(partonLevel_->npNLO());
152  std::for_each(partonLevel_->getComments().begin(),
153  partonLevel_->getComments().end(),
154  std::bind(&LHEEventProduct::addComment, product.get(), std::placeholders::_1));
155 
156  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
158  std::move(edp),
160 
161  partonLevel_.reset();
162 
164 }
165 
166 std::shared_ptr<edm::RunAuxiliary> LHESource::readRunAuxiliary_() {
168  resetNewRun();
169  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
170  aux->setProcessHistoryID(phid_);
171  return aux;
172 }
173 
174 std::shared_ptr<edm::LuminosityBlockAuxiliary> LHESource::readLuminosityBlockAuxiliary_() {
175  if (processingMode() == Runs)
176  return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
178  resetNewLumi();
179  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(
181  aux->setProcessHistoryID(phid_);
182  return aux;
183 }
184 
187  desc.setComment("A source which reads LHE files.");
189  desc.addUntracked<unsigned int>("skipEvents", 0U)->setComment("Skip the first 'skipEvents' events.");
190  descriptions.add("source", desc);
191 }
192 
edm::InputSource::resetNewRun
void resetNewRun()
Definition: InputSource.h:356
edm::RunPrincipal::putOrMerge
void putOrMerge(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:47
LHESource::fillRunInfoProduct
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LHESource.cc:92
edm::FromFiles::incrementFileIndex
void incrementFileIndex()
Definition: FromFiles.h:27
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
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:363
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:21
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:101
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:331
LHESource::nextEvent
void nextEvent()
Definition: LHESource.cc:53
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
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:48
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:233
edm::EventPrincipal::put
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
Definition: EventPrincipal.cc:185
LHESource::lheProvenanceHelper_
edm::LHEProvenanceHelper lheProvenanceHelper_
Definition: LHESource.h:61
LHESource::readLuminosityBlock_
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LHESource.cc:108
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:224
edm::InputSource::runAuxiliary
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:230
LaserDQM_cfg.fileNames
fileNames
Definition: LaserDQM_cfg.py:34
LuminosityBlockAuxiliary.h
edm::IDGeneratorSourceBase< PuttableSourceBase >::eventID
EventID const & eventID() const
Definition: IDGeneratorSourceBase.h:36
edm::LuminosityBlockAuxiliary::processHistoryID
ProcessHistoryID const & processHistoryID() const
Definition: LuminosityBlockAuxiliary.h:32
edm::InputSource::processHistoryRegistry
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:140
lhef::LHERunInfo
Definition: LHERunInfo.h:25
edm::ParameterSet
Definition: ParameterSet.h:47
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:174
RunPrincipal.h
LHESource::setRunAndEventInfo
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LHESource.cc:122
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:359
LHESource::putRunInfoProduct
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LHESource.cc:114
LuminosityBlockPrincipal.h
LesHouches.h
LHESource::readEvent_
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:135
InputSourceMacros.h
LHESource::~LHESource
~LHESource() override
Definition: LHESource.cc:49
edm::InputSource::Runs
Definition: InputSource.h:56
edm::EventPrincipal::fillEventPrincipal
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
Definition: EventPrincipal.cc:110
edm::RunPrincipal::fillRunPrincipal
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:28
LHEEventProduct.h
edm::Timestamp::invalidTimestamp
static Timestamp invalidTimestamp()
Definition: Timestamp.h:82
edm::InputSource::eventCached
bool eventCached() const
Definition: InputSource.h:360
edm::IDGeneratorSourceBase< PuttableSourceBase >::presentTime
TimeValue_t presentTime() const
Definition: IDGeneratorSourceBase.h:31
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
LHESource::readRunAuxiliary_
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LHESource.cc:166
LHESource::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LHESource.cc:185
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:51
edm::InputSource::resetRunAuxiliary
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:341
LHESource::LHESource
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:33
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:195
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::EventID
Definition: EventID.h:31
edm::InputSource::RunsLumisAndEvents
Definition: InputSource.h:56
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