Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14_0_X] Using explicit lazy parsing & concrete data types in SimpleFlatTableProducer #44807

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions CalibTracker/SiStripCommon/plugins/SealModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ DEFINE_FWK_MODULE(ShallowSimhitClustersProducer);
DEFINE_FWK_MODULE(ShallowTracksProducer);
DEFINE_FWK_MODULE(ShallowSimTracksProducer);
DEFINE_FWK_MODULE(ShallowGainCalibration);

#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h"
typedef SimpleFlatTableProducer<reco::Track> SimpleTrackFlatTableProducer;
DEFINE_FWK_MODULE(SimpleTrackFlatTableProducer);
1 change: 1 addition & 0 deletions DPGAnalysis/MuonTools/interface/MuDigiBaseProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class MuDigiBaseProducer : public SimpleFlatTableProducerBase<DIGI_T, MuonDigiCo

variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
variable.add<std::string>("doc")->setComment("few words description of the branch content");
variable.addUntracked<bool>("lazyEval")->setComment("set to True if the type read from the Event is unknown");

variable.ifValue(edm::ParameterDescription<std::string>("type", "int", true, comType),
edm::allowedValues<std::string>("int", "uint", "int16", "uint8"));
Expand Down
1 change: 1 addition & 0 deletions DPGAnalysis/MuonTools/interface/MuLocalRecoBaseProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class MuRecObjBaseProducer

varBase.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
varBase.add<std::string>("doc")->setComment("few words description of the branch content");
varBase.addUntracked<bool>("lazyEval")->setComment("if True, check object type during Event processing.");

return varBase;
};
Expand Down
10 changes: 6 additions & 4 deletions DPGAnalysis/MuonTools/python/common_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DEFAULT_VAL(NamedTuple):

defaults = DEFAULT_VAL()

def DetIdVar(expr, type, doc=None):
def DetIdVar(expr, type, doc=None, lazyEval=False):
""" Create a PSet for a DetId variable in the tree:
- expr is the expression to evaluate to compute the variable,
- type of the value (int, bool, or a string that the table producer understands),
Expand All @@ -22,10 +22,11 @@ def DetIdVar(expr, type, doc=None):
return cms.PSet(
type = cms.string(type),
expr = cms.string(expr),
doc = cms.string(doc if doc else expr)
doc = cms.string(doc if doc else expr),
lazyEval = cms.untracked.bool(lazyEval)
)

def GlobGeomVar(expr, doc=None, precision=-1):
def GlobGeomVar(expr, doc=None, precision=-1, lazyEval=False):
""" Create a PSet for a Global position/direction variable in the tree ,
- expr is the expression to evaluate to compute the variable,
- doc is a docstring, that will be passed to the table producer,
Expand All @@ -34,7 +35,8 @@ def GlobGeomVar(expr, doc=None, precision=-1):
return cms.PSet(
expr = cms.string(expr),
doc = cms.string(doc if doc else expr),
precision=cms.string(precision) if type(precision)==str else cms.int32(precision)
precision = cms.string(precision) if type(precision)==str else cms.int32(precision),
lazyEval = cms.untracked.bool(lazyEval)
)


Expand Down
4 changes: 2 additions & 2 deletions DPGAnalysis/MuonTools/python/nano_mu_reco_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from PhysicsTools.NanoAOD.common_cff import *
from DPGAnalysis.MuonTools.common_cff import *

from PhysicsTools.NanoAOD.simpleCandidateFlatTableProducer_cfi import simpleCandidateFlatTableProducer
from PhysicsTools.NanoAOD.simplePATMuonFlatTableProducer_cfi import simplePATMuonFlatTableProducer

from PhysicsTools.PatAlgos.producersLayer1.muonProducer_cfi import *

