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 
7 #include <boost/bind.hpp>
8 
17 
22 
26 
30 
31 #include "LH5Source.h"
32 
33 using namespace lhef;
34 
36  : ProducerSourceFromFiles(params, desc, false),
37  // reader_(new LH5Reader(params)),
38  reader_(new LH5Reader(fileNames(0), params.getUntrackedParameter<unsigned int>("skipEvents", 0))),
39  lheProvenanceHelper_(
40  edm::TypeID(typeid(LHEEventProduct)), edm::TypeID(typeid(LHERunInfoProduct)), productRegistryUpdate()),
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(new 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(new 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, processHistoryRegistry().getMapped(aux.processHistoryID()));
143 
144  std::unique_ptr<LHEEventProduct> product(
145  new LHEEventProduct(*partonLevel_->getHEPEUP(), partonLevel_->originalXWGTUP()));
146  if (partonLevel_->getPDF()) {
147  product->setPDF(*partonLevel_->getPDF());
148  }
149  std::for_each(partonLevel_->weights().begin(),
150  partonLevel_->weights().end(),
151  boost::bind(&LHEEventProduct::addWeight, product.get(), _1));
152  product->setScales(partonLevel_->scales());
153  product->setNpLO(partonLevel_->npLO());
154  product->setNpNLO(partonLevel_->npNLO());
155  std::for_each(partonLevel_->getComments().begin(),
156  partonLevel_->getComments().end(),
157  boost::bind(&LHEEventProduct::addComment, product.get(), _1));
158 
159  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<LHEEventProduct>(std::move(product)));
161  std::move(edp),
163 
164  partonLevel_.reset();
165 
167 }
168 
169 std::shared_ptr<edm::RunAuxiliary> LH5Source::readRunAuxiliary_() {
171  resetNewRun();
172  auto aux = std::make_shared<edm::RunAuxiliary>(eventID().run(), ts, edm::Timestamp::invalidTimestamp());
173  aux->setProcessHistoryID(phid_);
174  return aux;
175 }
176 
177 std::shared_ptr<edm::LuminosityBlockAuxiliary> LH5Source::readLuminosityBlockAuxiliary_() {
178  if (processingMode() == Runs)
179  return std::shared_ptr<edm::LuminosityBlockAuxiliary>();
181  resetNewLumi();
182  auto aux = std::make_shared<edm::LuminosityBlockAuxiliary>(
184  aux->setProcessHistoryID(phid_);
185  return aux;
186 }
187 
190  desc.setComment("A source which reads LHE files.");
192  desc.addUntracked<unsigned int>("skipEvents", 0U)->setComment("Skip the first 'skipEvents' events.");
193  // desc.addUntracked<int>("limitEvents", -1)->setComment("Limit the number of read events.");
194  descriptions.add("source", desc);
195 }
196 
edm::InputSource::resetNewRun
void resetNewRun()
Definition: InputSource.h:355
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:104
edm::InputSource::resetEventCached
void resetEventCached()
Definition: InputSource.h:362
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:20
cms::cuda::assert
assert(be >=bs)
TypeID.h
LH5Source::fillRunInfoProduct
void fillRunInfoProduct(lhef::LHERunInfo const &, LHERunInfoProduct &)
Definition: LH5Source.cc:95
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:177
edm::InputSource::processHistoryRegistryForUpdate
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:330
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:56
LHERunInfoProduct.h
MakerMacros.h
LHERunInfoProduct
Definition: LHERunInfoProduct.h:13
h
edm::EventPrincipal
Definition: EventPrincipal.h:46
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:117
edm::InputSource::luminosityBlockAuxiliary
std::shared_ptr< LuminosityBlockAuxiliary > luminosityBlockAuxiliary() const
Called by the framework to merge or insert lumi in principal cache.
Definition: InputSource.h:245
edm::EventPrincipal::put
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
Definition: EventPrincipal.cc:180
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:236
LH5Source::~LH5Source
~LH5Source() override
Definition: LH5Source.cc:52
edm::InputSource::runAuxiliary
std::shared_ptr< RunAuxiliary > runAuxiliary() const
Called by the framework to merge or insert run in principal cache.
Definition: InputSource.h:242
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:158
LH5Source::readLuminosityBlock_
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lumiPrincipal) override
Definition: LH5Source.cc:111
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:169
edm::InputSource::resetNewLumi
void resetNewLumi()
Definition: InputSource.h:358
LH5Source::endJob
void endJob() override
Definition: LH5Source.cc:54
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:80
edm::EventPrincipal::fillEventPrincipal
void fillEventPrincipal(EventAuxiliary const &aux, ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
Definition: EventPrincipal.cc:105
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:359
LH5Source::LH5Source
LH5Source(const edm::ParameterSet &params, const edm::InputSourceDescription &desc)
Definition: LH5Source.cc:35
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
LaserTracksInput_cfi.fileNames
fileNames
Definition: LaserTracksInput_cfi.py:8
edm::InputSource::resetRunAuxiliary
void resetRunAuxiliary(bool isNewRun=true) const
Definition: InputSource.h:340
LH5Source::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: LH5Source.cc:188
ParameterSet.h
edm::LHEProvenanceHelper::eventProductBranchDescription_
const BranchDescription eventProductBranchDescription_
Definition: LHEProvenanceHelper.h:24
LH5Source::readEvent_
void readEvent_(edm::EventPrincipal &eventPrincipal) override
Definition: LH5Source.cc:138
edm::RunPrincipal
Definition: RunPrincipal.h:34
edm::InputSource::processGUID
std::string const & processGUID() const
Accessor for global process identifier.
Definition: InputSource.h:207
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::EventID
Definition: EventID.h:31
LH5Source::setRunAndEventInfo
bool setRunAndEventInfo(edm::EventID &, edm::TimeValue_t &, edm::EventAuxiliary::ExperimentType &) override
Definition: LH5Source.cc:125
LH5Source
Definition: LH5Source.h:33
edm::InputSource::RunsLumisAndEvents
Definition: InputSource.h:80
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