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 
edm::InputSource::resetNewRun
void resetNewRun()
Definition: InputSource.h:356
LH5Source::lheProvenanceHelper_
edm::LHEProvenanceHelper lheProvenanceHelper_
Definition: LH5Source.h:61
edm::FromFiles::incrementFileIndex
void incrementFileIndex()
Definition: FromFiles.h:27
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
LHEEventProduct
Definition: LHEEventProduct.h:12
LH5Source::readRun_
void readRun_(edm::RunPrincipal &runPrincipal) override
Definition: LH5Source.cc:102
edm::InputSource::resetEventCached
void resetEventCached()
Definition: InputSource.h:363
edm::IDGeneratorSourceBase< PuttableSourceBase >::run
RunNumber_t run() const
Definition: IDGeneratorSourceBase.h:37
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
LH5Source::phid_
edm::ProcessHistoryID phid_
Definition: LH5Source.h:62
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
LH5Source::partonLevel_
std::shared_ptr< lhef::LHEEvent > partonLevel_
Definition: LH5Source.h:58
edm::LHEProvenanceHelper::lheInit
ProcessHistoryID lheInit(ProcessHistoryRegistry &processHistoryRegistry)
Definition: LHEProvenanceHelper.cc:117
edm::LuminosityBlockPrincipal
Definition: LuminosityBlockPrincipal.h:31
edm::InputSourceDescription
Definition: InputSourceDescription.h:21
cms::cuda::assert
assert(be >=bs)
TypeID.h
LH5Source::fillRunInfoProduct
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LH5Source.cc:93
edm::IDGeneratorSourceBase< PuttableSourceBase >::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: IDGeneratorSourceBase.h:39
lhe2HepMCConverter_cff.LHERunInfoProduct
LHERunInfoProduct
Definition: lhe2HepMCConverter_cff.py:5
LHERunInfoProduct::addHeader
void addHeader(const Header &header)
Definition: LHERunInfoProduct.h:52
LH5Source::readLuminosityBlockAuxiliary_
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
Definition: LH5Source.cc:175
edm::InputSource::processHistoryRegistryForUpdate
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:331
edm::Wrapper
Definition: Product.h:10
lhef::LHERunInfo::getComments
const std::vector< std::string > & getComments() const
Definition: LHERunInfo.h:57
edm::LuminosityBlockPrincipal::aux
LuminosityBlockAuxiliary const & aux() const
Definition: LuminosityBlockPrincipal.h:64
edm::RunPrincipal::put
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp) const
Definition: RunPrincipal.cc:38
lhe2HepMCConverter_cff.LHEEventProduct
LHEEventProduct
Definition: lhe2HepMCConverter_cff.py:4
LH5Source::nextEvent
void nextEvent()
Definition: LH5Source.cc:54
LHERunInfoProduct.h
MakerMacros.h
LHERunInfoProduct
Definition: LHERunInfoProduct.h:13
h
edm::EventPrincipal
Definition: EventPrincipal.h:48
lhef::LHERunInfo::getHeaders
const std::vector< Header > & getHeaders() const
Definition: LHERunInfo.h:56
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
EventPrincipal.h
LHERunInfoProduct::addComment
void addComment(const std::string &line)
Definition: LHERunInfoProduct.h:53
DEFINE_FWK_INPUT_SOURCE
#define DEFINE_FWK_INPUT_SOURCE(type)
Definition: InputSourceMacros.h:8
OrphanHandle.h
LH5Source::putRunInfoProduct
void putRunInfoProduct(edm::RunPrincipal &)
Definition: LH5Source.cc:115
edm::InputSource::luminosityBlockAuxiliary
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:233
edm::EventPrincipal::put
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
Definition: EventPrincipal.cc:185
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::EventAuxiliary
Definition: EventAuxiliary.h:14
LH5Reader.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::InputSource::processingMode
ProcessingMode processingMode() const
RunsLumisAndEvents (default), RunsAndLumis, or Runs.
Definition: InputSource.h:224
LH5Source::~LH5Source
~LH5Source() override
Definition: LH5Source.cc:50
edm::InputSource::runAuxiliary
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:230
LaserDQM_cfg.fileNames
fileNames
Definition: LaserDQM_cfg.py:34
LuminosityBlockAuxiliary.h
edm::IDGeneratorSourceBase< PuttableSourceBase >::eventID
EventID const & eventID() const
Definition: IDGeneratorSourceBase.h:36
edm::LuminosityBlockAuxiliary::processHistoryID
ProcessHistoryID const & processHistoryID() const
Definition: LuminosityBlockAuxiliary.h:32
edm::InputSource::processHistoryRegistry
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:140
LH5Source::readLuminosityBlock_
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LH5Source.cc:109
LH5Source::runInfoLast_
std::shared_ptr< lhef::LHERunInfo > runInfoLast_
Definition: LH5Source.h:57
LH5Source::runInfoProductLast_
std::unique_ptr< LHERunInfoProduct > runInfoProductLast_
Definition: LH5Source.h:60
lhef::LHERunInfo
Definition: LHERunInfo.h:25
edm::ParameterSet
Definition: ParameterSet.h:47
Timestamp.h
edm::ProducerSourceFromFiles::fillDescription
static void fillDescription(ParameterSetDescription &desc)
Definition: ProducerSourceFromFiles.cc:13
LHERunInfo.h
edm::LuminosityBlockPrincipal::fillLuminosityBlockPrincipal
void fillLuminosityBlockPrincipal(ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
Definition: LuminosityBlockPrincipal.cc:16
lhef
Definition: ExhumeHadronizer.h:12
RunPrincipal.h
edm::LHEProvenanceHelper::lheAugment
void lheAugment(lhef::LHERunInfo const *runInfo)
Definition: LHEProvenanceHelper.cc:94
printConversionInfo.aux
aux
Definition: printConversionInfo.py:19
createfilelist.int
int
Definition: createfilelist.py:10
edm::LHEProvenanceHelper::eventProductProvenance_
ProductProvenance eventProductProvenance_
Definition: LHEProvenanceHelper.h:26
LH5Source::readRunAuxiliary_
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
Definition: LH5Source.cc:167
edm::InputSource::resetNewLumi
void resetNewLumi()
Definition: InputSource.h:359
LH5Source::endJob
void endJob() override
Definition: LH5Source.cc:52
LH5Source::reader_
std::unique_ptr< lhef::LH5Reader > reader_
Definition: LH5Source.h:55
LuminosityBlockPrincipal.h
LesHouches.h
lhef::LH5Reader
Definition: LH5Reader.h:40
InputSourceMacros.h
edm::InputSource::Runs
Definition: InputSource.h:56
edm::EventPrincipal::fillEventPrincipal
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
Definition: EventPrincipal.cc:110
edm::RunPrincipal::fillRunPrincipal
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:28
LHEEventProduct.h
LH5Source.h
edm::Timestamp::invalidTimestamp
static Timestamp invalidTimestamp()
Definition: Timestamp.h:82
edm::InputSource::eventCached
bool eventCached() const
Definition: InputSource.h:360
LH5Source::LH5Source
LH5Source(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LH5Source.cc:33
edm::IDGeneratorSourceBase< PuttableSourceBase >::presentTime
TimeValue_t presentTime() const
Definition: IDGeneratorSourceBase.h:31
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::EventAuxiliary::ExperimentType
ExperimentType
Definition: EventAuxiliary.h:18
RunAuxiliary.h
LHEEvent.h
edm::InputSource::resetRunAuxiliary
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:341
LH5Source::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LH5Source.cc:186
ParameterSet.h
edm::LHEProvenanceHelper::eventProductBranchDescription_
const BranchDescription eventProductBranchDescription_
Definition: LHEProvenanceHelper.h:24
LH5Source::readEvent_
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LH5Source.cc:136
edm::RunPrincipal
Definition: RunPrincipal.h:34
edm::InputSource::processGUID
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:195
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
edm::EventID
Definition: EventID.h:31
LH5Source::setRunAndEventInfo
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LH5Source.cc:123
LH5Source
Definition: LH5Source.h:33
edm::InputSource::RunsLumisAndEvents
Definition: InputSource.h:56
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
edm::LHEProvenanceHelper::runProductBranchDescription_
const BranchDescription runProductBranchDescription_
Definition: LHEProvenanceHelper.h:25
LHEEventProduct::addComment
void addComment(const std::string &line)
Definition: LHEEventProduct.h:32
edm::Timestamp
Definition: Timestamp.h:30
LHEEventProduct::addWeight
void addWeight(const WGT &wgt)
Definition: LHEEventProduct.h:31