CMS 3D CMS Logo

GlobalVariablesTableProducer.cc
Go to the documentation of this file.
6 
7 #include <utility>
8 #include <vector>
9 #include <boost/ptr_container/ptr_vector.hpp>
10 
12 public:
14  edm::ParameterSet const& varsPSet = params.getParameter<edm::ParameterSet>("variables");
15  for (const std::string& vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
16  const auto& varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
17  const std::string& type = varPSet.getParameter<std::string>("type");
18  if (type == "int")
19  vars_.push_back(new IntVar(vname, nanoaod::FlatTable::IntColumn, varPSet, consumesCollector()));
20  else if (type == "float")
21  vars_.push_back(new FloatVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector()));
22  else if (type == "double")
23  vars_.push_back(new DoubleVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector()));
24  else if (type == "bool")
25  vars_.push_back(new BoolVar(vname, nanoaod::FlatTable::BoolColumn, varPSet, consumesCollector()));
26  else if (type == "candidatescalarsum")
27  vars_.push_back(
28  new CandidateScalarSumVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector()));
29  else if (type == "candidatesize")
30  vars_.push_back(new CandidateSizeVar(vname, nanoaod::FlatTable::IntColumn, varPSet, consumesCollector()));
31  else if (type == "candidatesummass")
32  vars_.push_back(new CandidateSumMassVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector()));
33  else
34  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
35  }
36 
37  produces<nanoaod::FlatTable>();
38  }
39 
41 
42  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
43  auto out = std::make_unique<nanoaod::FlatTable>(1, "", true);
44 
45  for (const auto& var : vars_)
46  var.fill(iEvent, *out);
47 
48  iEvent.put(std::move(out));
49  }
50 
51 protected:
52  class Variable {
53  public:
55  : name_(aname), doc_(cfg.getParameter<std::string>("doc")), type_(atype) {}
56  virtual void fill(const edm::Event& iEvent, nanoaod::FlatTable& out) const = 0;
57  virtual ~Variable() {}
58  const std::string& name() const { return name_; }
59  const nanoaod::FlatTable::ColumnType& type() const { return type_; }
60 
61  protected:
64  };
65  template <typename ValType>
66  class Identity {
67  public:
68  static ValType convert(ValType x) { return x; }
69  };
70  template <typename ValType>
71  class Size {
72  public:
73  static int convert(ValType x) { return x.size(); }
74  };
75 
76  template <typename ColType, typename ValType>
77  class Max {
78  public:
79  static ColType convert(ValType x) {
81  for (const auto& i : x)
82  if (i > v)
83  v = i;
84  return v;
85  }
86  };
87  template <typename ColType, typename ValType>
88  class Min {
89  public:
90  static ColType convert(ValType x) {
92  for (const auto& i : x)
93  if (i < v)
94  v = i;
95  return v;
96  }
97  };
98  template <typename ColType, typename ValType>
99  class ScalarPtSum {
100  public:
101  static ColType convert(ValType x) {
102  ColType v = 0;
103  for (const auto& i : x)
104  v += i.pt();
105  return v;
106  }
107  };
108  template <typename ColType, typename ValType>
109  class MassSum {
110  public:
111  static ColType convert(ValType x) {
112  if (x.empty())
113  return 0;
114  auto v = x[0].p4();
115  for (const auto& i : x)
116  v += i.p4();
117  return v.mass();
118  }
119  };
120  template <typename ColType, typename ValType>
121  class PtVectorSum {
122  public:
123  static ColType convert(ValType x) {
124  if (x.empty())
125  return 0;
126  auto v = x[0].p4();
127  v -= x[0].p4();
128  for (const auto& i : x)
129  v += i.p4();
130  return v.pt();
131  }
132  };
133 
134  template <typename ValType, typename ColType = ValType, typename Converter = Identity<ValType>>
135  class VariableT : public Variable {
136  public:
137  VariableT(const std::string& aname,
139  const edm::ParameterSet& cfg,
141  : Variable(aname, atype, cfg), src_(cc.consumes<ValType>(cfg.getParameter<edm::InputTag>("src"))) {}
142  ~VariableT() override {}
143  void fill(const edm::Event& iEvent, nanoaod::FlatTable& out) const override {
145  iEvent.getByToken(src_, handle);
146  out.template addColumnValue<ColType>(this->name_, Converter::convert(*handle), this->doc_, this->type_);
147  }
148 
149  protected:
151  };
160  boost::ptr_vector<Variable> vars_;
161 };
162 
nanoaod::FlatTable::FloatColumn
Definition: FlatTable.h:39
GlobalVariablesTableProducer::~GlobalVariablesTableProducer
~GlobalVariablesTableProducer() override
Definition: GlobalVariablesTableProducer.cc:40
mps_fire.i
i
Definition: mps_fire.py:355
GlobalVariablesTableProducer::VariableT
Definition: GlobalVariablesTableProducer.cc:135
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
GlobalVariablesTableProducer::Min::convert
static ColType convert(ValType x)
Definition: GlobalVariablesTableProducer.cc:90
GlobalVariablesTableProducer::Variable
Definition: GlobalVariablesTableProducer.cc:52
patZpeak.handle
handle
Definition: patZpeak.py:23
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
min
T min(T a, T b)
Definition: MathUtil.h:58
edm::EDGetTokenT< ValType >
edm
HLT enums.
Definition: AlignableModifier.h:19
GlobalVariablesTableProducer::VariableT::VariableT
VariableT(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc)
Definition: GlobalVariablesTableProducer.cc:137
GlobalVariablesTableProducer::IntVar
VariableT< int > IntVar
Definition: GlobalVariablesTableProducer.cc:152
EDProducer.h
DDAxes::x
GlobalVariablesTableProducer::ScalarPtSum
Definition: GlobalVariablesTableProducer.cc:99
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::Handle
Definition: AssociativeIterator.h:50
nanoaod::FlatTable::ColumnType
ColumnType
Definition: FlatTable.h:38
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
MakerMacros.h
GlobalVariablesTableProducer::DoubleVar
VariableT< double, float > DoubleVar
Definition: GlobalVariablesTableProducer.cc:154
GlobalVariablesTableProducer::Size
Definition: GlobalVariablesTableProducer.cc:71
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalVariablesTableProducer::Variable::Variable
Variable(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg)
Definition: GlobalVariablesTableProducer.cc:54
GlobalVariablesTableProducer::Variable::doc_
std::string doc_
Definition: GlobalVariablesTableProducer.cc:62
GlobalVariablesTableProducer::MassSum
Definition: GlobalVariablesTableProducer.cc:109
GlobalVariablesTableProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: GlobalVariablesTableProducer.cc:42
GlobalVariablesTableProducer::MassSum::convert
static ColType convert(ValType x)
Definition: GlobalVariablesTableProducer.cc:111
GlobalVariablesTableProducer::Min
Definition: GlobalVariablesTableProducer.cc:88
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GlobalVariablesTableProducer::Identity
Definition: GlobalVariablesTableProducer.cc:66
fileCollector.convert
def convert(infile, ofile)
Definition: fileCollector.py:47
GlobalVariablesTableProducer::Variable::name_
std::string name_
Definition: GlobalVariablesTableProducer.cc:62
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
GlobalVariablesTableProducer::GlobalVariablesTableProducer
GlobalVariablesTableProducer(edm::ParameterSet const &params)
Definition: GlobalVariablesTableProducer.cc:13
GlobalVariablesTableProducer::PtVectorSum
Definition: GlobalVariablesTableProducer.cc:121
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
GlobalVariablesTableProducer::Size::convert
static int convert(ValType x)
Definition: GlobalVariablesTableProducer.cc:73
GlobalVariablesTableProducer::BoolVar
VariableT< bool, uint8_t > BoolVar
Definition: GlobalVariablesTableProducer.cc:155
GlobalVariablesTableProducer::Identity::convert
static ValType convert(ValType x)
Definition: GlobalVariablesTableProducer.cc:68
GlobalVariablesTableProducer::Variable::name
const std::string & name() const
Definition: GlobalVariablesTableProducer.cc:58
GlobalVariablesTableProducer::VariableT::src_
edm::EDGetTokenT< ValType > src_
Definition: GlobalVariablesTableProducer.cc:150
createfilelist.int
int
Definition: createfilelist.py:10
edm::ParameterSet::getParameterNamesForType
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:168
iEvent
int iEvent
Definition: GenABIO.cc:224
GlobalVariablesTableProducer::vars_
boost::ptr_vector< Variable > vars_
Definition: GlobalVariablesTableProducer.cc:160
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
cc
GlobalVariablesTableProducer::CandidateSumMassVar
VariableT< edm::View< reco::Candidate >, float, MassSum< float, edm::View< reco::Candidate > > > CandidateSumMassVar
Definition: GlobalVariablesTableProducer.cc:158
FlatTable.h
looper.cfg
cfg
Definition: looper.py:297
GlobalVariablesTableProducer::Variable::~Variable
virtual ~Variable()
Definition: GlobalVariablesTableProducer.cc:57
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
GlobalVariablesTableProducer::Max
Definition: GlobalVariablesTableProducer.cc:77
nanoaod::FlatTable
Definition: FlatTable.h:36
nanoaod::FlatTable::IntColumn
Definition: FlatTable.h:40
type
type
Definition: HCALResponse.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
GlobalVariablesTableProducer::FloatVar
VariableT< float > FloatVar
Definition: GlobalVariablesTableProducer.cc:153
GlobalVariablesTableProducer::ScalarPtSum::convert
static ColType convert(ValType x)
Definition: GlobalVariablesTableProducer.cc:101
GlobalVariablesTableProducer
Definition: GlobalVariablesTableProducer.cc:11
nanoaod::FlatTable::BoolColumn
Definition: FlatTable.h:42
Exception
Definition: hltDiff.cc:246
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ConsumesCollector.h
Candidate.h
ParameterSet.h
GlobalVariablesTableProducer::Variable::type_
nanoaod::FlatTable::ColumnType type_
Definition: GlobalVariablesTableProducer.cc:63
edm::Event
Definition: Event.h:73
GlobalVariablesTableProducer::PtVectorSum::convert
static ColType convert(ValType x)
Definition: GlobalVariablesTableProducer.cc:123
GlobalVariablesTableProducer::VariableT::fill
void fill(const edm::Event &iEvent, nanoaod::FlatTable &out) const override
Definition: GlobalVariablesTableProducer.cc:143
GlobalVariablesTableProducer::Variable::fill
virtual void fill(const edm::Event &iEvent, nanoaod::FlatTable &out) const =0
edm::ConsumesCollector
Definition: ConsumesCollector.h:39
GlobalVariablesTableProducer::Variable::type
const nanoaod::FlatTable::ColumnType & type() const
Definition: GlobalVariablesTableProducer.cc:59
GlobalVariablesTableProducer::VariableT::~VariableT
~VariableT() override
Definition: GlobalVariablesTableProducer.cc:142
GlobalVariablesTableProducer::Max::convert
static ColType convert(ValType x)
Definition: GlobalVariablesTableProducer.cc:79
GlobalVariablesTableProducer::CandidateSizeVar
VariableT< edm::View< reco::Candidate >, int, Size< edm::View< reco::Candidate > > > CandidateSizeVar
Definition: GlobalVariablesTableProducer.cc:159
GlobalVariablesTableProducer::CandidateScalarSumVar
VariableT< edm::View< reco::Candidate >, float, ScalarPtSum< float, edm::View< reco::Candidate > > > CandidateScalarSumVar
Definition: GlobalVariablesTableProducer.cc:157