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
private
Enumerator
IsMain 
IsExtension 
DontKnowYetIfMainOrExtension 

Definition at line 31 of file TableOutputBranches.h.

Constructor & Destructor Documentation

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

Definition at line 14 of file TableOutputBranches.h.

References branch(), edm::BranchDescription::className(), defineBranchesFromFirstEvent(), fill(), and iEvent.

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

Member Function Documentation

void TableOutputBranches::branch ( TTree &  tree)

Definition at line 37 of file TableOutputBranches.cc.

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__(), fill(), and TableOutputBranches().

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

Definition at line 14 of file TableOutputBranches.cc.

References nanoaod::FlatTable::BoolColumn, nanoaod::FlatTable::columnDoc(), nanoaod::FlatTable::columnName(), nanoaod::FlatTable::columnType(), nanoaod::FlatTable::FloatColumn, mps_fire::i, nanoaod::FlatTable::IntColumn, m_baseName, m_floatBranches, m_intBranches, m_uint8Branches, nanoaod::FlatTable::name(), nanoaod::FlatTable::nColumns(), AlCaHLTBitMon_QueryRunRegistry::string, nanoaod::FlatTable::UInt8Column, and JetChargeProducer_cfi::var.

Referenced by fill(), and TableOutputBranches().

15 {
16  m_baseName=tab.name();
17  for(size_t i=0;i<tab.nColumns();i++){
18  const std::string & var=tab.columnName(i);
19  switch(tab.columnType(i)){
21  m_floatBranches.emplace_back(var, tab.columnDoc(i), "F");
22  break;
24  m_intBranches.emplace_back(var, tab.columnDoc(i), "I");
25  break;
27  m_uint8Branches.emplace_back(var, tab.columnDoc(i), "b");
28  break;
30  m_uint8Branches.emplace_back(var, tab.columnDoc(i), "O");
31  break;
32  }
33  }
34 }
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:45
std::vector< NamedBranchPtr > m_intBranches
std::vector< NamedBranchPtr > m_uint8Branches
const std::string & name() const
Definition: FlatTable.h:40
const std::string & columnName(unsigned int col) const
Definition: FlatTable.h:42
unsigned int nColumns() const
Definition: FlatTable.h:35
std::vector< NamedBranchPtr > m_floatBranches
const std::string & columnDoc(unsigned int col) const
Definition: FlatTable.h:49
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 64 of file TableOutputBranches.cc.

References branch(), defineBranchesFromFirstEvent(), nanoaod::FlatTable::doc(), DontKnowYetIfMainOrExtension, Exception, nanoaod::FlatTable::extension(), edm::OccurrenceForOutput::getByToken(), cmsBatch::handle, 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().

Referenced by TableOutputBranches().

65 {
67  if (extensions != m_extension) return; // do nothing, wait to be called with the proper flag
68  }
69 
71  iEvent.getByToken(m_token, handle);
72  const nanoaod::FlatTable & tab = *handle;
73  m_counter = tab.size();
74  m_singleton = tab.singleton();
75  if(!m_branchesBooked) {
77  if (extensions != m_extension) return; // do nothing, wait to be called with the proper flag
79  m_doc = tab.doc();
80  m_branchesBooked=true;
81  branch(tree);
82  }
83  if (!m_singleton && m_extension == IsExtension) {
84  if (m_counter != *reinterpret_cast<UInt_t *>(m_counterBranch->GetAddress())) {
85  throw cms::Exception("LogicError", "Mismatch in number of entries between extension and main table for " + tab.name());
86  }
87  }
88  for (auto & pair : m_floatBranches) fillColumn<float>(pair, tab);
89  for (auto & pair : m_intBranches) fillColumn<int>(pair, tab);
90  for (auto & pair : m_uint8Branches) fillColumn<uint8_t>(pair, tab);
91 }
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
bool extension() const
Definition: FlatTable.h:39
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
const std::string & doc() const
Definition: FlatTable.h:48
enum TableOutputBranches::@861 m_extension
std::vector< NamedBranchPtr > m_intBranches
std::vector< NamedBranchPtr > m_uint8Branches
const std::string & name() const
Definition: FlatTable.h:40
void branch(TTree &tree)
edm::EDGetToken m_token
unsigned int size() const
Definition: FlatTable.h:37
Definition: tree.py:1
bool singleton() const
Definition: FlatTable.h:38
std::vector< NamedBranchPtr > m_floatBranches
template<typename T >
void TableOutputBranches::fillColumn ( NamedBranchPtr pair,
const nanoaod::FlatTable tab 
)
inlineprivate

Definition at line 47 of file TableOutputBranches.h.

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

47  {
48  int idx = tab.columnIndex(pair.name);
49  if (idx == -1) throw cms::Exception("LogicError", "Missing column in input for "+m_baseName+"_"+pair.name);
50  pair.branch->SetAddress( const_cast<T *>(& tab.columnData<T>(idx).front() ) ); // SetAddress should take a const * !
51  }
boost::sub_range< const std::vector< T > > columnData(unsigned int column) const
get a column by index (const)
Definition: FlatTable.h:53
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
long double T

Member Data Documentation

std::string TableOutputBranches::m_baseName
private

Definition at line 29 of file TableOutputBranches.h.

Referenced by branch(), and defineBranchesFromFirstEvent().

bool TableOutputBranches::m_branchesBooked
private

Definition at line 44 of file TableOutputBranches.h.

Referenced by fill().

UInt_t TableOutputBranches::m_counter
private

Definition at line 33 of file TableOutputBranches.h.

Referenced by branch(), and fill().

TBranch* TableOutputBranches::m_counterBranch
private

Definition at line 40 of file TableOutputBranches.h.

Referenced by branch(), and fill().

std::string TableOutputBranches::m_doc
private

Definition at line 32 of file TableOutputBranches.h.

Referenced by branch(), and fill().

enum { ... } TableOutputBranches::m_extension

Referenced by branch(), and fill().

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

Definition at line 41 of file TableOutputBranches.h.

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

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

Definition at line 42 of file TableOutputBranches.h.

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

bool TableOutputBranches::m_singleton
private

Definition at line 30 of file TableOutputBranches.h.

Referenced by branch(), and fill().

edm::EDGetToken TableOutputBranches::m_token
private

Definition at line 28 of file TableOutputBranches.h.

Referenced by fill().

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

Definition at line 43 of file TableOutputBranches.h.

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