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 = false;
68  partonLevel = reader->next(&newFileOpened);
69 
70  if (!partonLevel) {
71  return;
72  }
73 
74  boost::shared_ptr<LHERunInfo> runInfoThis = partonLevel->getRunInfo();
75  if (runInfoThis != runInfoLast) {
76  runInfo = runInfoThis;
77  runInfoLast = runInfoThis;
78  }
79  if (runInfo) {
80  std::auto_ptr<LHERunInfoProduct> product(
81  new LHERunInfoProduct(*runInfo->getHEPRUP()));
82  std::for_each(runInfo->getHeaders().begin(),
83  runInfo->getHeaders().end(),
84  boost::bind(
86  product.get(), _1));
87  std::for_each(runInfo->getComments().begin(),
88  runInfo->getComments().end(),
89  boost::bind(&LHERunInfoProduct::addComment,
90  product.get(), _1));
91 
92  if (!runInfoProducts.empty()) {
93  if (runInfoProducts.front().mergeProduct(*product)) {
94  if (!wasMerged) {
95  runInfoProducts.pop_front();
96  runInfoProducts.push_front(product);
97  wasMerged = true;
98  }
99  } else {
101  // Initialize metadata, and save the process history ID for use every event.
104  }
105  }
106 
107  runInfo.reset();
108  }
109 }
110 
111 // This is the only way we can now access the run principal.
112 void
114  runAuxiliary()->setProcessHistoryID(phid_);
117 }
118 
119 void
121  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
123 }
124 
126 {
127  if (runInfoLast) {
129 
130  std::auto_ptr<LHERunInfoProduct> product(
131  new LHERunInfoProduct(*runInfo->getHEPRUP()));
132  std::for_each(runInfo->getHeaders().begin(),
133  runInfo->getHeaders().end(),
134  boost::bind(
136  product.get(), _1));
137  std::for_each(runInfo->getComments().begin(),
138  runInfo->getComments().end(),
139  boost::bind(&LHERunInfoProduct::addComment,
140  product.get(), _1));
141 
142  // keep a copy around in case of merging
143  runInfoProducts.push_back(new LHERunInfoProduct(*product));
144  wasMerged = false;
145 
148 
149  runInfo.reset();
150  }
151 }
152 
154 {
155  if (!runInfoProducts.empty()) {
156  std::auto_ptr<LHERunInfoProduct> product(
157  runInfoProducts.pop_front().release());
160  }
161  runPrincipal_ = nullptr;
162 }
163 
165 {
166  nextEvent();
167  if (!partonLevel) {
168  // We just finished an input file. See if there is another.
169  nextEvent();
170  if (!partonLevel) {
171  // No more input files.
172  return false;
173  }
174  }
175  return true;
176 }
177 
178 void
184 
185  std::auto_ptr<LHEEventProduct> product(
186  new LHEEventProduct(*partonLevel->getHEPEUP(),
187  partonLevel->originalXWGTUP())
188  );
189  if (partonLevel->getPDF()) {
190  product->setPDF(*partonLevel->getPDF());
191  }
192  std::for_each(partonLevel->weights().begin(),
193  partonLevel->weights().end(),
194  boost::bind(&LHEEventProduct::addWeight,
195  product.get(), _1));
196  product->setScales(partonLevel->scales());
197  product->setNpLO(partonLevel->npLO());
198  product->setNpNLO(partonLevel->npNLO());
199  std::for_each(partonLevel->getComments().begin(),
200  partonLevel->getComments().end(),
201  boost::bind(&LHEEventProduct::addComment,
202  product.get(), _1));
203 
206 
207  partonLevel.reset();
208 
210 }
211 
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:120
virtual void endRun(edm::Run &run) override
Definition: LHESource.cc:153
void addWeight(const WGT &wgt)
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:358
void put(BranchDescription const &bd, WrapperOwningHolder const &edp)
Definition: RunPrincipal.cc:34
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:253
boost::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:262
boost::shared_ptr< lhef::LHEEvent > partonLevel
Definition: LHESource.h:53
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
Definition: RunPrincipal.cc:22
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:214
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:125
unsigned long long TimeValue_t
Definition: Timestamp.h:28
virtual bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &) override
Definition: LHESource.cc:164
void nextEvent()
Definition: LHESource.cc:61
void resetEventCached()
Definition: InputSource.h:382
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:33
virtual void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:179
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
void addComment(const std::string &line)
bool wasMerged
Definition: LHESource.h:56
TimeValue_t presentTime() const
edm::RunPrincipal * runPrincipal_
Definition: LHESource.h:59
void setProcessHistoryID(ProcessHistoryID const &phid)
virtual void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LHESource.cc:113
boost::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:259
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Non-const accessor for process history registry.
Definition: InputSource.h:174
boost::shared_ptr< RunPrincipal > const runPrincipal() const
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=0)
EventID const & eventID() const
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_
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
Definition: LHESource.h:55
BranchDescription const eventProductBranchDescription_
void lheAugment(lhef::LHERunInfo const *runInfo)
Definition: Run.h:41
void put(BranchDescription const &bd, WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
bool eventCached() const
Definition: InputSource.h:379