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 void
85  runAuxiliary()->setProcessHistoryID(phid_);
88 }
89 
90 void
92  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
94 }
95 
97 {
98  if (runInfoLast) {
100 
101  std::auto_ptr<LHERunInfoProduct> product(
102  new LHERunInfoProduct(*runInfo->getHEPRUP()));
103  std::for_each(runInfo->getHeaders().begin(),
104  runInfo->getHeaders().end(),
105  boost::bind(
107  product.get(), _1));
108  std::for_each(runInfo->getComments().begin(),
109  runInfo->getComments().end(),
110  boost::bind(&LHERunInfoProduct::addComment,
111  product.get(), _1));
112 
113  // keep a copy around in case of merging
114  runInfoProducts.push_back(new LHERunInfoProduct(*product));
115  wasMerged = false;
116 
119 
120  runInfo.reset();
121  }
122 }
123 
125 {
126  if (!runInfoProducts.empty()) {
127  std::auto_ptr<LHERunInfoProduct> product(
128  runInfoProducts.pop_front().release());
131  }
132  runPrincipal_ = nullptr;
133 }
134 
136 {
137  nextEvent();
138  if (!partonLevel) {
139  return false;
140  }
141  return true;
142 }
143 
144 void
150 
151  std::auto_ptr<LHEEventProduct> product(
152  new LHEEventProduct(*partonLevel->getHEPEUP(),
153  partonLevel->originalXWGTUP())
154  );
155  if (partonLevel->getPDF()) {
156  product->setPDF(*partonLevel->getPDF());
157  }
158  std::for_each(partonLevel->weights().begin(),
159  partonLevel->weights().end(),
160  boost::bind(&LHEEventProduct::addWeight,
161  product.get(), _1));
162  std::for_each(partonLevel->getComments().begin(),
163  partonLevel->getComments().end(),
164  boost::bind(&LHEEventProduct::addComment,
165  product.get(), _1));
166 
169 
170  if (runInfo) {
171  std::auto_ptr<LHERunInfoProduct> product(
172  new LHERunInfoProduct(*runInfo->getHEPRUP()));
173  std::for_each(runInfo->getHeaders().begin(),
174  runInfo->getHeaders().end(),
175  boost::bind(
177  product.get(), _1));
178  std::for_each(runInfo->getComments().begin(),
179  runInfo->getComments().end(),
180  boost::bind(&LHERunInfoProduct::addComment,
181  product.get(), _1));
182 
183  if (!runInfoProducts.empty()) {
184  runInfoProducts.front().mergeProduct(*product);
185  if (!wasMerged) {
186  runInfoProducts.pop_front();
187  runInfoProducts.push_front(product);
188  wasMerged = true;
189  }
190  }
191 
192  runInfo.reset();
193  }
194 
195  partonLevel.reset();
196 
198 }
199 
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 readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LHESource.cc:91
virtual void endRun(edm::Run &run) override
Definition: LHESource.cc:124
void addWeight(const WGT &wgt)
void put(BranchDescription const &bd, WrapperOwningHolder const &edp)
Definition: RunPrincipal.cc:34
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:249
boost::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:258
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:210
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:96
unsigned long long TimeValue_t
Definition: Timestamp.h:28
virtual bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &) override
Definition: LHESource.cc:135
void nextEvent()
Definition: LHESource.cc:61
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
void resetEventCached()
Definition: InputSource.h:378
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:33
virtual void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LHESource.cc:145
void addComment(const std::string &line)
bool wasMerged
Definition: LHESource.h:56
ProductRegistry & productRegistryUpdate() const
Definition: InputSource.h:343
TimeValue_t presentTime() const
edm::RunPrincipal * runPrincipal_
Definition: LHESource.h:59
void setProcessHistoryID(ProcessHistoryID const &phid)
ProcessHistoryID lheInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry)
virtual void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LHESource.cc:84
boost::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:255
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Non-const accessor for process history registry.
Definition: InputSource.h:173
boost::shared_ptr< RunPrincipal > const runPrincipal() const
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:375