CMS 3D CMS Logo

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