Skip to content

Commit

Permalink
Merge pull request #39955 from vlimant/precision_and_type
Browse files Browse the repository at this point in the history
Setting precision in GlobalVariablesProducer
  • Loading branch information
cmsbuild authored Nov 19, 2022
2 parents c59ff76 + 87eb498 commit 6062b77
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
13 changes: 6 additions & 7 deletions PhysicsTools/NanoAOD/interface/SimpleFlatTableProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> {
public:
SimpleFlatTableProducerBase(edm::ParameterSet const &params)
: name_(params.getParameter<std::string>("name")),
doc_(params.existsAs<std::string>("doc") ? params.getParameter<std::string>("doc") : ""),
extension_(params.existsAs<bool>("extension") ? params.getParameter<bool>("extension") : false),
skipNonExistingSrc_(
params.existsAs<bool>("skipNonExistingSrc") ? params.getParameter<bool>("skipNonExistingSrc") : false),
doc_(params.getParameter<std::string>("doc")),
extension_(params.getParameter<bool>("extension")),
skipNonExistingSrc_(params.getParameter<bool>("skipNonExistingSrc")),
src_(consumes<TProd>(params.getParameter<edm::InputTag>("src"))) {
edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
for (const std::string &vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
Expand Down Expand Up @@ -151,9 +150,9 @@ class SimpleFlatTableProducerBase : public edm::stream::EDProducer<> {
edm::ParameterSetDescription desc;
std::string classname = ClassName<T>::name();
desc.add<std::string>("name")->setComment("name of the branch in the flat table output for " + classname);
desc.addOptional<std::string>("doc")->setComment("few words of self documentation");
desc.addOptional<bool>("extension", false)->setComment("whether or not to extend an existing same table");
desc.addOptional<bool>("skipNonExistingSrc", false)
desc.add<std::string>("doc", "")->setComment("few words of self documentation");
desc.add<bool>("extension", false)->setComment("whether or not to extend an existing same table");
desc.add<bool>("skipNonExistingSrc", false)
->setComment("whether or not to skip producing the table on absent input product");
desc.add<edm::InputTag>("src")->setComment("input collection to fill the flat table");

Expand Down
15 changes: 8 additions & 7 deletions PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
class GlobalVariablesTableProducer : public edm::stream::EDProducer<> {
public:
GlobalVariablesTableProducer(edm::ParameterSet const& params)
: name_(params.existsAs<std::string>("name") ? params.getParameter<std::string>("name") : ""),
extension_(params.existsAs<bool>("extension") ? params.getParameter<bool>("extension") : false) {
: name_(params.getParameter<std::string>("name")), extension_(params.getParameter<bool>("extension")) {
edm::ParameterSet const& varsPSet = params.getParameter<edm::ParameterSet>("variables");
for (const std::string& vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
const auto& varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
Expand Down Expand Up @@ -45,16 +44,16 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> {

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.addOptional<std::string>("name")->setComment("name of the branch in the flat table output");
desc.addOptional<bool>("extension", false)->setComment("whether or not to extend an existing same table");
desc.add<std::string>("name", "")->setComment("name of the branch in the flat table output");
desc.add<bool>("extension", false)->setComment("whether or not to extend an existing same table");
edm::ParameterSetDescription variable;
variable.ifValue(edm::ParameterDescription<std::string>(
"type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
edm::allowedValues<std::string>(
"int", "float", "double", "bool", "candidatescalarsum", "candidatesize", "candidatesummass"));
variable.add<edm::InputTag>("src")->setComment("input collection for the branch");
variable.add<std::string>("doc")->setComment("few words description of the branch content");
variable.addOptional<int>("precision")->setComment("precision to store the information [NOT USED IN THE CODE]");
variable.add<int>("precision", -1)->setComment("precision to store the information");
edm::ParameterSetDescription variables;
variables.setComment("a parameters set to define variable to fill the flat table");
variables.addNode(
Expand All @@ -76,13 +75,14 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> {
class Variable {
public:
Variable(const std::string& aname, const edm::ParameterSet& cfg)
: name_(aname), doc_(cfg.getParameter<std::string>("doc")) {}
: name_(aname), doc_(cfg.getParameter<std::string>("doc")), precision_(cfg.getParameter<int>("precision")) {}
virtual void fill(const edm::Event& iEvent, nanoaod::FlatTable& out) const = 0;
virtual ~Variable() {}
const std::string& name() const { return name_; }

protected:
std::string name_, doc_;
int precision_;
};
template <typename ValType>
class Identity {
Expand Down Expand Up @@ -160,7 +160,8 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> {
: Variable(aname, cfg), src_(cc.consumes<ValType>(cfg.getParameter<edm::InputTag>("src"))) {}
~VariableT() override {}
void fill(const edm::Event& iEvent, nanoaod::FlatTable& out) const override {
out.template addColumnValue<ColType>(this->name_, Converter::convert(iEvent.get(src_)), this->doc_);
out.template addColumnValue<ColType>(
this->name_, Converter::convert(iEvent.get(src_)), this->doc_, this->precision_);
}

protected:
Expand Down

0 comments on commit 6062b77

Please sign in to comment.