CMS 3D CMS Logo

LH5Source.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <functional>
3 #include <iostream>
4 #include <string>
5 #include <memory>
6 
15 
20 
24 
28 
29 #include "LH5Source.h"
30 
31 using namespace lhef;
32 
34  : ProducerSourceFromFiles(params, desc, false),
35  // reader_(new LH5Reader(params)),
36  reader_(new LH5Reader(fileNames(0), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
37  lheProvenanceHelper_(
38  edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
39  phid_() {
40  nextEvent();
42  // Initialize metadata, and save the process history ID for use every event.
44 
45  // These calls are not wanted, because the principals are used for putting the products.
46  //produces<LHEEventProduct>();
47  //produces<LHERunInfoProduct, edm::InRun>();
48 }
49 
51 
52 void LH5Source::endJob() { reader_.reset(); }
53 
55  if (partonLevel_) {
56  return;
57  }
58 
59  bool newFileOpened;
60  do {
61  newFileOpened = false;
62  partonLevel_ = reader_->next(&newFileOpened);
63  if (newFileOpened) {
65  }
66  } while (newFileOpened && !partonLevel_);
67 
68  if (!partonLevel_) {
69  return;
70  }
71 
72  auto runInfoThis = partonLevel_->getRunInfo();
73  if (runInfoThis != runInfoLast_) {
74  runInfoLast_ = runInfoThis;
75  std::unique_ptr<LHERunInfoProduct> product(new LHERunInfoProduct(*runInfoThis->getHEPRUP()));
76  fillRunInfoProduct(*runInfoThis, *product);
77 
78  if (runInfoProductLast_) {
79  if (!runInfoProductLast_->mergeProduct(*product)) {
80  //cannot be merged so must start new Run
81  runInfoProductLast_ = std::move(product);
82  lheProvenanceHelper_.lheAugment(runInfoThis.get());
83  // Initialize metadata, and save the process history ID for use every event.
86  }
87  } else {
88  runInfoProductLast_ = std::move(product);
89  }
90  }
91 }
92 
94  for (auto const& h : iInfo.getHeaders()) {
95  oProduct.addHeader(h);
96  }
97  for (auto const& c : iInfo.getComments()) {
98  oProduct.addComment(c);
99  }
100 }
101 
103  runAuxiliary()->setProcessHistoryID(phid_);
105 
106  putRunInfoProduct(runPrincipal);
107 }
108 
110  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
111  lumiPrincipal.fillLuminosityBlockPrincipal(
112  processHistoryRegistry().getMapped(lumiPrincipal.aux().processHistoryID()));
113 }
114 
116  if (runInfoProductLast_) {
117  auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
118  std::unique_ptr<edm::WrapperBase> rdp(new edm::Wrapper<LHERunInfoProduct>(std::move(product)));
120  }
121 }
122 
124  nextEvent();
125  if (!partonLevel_) {
126  // We just finished an input file. See if there is another.
127  nextEvent();
128  if (!partonLevel_) {
129  // No more input files.
130  return false;
131  }
132  }
133  return true;
134 }
135 
139  aux.setProcessHistoryID(phid_);
140  eventPrincipal.fillEventPrincipal(aux, processHistoryRegistry().getMapped(aux.processHistoryID()));
141 
142  std::unique_ptr<LHEEventProduct> product(
143  new LHEEventProduct(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP()));
144  if (partonLevel_->getPDF()) {
145  product->setPDF(*partonLevel_->getPDF());
146  }
147  std::for_each(partonLevel_->weights().begin(),
148  partonLevel_->weights().end(),
149  std::bind(&LHEEventProduct::addWeight, product.get(), std::placeholders::_1));
150  product->setScales(partonLevel_->scales());
151  product->setNpLO(partonLevel_->npLO());
152  product->setNpNLO(partonLevel_->npNLO());
153  std::for_each(partonLevel_->getComments().begin(),
154  partonLevel_->getComments().end(),
155  std::bind(&LHEEventProduct::addComment, product.get(), std::placeholders::_1));
156 
157  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
159  std::move(edp),
161 
162  partonLevel_.reset();
163 
165 }
166 
167 std::shared_ptr<edm::RunAuxiliary> LH5Source::readRunAuxiliary_() {
169  resetNewRun();
170  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
171  aux->setProcessHistoryID(phid_);
172  return aux;
173 }
174 
175 std::shared_ptr<edm::LuminosityBlockAuxiliary> LH5Source::readLuminosityBlockAuxiliary_() {
176  if (processingMode() == Runs)
177  return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
179  resetNewLumi();
180  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(
182  aux->setProcessHistoryID(phid_);
183  return aux;
184 }
185 
188  desc.setComment("A source which reads LHE files.");
190  desc.addUntracked<unsigned int>("skipEvents", 0U)->setComment("Skip the first 'skipEvents' events.");
191  // desc.addUntracked<int>("limitEvents", -1)->setComment("Limit the number of read events.");
192  descriptions.add("source", desc);
193 }
194 
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LH5Source.cc:109
std::unique_ptr< LHERunInfoProduct > runInfoProductLast_
Definition: LH5Source.h:60
edm::ProcessHistoryID phid_
Definition: LH5Source.h:62
void incrementFileIndex()
Definition: FromFiles.h:27
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:232
static Timestamp invalidTimestamp()
Definition: Timestamp.h:75
void addHeader(const Header &header)
void addComment(const std::string &line)
void fillLuminosityBlockPrincipal(ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
const std::vector< std::string > & getComments() const
Definition: LHERunInfo.h:57
void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LH5Source.cc:102
ProcessHistoryID const & processHistoryID() const
void addWeight(const WGT &wgt)
std::shared_ptr< lhef::LHERunInfo > runInfoLast_
Definition: LH5Source.h:57
assert(be >=bs)
static void fillDescription(ParameterSetDescription &desc)
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:341
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
std::shared_ptr< lhef::LHEEvent > partonLevel_
Definition: LH5Source.h:58
BranchDescription const runProductBranchDescription_
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: LH5Source.cc:175
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
void nextEvent()
Definition: LH5Source.cc:54
LH5Source(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LH5Source.cc:33
#define DEFINE_FWK_INPUT_SOURCE(type)
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:197
const std::vector< Header > & getHeaders() const
Definition: LHERunInfo.h:56
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LH5Source.cc:115
edm::LHEProvenanceHelper lheProvenanceHelper_
Definition: LH5Source.h:61
void endJob() override
Definition: LH5Source.cc:52
bool eventCached() const
Definition: InputSource.h:360
unsigned long long TimeValue_t
Definition: Timestamp.h:21
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LH5Source.cc:186
void resetEventCached()
Definition: InputSource.h:363
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:139
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
RunNumber_t run() const
Definition: EventID.h:38
void addComment(const std::string &line)
~LH5Source() override
Definition: LH5Source.cc:50
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LH5Source.cc:167
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:38
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LH5Source.cc:136
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:331
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
HLT enums.
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:235
LuminosityBlockAuxiliary const & aux() const
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:28
ProductProvenance eventProductProvenance_
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
def move(src, dest)
Definition: eostools.py:511
BranchDescription const eventProductBranchDescription_
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LH5Source.cc:93
void lheAugment(lhef::LHERunInfo const *runInfo)
std::unique_ptr< lhef::LH5Reader > reader_
Definition: LH5Source.h:55
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:226
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LH5Source.cc:123