CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 #include <boost/ptr_container/ptr_deque.hpp>
9 
18 
20 
24 
28 
29 #include "LHESource.h"
30 
31 using namespace lhef;
32 
34  const edm::InputSourceDescription &desc) :
35  ProducerSourceFromFiles(params, desc, false),
36  reader(new LHEReader(fileNames(), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
37  wasMerged(false),
38  lheProvenanceHelper_(edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
39  phid_(),
40  runPrincipal_()
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  } while (newFileOpened && !partonLevel);
72 
73  if (!partonLevel) {
74  return;
75  }
76 
77  boost::shared_ptr<LHERunInfo> runInfoThis = partonLevel->getRunInfo();
78  if (runInfoThis != runInfoLast) {
79  runInfo = runInfoThis;
80  runInfoLast = runInfoThis;
81  }
82  if (runInfo) {
83  std::auto_ptr<LHERunInfoProduct> product(
84  new LHERunInfoProduct(*runInfo->getHEPRUP()));
85  std::for_each(runInfo->getHeaders().begin(),
86  runInfo->getHeaders().end(),
87  boost::bind(
89  product.get(), _1));
90  std::for_each(runInfo->getComments().begin(),
91  runInfo->getComments().end(),
92  boost::bind(&LHERunInfoProduct::addComment,
93  product.get(), _1));
94 
95  if (!runInfoProducts.empty()) {
96  if (runInfoProducts.front().mergeProduct(*product)) {
97  if (!wasMerged) {
98  runInfoProducts.pop_front();
99  runInfoProducts.push_front(product);
100  wasMerged = true;
101  }
102  } else {
104  // Initialize metadata, and save the process history ID for use every event.
107  }
108  }
109 
110  runInfo.reset();
111  }
112 }
113 
114 // This is the only way we can now access the run principal.
115 void
117  runAuxiliary()->setProcessHistoryID(phid_);
120 }
121 
122 void
124  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
126 }
127 
129 {
130  if (runInfoLast) {
132 
133  std::unique_ptr<LHERunInfoProduct> product(
134  new LHERunInfoProduct(*runInfo->getHEPRUP()));
135  std::for_each(runInfo->getHeaders().begin(),
136  runInfo->getHeaders().end(),
137  boost::bind(
139  product.get(), _1));
140  std::for_each(runInfo->getComments().begin(),
141  runInfo->getComments().end(),
142  boost::bind(&LHERunInfoProduct::addComment,
143  product.get(), _1));
144 
145  // keep a copy around in case of merging
146  runInfoProducts.push_back(new LHERunInfoProduct(*product));
147  wasMerged = false;
148 
149  std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
151 
152  runInfo.reset();
153  }
154 }
155 
157 {
158  if (!runInfoProducts.empty()) {
159  std::unique_ptr<LHERunInfoProduct> product(
160  runInfoProducts.pop_front().release());
161  std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
163  }
164  runPrincipal_ = nullptr;
165 }
166 
168 {
169  nextEvent();
170  if (!partonLevel) {
171  // We just finished an input file. See if there is another.
172  nextEvent();
173  if (!partonLevel) {
174  // No more input files.
175  return false;
176  }
177  }
178  return true;
179 }
180 
181 void
187 
188  std::unique_ptr<LHEEventProduct> product(
189  new LHEEventProduct(*partonLevel->getHEPEUP(),
190  partonLevel->originalXWGTUP())
191  );
192  if (partonLevel->getPDF()) {
193  product->setPDF(*partonLevel->getPDF());
194  }
195  std::for_each(partonLevel->weights().begin(),
196  partonLevel->weights().end(),
197  boost::bind(&LHEEventProduct::addWeight,
198  product.get(), _1));
199  product->setScales(partonLevel->scales());
200  product->setNpLO(partonLevel->npLO());
201  product->setNpNLO(partonLevel->npNLO());
202  std::for_each(partonLevel->getComments().begin(),
203  partonLevel->getComments().end(),
204  boost::bind(&LHEEventProduct::addComment,
205  product.get(), _1));
206 
207  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
209 
210  partonLevel.reset();
211 
213 }
214 
boost::shared_ptr< lhef::LHERunInfo > runInfo
Definition: LHESource.h:52
virtual ~LHESource()
Definition: LHESource.cc:52
void addHeader(const Header &header)
void addComment(const std::string &line)
virtual void endJob() override
Definition: LHESource.cc:56
edm::ProcessHistoryID phid_
Definition: LHESource.h:58
edm::LHEProvenanceHelper lheProvenanceHelper_
Definition: LHESource.h:57
virtual void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LHESource.cc:123
assert(m_qm.get())
virtual void endRun(edm::Run &run) override
Definition: LHESource.cc:156
void addWeight(const WGT &wgt)
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:356
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:251
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp)
Definition: RunPrincipal.cc:33
boost::shared_ptr< lhef::LHEEvent > partonLevel
Definition: LHESource.h:53
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
Definition: RunPrincipal.cc:21
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:212
virtual bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LHESource.cc:167
boost::shared_ptr< lhef::LHERunInfo > runInfoLast
Definition: LHESource.h:51
BranchDescription const runProductBranchDescription_
void fillLuminosityBlockPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
#define DEFINE_FWK_INPUT_SOURCE(type)
virtual void beginRun(edm::Run &run) override
Definition: LHESource.cc:128
std::shared_ptr< RunPrincipal > const runPrincipal() const
unsigned long long TimeValue_t
Definition: Timestamp.h:28
void nextEvent()
Definition: LHESource.cc:61
void resetEventCached()
Definition: InputSource.h:380
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:33
virtual void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:182
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
void addComment(const std::string &line)
bool wasMerged
Definition: LHESource.h:56
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance)
TimeValue_t presentTime() const
edm::RunPrincipal * runPrincipal_
Definition: LHESource.h:59
void setProcessHistoryID(ProcessHistoryID const &phid)
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:257
virtual void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LHESource.cc:116
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
EventID const & eventID() const
ProcessHistoryRegistry & processHistoryRegistryForUpdate() const
Definition: InputSource.h:346
std::auto_ptr< lhef::LHEReader > reader
Definition: LHESource.h:49
tuple fileNames
Definition: LaserDQM_cfg.py:34
volatile std::atomic< bool > shutdown_flag false
ProductProvenance eventProductProvenance_
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:260
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
Definition: LHESource.h:55
BranchDescription const eventProductBranchDescription_
void lheAugment(lhef::LHERunInfo const *runInfo)
Definition: Run.h:43
bool eventCached() const
Definition: InputSource.h:377