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 
17 
19 
23 
27 
28 #include "LHESource.h"
29 
30 using namespace lhef;
31 
33  const edm::InputSourceDescription &desc) :
34  ExternalInputSource(params, desc, false),
35  reader(new LHEReader(fileNames(), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
36  wasMerged(false)
37 {
38  produces<LHEEventProduct>();
39  produces<LHERunInfoProduct, edm::InRun>();
40 }
41 
43 {
44 }
45 
47 {
48  reader.reset();
49 }
50 
52 {
53  if (partonLevel)
54  return;
55 
56  bool newFileOpened = false;
57  partonLevel = reader->next(&newFileOpened);
58 
59  if(newFileOpened) incrementFileIndex();
60  if (!partonLevel)
61  return;
62 
63  boost::shared_ptr<LHERunInfo> runInfoThis = partonLevel->getRunInfo();
64  if (runInfoThis != runInfoLast) {
65  runInfo = runInfoThis;
66  runInfoLast = runInfoThis;
67  }
68 }
69 
71 {
72  nextEvent();
73  if (runInfoLast) {
75 
76  std::auto_ptr<LHERunInfoProduct> product(
77  new LHERunInfoProduct(*runInfo->getHEPRUP()));
78  std::for_each(runInfo->getHeaders().begin(),
79  runInfo->getHeaders().end(),
80  boost::bind(
82  product.get(), _1));
83  std::for_each(runInfo->getComments().begin(),
84  runInfo->getComments().end(),
85  boost::bind(&LHERunInfoProduct::addComment,
86  product.get(), _1));
87 
88  // keep a copy around in case of merging
89  runInfoProducts.push_back(new LHERunInfoProduct(*product));
90  wasMerged = false;
91 
92  run.put(product);
93 
94  runInfo.reset();
95  }
96 }
97 
99 {
100  if (!runInfoProducts.empty()) {
101  std::auto_ptr<LHERunInfoProduct> product(
102  runInfoProducts.pop_front().release());
103  run.put(product);
104  }
105 }
106 
108 {
109  if (!partonLevel)
110  return false;
111 
112  std::auto_ptr<LHEEventProduct> product(
113  new LHEEventProduct(*partonLevel->getHEPEUP(),
114  partonLevel->originalXWGTUP())
115  );
116  if (partonLevel->getPDF()) {
117  product->setPDF(*partonLevel->getPDF());
118  }
119  std::for_each(partonLevel->weights().begin(),
120  partonLevel->weights().end(),
121  boost::bind(&LHEEventProduct::addWeight,
122  product.get(), _1));
123  product->setScales(partonLevel->scales());
124  product->setNpLO(partonLevel->npLO());
125  product->setNpNLO(partonLevel->npNLO());
126  std::for_each(partonLevel->getComments().begin(),
127  partonLevel->getComments().end(),
128  boost::bind(&LHEEventProduct::addComment,
129  product.get(), _1));
130  event.put(product);
131 
132  if (runInfo) {
133  std::auto_ptr<LHERunInfoProduct> product(
134  new LHERunInfoProduct(*runInfo->getHEPRUP()));
135  std::for_each(runInfo->getHeaders().begin(),
136  runInfo->getHeaders().end(),
137  boost::bind(
139  product.get(), _1));
140  std::for_each(runInfo->getComments().begin(),
141  runInfo->getComments().end(),
142  boost::bind(&LHERunInfoProduct::addComment,
143  product.get(), _1));
144 
145  if (!runInfoProducts.empty()) {
146  runInfoProducts.front().mergeProduct(*product);
147  if (!wasMerged) {
148  runInfoProducts.pop_front();
149  runInfoProducts.push_front(product);
150  wasMerged = true;
151  }
152  }
153 
154  runInfo.reset();
155  }
156 
157  partonLevel.reset();
158  return true;
159 }
160 
boost::shared_ptr< lhef::LHERunInfo > runInfo
Definition: LHESource.h:41
virtual ~LHESource()
Definition: LHESource.cc:42
void addHeader(const Header &header)
void addComment(const std::string &line)
void addWeight(const WGT &wgt)
virtual void endRun(edm::Run &run)
Definition: LHESource.cc:98
boost::shared_ptr< lhef::LHEEvent > partonLevel
Definition: LHESource.h:42
boost::shared_ptr< lhef::LHERunInfo > runInfoLast
Definition: LHESource.h:40
#define DEFINE_FWK_INPUT_SOURCE(type)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void nextEvent()
Definition: LHESource.cc:51
virtual void endJob()
Definition: LHESource.cc:46
LHESource(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LHESource.cc:32
virtual bool produce(edm::Event &event)
Definition: LHESource.cc:107
void addComment(const std::string &line)
bool wasMerged
Definition: LHESource.h:45
std::auto_ptr< lhef::LHEReader > reader
Definition: LHESource.h:38
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:81
tuple fileNames
Definition: LaserDQM_cfg.py:34
virtual void beginRun(edm::Run &run)
Definition: LHESource.cc:70
boost::ptr_deque< LHERunInfoProduct > runInfoProducts
Definition: LHESource.h:44
Definition: Run.h:33