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))),
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(newFileOpened) incrementFileIndex();
71  if (!partonLevel) {
72  return;
73  }
74 
75  boost::shared_ptr<LHERunInfo> runInfoThis = partonLevel->getRunInfo();
76  if (runInfoThis != runInfoLast) {
77  runInfo = runInfoThis;
78  runInfoLast = runInfoThis;
79  }
80 }
81 
82 // This is the only way we can now access the run principal.
83 boost::shared_ptr<edm::RunPrincipal>
84 LHESource::readRun_(boost::shared_ptr<edm::RunPrincipal> runPrincipal) {
85  runAuxiliary()->setProcessHistoryID(phid_);
86  runPrincipal->fillRunPrincipal();
88  return runPrincipal;
89 }
90 
91 boost::shared_ptr<edm::LuminosityBlockPrincipal>
92 LHESource::readLuminosityBlock_(boost::shared_ptr<edm::LuminosityBlockPrincipal> lumiPrincipal) {
93  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
94  lumiPrincipal->fillLuminosityBlockPrincipal();
95  return lumiPrincipal;
96 }
97 
99 {
100  if (runInfoLast) {
102 
103  std::auto_ptr<LHERunInfoProduct> product(
104  new LHERunInfoProduct(*runInfo->getHEPRUP()));
105  std::for_each(runInfo->getHeaders().begin(),
106  runInfo->getHeaders().end(),
107  boost::bind(
109  product.get(), _1));
110  std::for_each(runInfo->getComments().begin(),
111  runInfo->getComments().end(),
112  boost::bind(&LHERunInfoProduct::addComment,
113  product.get(), _1));
114 
115  // keep a copy around in case of merging
116  runInfoProducts.push_back(new LHERunInfoProduct(*product));
117  wasMerged = false;
118 
121 
122  runInfo.reset();
123  }
124 }
125 
127 {
128  if (!runInfoProducts.empty()) {
129  std::auto_ptr<LHERunInfoProduct> product(
130  runInfoProducts.pop_front().release());
133  }
134  runPrincipal_.reset();
135 }
136 
138 {
139  nextEvent();
140  if (!partonLevel) {
141  return false;
142  }
143  return true;
144 }
145 
149  EventSourceSentry sentry(*this);
152  eventPrincipal.fillEventPrincipal(aux);
153 
154  std::auto_ptr<LHEEventProduct> product(
155  new LHEEventProduct(*partonLevel->getHEPEUP(),
156  partonLevel->originalXWGTUP())
157  );
158  if (partonLevel->getPDF()) {
159  product->setPDF(*partonLevel->getPDF());
160  }
161  std::for_each(partonLevel->weights().begin(),
162  partonLevel->weights().end(),
163  boost::bind(&LHEEventProduct::addWeight,
164  product.get(), _1));
165  std::for_each(partonLevel->getComments().begin(),
166  partonLevel->getComments().end(),
167  boost::bind(&LHEEventProduct::addComment,
168  product.get(), _1));
169 
172 
173  if (runInfo) {
174  std::auto_ptr<LHERunInfoProduct> product(
175  new LHERunInfoProduct(*runInfo->getHEPRUP()));
176  std::for_each(runInfo->getHeaders().begin(),
177  runInfo->getHeaders().end(),
178  boost::bind(
180  product.get(), _1));
181  std::for_each(runInfo->getComments().begin(),
182  runInfo->getComments().end(),
183  boost::bind(&LHERunInfoProduct::addComment,
184  product.get(), _1));
185 
186  if (!runInfoProducts.empty()) {
187  runInfoProducts.front().mergeProduct(*product);
188  if (!wasMerged) {
189  runInfoProducts.pop_front();
190  runInfoProducts.push_front(product);
191  wasMerged = true;
192  }
193  }
194 
195  runInfo.reset();
196  }
197 
198  partonLevel.reset();
199 
201  return &eventPrincipal;
202 }
203 
void fillEventPrincipal(EventAuxiliary const &aux, boost::shared_ptr< EventSelectionIDVector > eventSelectionIDs=boost::shared_ptr< EventSelectionIDVector >(), boost::shared_ptr< BranchListIndexes > branchListIndexes=boost::shared_ptr< BranchListIndexes >(), boost::shared_ptr< BranchMapper > mapper=boost::shared_ptr< BranchMapper >(new BranchMapper), DelayedReader *reader=0)
boost::shared_ptr< lhef::LHERunInfo > runInfo
Definition: LHESource.h:52
void incrementFileIndex()
Definition: FromFiles.h:27
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 endRun(edm::Run &run) override
Definition: LHESource.cc:126
void addWeight(const WGT &wgt)
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:238
boost::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:247
boost::shared_ptr< lhef::LHEEvent > partonLevel
Definition: LHESource.h:53
void put(ConstBranchDescription const &bd, WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)
boost::shared_ptr< edm::RunPrincipal > runPrincipal_
Definition: LHESource.h:59
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:199
boost::shared_ptr< lhef::LHERunInfo > runInfoLast
Definition: LHESource.h:51
virtual boost::shared_ptr< edm::LuminosityBlockPrincipal > readLuminosityBlock_(boost::shared_ptr< edm::LuminosityBlockPrincipal > lumiPrincipal) override
Definition: LHESource.cc:92
#define DEFINE_FWK_INPUT_SOURCE(type)
virtual void beginRun(edm::Run &run) override
Definition: LHESource.cc:98
unsigned long long TimeValue_t
Definition: Timestamp.h:27
virtual bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &) override
Definition: LHESource.cc:137
void nextEvent()
Definition: LHESource.cc:61
void resetEventCached()
Definition: InputSource.h:350
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:33
void addComment(const std::string &line)
bool wasMerged
Definition: LHESource.h:56
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:316
TimeValue_t presentTime() const
virtual boost::shared_ptr< edm::RunPrincipal > readRun_(boost::shared_ptr< edm::RunPrincipal > runPrincipal) override
Definition: LHESource.cc:84
void setProcessHistoryID(ProcessHistoryID const &phid)
ConstBranchDescription eventProductBranchDescription_
boost::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:244
boost::shared_ptr< RunPrincipal > const runPrincipal() const
EventID const & eventID() const
virtual edm::EventPrincipal * readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:147
ProcessHistoryID lheInit(ProductRegistry &productRegistry)
std::auto_ptr< lhef::LHEReader > reader
Definition: LHESource.h:49
tuple fileNames
Definition: LaserDQM_cfg.py:34
ProductProvenance eventProductProvenance_
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
Definition: LHESource.h:55
void lheAugment(lhef::LHERunInfo const *runInfo)
Definition: Run.h:36
ConstBranchDescription runProductBranchDescription_
bool eventCached() const
Definition: InputSource.h:347