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 
void putOrMerge(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:44
void incrementFileIndex()
Definition: FromFiles.h:27
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:232
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: LHESource.cc:174
static Timestamp invalidTimestamp()
Definition: Timestamp.h:75
void addHeader(const Header &header)
void addComment(const std::string &line)
void endJob() override
Definition: LHESource.cc:51
edm::ProcessHistoryID phid_
Definition: LHESource.h:62
void fillLuminosityBlockPrincipal(ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LHESource.cc:166
const std::vector< std::string > & getComments() const
Definition: LHERunInfo.h:57
ProcessHistoryID const & processHistoryID() const
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LHESource.cc:92
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:108
void addWeight(const WGT &wgt)
std::shared_ptr< lhef::LHERunInfo > runInfoLast_
Definition: LHESource.h:57
assert(be >=bs)
static void fillDescription(ParameterSetDescription &desc)
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:341
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LHESource.cc:122
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
BranchDescription const runProductBranchDescription_
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
#define DEFINE_FWK_INPUT_SOURCE(type)
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:197
std::shared_ptr< lhef::LHEEvent > partonLevel_
Definition: LHESource.h:58
const std::vector< Header > & getHeaders() const
Definition: LHERunInfo.h:56
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LHESource.cc:185
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LHESource.cc:114
bool eventCached() const
Definition: InputSource.h:360
unsigned long long TimeValue_t
Definition: Timestamp.h:21
void nextEvent()
Definition: LHESource.cc:53
void resetEventCached()
Definition: InputSource.h:363
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:33
~LHESource() override
Definition: LHESource.cc:49
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:135
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:139
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
RunNumber_t run() const
Definition: EventID.h:38
void addComment(const std::string &line)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::unique_ptr< lhef::LHEReader > reader_
Definition: LHESource.h:55
void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LHESource.cc:101
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:331
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
HLT enums.
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:235
LuminosityBlockAuxiliary const & aux() const
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:25
ProductProvenance eventProductProvenance_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
def move(src, dest)
Definition: eostools.py:511
BranchDescription const eventProductBranchDescription_
void lheAugment(lhef::LHERunInfo const *runInfo)
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:226