CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
TableOutputBranches Class Reference

#include <TableOutputBranches.h>

Classes

struct  NamedBranchPtr
 

Public Member Functions

void branch (TTree &tree)
 
void defineBranchesFromFirstEvent (const nanoaod::FlatTable &tab)
 
void fill (const edm::OccurrenceForOutput &iWhatever, TTree &tree, bool extensions)
 
 TableOutputBranches (const edm::BranchDescription *desc, const edm::EDGetToken &token)
 

Private Types

enum  { IsMain = 0, IsExtension = 1, DontKnowYetIfMainOrExtension = 2 }
 
typedef Int_t CounterType
 

Private Member Functions

template<typename T >
void fillColumn (NamedBranchPtr &pair, const nanoaod::FlatTable &tab)
 

Private Attributes

std::string m_baseName
 
bool m_branchesBooked
 
CounterType m_counter
 
TBranch * m_counterBranch = nullptr
 
std::string m_doc
 
std::vector< NamedBranchPtrm_doubleBranches
 
enum TableOutputBranches:: { ... }  m_extension
 
std::vector< NamedBranchPtrm_floatBranches
 
std::vector< NamedBranchPtrm_int16Branches
 
std::vector< NamedBranchPtrm_int32Branches
 
std::vector< NamedBranchPtrm_int8Branches
 
bool m_singleton = false
 
edm::EDGetToken m_token
 
std::vector< NamedBranchPtrm_uint16Branches
 
std::vector< NamedBranchPtrm_uint32Branches
 
std::vector< NamedBranchPtrm_uint8Branches
 

Detailed Description

Definition at line 12 of file TableOutputBranches.h.

Member Typedef Documentation

◆ CounterType

typedef Int_t TableOutputBranches::CounterType
private

Definition at line 33 of file TableOutputBranches.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
IsMain 
IsExtension 
DontKnowYetIfMainOrExtension 

Definition at line 31 of file TableOutputBranches.h.

Constructor & Destructor Documentation

◆ TableOutputBranches()

TableOutputBranches::TableOutputBranches ( const edm::BranchDescription desc,
const edm::EDGetToken token 
)
inline

Definition at line 14 of file TableOutputBranches.h.

References submitPVResolutionJobs::desc.

16  if (desc->className() != "nanoaod::FlatTable")
17  throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects");
18  }
enum TableOutputBranches::@880 m_extension
edm::EDGetToken m_token

Member Function Documentation

◆ branch()

void TableOutputBranches::branch ( TTree &  tree)

Definition at line 50 of file TableOutputBranches.cc.

References electrons_cff::branchName, Exception, IsExtension, m_baseName, m_counter, m_counterBranch, m_doc, m_doubleBranches, m_extension, m_floatBranches, m_int16Branches, m_int32Branches, m_int8Branches, m_singleton, m_uint16Branches, m_uint32Branches, m_uint8Branches, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by python.cmstools.EventTree::__getattr__(), and fill().

50  {
51  if (!m_singleton) {
52  if (m_extension == IsExtension) {
53  m_counterBranch = tree.FindBranch(("n" + m_baseName).c_str());
54  if (!m_counterBranch) {
55  throw cms::Exception("LogicError",
56  "Trying to save an extension table for " + m_baseName +
57  " before having saved the corresponding main table\n");
58  }
59  } else {
60  if (tree.FindBranch(("n" + m_baseName).c_str()) != nullptr) {
61  throw cms::Exception("LogicError", "Trying to save multiple main tables for " + m_baseName + "\n");
62  }
63  m_counterBranch = tree.Branch(("n" + m_baseName).c_str(), &m_counter, ("n" + m_baseName + "/I").c_str());
64  m_counterBranch->SetTitle(m_doc.c_str());
65  }
66  }
67  std::string varsize = m_singleton ? "" : "[n" + m_baseName + "]";
68  for (std::vector<NamedBranchPtr> *branches : {&m_int8Branches,
75  &m_doubleBranches}) {
76  for (auto &pair : *branches) {
77  std::string branchName = makeBranchName(m_baseName, pair.name);
78  pair.branch =
79  tree.Branch(branchName.c_str(), (void *)nullptr, (branchName + varsize + "/" + pair.rootTypeCode).c_str());
80  pair.branch->SetTitle(pair.title.c_str());
81  }
82  }
83 }
enum TableOutputBranches::@880 m_extension
std::vector< NamedBranchPtr > m_uint32Branches
std::vector< NamedBranchPtr > m_int8Branches
std::vector< NamedBranchPtr > m_int32Branches
std::vector< NamedBranchPtr > m_uint16Branches
std::vector< NamedBranchPtr > m_uint8Branches
std::vector< NamedBranchPtr > m_int16Branches
Definition: tree.py:1
std::vector< NamedBranchPtr > m_floatBranches
std::vector< NamedBranchPtr > m_doubleBranches

◆ defineBranchesFromFirstEvent()

void TableOutputBranches::defineBranchesFromFirstEvent ( const nanoaod::FlatTable tab)

Definition at line 12 of file TableOutputBranches.cc.

