Skip to content

Commit

Permalink
Move nanoaod dataformats to nanoaod namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetruc committed Oct 2, 2017
1 parent a36123f commit 711bfda
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 191 deletions.
4 changes: 4 additions & 0 deletions DataFormats/NanoAOD/interface/FlatTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "FWCore/Utilities/interface/Exception.h"
#include "DataFormats/PatCandidates/interface/libminifloat.h"

namespace nanoaod {

namespace flatTableHelper {
template<typename T> struct MaybeMantissaReduce {
MaybeMantissaReduce(int mantissaBits) {}
Expand All @@ -21,6 +23,7 @@ namespace flatTableHelper {
inline void bulk(boost::sub_range<std::vector<float>> data) const { if (bits_ > 0) MiniFloatConverter::reduceMantissaToNbitsRounding(bits_, data.begin(), data.end(), data.begin()); }
};
}

class FlatTable {
public:
enum ColumnType { FloatColumn, IntColumn, UInt8Column, BoolColumn }; // We could have other Float types with reduced mantissa, and similar
Expand Down Expand Up @@ -155,5 +158,6 @@ template<> inline std::vector<float> & FlatTable::bigVector<float>() { retur
template<> inline std::vector<int> & FlatTable::bigVector<int>() { return ints_; }
template<> inline std::vector<uint8_t> & FlatTable::bigVector<uint8_t>() { return uint8s_; }

} // nanoaod

#endif
6 changes: 5 additions & 1 deletion DataFormats/NanoAOD/interface/MergeableCounterTable.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#ifndef DataFormats_NanoAOD_MergeableCounterTable_h
#define DataFormats_NanoAOD_MergeableCounterTable_h

#include <FWCore/Utilities/interface/Exception.h>
#include "FWCore/Utilities/interface/Exception.h"
#include <vector>
#include <string>

namespace nanoaod {

class MergeableCounterTable {
public:
MergeableCounterTable() {}
Expand Down Expand Up @@ -104,4 +106,6 @@ class MergeableCounterTable {
}
};

} // namespace nanoaod

#endif
4 changes: 4 additions & 0 deletions DataFormats/NanoAOD/interface/UniqueString.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <string>

namespace nanoaod {

class UniqueString {
public:
UniqueString() {}
Expand All @@ -15,4 +17,6 @@ class UniqueString {
std::string str_;
};

} // namespace nanoaod

#endif
4 changes: 2 additions & 2 deletions DataFormats/NanoAOD/src/FlatTable.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <DataFormats/NanoAOD/interface/FlatTable.h>
#include "DataFormats/NanoAOD/interface/FlatTable.h"

int FlatTable::columnIndex(const std::string & name) const {
int nanoaod::FlatTable::columnIndex(const std::string & name) const {
for (unsigned int i = 0, n = columns_.size(); i < n; ++i) {
if (columns_[i].name == name) return i;
}
Expand Down
13 changes: 7 additions & 6 deletions DataFormats/NanoAOD/src/classes.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#include "Rtypes.h"

#include <DataFormats/NanoAOD/interface/FlatTable.h>
#include <DataFormats/NanoAOD/interface/MergeableCounterTable.h>
#include <DataFormats/NanoAOD/interface/UniqueString.h>
#include "DataFormats/NanoAOD/interface/FlatTable.h"
#include "DataFormats/NanoAOD/interface/MergeableCounterTable.h"
#include "DataFormats/NanoAOD/interface/UniqueString.h"
#include "DataFormats/Common/interface/Wrapper.h"

namespace DataFormats_NanoAOD {
struct dictionary {
edm::Wrapper<FlatTable> w_table;
edm::Wrapper<MergeableCounterTable> w_mtable;
edm::Wrapper<UniqueString> w_ustr;
nanoaod::FlatTable table;
edm::Wrapper<nanoaod::FlatTable> w_table;
edm::Wrapper<nanoaod::MergeableCounterTable> w_mtable;
edm::Wrapper<nanoaod::UniqueString> w_ustr;
};
}
48 changes: 24 additions & 24 deletions DataFormats/NanoAOD/src/classes_def.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<lcgdict>
<class name="FlatTable::Column" ClassVersion="3">
<version ClassVersion="3" checksum="3947803302"/>
<class name="nanoaod::FlatTable::Column" ClassVersion="3">
<version ClassVersion="3" checksum="3066258528"/>
</class>
<class name="std::vector<FlatTable::Column>" />
<class name="FlatTable" ClassVersion="3">
<version ClassVersion="3" checksum="3559888950"/>
<class name="std::vector<nanoaod::FlatTable::Column>" />
<class name="nanoaod::FlatTable" ClassVersion="3">
<version ClassVersion="3" checksum="2443023556"/>
</class>
<class name="edm::Wrapper<FlatTable>" />
<class name="edm::Wrapper<nanoaod::FlatTable>" />

<class name="MergeableCounterTable::FloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="2459898836"/>
<class name="nanoaod::MergeableCounterTable::FloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="828208870"/>
</class>
<class name="MergeableCounterTable::IntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="213915508"/>
<class name="nanoaod::MergeableCounterTable::IntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="1191014438"/>
</class>
<class name="MergeableCounterTable::VFloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="3802388249"/>
<class name="nanoaod::MergeableCounterTable::VFloatColumn" ClassVersion="3">
<version ClassVersion="3" checksum="719259663"/>
</class>
<class name="MergeableCounterTable::VIntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="3160379289"/>
<class name="nanoaod::MergeableCounterTable::VIntColumn" ClassVersion="3">
<version ClassVersion="3" checksum="2535066991"/>
</class>
<class name="std::vector<MergeableCounterTable::FloatColumn>" />
<class name="std::vector<MergeableCounterTable::VFloatColumn>" />
<class name="std::vector<MergeableCounterTable::IntColumn>" />
<class name="std::vector<MergeableCounterTable::VIntColumn>" />
<class name="MergeableCounterTable" ClassVersion="3">
<version ClassVersion="3" checksum="1055793220"/>
<class name="std::vector<nanoaod::MergeableCounterTable::FloatColumn>" />
<class name="std::vector<nanoaod::MergeableCounterTable::VFloatColumn>" />
<class name="std::vector<nanoaod::MergeableCounterTable::IntColumn>" />
<class name="std::vector<nanoaod::MergeableCounterTable::VIntColumn>" />
<class name="nanoaod::MergeableCounterTable" ClassVersion="3">
<version ClassVersion="3" checksum="677965884"/>
</class>
<class name="edm::Wrapper<MergeableCounterTable>" />
<class name="UniqueString" ClassVersion="3">
<version ClassVersion="3" checksum="3967771225"/>
<class name="edm::Wrapper<nanoaod::MergeableCounterTable>" />
<class name="nanoaod::UniqueString" ClassVersion="3">
<version ClassVersion="3" checksum="2793726511"/>
</class>
<class name="edm::Wrapper<UniqueString>" />
<class name="edm::Wrapper<nanoaod::UniqueString>" />
</lcgdict>

10 changes: 5 additions & 5 deletions PhysicsTools/NanoAOD/plugins/CandMCMatchTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {
src_(consumes<reco::CandidateView>(params.getParameter<edm::InputTag>("src"))),
candMap_(consumes<edm::Association<reco::GenParticleCollection>>(params.getParameter<edm::InputTag>("mcMap")))
{
produces<FlatTable>();
produces<nanoaod::FlatTable>();
const std::string & type = params.getParameter<std::string>("objType");
if (type == "Muon") type_ = MMuon;
else if (type == "Electron") type_ = MElectron;
Expand Down Expand Up @@ -53,7 +53,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {
iEvent.getByToken(src_, cands);
unsigned int ncand = cands->size();

auto tab = std::make_unique<FlatTable>(ncand, objName_, false, true);
auto tab = std::make_unique<nanoaod::FlatTable>(ncand, objName_, false, true);

edm::Handle<edm::Association<reco::GenParticleCollection>> map;
iEvent.getByToken(candMap_, map);
Expand Down Expand Up @@ -101,8 +101,8 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {
};
}

tab->addColumn<int>(branchName_+"Idx", key, "Index into genParticle list for "+doc_, FlatTable::IntColumn);
tab->addColumn<uint8_t>(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, FlatTable::UInt8Column);
tab->addColumn<int>(branchName_+"Idx", key, "Index into genParticle list for "+doc_, nanoaod::FlatTable::IntColumn);
tab->addColumn<uint8_t>(branchName_+"Flav", flav, "Flavour of genParticle for "+doc_+": "+flavDoc_, nanoaod::FlatTable::UInt8Column);

iEvent.put(std::move(tab));
}
Expand All @@ -127,7 +127,7 @@ class CandMCMatchTableProducer : public edm::global::EDProducer<> {

static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
edm::ParameterSetDescription desc;
desc.add<std::string>("objName")->setComment("name of the FlatTable to extend with this table");
desc.add<std::string>("objName")->setComment("name of the nanoaod::FlatTable to extend with this table");
desc.add<std::string>("branchName")->setComment("name of the column to write (the final branch in the nanoaod will be <objName>_<branchName>Idx and <objName>_<branchName>Flav");
desc.add<std::string>("docString")->setComment("documentation to forward to the output");
desc.add<edm::InputTag>("src")->setComment("physics object collection for the reconstructed objects (e.g. leptons)");
Expand Down
44 changes: 22 additions & 22 deletions PhysicsTools/NanoAOD/plugins/GenWeightsTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
debug_(params.getUntrackedParameter<bool>("debug",false)), debugRun_(debug_.load()),
hasIssuedWarning_(false)
{
produces<FlatTable>();
produces<FlatTable>("LHEScale");
produces<FlatTable>("LHEPdf");
produces<FlatTable>("LHENamed");
produces<MergeableCounterTable,edm::InRun>();
produces<nanoaod::FlatTable>();
produces<nanoaod::FlatTable>("LHEScale");
produces<nanoaod::FlatTable>("LHEPdf");
produces<nanoaod::FlatTable>("LHENamed");
produces<nanoaod::MergeableCounterTable,edm::InRun>();
if (namedWeightIDs_.size() != namedWeightLabels_.size()) {
throw cms::Exception("Configuration", "Size mismatch between namedWeightIDs & namedWeightLabels");
}
Expand All @@ -138,13 +138,13 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
double weight = genInfo->weight();

// table for gen info, always available
auto out = std::make_unique<FlatTable>(1, "genWeight", true);
auto out = std::make_unique<nanoaod::FlatTable>(1, "genWeight", true);
out->setDoc("generator weight");
out->addColumnValue<float>("", weight, "generator weight", FlatTable::FloatColumn);
out->addColumnValue<float>("", weight, "generator weight", nanoaod::FlatTable::FloatColumn);
iEvent.put(std::move(out));

// tables for LHE weights, may not be filled
std::unique_ptr<FlatTable> lheScaleTab, lhePdfTab, lheNamedTab;
std::unique_ptr<nanoaod::FlatTable> lheScaleTab, lhePdfTab, lheNamedTab;

edm::Handle<LHEEventProduct> lheInfo;
if (iEvent.getByToken(lheTag_, lheInfo)) {
Expand All @@ -156,9 +156,9 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
// minimal book-keeping of weights
counter->incGenOnly(weight);
// make dummy values
lheScaleTab.reset(new FlatTable(1, "LHEScaleWeights", true));
lhePdfTab.reset(new FlatTable(1, "LHEPdfWeights", true));
lheNamedTab.reset(new FlatTable(1, "LHENamedWeights", true));
lheScaleTab.reset(new nanoaod::FlatTable(1, "LHEScaleWeights", true));
lhePdfTab.reset(new nanoaod::FlatTable(1, "LHEPdfWeights", true));
lheNamedTab.reset(new nanoaod::FlatTable(1, "LHENamedWeights", true));
if (!hasIssuedWarning_.exchange(true)) {
edm::LogWarning("LHETablesProducer") << "No LHEEventProduct, so there will be no LHE Tables\n";
}
Expand All @@ -174,9 +174,9 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
const DynamicWeightChoice * weightChoice,
double genWeight,
const LHEEventProduct & lheProd,
std::unique_ptr<FlatTable> & outScale,
std::unique_ptr<FlatTable> & outPdf,
std::unique_ptr<FlatTable> & outNamed ) const
std::unique_ptr<nanoaod::FlatTable> & outScale,
std::unique_ptr<nanoaod::FlatTable> & outPdf,
std::unique_ptr<nanoaod::FlatTable> & outNamed ) const
{
bool lheDebug = debug_.exchange(false); // make sure only the first thread dumps out this (even if may still be mixed up with other output, but nevermind)

Expand All @@ -199,16 +199,16 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
if (mNamed != namedWeightIDs_.end()) wNamed[mNamed-namedWeightIDs_.begin()] = weight.wgt/w0;
}

outScale.reset(new FlatTable(wScale.size(), "LHEScaleWeight", false));
outScale->addColumn<float>("", wScale, weightChoice->scaleWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_);
outScale.reset(new nanoaod::FlatTable(wScale.size(), "LHEScaleWeight", false));
outScale->addColumn<float>("", wScale, weightChoice->scaleWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);

outPdf.reset(new FlatTable(wPDF.size(), "LHEPdfWeight", false));
outPdf->addColumn<float>("", wPDF, weightChoice->pdfWeightsDoc, FlatTable::FloatColumn, lheWeightPrecision_);
outPdf.reset(new nanoaod::FlatTable(wPDF.size(), "LHEPdfWeight", false));
outPdf->addColumn<float>("", wPDF, weightChoice->pdfWeightsDoc, nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);

outNamed.reset(new FlatTable(1, "LHEWeight", true));
outNamed->addColumnValue<float>("originalXWGTUP", lheProd.originalXWGTUP(), "Nominal event weight in the LHE file", FlatTable::FloatColumn);
outNamed.reset(new nanoaod::FlatTable(1, "LHEWeight", true));
outNamed->addColumnValue<float>("originalXWGTUP", lheProd.originalXWGTUP(), "Nominal event weight in the LHE file", nanoaod::FlatTable::FloatColumn);
for (unsigned int i = 0, n = wNamed.size(); i < n; ++i) {
outNamed->addColumnValue<float>(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", FlatTable::FloatColumn, lheWeightPrecision_);
outNamed->addColumnValue<float>(namedWeightLabels_[i], wNamed[i], "LHE weight for id "+namedWeightIDs_[i]+", relative to nominal", nanoaod::FlatTable::FloatColumn, lheWeightPrecision_);
}

counter->incLHE(genWeight, wScale, wPDF, wNamed);
Expand Down Expand Up @@ -355,7 +355,7 @@ class GenWeightsTableProducer : public edm::global::EDProducer<edm::StreamCache<
}
// write the total to the run
void globalEndRunProduce(edm::Run& iRun, edm::EventSetup const&, Counter const* runCounter) const override {
auto out = std::make_unique<MergeableCounterTable>();
auto out = std::make_unique<nanoaod::MergeableCounterTable>();
out->addInt("genEventCount", "event count", runCounter->num);
out->addFloat("genEventSumw", "sum of gen weights", runCounter->sumw);
out->addFloat("genEventSumw2", "sum of gen (weight^2)", runCounter->sumw2);
Expand Down
28 changes: 14 additions & 14 deletions PhysicsTools/NanoAOD/plugins/GlobalVariablesTableProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> {
for (const std::string & vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
const auto & varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
const std::string & type = varPSet.getParameter<std::string>("type");
if (type == "int") vars_.push_back(new IntVar(vname, FlatTable::IntColumn, varPSet, consumesCollector()));
else if (type == "float") vars_.push_back(new FloatVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector()));
else if (type == "double") vars_.push_back(new DoubleVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector()));
else if (type == "bool") vars_.push_back(new BoolVar(vname, FlatTable::UInt8Column, varPSet, consumesCollector()));
else if (type == "candidatescalarsum") vars_.push_back(new CandidateScalarSumVar(vname, FlatTable::FloatColumn, varPSet, consumesCollector()));
else if (type == "candidatesize") vars_.push_back(new CandidateSizeVar(vname, FlatTable::IntColumn, varPSet, consumesCollector()));
if (type == "int") vars_.push_back(new IntVar(vname, nanoaod::FlatTable::IntColumn, varPSet, consumesCollector()));
else if (type == "float") vars_.push_back(new FloatVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector()));
else if (type == "double") vars_.push_back(new DoubleVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector()));
else if (type == "bool") vars_.push_back(new BoolVar(vname, nanoaod::FlatTable::UInt8Column, varPSet, consumesCollector()));
else if (type == "candidatescalarsum") vars_.push_back(new CandidateScalarSumVar(vname, nanoaod::FlatTable::FloatColumn, varPSet, consumesCollector()));
else if (type == "candidatesize") vars_.push_back(new CandidateSizeVar(vname, nanoaod::FlatTable::IntColumn, varPSet, consumesCollector()));
else throw cms::Exception("Configuration", "unsupported type "+type+" for variable "+vname);
}

produces<FlatTable>();
produces<nanoaod::FlatTable>();
}

~GlobalVariablesTableProducer() override {}

void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
auto out = std::make_unique<FlatTable>(1, "", true);
auto out = std::make_unique<nanoaod::FlatTable>(1, "", true);

for (const auto & var : vars_) var.fill(iEvent, *out);

Expand All @@ -42,15 +42,15 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> {
protected:
class Variable {
public:
Variable(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg) :
Variable(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg) :
name_(aname), doc_(cfg.getParameter<std::string>("doc")), type_(atype) {}
virtual void fill(const edm::Event &iEvent, FlatTable & out) const = 0;
virtual void fill(const edm::Event &iEvent, nanoaod::FlatTable & out) const = 0;
virtual ~Variable() {}
const std::string & name() const { return name_; }
const FlatTable::ColumnType & type() const { return type_; }
const nanoaod::FlatTable::ColumnType & type() const { return type_; }
protected:
std::string name_, doc_;
FlatTable::ColumnType type_;
nanoaod::FlatTable::ColumnType type_;
};
template <typename ValType>
class Identity {
Expand Down Expand Up @@ -109,10 +109,10 @@ class GlobalVariablesTableProducer : public edm::stream::EDProducer<> {
template<typename ValType, typename ColType=ValType, typename Converter=Identity<ValType> >
class VariableT : public Variable {
public:
VariableT(const std::string & aname, FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) :
VariableT(const std::string & aname, nanoaod::FlatTable::ColumnType atype, const edm::ParameterSet & cfg, edm::ConsumesCollector && cc) :
Variable(aname, atype, cfg), src_(cc.consumes<ValType>(cfg.getParameter<edm::InputTag>("src"))) {}
~VariableT() override {}
void fill(const edm::Event &iEvent, FlatTable & out) const override {
void fill(const edm::Event &iEvent, nanoaod::FlatTable & out) const override {
edm::Handle<ValType> handle;
iEvent.getByToken(src_, handle);
out.template addColumnValue<ColType>(this->name_, Converter::convert(*handle), this->doc_, this->type_);
Expand Down
Loading

0 comments on commit 711bfda

Please sign in to comment.