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_(edm::TypeID(typeid(LHEEventProduct)),
37  edm::TypeID(typeid(LHERunInfoProduct)),
38  productRegistryUpdate(),
39  *branchIDListHelper()),
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 = std::make_unique<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 = std::make_unique<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,
142  processHistoryRegistry().getMapped(aux.processHistoryID()),
145 
146  std::unique_ptr<LHEEventProduct> product =
147  std::make_unique<LHEEventProduct>(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP());
148  if (partonLevel_->getPDF()) {
149  product->setPDF(*partonLevel_->getPDF());
150  }
151  std::for_each(partonLevel_->weights().begin(),
152  partonLevel_->weights().end(),
153  std::bind(&LHEEventProduct::addWeight, product.get(), std::placeholders::_1));
154  product->setScales(partonLevel_->scales());
155  product->setNpLO(partonLevel_->npLO());
156  product->setNpNLO(partonLevel_->npNLO());
157  std::for_each(partonLevel_->getComments().begin(),
158  partonLevel_->getComments().end(),
159  std::bind(&LHEEventProduct::addComment, product.get(), std::placeholders::_1));
160 
161  std::unique_ptr<edm::WrapperBase> edp = std::make_unique<edm::Wrapper<LHEEventProduct>>(std::move(product));
163  std::move(edp),
165 
166  partonLevel_.reset();
167 
169 }
170 
171 std::shared_ptr<edm::RunAuxiliary> LHESource::readRunAuxiliary_() {
173  resetNewRun();
174  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
175  aux->setProcessHistoryID(phid_);
176  return aux;
177 }
178 
179 std::shared_ptr<edm::LuminosityBlockAuxiliary> LHESource::readLuminosityBlockAuxiliary_() {
180  if (processingMode() == Runs)
181  return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
183  resetNewLumi();
184  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(
186  aux->setProcessHistoryID(phid_);
187  return aux;
188 }
189 
192  desc.setComment("A source which reads LHE files.");
194  desc.addUntracked<unsigned int>("skipEvents", 0U)->setComment("Skip the first 'skipEvents' events.");
195  descriptions.add("source", desc);
196 }
197 
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:261
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: LHESource.cc:179
static Timestamp invalidTimestamp()
Definition: Timestamp.h:75
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
void fillLuminosityBlockPrincipal(ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LHESource.cc:171
const std::vector< std::string > & getComments() const
Definition: LHERunInfo.h:57
ProcessHistoryID const & processHistoryID() const
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
BranchListIndexes branchListIndexes_
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:370
std::vector< EventSelectionID > EventSelectionIDVector
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LHESource.cc:124
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:226
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:190
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LHESource.cc:116
bool eventCached() const
Definition: InputSource.h:389
unsigned long long TimeValue_t
Definition: Timestamp.h:21
void nextEvent()
Definition: LHESource.cc:55
void resetEventCached()
Definition: InputSource.h:392
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:33
~LHESource() override
Definition: LHESource.cc:51
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:137
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:168
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:103
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:360
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:264
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:255