12 #include <boost/ptr_container/ptr_vector.hpp> 14 template<
typename T,
typename TProd>
22 src_(consumes<TProd>( params.getParameter<
edm::InputTag>(
"src") ))
32 else throw cms::Exception(
"Configuration",
"unsupported type "+type+
" for variable "+vname);
35 produces<nanoaod::FlatTable>();
48 std::unique_ptr<nanoaod::FlatTable>
out =
fillTable(iEvent, src);
63 name_(aname), doc_(cfg.getParameter<
std::
string>(
"doc")),
type_(atype),
64 precision_(cfg.existsAs<
int>(
"precision") ? cfg.getParameter<
int>(
"precision") : (cfg.existsAs<
std::
string>(
"precision") ? -2 : -1))
81 template<
typename StringFunctor,
typename ValType>
88 std::vector<ValType>
vals(selobjs.size());
89 for (
unsigned int i = 0,
n =
vals.size();
i <
n; ++
i) {
93 else vals[
i] = func_(*selobjs[
i]);
102 typedef FuncVariable<StringObjectFunction<T>,
int>
IntVar;
103 typedef FuncVariable<StringObjectFunction<T>,
float>
FloatVar;
104 typedef FuncVariable<StringObjectFunction<T>,uint8_t>
UInt8Var;
105 typedef FuncVariable<StringCutObjectSelector<T>,uint8_t>
BoolVar;
116 singleton_(params.getParameter<
bool>(
"singleton")),
117 maxLen_(params.existsAs<unsigned
int>(
"maxLen") ? params.getParameter<unsigned
int>(
"maxLen") :
std::numeric_limits<unsigned
int>::
max()),
118 cut_(!singleton_ ? params.getParameter<
std::
string>(
"cut") :
"",
true)
130 else throw cms::Exception(
"Configuration",
"unsupported type "+type+
" for variable "+vname);
138 std::vector<const T *> selobjs;
139 std::vector<edm::Ptr<T>> selptrs;
141 assert(
prod->size() == 1);
142 selobjs.push_back(& (*
prod)[0] );
143 if (!extvars_.empty()) selptrs.emplace_back(
prod->ptrAt(0));
145 for (
unsigned int i = 0,
n =
prod->size();
i <
n; ++
i) {
146 const auto &
obj = (*prod)[
i];
148 selobjs.push_back(&
obj);
149 if (!extvars_.empty()) selptrs.emplace_back(
prod->ptrAt(
i));
151 if(selobjs.size()>=maxLen_)
break;
154 auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->
name_, singleton_, this->
extension_);
156 for (
const auto &
var : this->extvars_)
var.fill(iEvent, selptrs, *
out);
171 template<
typename TIn,
typename ValType=TIn>
175 ExtVariable(aname, atype, cfg), token_(cc.consumes<
edm::ValueMap<TIn>>(cfg.getParameter<
edm::InputTag>(
"src"))) {}
179 std::vector<ValType>
vals(selptrs.size());
180 for (
unsigned int i = 0,
n =
vals.size();
i <
n; ++
i) {
181 vals[
i] = (*vmap)[selptrs[
i]];
206 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
207 std::vector<const T *> selobjs(1, prod.
product());
222 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
223 std::vector<const T *> selobjs(1, & (*
prod)[0]);
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
virtual std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< TProd > &prod) const =0
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
~SimpleFlatTableProducerBase() override
ValueMapVariable< int > IntExtVar
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Variable(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg)
VariableBase(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg)
const edm::EDGetTokenT< TProd > src_
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< edm::View< T >> &prod) const override
~FirstObjectSimpleFlatTableProducer() override
void fill(std::vector< const T * > selobjs, nanoaod::FlatTable &out) const override
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< edm::View< T >> &prod) const override
edm::EDGetTokenT< edm::ValueMap< TIn > > token_
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
ValueMapVariable(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc)
ExtVariable(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg)
StringFunctor precisionFunc_
SimpleFlatTableProducerBase(edm::ParameterSet const ¶ms)
ValueMapVariable< float > FloatExtVar
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
~EventSingletonSimpleFlatTableProducer() override
SimpleFlatTableProducerBase< T, edm::View< T > > base
~SimpleFlatTableProducer() override
const unsigned int maxLen_
FuncVariable< StringCutObjectSelector< T >, uint8_t > BoolVar
FuncVariable< StringObjectFunction< T >, uint8_t > UInt8Var
SimpleFlatTableProducer(edm::ParameterSet const ¶ms)
ValueMapVariable< bool, uint8_t > BoolExtVar
boost::ptr_vector< ExtVariable > extvars_
FuncVariable< StringObjectFunction< T >, int > IntVar
T const * product() const
boost::ptr_vector< Variable > vars_
nanoaod::FlatTable::ColumnType type_
ValueMapVariable< double, float > DoubleExtVar
void fill(const edm::Event &iEvent, std::vector< edm::Ptr< T >> selptrs, nanoaod::FlatTable &out) const override
static float reduceMantissaToNbitsRounding(const float &f)
const std::string & name() const
FirstObjectSimpleFlatTableProducer(edm::ParameterSet const ¶ms)
EventSingletonSimpleFlatTableProducer(edm::ParameterSet const ¶ms)
FuncVariable< StringObjectFunction< T >, float > FloatVar
FuncVariable(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg)
const StringCutObjectSelector< T > cut_
const nanoaod::FlatTable::ColumnType & type() const
ValueMapVariable< int, uint8_t > UInt8ExtVar
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &, const edm::Handle< T > &prod) const override