CMS 3D CMS Logo

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

#include <LumiOutputBranches.h>

Classes

struct  NamedBranchPtr
 

Public Member Functions

void branch (TTree &tree)
 
void defineBranchesFromFirstEvent (const nanoaod::FlatTable &tab)
 
void fill (const edm::LuminosityBlockForOutput &iLumi, TTree &tree, bool extensions)
 
 LumiOutputBranches (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
 
std::string m_doc
 
enum LumiOutputBranches:: { ... }  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 LumiOutputBranches.h.

Member Typedef Documentation

◆ CounterType

typedef Int_t LumiOutputBranches::CounterType
private

Definition at line 38 of file LumiOutputBranches.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
IsMain 
IsExtension 
DontKnowYetIfMainOrExtension 

Definition at line 36 of file LumiOutputBranches.h.

Constructor & Destructor Documentation

◆ LumiOutputBranches()

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

Definition at line 14 of file LumiOutputBranches.h.

References submitPVResolutionJobs::desc.

15  : m_token(token),
16  m_singleton(false),
18  m_counter(0),
19  m_counterBranch(nullptr),
20  m_branchesBooked(false) {
21  if (desc->className() != "nanoaod::FlatTable")
22  throw cms::Exception("Configuration", "NanoAODOutputModule can only write out nanoaod::FlatTable objects");
23  }
enum LumiOutputBranches::@879 m_extension
edm::EDGetToken m_token

Member Function Documentation

◆ branch()

void LumiOutputBranches::branch ( TTree &  tree)

Definition at line 34 of file LumiOutputBranches.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__(), and fill().

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

◆ defineBranchesFromFirstEvent()

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

Definition at line 11 of file LumiOutputBranches.cc.

References nanoaod::FlatTable::Bool, nanoaod::FlatTable::columnDoc(), nanoaod::FlatTable::columnName(), nanoaod::FlatTable::columnType(), Exception, nanoaod::FlatTable::Float, mps_fire::i, nanoaod::FlatTable::Int32, m_baseName, m_floatBranches, m_intBranches, m_uint8Branches, nanoaod::FlatTable::name(), nanoaod::FlatTable::nColumns(), AlCaHLTBitMon_QueryRunRegistry::string, nanoaod::FlatTable::UInt8, and trigObjTnPSource_cfi::var.

Referenced by fill().

11  {
12  m_baseName = tab.name();
13  for (size_t i = 0; i < tab.nColumns(); i++) {
14  const std::string &var = tab.columnName(i);
15  switch (tab.columnType(i)) {
17  m_floatBranches.emplace_back(var, tab.columnDoc(i), "F");
18  break;
20  m_intBranches.emplace_back(var, tab.columnDoc(i), "I");
21  break;
23  m_uint8Branches.emplace_back(var, tab.columnDoc(i), "b");
24  break;
26  m_uint8Branches.emplace_back(var, tab.columnDoc(i), "O");
27  break;
28  default:
29  throw cms::Exception("LogicError", "Unsupported type");
30  }
31  }
32 }
const std::string & columnName(unsigned int col) const
Definition: FlatTable.h:64
std::vector< NamedBranchPtr > m_floatBranches
std::vector< NamedBranchPtr > m_uint8Branches
const std::string & name() const
Definition: FlatTable.h:62
std::vector< NamedBranchPtr > m_intBranches
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

◆ fill()

void LumiOutputBranches::fill ( const edm::LuminosityBlockForOutput iLumi,
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 62 of file LumiOutputBranches.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_extension, m_floatBranches, m_intBranches, m_singleton, m_token, m_uint8Branches, SiStripPI::max, nanoaod::FlatTable::name(), nanoaod::FlatTable::singleton(), nanoaod::FlatTable::size(), findQualityFiles::size, and to_string().

62  {
64  if (extensions != m_extension)
65  return; // do nothing, wait to be called with the proper flag
66  }
67 
69  iLumi.getByToken(m_token, handle);
70  const nanoaod::FlatTable &tab = *handle;
71  auto size = tab.size();
72  // ROOT native array size branches may only be signed integers,
73  // until this is changed we need to make sure the vector sizes do not exceed that
75  throw cms::Exception("Table " + tab.name() + " size is " + std::to_string(size) +
76  ", is too large for ROOT native array branch");
77  }
78  m_counter = size;
79  m_singleton = tab.singleton();
80  if (!m_branchesBooked) {
82  if (extensions != m_extension)
83  return; // do nothing, wait to be called with the proper flag
85  m_doc = tab.doc();
86  m_branchesBooked = true;
87  branch(tree);
88  }
89  if (!m_singleton && m_extension == IsExtension) {
90  if (m_counter != *reinterpret_cast<CounterType *>(m_counterBranch->GetAddress())) {
91  throw cms::Exception("LogicError",
92  "Mismatch in number of entries between extension and main table for " + tab.name());
93  }
94  }
95  for (auto &pair : m_floatBranches)
96  fillColumn<float>(pair, tab);
97  for (auto &pair : m_intBranches)
98  fillColumn<int>(pair, tab);
99  for (auto &pair : m_uint8Branches)
100  fillColumn<uint8_t>(pair, tab);
101 }
size
Write out results.
void defineBranchesFromFirstEvent(const nanoaod::FlatTable &tab)
std::vector< NamedBranchPtr > m_floatBranches
bool extension() const
Definition: FlatTable.h:61
BasicHandle getByToken(EDGetToken token, TypeID const &typeID) const
std::vector< NamedBranchPtr > m_uint8Branches
const std::string & name() const
Definition: FlatTable.h:62
static std::string to_string(const XMLCh *ch)
enum LumiOutputBranches::@879 m_extension
const std::string & doc() const
Definition: FlatTable.h:70
std::vector< NamedBranchPtr > m_intBranches
edm::EDGetToken m_token
void branch(TTree &tree)
bool singleton() const
Definition: FlatTable.h:60
Definition: tree.py:1
unsigned int size() const
Definition: FlatTable.h:59