References nanoaod::FlatTable::Bool, nanoaod::FlatTable::columnDoc(), nanoaod::FlatTable::columnName(), nanoaod::FlatTable::columnType(), nanoaod::FlatTable::Double, Exception, nanoaod::FlatTable::Float, mps_fire::i, nanoaod::FlatTable::Int16, nanoaod::FlatTable::Int32, nanoaod::FlatTable::Int8, m_baseName, m_doubleBranches, m_floatBranches, m_int16Branches, m_int32Branches, m_int8Branches, m_uint16Branches, m_uint32Branches, m_uint8Branches, nanoaod::FlatTable::name(), nanoaod::FlatTable::nColumns(), AlCaHLTBitMon_QueryRunRegistry::string, nanoaod::FlatTable::UInt16, nanoaod::FlatTable::UInt32, nanoaod::FlatTable::UInt8, and trigObjTnPSource_cfi::var.

Referenced by fill().

12  {
13  m_baseName = tab.name();
14  for (size_t i = 0; i < tab.nColumns(); i++) {
15  const std::string &var = tab.columnName(i);
16  switch (tab.columnType(i)) {
18  m_int8Branches.emplace_back(var, tab.columnDoc(i), "B");
19  break;
21  m_uint8Branches.emplace_back(var, tab.columnDoc(i), "b");
22  break;
24  m_int16Branches.emplace_back(var, tab.columnDoc(i), "S");
25  break;
27  m_uint16Branches.emplace_back(var, tab.columnDoc(i), "s");
28  break;
30  m_int32Branches.emplace_back(var, tab.columnDoc(i), "I");
31  break;
33  m_uint32Branches.emplace_back(var, tab.columnDoc(i), "i");
34  break;
36  m_uint8Branches.emplace_back(var, tab.columnDoc(i), "O");
37  break;
39  m_floatBranches.emplace_back(var, tab.columnDoc(i), "F");
40  break;
42  m_doubleBranches.emplace_back(var, tab.columnDoc(i), "D");
43  break;
44  default:
45  throw cms::Exception("LogicError", "Unsupported type");
46  }
47  }
48 }
std::vector< NamedBranchPtr > m_uint32Branches
const std::string & columnName(unsigned int col) const
Definition: FlatTable.h:64
const std::string & name() const
Definition: FlatTable.h:62
std::vector< NamedBranchPtr > m_int8Branches
std::vector< NamedBranchPtr > m_int32Branches
std::vector< NamedBranchPtr > m_uint16Branches
std::vector< NamedBranchPtr > m_uint8Branches
std::vector< NamedBranchPtr > m_int16Branches
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:67
unsigned int nColumns() const
Definition: FlatTable.h:57
const std::string & columnDoc(unsigned int col) const
Definition: FlatTable.h:71
std::vector< NamedBranchPtr > m_floatBranches
std::vector< NamedBranchPtr > m_doubleBranches

◆ fill()

void TableOutputBranches::fill ( const edm::OccurrenceForOutput iWhatever,
TTree &  tree,
bool  extensions 
)

Fill the current table, if extensions == table.extension(). This parameter is used so that the fill is called first for non-extensions and then for extensions

Definition at line 85 of file TableOutputBranches.cc.

References branch(), defineBranchesFromFirstEvent(), nanoaod::FlatTable::doc(), DontKnowYetIfMainOrExtension, Exception, nanoaod::FlatTable::extension(), edm::OccurrenceForOutput::getByToken(), patZpeak::handle, IsExtension, IsMain, m_branchesBooked, m_counter, m_counterBranch, m_doc, m_doubleBranches, m_extension, m_floatBranches, m_int16Branches, m_int32Branches, m_int8Branches, m_singleton, m_token, m_uint16Branches, m_uint32Branches, m_uint8Branches, SiStripPI::max, nanoaod::FlatTable::name(), nanoaod::FlatTable::singleton(), nanoaod::FlatTable::size(), findQualityFiles::size, and to_string().

