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_(edm::TypeID(typeid(LHEEventProduct)),
38  edm::TypeID(typeid(LHERunInfoProduct)),
39  productRegistryUpdate(),
40  *branchIDListHelper()),
41  phid_() {
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 void LH5Source::endJob() { reader_.reset(); }
55 
57  if (partonLevel_) {
58  return;
59  }
60 
61  bool newFileOpened;
62  do {
63  newFileOpened = false;
64  partonLevel_ = reader_->next(&newFileOpened);
65  if (newFileOpened) {
67  }
68  } while (newFileOpened && !partonLevel_);
69 
70  if (!partonLevel_) {
71  return;
72  }
73 
74  auto runInfoThis = partonLevel_->getRunInfo();
75  if (runInfoThis != runInfoLast_) {
76  runInfoLast_ = runInfoThis;
77  std::unique_ptr<LHERunInfoProduct> product = std::make_unique<LHERunInfoProduct>(*runInfoThis->getHEPRUP());
78  fillRunInfoProduct(*runInfoThis, *product);
79 
80  if (runInfoProductLast_) {
81  if (!runInfoProductLast_->mergeProduct(*product)) {
82  //cannot be merged so must start new Run
83  runInfoProductLast_ = std::move(product);
84  lheProvenanceHelper_.lheAugment(runInfoThis.get());
85  // Initialize metadata, and save the process history ID for use every event.
88  }
89  } else {
90  runInfoProductLast_ = std::move(product);
91  }
92  }
93 }
94 
96  for (auto const& h : iInfo.getHeaders()) {
97  oProduct.addHeader(h);
98  }
99  for (auto const& c : iInfo.getComments()) {
100  oProduct.addComment(c);
101  }
102 }
103 
105  runAuxiliary()->setProcessHistoryID(phid_);
107 
108  putRunInfoProduct(runPrincipal);
109 }
110 
112  luminosityBlockAuxiliary()->setProcessHistoryID(phid_);
113  lumiPrincipal.fillLuminosityBlockPrincipal(
114  processHistoryRegistry().getMapped(lumiPrincipal.aux().processHistoryID()));
115 }
116 
118  if (runInfoProductLast_) {
119  auto product = std::make_unique<LHERunInfoProduct>(*runInfoProductLast_);
120  std::unique_ptr<edm::WrapperBase> rdp = std::make_unique<edm::Wrapper<LHERunInfoProduct>>(std::move(product));
122  }
123 }
124 
126  nextEvent();
127  if (!partonLevel_) {
128  // We just finished an input file. See if there is another.
129  nextEvent();
130  if (!partonLevel_) {
131  // No more input files.
132  return false;
133  }
134  }
135  return true;
136 }
137 
141  aux.setProcessHistoryID(phid_);
142  eventPrincipal.fillEventPrincipal(aux,
143  processHistoryRegistry().getMapped(aux.processHistoryID()),
146 
147  std::unique_ptr<LHEEventProduct> product =
148  std::make_unique<LHEEventProduct>(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP());
149  if (partonLevel_->getPDF()) {
150  product->setPDF(*partonLevel_->getPDF());
151  }
152  std::for_each(partonLevel_->weights().begin(),
153  partonLevel_->weights().end(),
154  std::bind(&LHEEventProduct::addWeight, product.get(), std::placeholders::_1));
155  product->setScales(partonLevel_->scales());
156  product->setNpLO(partonLevel_->npLO());
157  product->setNpNLO(partonLevel_->npNLO());
158  std::for_each(partonLevel_->getComments().begin(),
159  partonLevel_->getComments().end(),
160  std::bind(&LHEEventProduct::addComment, product.get(), std::placeholders::_1));
161 
162  std::unique_ptr<edm::WrapperBase> edp = std::make_unique<edm::Wrapper<LHEEventProduct>>(std::move(product));
164  std::move(edp),
166 
167  partonLevel_.reset();
168 
170 }
171 
172 std::shared_ptr<edm::RunAuxiliary> LH5Source::readRunAuxiliary_() {
174  resetNewRun();
175  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
176  aux->setProcessHistoryID(phid_);
177  return aux;
178 }
179 
180 std::shared_ptr<edm::LuminosityBlockAuxiliary> LH5Source::readLuminosityBlockAuxiliary_() {
181  if (processingMode() == Runs)
182  return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
184  resetNewLumi();
185  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(
187  aux->setProcessHistoryID(phid_);
188  return aux;
189 }
190 
193  desc.setComment("A source which reads LHE files.");
195  desc.addUntracked<unsigned int>("skipEvents", 0U)->setComment("Skip the first 'skipEvents' events.");
196  // desc.addUntracked<int>("limitEvents", -1)->setComment("Limit the number of read events.");
197  descriptions.add("source", desc);
198 }
199 
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LH5Source.cc:111
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:261
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:104
ProcessHistoryID const & processHistoryID() const
BranchListIndexes branchListIndexes_
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:370
std::vector< EventSelectionID > EventSelectionIDVector
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:180
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
void nextEvent()
Definition: LH5Source.cc:56
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:226
const std::vector< Header > & getHeaders() const
Definition: LHERunInfo.h:56
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LH5Source.cc:117
edm::LHEProvenanceHelper lheProvenanceHelper_
Definition: LH5Source.h:61
void endJob() override
Definition: LH5Source.cc:54
bool eventCached() const
Definition: InputSource.h:389
unsigned long long TimeValue_t
Definition: Timestamp.h:21
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LH5Source.cc:191
void resetEventCached()
Definition: InputSource.h:392
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:168
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
RunNumber_t run() const
Definition: EventID.h:38
void addComment(const std::string &line)
~LH5Source() override
Definition: LH5Source.cc:52
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LH5Source.cc:172
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:35
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LH5Source.cc:138
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:360
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:264
LuminosityBlockAuxiliary const & aux() const
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:25
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:95
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:255
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LH5Source.cc:125