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  if(newFileOpened) incrementFileIndex();
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 }
80 
81 // This is the only way we can now access the run principal.
82 boost::shared_ptr<edm::RunPrincipal>
83 LHESource::readRun_(boost::shared_ptr<edm::RunPrincipal> runPrincipal) {
84  runAuxiliary()->setProcessHistoryID(phid_);
85  runPrincipal->fillRunPrincipal();
87  return runPrincipal;
88 }
89 
90 boost::shared_ptr<edm::LuminosityBlockPrincipal>
91 LHESource::readLuminosityBlock_(boost::shared_ptr<edm::LuminosityBlockPrincipal> lumiPrincipal) {
92  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
93  lumiPrincipal->fillLuminosityBlockPrincipal();
94  return lumiPrincipal;
95 }
96 
98 {
99  if (runInfoLast) {
101 
102  std::auto_ptr<LHERunInfoProduct> product(
103  new LHERunInfoProduct(*runInfo->getHEPRUP()));
104  std::for_each(runInfo->getHeaders().begin(),
105  runInfo->getHeaders().end(),
106  boost::bind(
108  product.get(), _1));
109  std::for_each(runInfo->getComments().begin(),
110  runInfo->getComments().end(),
111  boost::bind(&LHERunInfoProduct::addComment,
112  product.get(), _1));
113 
114  // keep a copy around in case of merging
115  runInfoProducts.push_back(new LHERunInfoProduct(*product));
116  wasMerged = false;
117 
120 
121  runInfo.reset();
122  }
123 }
124 
126 {
127  if (!runInfoProducts.empty()) {
128  std::auto_ptr<LHERunInfoProduct> product(
129  runInfoProducts.pop_front().release());
132  }
133  runPrincipal_.reset();
134 }
135 
137 {
138  nextEvent();
139  if (!partonLevel) {
140  return false;
141  }
142  return true;
143 }
144 
148  EventSourceSentry sentry(*this);
151  eventPrincipal.fillEventPrincipal(aux);
152 
153  std::auto_ptr<LHEEventProduct> product(
154  new LHEEventProduct(*partonLevel->getHEPEUP()));
155  if (partonLevel->getPDF()) {
156  product->setPDF(*partonLevel->getPDF());
157  }
158  std::for_each(partonLevel->getComments().begin(),
159  partonLevel->getComments().end(),
160  boost::bind(&LHEEventProduct::addComment,
161  product.get(), _1));
162 
165 
166  if (runInfo) {
167  std::auto_ptr<LHERunInfoProduct> product(
168  new LHERunInfoProduct(*runInfo->getHEPRUP()));
169  std::for_each(runInfo->getHeaders().begin(),
170  runInfo->getHeaders().end(),
171  boost::bind(
173  product.get(), _1));
174  std::for_each(runInfo->getComments().begin(),
175  runInfo->getComments().end(),
176  boost::bind(&LHERunInfoProduct::addComment,
177  product.get(), _1));
178 
179  if (!runInfoProducts.empty()) {
180  runInfoProducts.front().mergeProduct(*product);
181  if (!wasMerged) {
182  runInfoProducts.pop_front();
183  runInfoProducts.push_front(product);
184  wasMerged = true;
185  }
186  }
187 
188  runInfo.reset();
189  }
190 
191  partonLevel.reset();
192 
194  return &eventPrincipal;
195 }
196 
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:125
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:91
#define DEFINE_FWK_INPUT_SOURCE(type)
virtual void beginRun(edm::Run &run) override
Definition: LHESource.cc:97
unsigned long long TimeValue_t
Definition: Timestamp.h:27
virtual bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &) override
Definition: LHESource.cc:136
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:83
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:146
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