muonFlatTableProducer = simpleCandidateFlatTableProducer.clone(
muonFlatTableProducer = simplePATMuonFlatTableProducer.clone(
src = cms.InputTag("patMuons"),
name = cms.string("muon"),
doc = cms.string("RECO muon information"),
Expand Down
2 changes: 2 additions & 0 deletions DataFormats/Candidate/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@
<class name="edm::reftobase::RefHolder<reco::VertexCompositePtrCandidateRef>" />
<class name="edm::reftobase::VectorHolder<reco::Candidate, reco::VertexCompositePtrCandidateRefVector>" />
<class name="edm::reftobase::RefVectorHolder<reco::VertexCompositePtrCandidateRefVector>" />
<class name="edm::PtrVector<reco::VertexCompositePtrCandidate>" />
<class name="edm::Wrapper<edm::PtrVector<reco::VertexCompositePtrCandidate> >" />


<class name="reco::NamedCompositeCandidateCollection" />
Expand Down
29 changes: 20 additions & 9 deletions PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class FuncVariable : public Variable<ObjType> {
public:
FuncVariable(const std::string &aname, const edm::ParameterSet &cfg)
: Variable<ObjType>(aname, cfg),
func_(cfg.getParameter<std::string>("expr"), true),
func_(cfg.getParameter<std::string>("expr"), cfg.getUntrackedParameter<bool>("lazyEval")),
precisionFunc_(cfg.existsAs<std::string>("precision") ? cfg.getParameter<std::string>("precision") : "23",
true) {}
cfg.getUntrackedParameter<bool>("lazyEval")) {}
~FuncVariable() override {}

void fill(std::vector<const ObjType *> &selobjs, nanoaod::FlatTable &out) const override {
Expand Down Expand Up @@ -212,6 +212,8 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> {
edm::ParameterSetDescription variable;
variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
variable.add<std::string>("doc")->setComment("few words description of the branch content");
variable.addUntracked<bool>("lazyEval", false)
->setComment("if true, can use methods of inheriting classes in `expr`. Can cause problems with threading.");
variable.ifValue(
edm::ParameterDescription<std::string>(
"type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
Expand Down Expand Up @@ -271,7 +273,8 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<
singleton_(params.getParameter<bool>("singleton")),
maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
: std::numeric_limits<unsigned int>::max()),
cut_(!singleton_ ? params.getParameter<std::string>("cut") : "", true) {
cut_(!singleton_ ? params.getParameter<std::string>("cut") : "",
!singleton_ ? params.getUntrackedParameter<bool>("lazyEval") : false) {
if (params.existsAs<edm::ParameterSet>("externalVariables")) {
edm::ParameterSet const &extvarsPSet = params.getParameter<edm::ParameterSet>("externalVariables");
for (const std::string &vname : extvarsPSet.getParameterNamesForType<edm::ParameterSet>()) {
Expand Down Expand Up @@ -312,11 +315,17 @@ class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<
static edm::ParameterSetDescription baseDescriptions() {
edm::ParameterSetDescription desc = SimpleFlatTableProducerBase<T, edm::View<T>>::baseDescriptions();

desc.ifValue(edm::ParameterDescription<bool>(
"singleton", false, true, edm::Comment("whether or not the input collection is single-element")),
false >> edm::ParameterDescription<std::string>(
"cut", "", true, edm::Comment("selection on the main input collection")) or
true >> edm::EmptyGroupDescription());
desc.ifValue(
edm::ParameterDescription<bool>(
"singleton", false, true, edm::Comment("whether or not the input collection is single-element")),
false >> (edm::ParameterDescription<std::string>(
"cut", "", true, edm::Comment("selection on the main input collection")) and
edm::ParameterDescription<bool>("lazyEval",
false,
false,
edm::Comment("if true, can use methods of inheriting classes. Can "
"cause problems when multi-threading."))) or
true >> edm::EmptyGroupDescription());
desc.addOptional<unsigned int>("maxLen")->setComment(
"define the maximum length of the input collection to put in the branch");

Expand Down Expand Up @@ -442,6 +451,8 @@ class SimpleTypedExternalFlatTableProducer : public SimpleFlatTableProducer<T> {
extvariable.add<std::string>("expr")->setComment(
"a function to define the content of the branch in the flat table");
extvariable.add<std::string>("doc")->setComment("few words description of the branch content");
extvariable.addUntracked<bool>("lazyEval", false)
->setComment("if true, can use methods of inheriting classes in `expr`. Can cause problems with threading.");
extvariable.ifValue(
edm::ParameterDescription<std::string>(
"type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
Expand Down Expand Up @@ -482,7 +493,7 @@ class BXVectorSimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, BX
: SimpleFlatTableProducerBase<T, BXVector<T>>(params),
maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
: std::numeric_limits<unsigned int>::max()),
cut_(params.getParameter<std::string>("cut"), true),
cut_(params.getParameter<std::string>("cut"), false),
minBX_(params.getParameter<int>("minBX")),
maxBX_(params.getParameter<int>("maxBX")),
alwaysWriteBXValue_(params.getParameter<bool>("alwaysWriteBXValue")),
Expand Down
69 changes: 20 additions & 49 deletions PhysicsTools/NanoAOD/plugins/SimpleFlatTableProducerPlugins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
#include "DataFormats/Candidate/interface/Candidate.h"
typedef SimpleFlatTableProducer<reco::Candidate> SimpleCandidateFlatTableProducer;

#include "DataFormats/TrackReco/interface/Track.h"
typedef SimpleFlatTableProducer<reco::Track> SimpleTrackFlatTableProducer;

#include "DataFormats/JetReco/interface/PFJet.h"
typedef SimpleFlatTableProducer<reco::PFJet> SimplePFJetFlatTableProducer;

#include "DataFormats/VertexReco/interface/Vertex.h"
typedef SimpleFlatTableProducer<reco::Vertex> SimpleVertexFlatTableProducer;

#include "DataFormats/Candidate/interface/VertexCompositePtrCandidate.h"
typedef SimpleFlatTableProducer<reco::VertexCompositePtrCandidate> SimpleSecondaryVertexFlatTableProducer;

#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
typedef SimpleFlatTableProducer<reco::GenParticle> SimpleGenParticleFlatTableProducer;

typedef SimpleTypedExternalFlatTableProducer<reco::Candidate, reco::Candidate>
SimpleCandidate2CandidateFlatTableProducer;

Expand Down Expand Up @@ -30,45 +45,13 @@ typedef EventSingletonSimpleFlatTableProducer<OnlineLuminosityRecord> SimpleOnli
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
typedef EventSingletonSimpleFlatTableProducer<reco::BeamSpot> SimpleBeamspotFlatTableProducer;

#include "DataFormats/L1Trigger/interface/EGamma.h"
typedef BXVectorSimpleFlatTableProducer<l1t::EGamma> SimpleTriggerL1EGFlatTableProducer;

#include "DataFormats/L1Trigger/interface/Jet.h"
typedef BXVectorSimpleFlatTableProducer<l1t::Jet> SimpleTriggerL1JetFlatTableProducer;

#include "DataFormats/L1Trigger/interface/Tau.h"
typedef BXVectorSimpleFlatTableProducer<l1t::Tau> SimpleTriggerL1TauFlatTableProducer;

#include "DataFormats/L1Trigger/interface/Muon.h"
typedef BXVectorSimpleFlatTableProducer<l1t::Muon> SimpleTriggerL1MuonFlatTableProducer;

#include "DataFormats/L1Trigger/interface/EtSum.h"
typedef BXVectorSimpleFlatTableProducer<l1t::EtSum> SimpleTriggerL1EtSumFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingVertex.h"
typedef SimpleFlatTableProducer<Run3ScoutingVertex> SimpleRun3ScoutingVertexFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingPhoton.h"
typedef SimpleFlatTableProducer<Run3ScoutingPhoton> SimpleRun3ScoutingPhotonFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingMuon.h"
typedef SimpleFlatTableProducer<Run3ScoutingMuon> SimpleRun3ScoutingMuonFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingElectron.h"
typedef SimpleFlatTableProducer<Run3ScoutingElectron> SimpleRun3ScoutingElectronFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingTrack.h"
typedef SimpleFlatTableProducer<Run3ScoutingTrack> SimpleRun3ScoutingTrackFlatTableProducer;

#include "DataFormats/VertexReco/interface/Vertex.h"
typedef SimpleFlatTableProducer<reco::Vertex> SimpleVertexFlatTableProducer;

#include "DataFormats/VertexReco/interface/TrackTimeLifeInfo.h"
typedef SimpleTypedExternalFlatTableProducer<reco::Candidate, TrackTimeLifeInfo>
SimpleCandidate2TrackTimeLifeInfoFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimpleCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimplePFJetFlatTableProducer);
DEFINE_FWK_MODULE(SimpleVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleSecondaryVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenParticleFlatTableProducer);
DEFINE_FWK_MODULE(SimpleCandidate2CandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenEventFlatTableProducer);
DEFINE_FWK_MODULE(SimpleGenFilterFlatTableProducerLumi);
Expand All @@ -78,15 +61,3 @@ DEFINE_FWK_MODULE(SimpleLocalTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimpleXYZPointFlatTableProducer);
DEFINE_FWK_MODULE(SimpleOnlineLuminosityFlatTableProducer);
DEFINE_FWK_MODULE(SimpleBeamspotFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1EGFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1JetFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1MuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1TauFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1EtSumFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingPhotonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingMuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimpleVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleCandidate2TrackTimeLifeInfoFlatTableProducer);
24 changes: 24 additions & 0 deletions PhysicsTools/NanoAOD/plugins/SimpleL1TFlatTableProducerPlugins.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h"

#include "DataFormats/L1Trigger/interface/EGamma.h"
typedef BXVectorSimpleFlatTableProducer<l1t::EGamma> SimpleTriggerL1EGFlatTableProducer;

#include "DataFormats/L1Trigger/interface/Jet.h"
typedef BXVectorSimpleFlatTableProducer<l1t::Jet> SimpleTriggerL1JetFlatTableProducer;

#include "DataFormats/L1Trigger/interface/Tau.h"
typedef BXVectorSimpleFlatTableProducer<l1t::Tau> SimpleTriggerL1TauFlatTableProducer;

#include "DataFormats/L1Trigger/interface/Muon.h"
typedef BXVectorSimpleFlatTableProducer<l1t::Muon> SimpleTriggerL1MuonFlatTableProducer;

#include "DataFormats/L1Trigger/interface/EtSum.h"
typedef BXVectorSimpleFlatTableProducer<l1t::EtSum> SimpleTriggerL1EtSumFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"

DEFINE_FWK_MODULE(SimpleTriggerL1EGFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1JetFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1MuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1TauFlatTableProducer);
DEFINE_FWK_MODULE(SimpleTriggerL1EtSumFlatTableProducer);
50 changes: 50 additions & 0 deletions PhysicsTools/NanoAOD/plugins/SimplePATFlatTableProducerPlugins.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h"

#include "DataFormats/PatCandidates/interface/Electron.h"
typedef SimpleFlatTableProducer<pat::Electron> SimplePATElectronFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Muon.h"
typedef SimpleFlatTableProducer<pat::Muon> SimplePATMuonFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Tau.h"
typedef SimpleFlatTableProducer<pat::Tau> SimplePATTauFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Photon.h"
typedef SimpleFlatTableProducer<pat::Photon> SimplePATPhotonFlatTableProducer;

#include "DataFormats/PatCandidates/interface/Jet.h"
typedef SimpleFlatTableProducer<pat::Jet> SimplePATJetFlatTableProducer;

#include "DataFormats/PatCandidates/interface/IsolatedTrack.h"
typedef SimpleFlatTableProducer<pat::IsolatedTrack> SimplePATIsolatedTrackFlatTableProducer;

#include "DataFormats/PatCandidates/interface/GenericParticle.h"
typedef SimpleFlatTableProducer<pat::GenericParticle> SimplePATGenericParticleFlatTableProducer;

#include "DataFormats/PatCandidates/interface/PackedCandidate.h"
typedef SimpleFlatTableProducer<pat::PackedCandidate> SimplePATCandidateFlatTableProducer;

#include "DataFormats/PatCandidates/interface/MET.h"
typedef SimpleFlatTableProducer<pat::MET> SimplePATMETFlatTableProducer;

#include "DataFormats/VertexReco/interface/TrackTimeLifeInfo.h"
typedef SimpleTypedExternalFlatTableProducer<pat::Electron, TrackTimeLifeInfo>
SimplePATElectron2TrackTimeLifeInfoFlatTableProducer;
typedef SimpleTypedExternalFlatTableProducer<pat::Muon, TrackTimeLifeInfo>
SimplePATMuon2TrackTimeLifeInfoFlatTableProducer;
typedef SimpleTypedExternalFlatTableProducer<pat::Tau, TrackTimeLifeInfo>
SimplePATTau2TrackTimeLifeInfoFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimplePATElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATMuonFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATTauFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATPhotonFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATJetFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATIsolatedTrackFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATGenericParticleFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATCandidateFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATMETFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATElectron2TrackTimeLifeInfoFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATMuon2TrackTimeLifeInfoFlatTableProducer);
DEFINE_FWK_MODULE(SimplePATTau2TrackTimeLifeInfoFlatTableProducer);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h"

#include "DataFormats/Scouting/interface/Run3ScoutingVertex.h"
typedef SimpleFlatTableProducer<Run3ScoutingVertex> SimpleRun3ScoutingVertexFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingPhoton.h"
typedef SimpleFlatTableProducer<Run3ScoutingPhoton> SimpleRun3ScoutingPhotonFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingMuon.h"
typedef SimpleFlatTableProducer<Run3ScoutingMuon> SimpleRun3ScoutingMuonFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingElectron.h"
typedef SimpleFlatTableProducer<Run3ScoutingElectron> SimpleRun3ScoutingElectronFlatTableProducer;

#include "DataFormats/Scouting/interface/Run3ScoutingTrack.h"
typedef SimpleFlatTableProducer<Run3ScoutingTrack> SimpleRun3ScoutingTrackFlatTableProducer;

#include "FWCore/Framework/interface/MakerMacros.h"
DEFINE_FWK_MODULE(SimpleRun3ScoutingVertexFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingPhotonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingMuonFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingElectronFlatTableProducer);
DEFINE_FWK_MODULE(SimpleRun3ScoutingTrackFlatTableProducer);
Loading