From b0c0009e28b163aa678395192f3e5323c7984fd6 Mon Sep 17 00:00:00 2001 From: Justin Williams Date: Mon, 5 Oct 2020 07:16:10 -0500 Subject: [PATCH] storing LHCInfo in nanoAOD per luminosity block instead of per event --- .../NanoAOD/plugins/LHCInfoProducer.cc | 41 ++++++------------- .../NanoAOD/plugins/NanoAODOutputModule.cc | 16 ++++++++ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/PhysicsTools/NanoAOD/plugins/LHCInfoProducer.cc b/PhysicsTools/NanoAOD/plugins/LHCInfoProducer.cc index 72617ba9e8094..f6c3aa83dd734 100644 --- a/PhysicsTools/NanoAOD/plugins/LHCInfoProducer.cc +++ b/PhysicsTools/NanoAOD/plugins/LHCInfoProducer.cc @@ -41,56 +41,41 @@ #include "DataFormats/NanoAOD/interface/FlatTable.h" #include "DataFormats/Common/interface/ValueMap.h" +#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h" #include "FWCore/Utilities/interface/transform.h" -// LHC Info #include "CondFormats/RunInfo/interface/LHCInfo.h" #include "CondFormats/DataRecord/interface/LHCInfoRcd.h" -#include "CondTools/RunInfo/interface/LHCInfoPopConSourceHandler.h" -class LHCInfoProducer : public edm::global::EDProducer<> { +class LHCInfoProducer : public edm::global::EDProducer { public: - LHCInfoProducer(edm::ParameterSet const& ps) : precision_(ps.getParameter("precision")) { - produces("lhcInfoTab"); + LHCInfoProducer(edm::ParameterSet const&) { + produces(); } ~LHCInfoProducer() override {} // ------------ method called to produce the data ------------ - void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override { - // Get LHCInfo handle + void produce(edm::StreamID id, edm::Event& iEvent, const edm::EventSetup& iSetup) const override {} + + void globalBeginLuminosityBlockProduce(edm::LuminosityBlock& iLumi, edm::EventSetup const& iSetup) const override { edm::ESHandle lhcInfo; iSetup.get().get(lhcInfo); - - std::unique_ptr out = fillTable(iEvent, lhcInfo); - out->setDoc("LHC Info"); - - iEvent.put(std::move(out), "lhcInfoTab"); - } - - std::unique_ptr fillTable(const edm::Event& iEvent, const edm::ESHandle& prod) const { - const LHCInfo* info = prod.product(); - float crossingAngle = info->crossingAngle(); - float betaStar = info->betaStar(); - float energy = info->energy(); - - auto out = std::make_unique(1, "LHCInfo", true); - out->addColumnValue("crossingAngle", crossingAngle, "LHC crossing angle", precision_); - out->addColumnValue("betaStar", betaStar, "LHC beta star", precision_); - out->addColumnValue("energy", energy, "LHC beam energy", precision_); - return out; + const LHCInfo* info = lhcInfo.product(); + auto out = std::make_unique(); + out->addFloat("crossingAngle", "LHC crossing angle", info->crossingAngle()); + out->addFloat("betaStar", "LHC beta star", info->betaStar()); + out->addFloat("energy", "LHC beam energy", info->energy()); + iLumi.put(std::move(out)); } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ - static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) { edm::ParameterSetDescription desc; desc.setUnknown(); descriptions.addDefault(desc); } -protected: - const unsigned int precision_; }; DEFINE_FWK_MODULE(LHCInfoProducer); diff --git a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc index 02198c149c17c..715b0b090143d 100644 --- a/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc +++ b/PhysicsTools/NanoAOD/plugins/NanoAODOutputModule.cc @@ -125,6 +125,7 @@ class NanoAODOutputModule : public edm::one::OutputModule<> { std::vector m_evstrings; std::vector m_runTables; + std::vector m_lumiTables; std::vector> m_nanoMetadata; }; @@ -224,6 +225,10 @@ void NanoAODOutputModule::writeLuminosityBlock(edm::LuminosityBlockForOutput con jr->reportLumiSection(m_jrToken, iLumi.id().run(), iLumi.id().value()); m_commonLumiBranches.fill(iLumi.id()); + + for (auto& t : m_lumiTables) + t.fill(iLumi, *m_lumiTree); + m_lumiTree->Fill(); m_processHistoryRegistry.registerProcessHistory(iLumi.processHistory()); @@ -287,6 +292,7 @@ void NanoAODOutputModule::openFile(edm::FileBlock const&) { m_triggers_areSorted = false; m_evstrings.clear(); m_runTables.clear(); + m_lumiTables.clear(); const auto& keeps = keptProducts(); for (const auto& keep : keeps[edm::InEvent]) { if (keep.first->className() == "nanoaod::FlatTable") @@ -300,6 +306,16 @@ void NanoAODOutputModule::openFile(edm::FileBlock const&) { throw cms::Exception("Configuration", "NanoAODOutputModule cannot handle class " + keep.first->className()); } + for (const auto& keep : keeps[edm::InLumi]) { + if (keep.first->className() == "nanoaod::MergeableCounterTable") + m_lumiTables.push_back(SummaryTableOutputBranches(keep.first, keep.second)); + else if (keep.first->className() == "nanoaod::UniqueString" && keep.first->moduleLabel() == "nanoMetadata") + m_nanoMetadata.emplace_back(keep.first->productInstanceName(), keep.second); + else + throw cms::Exception("Configuration", + "NanoAODOutputModule cannot handle class " + keep.first->className() + " in LuminosityBlock branch"); + } + for (const auto& keep : keeps[edm::InRun]) { if (keep.first->className() == "nanoaod::MergeableCounterTable") m_runTables.push_back(SummaryTableOutputBranches(keep.first, keep.second));