File indexing completed on 2025-01-31 02:19:50
0001 #ifndef PhysicsTools_NanoAOD_SummaryTableOutputBranches_h
0002 #define PhysicsTools_NanoAOD_SummaryTableOutputBranches_h
0003
0004 #include <string>
0005 #include <vector>
0006 #include <TTree.h>
0007 #include "FWCore/Framework/interface/OccurrenceForOutput.h"
0008 #include "DataFormats/NanoAOD/interface/MergeableCounterTable.h"
0009 #include "DataFormats/Provenance/interface/ProductDescription.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011
0012 class SummaryTableOutputBranches {
0013 public:
0014 SummaryTableOutputBranches(const edm::ProductDescription *desc, const edm::EDGetToken &token)
0015 : m_token(token), m_fills(0) {
0016 if (desc->className() != "nanoaod::MergeableCounterTable")
0017 throw cms::Exception("Configuration", "NanoAODOutputModule can only write out MergableCounterTable objects");
0018 }
0019
0020 void fill(const edm::OccurrenceForOutput &iWhatever, TTree &tree);
0021
0022 private:
0023 edm::EDGetToken m_token;
0024
0025 struct NamedBranchPtr {
0026 std::string name;
0027 TBranch *branch;
0028 NamedBranchPtr(const std::string &aname, TBranch *branchptr = nullptr) : name(aname), branch(branchptr) {}
0029 };
0030 std::vector<NamedBranchPtr> m_intBranches, m_floatBranches, m_floatWithNormBranches;
0031
0032 struct NamedVectorBranchPtr : public NamedBranchPtr {
0033 UInt_t count;
0034 TBranch *counterBranch;
0035 NamedVectorBranchPtr(const std::string &aname,
0036 TBranch *counterBranchptr = nullptr,
0037 TBranch *valueBranchptr = nullptr)
0038 : NamedBranchPtr(aname, valueBranchptr), counterBranch(counterBranchptr) {}
0039 };
0040 std::vector<NamedVectorBranchPtr> m_vintBranches, m_vfloatBranches, m_vfloatWithNormBranches;
0041
0042 unsigned long m_fills;
0043
0044 void updateBranches(const nanoaod::MergeableCounterTable &tab, TTree &tree);
0045
0046 template <typename T, typename Col>
0047 void makeScalarBranches(const std::vector<Col> &tabcols,
0048 TTree &tree,
0049 const std::string &rootType,
0050 std::vector<NamedBranchPtr> &branches);
0051 template <typename Col>
0052 void makeVectorBranches(const std::vector<Col> &tabcols,
0053 TTree &tree,
0054 const std::string &rootType,
0055 std::vector<NamedVectorBranchPtr> &branches);
0056
0057 template <typename Col>
0058 void fillScalarBranches(const std::vector<Col> &tabcols, std::vector<NamedBranchPtr> &branches);
0059 template <typename Col>
0060 void fillVectorBranches(const std::vector<Col> &tabcols, std::vector<NamedVectorBranchPtr> &branches);
0061 };
0062
0063 #endif