File indexing completed on 2024-04-06 12:23:42
0001 #ifndef PhysicsTools_NanoAOD_LumiOutputBranches_h
0002 #define PhysicsTools_NanoAOD_LumiOutputBranches_h
0003
0004 #include <string>
0005 #include <vector>
0006 #include <TTree.h>
0007 #include "FWCore/Framework/interface/LuminosityBlockForOutput.h"
0008 #include "DataFormats/NanoAOD/interface/FlatTable.h"
0009 #include "DataFormats/Provenance/interface/BranchDescription.h"
0010 #include "FWCore/Utilities/interface/EDGetToken.h"
0011
0012 class LumiOutputBranches {
0013 public:
0014 LumiOutputBranches(const edm::BranchDescription *desc, const edm::EDGetToken &token)
0015 : m_token(token),
0016 m_singleton(false),
0017 m_extension(DontKnowYetIfMainOrExtension),
0018 m_counter(0),
0019 m_counterBranch(nullptr),
0020 m_branchesBooked(false) {
0021 if (desc->className() != "nanoaod::FlatTable")
0022 throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects");
0023 }
0024
0025 void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab);
0026 void branch(TTree &tree);
0027
0028
0029
0030 void fill(const edm::LuminosityBlockForOutput &iLumi, TTree &tree, bool extensions);
0031
0032 private:
0033 edm::EDGetToken m_token;
0034 std::string m_baseName;
0035 bool m_singleton;
0036 enum { IsMain = 0, IsExtension = 1, DontKnowYetIfMainOrExtension = 2 } m_extension;
0037 std::string m_doc;
0038 typedef Int_t CounterType;
0039 CounterType m_counter;
0040 struct NamedBranchPtr {
0041 std::string name, title, rootTypeCode;
0042 TBranch *branch;
0043 NamedBranchPtr(const std::string &aname,
0044 const std::string &atitle,
0045 const std::string &rootType,
0046 TBranch *branchptr = nullptr)
0047 : name(aname), title(atitle), rootTypeCode(rootType), branch(branchptr) {}
0048 };
0049 TBranch *m_counterBranch;
0050 std::vector<NamedBranchPtr> m_floatBranches;
0051 std::vector<NamedBranchPtr> m_intBranches;
0052 std::vector<NamedBranchPtr> m_uint8Branches;
0053 bool m_branchesBooked;
0054
0055 template <typename T>
0056 void fillColumn(NamedBranchPtr &pair, const nanoaod::FlatTable &tab) {
0057 int idx = tab.columnIndex(pair.name);
0058 if (idx == -1)
0059 throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
0060 pair.branch->SetAddress(const_cast<T *>(&tab.columnData<T>(idx).front()));
0061 }
0062 };
0063
0064 #endif