12 #include <boost/ptr_container/ptr_vector.hpp> 14 template<
typename T,
typename TProd>
23 src_(
skipNonExistingSrc_ ? mayConsume<TProd>(params.getParameter<
edm::InputTag>(
"src")) : consumes<TProd>(params.getParameter<
edm::InputTag>(
"src")))
33 else throw cms::Exception(
"Configuration",
"unsupported type "+type+
" for variable "+vname);
36 produces<nanoaod::FlatTable>();
49 std::unique_ptr<nanoaod::FlatTable>
out =
fillTable(iEvent, src);
65 name_(aname), doc_(cfg.getParameter<
std::
string>(
"doc")),
type_(atype),
66 precision_(cfg.existsAs<
int>(
"precision") ? cfg.getParameter<
int>(
"precision") : (cfg.existsAs<
std::
string>(
"precision") ? -2 : -1))
83 template<
typename StringFunctor,
typename ValType>
90 std::vector<ValType>
vals(selobjs.size());
91 for (
unsigned int i = 0,
n =
vals.size();
i <
n; ++
i) {
95 else vals[
i] = func_(*selobjs[
i]);
104 typedef FuncVariable<StringObjectFunction<T>,
int>
IntVar;
105 typedef FuncVariable<StringObjectFunction<T>,
float>
FloatVar;
106 typedef FuncVariable<StringObjectFunction<T>,uint8_t>
UInt8Var;
107 typedef FuncVariable<StringCutObjectSelector<T>,uint8_t>
BoolVar;
118 singleton_(params.getParameter<
bool>(
"singleton")),
119 maxLen_(params.existsAs<unsigned
int>(
"maxLen") ? params.getParameter<unsigned
int>(
"maxLen") :
std::numeric_limits<unsigned
int>::
max()),
120 cut_(!singleton_ ? params.getParameter<
std::
string>(
"cut") :
"",
true)
132 else throw cms::Exception(
"Configuration",
"unsupported type "+type+
" for variable "+vname);
140 std::vector<const T *> selobjs;
141 std::vector<edm::Ptr<T>> selptrs;
144 assert(
prod->size() == 1);
145 selobjs.push_back(&(*
prod)[0]);
146 if (!extvars_.empty()) selptrs.emplace_back(
prod->ptrAt(0));
148 for (
unsigned int i = 0,
n =
prod->size();
i <
n; ++
i) {
149 const auto &
obj = (*prod)[
i];
151 selobjs.push_back(&
obj);
152 if (!extvars_.empty()) selptrs.emplace_back(
prod->ptrAt(
i));
154 if (selobjs.size() >= maxLen_)
break;
158 auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->
name_, singleton_, this->
extension_);
160 for (
const auto &
var : this->extvars_)
var.fill(iEvent, selptrs, *
out);
175 template<
typename TIn,
typename ValType=TIn>
183 std::vector<ValType>
vals;
185 vals.resize(selptrs.size());
186 for (
unsigned int i = 0,
n = vals.size();
i <
n; ++
i) {
187 vals[
i] = (*vmap)[selptrs[
i]];
214 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
215 std::vector<const T *> selobjs(1, prod.
product());
230 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
231 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
const bool skipNonExistingSrc_
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
ExtVariable(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg)
ValueMapVariable(const std::string &aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc, bool skipNonExistingSrc=false)
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 bool skipNonExistingSrc_
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