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::EventForOutput &iEvent, TTree &tree, bool extensions)
 
 TableOutputBranches (const edm::BranchDescription *desc, const edm::EDGetToken &token)
 

Private Types

enum  { IsMain = 0, IsExtension = 1, DontKnowYetIfMainOrExtension = 2 }
 

Private Member Functions

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

Private Attributes

std::string m_baseName
 
bool m_branchesBooked
 
UInt_t m_counter
 
TBranch * m_counterBranch
 
std::string m_doc
 
enum TableOutputBranches:: { ... }  m_extension
 
std::vector< NamedBranchPtrm_floatBranches
 
std::vector< NamedBranchPtrm_intBranches
 
bool m_singleton
 
edm::EDGetToken m_token
 
std::vector< NamedBranchPtrm_uint8Branches
 

Detailed Description

Definition at line 12 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.

16  if (desc->className() != "nanoaod::FlatTable")
17  throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects");
18  }

References edm::BranchDescription::className().

Member Function Documentation

◆ branch()

void TableOutputBranches::branch ( TTree &  tree)

Definition at line 32 of file TableOutputBranches.cc.

32  {
33  if (!m_singleton) {
34  if (m_extension == IsExtension) {
35  m_counterBranch = tree.FindBranch(("n" + m_baseName).c_str());
36  if (!m_counterBranch) {
37  throw cms::Exception("LogicError",
38  "Trying to save an extension table for " + m_baseName +
39  " before having saved the corresponding main table\n");
40  }
41  } else {
42  if (tree.FindBranch(("n" + m_baseName).c_str()) != nullptr) {
43  throw cms::Exception("LogicError", "Trying to save multiple main tables for " + m_baseName + "\n");
44  }
45  m_counterBranch = tree.Branch(("n" + m_baseName).c_str(), &m_counter, ("n" + m_baseName + "/i").c_str());
46  m_counterBranch->SetTitle(m_doc.c_str());
47  }
48  }
49  std::string varsize = m_singleton ? "" : "[n" + m_baseName + "]";
50  for (std::vector<NamedBranchPtr> *branches : {&m_floatBranches, &m_intBranches, &m_uint8Branches}) {
51  for (auto &pair : *branches) {
52  std::string branchName = makeBranchName(m_baseName, pair.name);
53  pair.branch =
54  tree.Branch(branchName.c_str(), (void *)nullptr, (branchName + varsize + "/" + pair.rootTypeCode).c_str());
55  pair.branch->SetTitle(pair.title.c_str());
56  }
57  }
58 }

References electrons_cff::branchName, Exception, IsExtension, m_baseName, m_counter, m_counterBranch, m_doc, m_extension, m_floatBranches, m_intBranches, m_singleton, m_uint8Branches, and AlCaHLTBitMon_QueryRunRegistry::string.

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

◆ defineBranchesFromFirstEvent()

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

◆ fill()

void TableOutputBranches::fill ( const edm::EventForOutput iEvent,
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 60 of file TableOutputBranches.cc.

60  {
62  if (extensions != m_extension)
63  return; // do nothing, wait to be called with the proper flag
64  }
65 
67  iEvent.getByToken(m_token, handle);
68  const nanoaod::FlatTable &tab = *handle;
69  m_counter = tab.size();
70  m_singleton = tab.singleton();
71  if (!m_branchesBooked) {
73  if (extensions != m_extension)
74  return; // do nothing, wait to be called with the proper flag
76  m_doc = tab.doc();
77  m_branchesBooked = true;
78  branch(tree);
79  }
80  if (!m_singleton && m_extension == IsExtension) {
81  if (m_counter != *reinterpret_cast<UInt_t *>(m_counterBranch->GetAddress())) {
82  throw cms::Exception("LogicError",
83  "Mismatch in number of entries between extension and main table for " + tab.name());
84  }
85  }
86  for (auto &pair : m_floatBranches)
87  fillColumn<float>(pair, tab);
88  for (auto &pair : m_intBranches)
89  fillColumn<int>(pair, tab);
90  for (auto &pair : m_uint8Branches)
91  fillColumn<uint8_t>(pair, tab);
92 }

References branch(), defineBranchesFromFirstEvent(), nanoaod::FlatTable::doc(), DontKnowYetIfMainOrExtension, Exception, nanoaod::FlatTable::extension(), patZpeak::handle, iEvent, IsExtension, IsMain, m_branchesBooked, m_counter, m_counterBranch, m_doc, m_extension, m_floatBranches, m_intBranches, m_singleton, m_token, m_uint8Branches, nanoaod::FlatTable::name(), nanoaod::FlatTable::singleton(), and nanoaod::FlatTable::size().

◆ fillColumn()

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

Definition at line 50 of file TableOutputBranches.h.