85  {
87  if (extensions != m_extension)
88  return; // do nothing, wait to be called with the proper flag
89  }
90 
92  iWhatever.getByToken(m_token, handle);
93  const nanoaod::FlatTable &tab = *handle;
94  auto size = tab.size();
95  // ROOT native array size branches may only be signed integers,
96  // until this is changed we need to make sure the vector sizes do not exceed that
98  throw cms::Exception("Table " + tab.name() + " size is " + std::to_string(size) +
99  ", is too large for ROOT native array branch");
100  }
101  m_counter = size;
102  m_singleton = tab.singleton();
103  if (!m_branchesBooked) {
105  if (extensions != m_extension)
106  return; // do nothing, wait to be called with the proper flag
108  m_doc = tab.doc();
109  m_branchesBooked = true;
110  branch(tree);
111  }
112  if (!m_singleton && m_extension == IsExtension) {
113  if (m_counter != *reinterpret_cast<CounterType *>(m_counterBranch->GetAddress())) {
114  throw cms::Exception("LogicError",
115  "Mismatch in number of entries between extension and main table for " + tab.name());
116  }
117  }
118  for (auto &pair : m_int8Branches)
119  fillColumn<int8_t>(pair, tab);
120  for (auto &pair : m_uint8Branches)
121  fillColumn<uint8_t>(pair, tab);
122  for (auto &pair : m_int16Branches)
123  fillColumn<int16_t>(pair, tab);
124  for (auto &pair : m_uint16Branches)
125  fillColumn<uint16_t>(pair, tab);
126  for (auto &pair : m_int32Branches)
127  fillColumn<int32_t>(pair, tab);
128  for (auto &pair : m_uint32Branches)
129  fillColumn<uint32_t>(pair, tab);
130  for (auto &pair : m_floatBranches)
131  fillColumn<float>(pair, tab);
132  for (auto &pair : m_doubleBranches)
133  fillColumn<double>(pair, tab);
134 }
size
Write out results.
enum TableOutputBranches::@880 m_extension
std::vector< NamedBranchPtr > m_uint32Branches
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
bool extension() const
Definition: FlatTable.h:61
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
const std::string & name() const
Definition: FlatTable.h:62
static std::string to_string(const XMLCh *ch)
const std::string & doc() const
Definition: FlatTable.h:70
std::vector< NamedBranchPtr > m_int8Branches
std::vector< NamedBranchPtr > m_int32Branches
std::vector< NamedBranchPtr > m_uint16Branches
std::vector< NamedBranchPtr > m_uint8Branches
void branch(TTree &tree)
edm::EDGetToken m_token
bool singleton() const
Definition: FlatTable.h:60
std::vector< NamedBranchPtr > m_int16Branches
Definition: tree.py:1
std::vector< NamedBranchPtr > m_floatBranches
unsigned int size() const
Definition: FlatTable.h:59
std::vector< NamedBranchPtr > m_doubleBranches

◆ fillColumn()

template<typename T >
void TableOutputBranches::fillColumn ( NamedBranchPtr pair,
const nanoaod::FlatTable tab 
)
inlineprivate

Definition at line 56 of file TableOutputBranches.h.

References TableOutputBranches::NamedBranchPtr::branch, nanoaod::FlatTable::columnData(), nanoaod::FlatTable::columnIndex(), Exception, heavyIonCSV_trainingSettings::idx, m_baseName, TableOutputBranches::NamedBranchPtr::name, and nanoaod::FlatTable::size().

56  {
57  int idx = tab.columnIndex(pair.name);
58  if (idx == -1)
59  throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
60  pair.branch->SetAddress(
61  tab.size() == 0 ? static_cast<T *>(nullptr)
62  : const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
63  }
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
auto columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:75
long double T
unsigned int size() const
Definition: FlatTable.h:59

Member Data Documentation

◆ m_baseName

std::string TableOutputBranches::m_baseName
private

Definition at line 29 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fillColumn().

◆ m_branchesBooked

bool TableOutputBranches::m_branchesBooked
private

Definition at line 53 of file TableOutputBranches.h.

Referenced by fill().

◆ m_counter

CounterType TableOutputBranches::m_counter
private

Definition at line 34 of file TableOutputBranches.h.

Referenced by branch(), and fill().

◆ m_counterBranch

TBranch* TableOutputBranches::m_counterBranch = nullptr
private

Definition at line 44 of file TableOutputBranches.h.

Referenced by branch(), and fill().

◆ m_doc

std::string TableOutputBranches::m_doc
private

Definition at line 32 of file TableOutputBranches.h.

Referenced by branch(), and fill().

◆ m_doubleBranches

std::vector<NamedBranchPtr> TableOutputBranches::m_doubleBranches
private

Definition at line 52 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().

◆ m_extension

enum { ... } TableOutputBranches::m_extension

Referenced by branch(), and fill().

◆ m_floatBranches

std::vector<NamedBranchPtr> TableOutputBranches::m_floatBranches
private

Definition at line 51 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().

◆ m_int16Branches

std::vector<NamedBranchPtr> TableOutputBranches::m_int16Branches
private

Definition at line 47 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().

◆ m_int32Branches

std::vector<NamedBranchPtr> TableOutputBranches::m_int32Branches
private

Definition at line 49 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().

◆ m_int8Branches

std::vector<NamedBranchPtr> TableOutputBranches::m_int8Branches
private

Definition at line 45 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().

◆ m_singleton

bool TableOutputBranches::m_singleton = false
private

Definition at line 30 of file TableOutputBranches.h.

Referenced by branch(), and fill().

◆ m_token

edm::EDGetToken TableOutputBranches::m_token
private

Definition at line 28 of file TableOutputBranches.h.

Referenced by fill().

◆ m_uint16Branches

std::vector<NamedBranchPtr> TableOutputBranches::m_uint16Branches
private

Definition at line 48 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().

◆ m_uint32Branches

std::vector<NamedBranchPtr> TableOutputBranches::m_uint32Branches
private

Definition at line 50 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().

◆ m_uint8Branches

std::vector<NamedBranchPtr> TableOutputBranches::m_uint8Branches
private

Definition at line 46 of file TableOutputBranches.h.

Referenced by branch(), defineBranchesFromFirstEvent(), and fill().