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") : -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) {
90 vals[
i] = func_(*selobjs[
i]);
98 typedef FuncVariable<StringObjectFunction<T>,
int>
IntVar;
99 typedef FuncVariable<StringObjectFunction<T>,
float>
FloatVar;
100 typedef FuncVariable<StringObjectFunction<T>,uint8_t>
UInt8Var;
101 typedef FuncVariable<StringCutObjectSelector<T>,uint8_t>
BoolVar;
112 singleton_(params.getParameter<
bool>(
"singleton")),
113 maxLen_(params.existsAs<unsigned
int>(
"maxLen") ? params.getParameter<unsigned
int>(
"maxLen") :
std::numeric_limits<unsigned
int>::
max()),
114 cut_(!singleton_ ? params.getParameter<
std::
string>(
"cut") :
"",
true)
126 else throw cms::Exception(
"Configuration",
"unsupported type "+type+
" for variable "+vname);
134 std::vector<const T *> selobjs;
135 std::vector<edm::Ptr<T>> selptrs;
137 assert(
prod->size() == 1);
138 selobjs.push_back(& (*
prod)[0] );
139 if (!extvars_.empty()) selptrs.emplace_back(
prod->ptrAt(0));
141 for (
unsigned int i = 0,
n =
prod->size();
i <
n; ++
i) {
142 const auto &
obj = (*prod)[
i];
144 selobjs.push_back(&
obj);
145 if (!extvars_.empty()) selptrs.emplace_back(
prod->ptrAt(
i));
147 if(selobjs.size()>=maxLen_)
break;
150 auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->
name_, singleton_, this->
extension_);
152 for (
const auto &
var : this->extvars_)
var.fill(iEvent, selptrs, *
out);
167 template<
typename TIn,
typename ValType=TIn>
171 ExtVariable(aname, atype, cfg), token_(cc.consumes<
edm::ValueMap<TIn>>(cfg.getParameter<
edm::InputTag>(
"src"))) {}
175 std::vector<ValType>
vals(selptrs.size());
176 for (
unsigned int i = 0,
n =
vals.size();
i <
n; ++
i) {
177 vals[
i] = (*vmap)[selptrs[
i]];
202 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
203 std::vector<const T *> selobjs(1, prod.
product());
218 auto out = std::make_unique<nanoaod::FlatTable>(1, this->
name_,
true, this->
extension_);
219 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)
#define DEFINE_FWK_MODULE(type)
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)
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_
EventSingletonSimpleFlatTableProducer< GenEventInfoProduct > SimpleGenEventFlatTableProducer
FuncVariable< StringObjectFunction< T >, int > IntVar
T const * product() const
boost::ptr_vector< Variable > vars_
SimpleFlatTableProducer< reco::Candidate > SimpleCandidateFlatTableProducer
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
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