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 
68  bool newFileOpened;
69  do {
70  newFileOpened = false;
71  partonLevel = reader->next(&newFileOpened);
72  } while (newFileOpened && !partonLevel);
73 
74 
75 
76  if (!partonLevel) {
77  return;
78  }
79 
80  boost::shared_ptr<LHERunInfo> runInfoThis = partonLevel->getRunInfo();
81  if (runInfoThis != runInfoLast) {
82  runInfo = runInfoThis;
83  runInfoLast = runInfoThis;
84  }
85  if (runInfo) {
86  std::auto_ptr<LHERunInfoProduct> product(
87  new LHERunInfoProduct(*runInfo->getHEPRUP()));
88  std::for_each(runInfo->getHeaders().begin(),
89  runInfo->getHeaders().end(),
90  boost::bind(
92  product.get(), _1));
93  std::for_each(runInfo->getComments().begin(),
94  runInfo->getComments().end(),
95  boost::bind(&LHERunInfoProduct::addComment,
96  product.get(), _1));
97 
98  if (!runInfoProducts.empty()) {
99  if (runInfoProducts.front().mergeProduct(*product)) {
100  if (!wasMerged) {
101  runInfoProducts.pop_front();
102  runInfoProducts.push_front(product);
103  wasMerged = true;
104  }
105  } else {
107  // Initialize metadata, and save the process history ID for use every event.
110  }
111  }
112 
113  runInfo.reset();
114  }
115 }
116 
117 // This is the only way we can now access the run principal.
118 void
120  runAuxiliary()->setProcessHistoryID(phid_);
123 }
124 
125 void
127  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
129 }
130 
132 {
133  if (runInfoLast) {
135 
136  std::auto_ptr<LHERunInfoProduct> product(
137  new LHERunInfoProduct(*runInfo->getHEPRUP()));
138  std::for_each(runInfo->getHeaders().begin(),
139  runInfo->getHeaders().end(),
140  boost::bind(
142  product.get(), _1));
143  std::for_each(runInfo->getComments().begin(),
144  runInfo->getComments().end(),
145  boost::bind(&LHERunInfoProduct::addComment,
146  product.get(), _1));
147 
148  // keep a copy around in case of merging
149  runInfoProducts.push_back(new LHERunInfoProduct(*product));
150  wasMerged = false;
151 
154 
155  runInfo.reset();
156  }
157 }
158 
160 {
161  if (!runInfoProducts.empty()) {
162  std::auto_ptr<LHERunInfoProduct> product(
163  runInfoProducts.pop_front().release());
166  }
167  runPrincipal_ = nullptr;
168 }
169 
171 {
172  nextEvent();
173  if (!partonLevel) {
174  // We just finished an input file. See if there is another.
175  nextEvent();
176  if (!partonLevel) {
177  // No more input files.
178  return false;
179  }
180  }
181  return true;
182 }
183 
184 void
190 
191  std::auto_ptr<LHEEventProduct> product(
192  new LHEEventProduct(*partonLevel->getHEPEUP(),
193  partonLevel->originalXWGTUP())
194  );
195  if (partonLevel->getPDF()) {
196  product->setPDF(*partonLevel->getPDF());
197  }
198  std::for_each(partonLevel->weights().begin(),
199  partonLevel->weights().end(),
200  boost::bind(&LHEEventProduct::addWeight,
201  product.get(), _1));
202  product->setScales(partonLevel->scales());
203  product->setNpLO(partonLevel->npLO());
204  product->setNpNLO(partonLevel->npNLO());
205  std::for_each(partonLevel->getComments().begin(),
206  partonLevel->getComments().end(),
207  boost::bind(&LHEEventProduct::addComment,
208  product.get(), _1));
209 
212 
213  partonLevel.reset();
214 
216 }
217 
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:126
virtual void endRun(edm::Run &run) override
Definition: LHESource.cc:159
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:131
unsigned long long TimeValue_t
Definition: Timestamp.h:28
virtual bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &) override
Definition: LHESource.cc:170
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:185
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:119
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