◆ fillColumn()

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

Definition at line 56 of file LumiOutputBranches.h.

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

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(const_cast<T *>(&tab.columnData<T>(idx).front())); // SetAddress should take a const * !
61  }
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

Member Data Documentation

◆ m_baseName

std::string LumiOutputBranches::m_baseName
private

Definition at line 34 of file LumiOutputBranches.h.

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

◆ m_branchesBooked

bool LumiOutputBranches::m_branchesBooked
private

Definition at line 53 of file LumiOutputBranches.h.

Referenced by fill().

◆ m_counter

CounterType LumiOutputBranches::m_counter
private

Definition at line 39 of file LumiOutputBranches.h.

Referenced by branch(), and fill().

◆ m_counterBranch

TBranch* LumiOutputBranches::m_counterBranch
private

Definition at line 49 of file LumiOutputBranches.h.

Referenced by branch(), and fill().

◆ m_doc

std::string LumiOutputBranches::m_doc
private

Definition at line 37 of file LumiOutputBranches.h.

Referenced by branch(), and fill().

◆ m_extension

enum { ... } LumiOutputBranches::m_extension

Referenced by branch(), and fill().

◆ m_floatBranches

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

Definition at line 50 of file LumiOutputBranches.h.

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

◆ m_intBranches

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

Definition at line 51 of file LumiOutputBranches.h.

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

◆ m_singleton

bool LumiOutputBranches::m_singleton
private

Definition at line 35 of file LumiOutputBranches.h.

Referenced by branch(), and fill().

◆ m_token

edm::EDGetToken LumiOutputBranches::m_token
private

Definition at line 33 of file LumiOutputBranches.h.

Referenced by fill().

◆ m_uint8Branches

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

Definition at line 52 of file LumiOutputBranches.h.

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