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(), 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_);
113 }
114 
116  if (runInfoProductLast_) {
117  auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
118  std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
120  }
121 }
122 
124  nextEvent();
125  if (!partonLevel_) {
126  // We just finished an input file. See if there is another.
127  nextEvent();
128  if (!partonLevel_) {
129  // No more input files.
130  return false;
131  }
132  }
133  return true;
134 }
135 
141 
142  std::unique_ptr<LHEEventProduct> product(
143  new LHEEventProduct(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP()));
144  if (partonLevel_->getPDF()) {
145  product->setPDF(*partonLevel_->getPDF());
146  }
147  std::for_each(partonLevel_->weights().begin(),
148  partonLevel_->weights().end(),
149  boost::bind(&LHEEventProduct::addWeight, product.get(), _1));
150  product->setScales(partonLevel_->scales());
151  product->setNpLO(partonLevel_->npLO());
152  product->setNpNLO(partonLevel_->npNLO());
153  std::for_each(partonLevel_->getComments().begin(),
154  partonLevel_->getComments().end(),
155  boost::bind(&LHEEventProduct::addComment, product.get(), _1));
156 
157  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
159  std::move(edp),
161 
162  partonLevel_.reset();
163 
165 }
166 
167 std::shared_ptr<edm::RunAuxiliary> LHESource::readRunAuxiliary_() {
169  resetNewRun();
170  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
171  aux->setProcessHistoryID(phid_);
172  return aux;
173 }
174 
175 std::shared_ptr<edm::LuminosityBlockAuxiliary> LHESource::readLuminosityBlockAuxiliary_() {
176  if (processingMode() == Runs)
177  return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
179  resetNewLumi();
180  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(
182  aux->setProcessHistoryID(phid_);
183  return aux;
184 }
185 
188  desc.setComment("A source which reads LHE files.");
190  desc.addUntracked<unsigned int>("skipEvents", 0U)->setComment("Skip the first 'skipEvents' events.");
191  descriptions.add("source", desc);
192 }
193 
RunNumber_t run() const
Definition: EventID.h:38
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
const std::vector< std::string > & getComments() const
Definition: LHERunInfo.h:57
void incrementFileIndex()
Definition: FromFiles.h:27
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: LHESource.cc:175
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
static Timestamp invalidTimestamp()
Definition: Timestamp.h:82
void addHeader(const Header &header)
void addComment(const std::string &line)
void endJob() override
Definition: LHESource.cc:53
edm::ProcessHistoryID phid_
Definition: LHESource.h:62
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LHESource.cc:167
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LHESource.cc:94
edm::LHEProvenanceHelper lheProvenanceHelper_
Definition: LHESource.h:61
std::unique_ptr< LHERunInfoProduct > runInfoProductLast_
Definition: LHESource.h:60
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LHESource.cc:110
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:36
void addWeight(const WGT &wgt)
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:337
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:233
std::shared_ptr< lhef::LHERunInfo > runInfoLast_
Definition: LHESource.h:57
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
Definition: RunPrincipal.cc:26
static void fillDescription(ParameterSetDescription &desc)
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:204
#define DEFINE_FWK_INPUT_SOURCE(type)
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LHESource.cc:123
BranchDescription const runProductBranchDescription_
void setComment(std::string const &value)
void fillLuminosityBlockPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
std::shared_ptr< lhef::LHEEvent > partonLevel_
Definition: LHESource.h:58
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LHESource.cc:186
const std::vector< Header > & getHeaders() const
Definition: LHERunInfo.h:56
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LHESource.cc:115
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
unsigned long long TimeValue_t
Definition: Timestamp.h:28
void nextEvent()
Definition: LHESource.cc:55
void resetEventCached()
Definition: InputSource.h:359
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:35
~LHESource() override
Definition: LHESource.cc:51
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:136
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
void addComment(const std::string &line)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void setProcessHistoryID(ProcessHistoryID const &phid)
std::unique_ptr< lhef::LHEReader > reader_
Definition: LHESource.h:55
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:239
void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LHESource.cc:103
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:327
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
HLT enums.
ProductProvenance eventProductProvenance_
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:242
def move(src, dest)
Definition: eostools.py:511
BranchDescription const eventProductBranchDescription_
void lheAugment(lhef::LHERunInfo const *runInfo)
bool eventCached() const
Definition: InputSource.h:356