14 template <
typename T,
typename TProd>
19 doc_(params.existsAs<std::
string>(
"doc") ? params.getParameter<std::
string>(
"doc") :
""),
20 extension_(params.existsAs<bool>(
"extension") ? params.getParameter<bool>(
"extension") :
false),
22 params.existsAs<bool>(
"skipNonExistingSrc") ? params.getParameter<bool>(
"skipNonExistingSrc") :
false),
24 : consumes<TProd>(params.getParameter<edm::
InputTag>(
"src"))) {
30 vars_.push_back(std::make_unique<IntVar>(vname, varPSet));
31 else if (type ==
"float")
32 vars_.push_back(std::make_unique<FloatVar>(vname, varPSet));
33 else if (type ==
"uint8")
34 vars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
35 else if (type ==
"bool")
36 vars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
38 throw cms::Exception(
"Configuration",
"unsupported type " + type +
" for variable " + vname);
41 produces<nanoaod::FlatTable>();
54 std::unique_ptr<nanoaod::FlatTable>
out =
fillTable(iEvent, src);
72 precision_(cfg.existsAs<int>(
"precision") ? cfg.getParameter<int>(
"precision")
73 : (cfg.existsAs<std::
string>(
"precision") ? -2 : -1)) {}
88 template <
typename StringFunctor,
typename ValType>
98 std::vector<ValType> vals(selobjs.size());
99 for (
unsigned int i = 0,
n = vals.size();
i <
n; ++
i) {
100 if constexpr (std::is_same<ValType, float>()) {
118 typedef FuncVariable<StringObjectFunction<T>,
int>
IntVar;
119 typedef FuncVariable<StringObjectFunction<T>,
float>
FloatVar;
120 typedef FuncVariable<StringObjectFunction<T>, uint8_t>
UInt8Var;
121 typedef FuncVariable<StringCutObjectSelector<T>,
bool>
BoolVar;
122 std::vector<std::unique_ptr<Variable>>
vars_;
125 template <
typename T>
132 singleton_(params.getParameter<bool>(
"singleton")),
133 maxLen_(params.existsAs<unsigned int>(
"maxLen") ? params.getParameter<unsigned int>(
"maxLen")
134 : std::numeric_limits<unsigned int>::
max()),
143 std::make_unique<IntExtVar>(vname, varPSet, this->consumesCollector(), this->
skipNonExistingSrc_));
144 else if (type ==
"float")
146 std::make_unique<FloatExtVar>(vname, varPSet, this->consumesCollector(), this->
skipNonExistingSrc_));
147 else if (type ==
"double")
149 std::make_unique<DoubleExtVar>(vname, varPSet, this->consumesCollector(), this->
skipNonExistingSrc_));
150 else if (type ==
"uint8")
152 std::make_unique<UInt8ExtVar>(vname, varPSet, this->consumesCollector(), this->
skipNonExistingSrc_));
153 else if (type ==
"bool")
155 std::make_unique<BoolExtVar>(vname, varPSet, this->consumesCollector(), this->
skipNonExistingSrc_));
157 throw cms::Exception(
"Configuration",
"unsupported type " + type +
" for variable " + vname);
166 std::vector<const T *> selobjs;
167 std::vector<edm::Ptr<T>> selptrs;
170 assert(prod->size() == 1);
171 selobjs.push_back(&(*prod)[0]);
173 selptrs.emplace_back(prod->ptrAt(0));
175 for (
unsigned int i = 0,
n = prod->size();
i <
n; ++
i) {
176 const auto &
obj = (*prod)[
i];
178 selobjs.push_back(&
obj);
180 selptrs.emplace_back(prod->ptrAt(
i));
191 var->fill(iEvent, selptrs, *
out);
205 template <
typename TIn,
typename ValType = TIn>
211 bool skipNonExistingSrc =
false)
215 : cc.consumes<edm::ValueMap<TIn>>(cfg.getParameter<edm::
InputTag>(
"src"))) {}
219 std::vector<ValType> vals;
221 vals.resize(selptrs.size());
222 for (
unsigned int i = 0,
n = vals.size();
i <
n; ++
i) {
223 vals[
i] = (*vmap)[selptrs[
i]];
226 out.template addColumn<ValType>(this->
name_, vals, this->
doc_, this->precision_);
238 std::vector<std::unique_ptr<ExtVariable>>
extvars_;
241 template <
typename T>
249 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
250 std::vector<const T *> selobjs(1, prod.
product());
257 template <
typename T>
267 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
268 std::vector<const T *> selobjs(1, &(*prod)[0]);
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
~SimpleFlatTableProducerBase() override
ValueMapVariable< int > IntExtVar
ValueMapVariable(const std::string &aname, const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc, bool skipNonExistingSrc=false)
ValueMapVariable< double, float > DoubleExtVar
void fill(const edm::Event &iEvent, std::vector< edm::Ptr< T >> selptrs, nanoaod::FlatTable &out) const override
const bool skipNonExistingSrc_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const edm::EDGetTokenT< TProd > src_
~FirstObjectSimpleFlatTableProducer() override
edm::EDGetTokenT< edm::ValueMap< TIn > > token_
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< edm::View< T >> &prod) const override
FuncVariable< StringObjectFunction< T >, uint8_t > UInt8Var
StringFunctor precisionFunc_
SimpleFlatTableProducerBase(edm::ParameterSet const ¶ms)
ValueMapVariable< float > FloatExtVar
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
std::vector< std::unique_ptr< ExtVariable > > extvars_
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &, const edm::Handle< T > &prod) const override
ValueMapVariable< int, uint8_t > UInt8ExtVar
virtual void fill(std::vector< const T * > selobjs, nanoaod::FlatTable &out) const =0
~EventSingletonSimpleFlatTableProducer() override
SimpleFlatTableProducerBase< T, edm::View< T > > base
~SimpleFlatTableProducer() override
const bool skipNonExistingSrc_
FuncVariable< StringObjectFunction< T >, int > IntVar
list var
if using global norm cols_to_minmax = ['t_delta', 't_hmaxNearP','t_emaxNearP', 't_hAnnular', 't_eAnnular','t_pt','t_nVtx','t_ieta','t_eHcal10', 't_eHcal30','t_rhoh','t_eHcal'] df[cols_to_minmax] = df[cols_to_minmax].apply(lambda x: (x - x.min()) / (x.max() - x.min()) if (x.max() - x.min() > 0) else 1.0/200.0)
const unsigned int maxLen_
SimpleFlatTableProducer(edm::ParameterSet const ¶ms)
virtual void fill(const edm::Event &iEvent, std::vector< edm::Ptr< T >> selptrs, nanoaod::FlatTable &out) const =0
ValueMapVariable< bool > BoolExtVar
FuncVariable< StringCutObjectSelector< T >, bool > BoolVar
T const * product() const
T getParameter(std::string const &) const
virtual std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< TProd > &prod) const =0
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< edm::View< T >> &prod) const override
static float reduceMantissaToNbitsRounding(const float &f)
ExtVariable(const std::string &aname, const edm::ParameterSet &cfg)
FuncVariable(const std::string &aname, const edm::ParameterSet &cfg)
const std::string & name() const
void fill(std::vector< const T * > selobjs, nanoaod::FlatTable &out) const override
FirstObjectSimpleFlatTableProducer(edm::ParameterSet const ¶ms)
EventSingletonSimpleFlatTableProducer(edm::ParameterSet const ¶ms)
std::vector< std::unique_ptr< Variable > > vars_
Variable(const std::string &aname, const edm::ParameterSet &cfg)
FuncVariable< StringObjectFunction< T >, float > FloatVar
VariableBase(const std::string &aname, const edm::ParameterSet &cfg)
const StringCutObjectSelector< T > cut_