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  const edm::InputSourceDescription &desc) :
37  ProducerSourceFromFiles(params, desc, false),
38  reader_(new LHEReader(fileNames(), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
39  lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
40  phid_()
41 {
42  nextEvent();
44  // Initialize metadata, and save the process history ID for use every event.
46 
47  // These calls are not wanted, because the principals are used for putting the products.
48  //produces<LHEEventProduct>();
49  //produces<LHERunInfoProduct, edm::InRun>();
50 }
51 
53 {
54 }
55 
57 {
58  reader_.reset();
59 }
60 
62 {
63  if (partonLevel_) {
64  return;
65  }
66 
67  bool newFileOpened;
68  do {
69  newFileOpened = false;
70  partonLevel_ = reader_->next(&newFileOpened);
71  if(newFileOpened) {
73  }
74  } while (newFileOpened && !partonLevel_);
75 
76  if (!partonLevel_) {
77  return;
78  }
79 
80  auto runInfoThis = partonLevel_->getRunInfo();
81  if (runInfoThis != runInfoLast_) {
82  runInfoLast_ = runInfoThis;
83  std::unique_ptr<LHERunInfoProduct> product(
84  new LHERunInfoProduct(*runInfoThis->getHEPRUP()));
85  fillRunInfoProduct(*runInfoThis, *product);
86 
87  if (runInfoProductLast_) {
88  if (!runInfoProductLast_->mergeProduct(*product)) {
89  //cannot be merged so must start new Run
90  runInfoProductLast_ = std::move(product);
91  lheProvenanceHelper_.lheAugment(runInfoThis.get());
92  // Initialize metadata, and save the process history ID for use every event.
95  }
96  } else {
97  runInfoProductLast_ = std::move(product);
98  }
99  }
100 }
101 
102 void
104  for(auto const& h: iInfo.getHeaders()) {
105  oProduct.addHeader(h);
106  }
107  for(auto const& c: iInfo.getComments()) {
108  oProduct.addComment(c);
109  }
110 }
111 
112 
113 void
115  runAuxiliary()->setProcessHistoryID(phid_);
117 
118  putRunInfoProduct(runPrincipal);
119 }
120 
121 void
123  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
125 }
126 
128  if (runInfoProductLast_) {
129  auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
130  std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
132  }
133 }
134 
136 {
137  nextEvent();
138  if (!partonLevel_) {
139  // We just finished an input file. See if there is another.
140  nextEvent();
141  if (!partonLevel_) {
142  // No more input files.
143  return false;
144  }
145  }
146  return true;
147 }
148 
149 void
155 
156  std::unique_ptr<LHEEventProduct> product(
157  new LHEEventProduct(*partonLevel_->getHEPEUP(),
158  partonLevel_->originalXWGTUP())
159  );
160  if (partonLevel_->getPDF()) {
161  product->setPDF(*partonLevel_->getPDF());
162  }
163  std::for_each(partonLevel_->weights().begin(),
164  partonLevel_->weights().end(),
165  boost::bind(&LHEEventProduct::addWeight,
166  product.get(), _1));
167  product->setScales(partonLevel_->scales());
168  product->setNpLO(partonLevel_->npLO());
169  product->setNpNLO(partonLevel_->npNLO());
170  std::for_each(partonLevel_->getComments().begin(),
171  partonLevel_->getComments().end(),
172  boost::bind(&LHEEventProduct::addComment,
173  product.get(), _1));
174 
175  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
177 
178  partonLevel_.reset();
179 
181 }
182 
183 std::shared_ptr<edm::RunAuxiliary>
186  resetNewRun();
187  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
188  aux->setProcessHistoryID(phid_);
189  return aux;
190 }
191 
192 std::shared_ptr<edm::LuminosityBlockAuxiliary>
194  if (processingMode() == Runs) return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
196  resetNewLumi();
197  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(eventID().run(), eventID().luminosityBlock(),
199  aux->setProcessHistoryID(phid_);
200  return aux;
201 }
202 
RunNumber_t run() const
Definition: EventID.h:39
const std::vector< std::string > & getComments() const
Definition: LHERunInfo.h:59
void incrementFileIndex()
Definition: FromFiles.h:27
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: LHESource.cc:193
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void addHeader(const Header &header)
void addComment(const std::string &line)
void endJob() override
Definition: LHESource.cc:56
edm::ProcessHistoryID phid_
Definition: LHESource.h:62
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LHESource.cc:184
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LHESource.cc:103
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:122
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:39
void addWeight(const WGT &wgt)
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:345
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:240
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
Definition: RunPrincipal.cc:28
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
boost::shared_ptr< lhef::LHEEvent > partonLevel_
Definition: LHESource.h:58
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:211
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LHESource.cc:135
BranchDescription const runProductBranchDescription_
void fillLuminosityBlockPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
#define DEFINE_FWK_INPUT_SOURCE(type)
const std::vector< Header > & getHeaders() const
Definition: LHERunInfo.h:58
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LHESource.cc:127
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:61
void resetEventCached()
Definition: InputSource.h:367
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:35
~LHESource() override
Definition: LHESource.cc:52
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:150
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
void addComment(const std::string &line)
boost::shared_ptr< lhef::LHERunInfo > runInfoLast_
Definition: LHESource.h:57
TimeValue_t presentTime() const
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:246
void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LHESource.cc:114
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:335
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
HLT enums.
EventID const & eventID() const
ProductProvenance eventProductProvenance_
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:249
def move(src, dest)
Definition: eostools.py:511
BranchDescription const eventProductBranchDescription_
void lheAugment(lhef::LHERunInfo const *runInfo)
bool eventCached() const
Definition: InputSource.h:364