50  {
51  int idx = tab.columnIndex(pair.name);
52  if (idx == -1)
53  throw cms::Exception("LogicError", "Missing column in input for " + m_baseName + "_" + pair.name);
54  pair.branch->SetAddress(const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
55  }

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

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 47 of file TableOutputBranches.h.

Referenced by fill().

◆ m_counter

UInt_t TableOutputBranches::m_counter
private

Definition at line 33 of file TableOutputBranches.h.

Referenced by branch(), and fill().

◆ m_counterBranch

TBranch* TableOutputBranches::m_counterBranch
private

Definition at line 43 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_extension

enum { ... } TableOutputBranches::m_extension

Referenced by branch(), and fill().

◆ m_floatBranches

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

Definition at line 44 of file TableOutputBranches.h.

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

◆ m_intBranches

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

Definition at line 45 of file TableOutputBranches.h.

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

◆ m_singleton

bool TableOutputBranches::m_singleton
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_uint8Branches

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

Definition at line 46 of file TableOutputBranches.h.

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

TableOutputBranches::DontKnowYetIfMainOrExtension
Definition: TableOutputBranches.h:31
nanoaod::FlatTable::FloatColumn
Definition: FlatTable.h:39
TableOutputBranches::IsMain
Definition: TableOutputBranches.h:31
TableOutputBranches::m_baseName
std::string m_baseName
Definition: TableOutputBranches.h:29
mps_fire.i
i
Definition: mps_fire.py:355
TableOutputBranches::defineBranchesFromFirstEvent
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
Definition: TableOutputBranches.cc:11
TableOutputBranches::m_uint8Branches
std::vector< NamedBranchPtr > m_uint8Branches
Definition: TableOutputBranches.h:46
nanoaod::FlatTable::singleton
bool singleton() const
Definition: FlatTable.h:53
patZpeak.handle
handle
Definition: patZpeak.py:23
electrons_cff.branchName
branchName
Definition: electrons_cff.py:492
tree
Definition: tree.py:1
TableOutputBranches::m_singleton
bool m_singleton
Definition: TableOutputBranches.h:30
edm::Handle
Definition: AssociativeIterator.h:50
training_settings.idx
idx
Definition: training_settings.py:16
nanoaod::FlatTable::doc
const std::string & doc() const
Definition: FlatTable.h:63
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
TableOutputBranches::branch
void branch(TTree &tree)
Definition: TableOutputBranches.cc:32
TableOutputBranches::m_token
edm::EDGetToken m_token
Definition: TableOutputBranches.h:28
nanoaod::FlatTable::columnDoc
const std::string & columnDoc(unsigned int col) const
Definition: FlatTable.h:64
nanoaod::FlatTable::columnType
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:60
nanoaod::FlatTable::extension
bool extension() const
Definition: FlatTable.h:54
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TableOutputBranches::m_counter
UInt_t m_counter
Definition: TableOutputBranches.h:33
nanoaod::FlatTable::columnIndex
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
iEvent
int iEvent
Definition: GenABIO.cc:224
TableOutputBranches::m_floatBranches
std::vector< NamedBranchPtr > m_floatBranches
Definition: TableOutputBranches.h:44
nanoaod::FlatTable::UInt8Column
Definition: FlatTable.h:41
TableOutputBranches::m_intBranches
std::vector< NamedBranchPtr > m_intBranches
Definition: TableOutputBranches.h:45
nanoaod::FlatTable::name
const std::string & name() const
Definition: FlatTable.h:55
nanoaod::FlatTable
Definition: FlatTable.h:36
nanoaod::FlatTable::IntColumn
Definition: FlatTable.h:40
nanoaod::FlatTable::columnData
boost::sub_range< const std::vector< T > > columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:68
nanoaod::FlatTable::columnName
const std::string & columnName(unsigned int col) const
Definition: FlatTable.h:57
nanoaod::FlatTable::nColumns
unsigned int nColumns() const
Definition: FlatTable.h:50
T
long double T
Definition: Basic3DVectorLD.h:48
nanoaod::FlatTable::BoolColumn
Definition: FlatTable.h:42
Exception
Definition: hltDiff.cc:246
TableOutputBranches::m_branchesBooked
bool m_branchesBooked
Definition: TableOutputBranches.h:47
TableOutputBranches::m_extension
enum TableOutputBranches::@856 m_extension
edm::BranchDescription::className
std::string const & className() const
Definition: BranchDescription.h:79
cms::Exception
Definition: Exception.h:70
TableOutputBranches::IsExtension
Definition: TableOutputBranches.h:31
TableOutputBranches::m_doc
std::string m_doc
Definition: TableOutputBranches.h:32
TableOutputBranches::m_counterBranch
TBranch * m_counterBranch
Definition: TableOutputBranches.h:43
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316
nanoaod::FlatTable::size
unsigned int size() const
Definition: FlatTable.h:52