CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
nanoaod::FlatTable Class Reference

#include <FlatTable.h>

Classes

struct  Column
 
struct  dependent_false
 
class  RowView
 

Public Types

enum  ColumnType { ColumnType::Float, ColumnType::Int, ColumnType::UInt8, ColumnType::Bool }
 

Public Member Functions

template<typename T , typename C >
void addColumn (const std::string &name, const C &values, const std::string &docString, int mantissaBits=-1)
 
template<typename T , typename C >
void addColumnValue (const std::string &name, const C &value, const std::string &docString, int mantissaBits=-1)
 
void addExtension (const FlatTable &extension)
 
template<typename T >
auto columnData (unsigned int column)
 get a column by index (non-const) More...
 
template<typename T >
auto columnData (unsigned int column) const
 get a column by index (const) More...
 
const std::string & columnDoc (unsigned int col) const
 
int columnIndex (const std::string &name) const
 
const std::string & columnName (unsigned int col) const
 
ColumnType columnType (unsigned int col) const
 
template<typename T >
const auto & columValue (unsigned int column) const
 get a column value for singleton (const) More...
 
const std::string & doc () const
 
bool extension () const
 
 FlatTable ()
 
 FlatTable (unsigned int size, const std::string &name, bool singleton, bool extension=false)
 
double getAnyValue (unsigned int row, unsigned int column) const
 
const std::string & name () const
 
unsigned int nColumns () const
 
unsigned int nRows () const
 
RowView row (unsigned int row) const
 
void setDoc (const std::string &doc)
 
bool singleton () const
 
unsigned int size () const
 
 ~FlatTable ()
 

Static Public Member Functions

template<typename T >
static ColumnType defaultColumnType ()
 

Private Member Functions

template<typename T >
auto beginData (unsigned int column)
 
template<typename T >
auto beginData (unsigned int column) const
 
template<typename T >
auto & bigVector ()
 
template<typename T >
const auto & bigVector () const
 

Static Private Member Functions

template<typename T , class This >
static auto & bigVectorImpl (This &table)
 

Private Attributes

std::vector< Columncolumns_
 
std::string doc_
 
bool extension_
 
std::vector< float > floats_
 
std::vector< int > ints_
 
std::string name_
 
bool singleton_
 
unsigned int size_
 
std::vector< uint8_t > uint8s_
 

Detailed Description

Definition at line 38 of file FlatTable.h.

Member Enumeration Documentation

◆ ColumnType

Enumerator
Float 
Int 
UInt8 
Bool 

Definition at line 40 of file FlatTable.h.

40  {
41  Float,
42  Int,
43  UInt8,
44  Bool
45  }; // We could have other Float types with reduced mantissa, and similar

Constructor & Destructor Documentation

◆ FlatTable() [1/2]

nanoaod::FlatTable::FlatTable ( )
inline

Definition at line 47 of file FlatTable.h.

47 : size_(0) {}

◆ FlatTable() [2/2]

nanoaod::FlatTable::FlatTable ( unsigned int  size,
const std::string &  name,
bool  singleton,
bool  extension = false 
)
inline

Definition at line 48 of file FlatTable.h.

◆ ~FlatTable()

nanoaod::FlatTable::~FlatTable ( )
inline

Definition at line 50 of file FlatTable.h.

50 {}

Member Function Documentation

◆ addColumn()

template<typename T , typename C >
void nanoaod::FlatTable::addColumn ( const std::string &  name,
const C &  values,
const std::string &  docString,
int  mantissaBits = -1 
)
inline

Definition at line 110 of file FlatTable.h.

110  {
111  if (columnIndex(name) != -1)
112  throw cms::Exception("LogicError", "Duplicated column: " + name);
113  if (values.size() != size())
114  throw cms::Exception("LogicError", "Mismatched size for " + name);
115  auto &vec = bigVector<T>();
116  columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
117  vec.insert(vec.end(), values.begin(), values.end());
118  flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).bulk(columnData<T>(columns_.size() - 1));
119  }

References nanoaod::flatTableHelper::MaybeMantissaReduce< T >::bulk(), columnIndex(), columns_, electrons_cff::docString, Exception, hgcalConcentratorProducer_cfi::mantissaBits, name(), size(), and contentValuesCheck::values.

◆ addColumnValue()

template<typename T , typename C >
void nanoaod::FlatTable::addColumnValue ( const std::string &  name,
const C &  value,
const std::string &  docString,
int  mantissaBits = -1 
)
inline

Definition at line 122 of file FlatTable.h.

122  {
123  if (!singleton())
124  throw cms::Exception("LogicError", "addColumnValue works only for singleton tables");
125  if (columnIndex(name) != -1)
126  throw cms::Exception("LogicError", "Duplicated column: " + name);
127  auto &vec = bigVector<T>();
128  columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
129  vec.push_back(flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).one(value));
130  }

References columnIndex(), columns_, electrons_cff::docString, Exception, hgcalConcentratorProducer_cfi::mantissaBits, name(), SiPixelPI::one, and singleton().

◆ addExtension()

void nanoaod::FlatTable::addExtension ( const FlatTable extension)

Definition at line 11 of file FlatTable.cc.

11  {
12  if (extension() || !other.extension() || name() != other.name() || size() != other.size())
13  throw cms::Exception("LogicError", "Mismatch in adding extension");
14  for (unsigned int i = 0, n = other.nColumns(); i < n; ++i) {
15  switch (other.columnType(i)) {
16  case ColumnType::Float:
17  addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i));
18  break;
19  case ColumnType::Int:
20  addColumn<int>(other.columnName(i), other.columnData<int>(i), other.columnDoc(i));
21  break;
22  case ColumnType::Bool:
23  addColumn<bool>(other.columnName(i), other.columnData<bool>(i), other.columnDoc(i));
24  break;
25  case ColumnType::UInt8:
26  addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i));
27  break;
28  default:
29  throw cms::Exception("LogicError", "Unsupported type");
30  }
31  }
32 }

References Exception, runGCPTkAlMap::extension, mps_fire::i, dqmiodumpmetadata::n, Skims_PA_cff::name, trackingPlots::other, and findQualityFiles::size.

Referenced by NanoAODDQM::analyze().

◆ beginData() [1/2]

template<typename T >
auto nanoaod::FlatTable::beginData ( unsigned int  column)
inlineprivate

Definition at line 166 of file FlatTable.h.

166  {
167  return bigVector<T>().begin() + columns_[column].firstIndex;
168  }

References columns_.

◆ beginData() [2/2]

template<typename T >
auto nanoaod::FlatTable::beginData ( unsigned int  column) const
inlineprivate

Definition at line 162 of file FlatTable.h.

162  {
163  return bigVector<T>().cbegin() + columns_[column].firstIndex;
164  }

References columns_.

◆ bigVector() [1/2]

template<typename T >
auto& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 175 of file FlatTable.h.

175  {
176  return bigVectorImpl<T>(*this);
177  }

◆ bigVector() [2/2]

template<typename T >
const auto& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 171 of file FlatTable.h.

171  {
172  return bigVectorImpl<T>(*this);
173  }

◆ bigVectorImpl()

template<typename T , class This >
static auto& nanoaod::FlatTable::bigVectorImpl ( This &  table)
inlinestaticprivate

Definition at line 180 of file FlatTable.h.

180  {
181  // helper function to avoid code duplication, for the two accessor functions that differ only in const-ness
182  if constexpr (std::is_same<T, float>())
184  else if constexpr (std::is_same<T, int>())
186  else if constexpr (std::is_same<T, uint8_t>())
188  else if constexpr (std::is_same<T, bool>())
190  else
191  static_assert(dependent_false<T>::value, "unsupported type");
192  }

References TableParser::table.

◆ columnData() [1/2]

template<typename T >
auto nanoaod::FlatTable::columnData ( unsigned int  column)
inline

get a column by index (non-const)

Definition at line 77 of file FlatTable.h.

77  {
78  auto begin = beginData<T>(column);
79  return edm::Span(begin, begin + size_);
80  }

References size_.

◆ columnData() [2/2]

template<typename T >
auto nanoaod::FlatTable::columnData ( unsigned int  column) const
inline

get a column by index (const)

Definition at line 70 of file FlatTable.h.

70  {
71  auto begin = beginData<T>(column);
72  return edm::Span(begin, begin + size_);
73  }

References size_.

Referenced by TableOutputBranches::fillColumn().

◆ columnDoc()

const std::string& nanoaod::FlatTable::columnDoc ( unsigned int  col) const
inline

Definition at line 66 of file FlatTable.h.

66 { return columns_[col].doc; }

References cuy::col, and columns_.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

◆ columnIndex()

int nanoaod::FlatTable::columnIndex ( const std::string &  name) const

Definition at line 3 of file FlatTable.cc.

3  {
4  for (unsigned int i = 0, n = columns_.size(); i < n; ++i) {
5  if (columns_[i].name == name)
6  return i;
7  }
8  return -1;
9 }

References columns_, mps_fire::i, dqmiodumpmetadata::n, and name().

Referenced by addColumn(), addColumnValue(), TableOutputBranches::fillColumn(), and nanoaod::FlatTable::RowView::getAnyValue().

◆ columnName()

const std::string& nanoaod::FlatTable::columnName ( unsigned int  col) const
inline

Definition at line 59 of file FlatTable.h.

59 { return columns_[col].name; }

References cuy::col, and columns_.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

◆ columnType()

ColumnType nanoaod::FlatTable::columnType ( unsigned int  col) const
inline

Definition at line 62 of file FlatTable.h.

62 { return columns_[col].type; }

References cuy::col, and columns_.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

◆ columValue()

template<typename T >
const auto& nanoaod::FlatTable::columValue ( unsigned int  column) const
inline

get a column value for singleton (const)

Definition at line 84 of file FlatTable.h.

84  {
85  if (!singleton())
86  throw cms::Exception("LogicError", "columnValue works only for singleton tables");
87  return *beginData<T>(column);
88  }

References Exception, and singleton().

◆ defaultColumnType()

template<typename T >
static ColumnType nanoaod::FlatTable::defaultColumnType ( )
inlinestatic

Definition at line 137 of file FlatTable.h.

137  {
138  if constexpr (std::is_same<T, float>())
139  return ColumnType::Float;
140  else if constexpr (std::is_same<T, int>())
142  else if constexpr (std::is_same<T, uint8_t>())
143  return ColumnType::UInt8;
144  else if constexpr (std::is_same<T, bool>())
146  else
147  static_assert(dependent_false<T>::value, "unsupported type");
148  }

References Bool, Float, Int, and UInt8.

◆ doc()

const std::string& nanoaod::FlatTable::doc ( ) const
inline

Definition at line 65 of file FlatTable.h.

65 { return doc_; }

References doc_.

Referenced by TableOutputBranches::fill(), and setDoc().

◆ extension()

bool nanoaod::FlatTable::extension ( ) const
inline

Definition at line 56 of file FlatTable.h.

56 { return extension_; }

References extension_.

Referenced by TableOutputBranches::fill().

◆ getAnyValue()

double nanoaod::FlatTable::getAnyValue ( unsigned int  row,
unsigned int  column 
) const

Definition at line 34 of file FlatTable.cc.

34  {
35  if (column >= nColumns())
36  throw cms::Exception("LogicError", "Invalid column");
37  switch (columnType(column)) {
38  case ColumnType::Float:
39  return *(beginData<float>(column) + row);
40  case ColumnType::Int:
41  return *(beginData<int>(column) + row);
42  case ColumnType::Bool:
43  return *(beginData<bool>(column) + row);
44  case ColumnType::UInt8:
45  return *(beginData<uint8_t>(column) + row);
46  }
47  throw cms::Exception("LogicError", "Unsupported type");
48 }

References Exception.

Referenced by nanoaod::FlatTable::RowView::getAnyValue().

◆ name()

const std::string& nanoaod::FlatTable::name ( ) const
inline

◆ nColumns()

unsigned int nanoaod::FlatTable::nColumns ( ) const
inline

Definition at line 52 of file FlatTable.h.

52 { return columns_.size(); };

References columns_.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

◆ nRows()

unsigned int nanoaod::FlatTable::nRows ( ) const
inline

Definition at line 53 of file FlatTable.h.

53 { return size_; };

References size_.

◆ row()

RowView nanoaod::FlatTable::row ( unsigned int  row) const
inline

Definition at line 107 of file FlatTable.h.

107 { return RowView(*this, row); }

◆ setDoc()

void nanoaod::FlatTable::setDoc ( const std::string &  doc)
inline

Definition at line 64 of file FlatTable.h.

64 { doc_ = doc; }

References doc(), and doc_.

◆ singleton()

bool nanoaod::FlatTable::singleton ( ) const
inline

Definition at line 55 of file FlatTable.h.

55 { return singleton_; }

References singleton_.

Referenced by addColumnValue(), columValue(), and TableOutputBranches::fill().

◆ size()

unsigned int nanoaod::FlatTable::size ( void  ) const
inline

Member Data Documentation

◆ columns_

std::vector<Column> nanoaod::FlatTable::columns_
private

◆ doc_

std::string nanoaod::FlatTable::doc_
private

Definition at line 195 of file FlatTable.h.

Referenced by doc(), and setDoc().

◆ extension_

bool nanoaod::FlatTable::extension_
private

Definition at line 196 of file FlatTable.h.

Referenced by extension().

◆ floats_

std::vector<float> nanoaod::FlatTable::floats_
private

Definition at line 198 of file FlatTable.h.

◆ ints_

std::vector<int> nanoaod::FlatTable::ints_
private

Definition at line 199 of file FlatTable.h.

◆ name_

std::string nanoaod::FlatTable::name_
private

Definition at line 195 of file FlatTable.h.

Referenced by name().

◆ singleton_

bool nanoaod::FlatTable::singleton_
private

Definition at line 196 of file FlatTable.h.

Referenced by singleton().

◆ size_

unsigned int nanoaod::FlatTable::size_
private

Definition at line 194 of file FlatTable.h.

Referenced by columnData(), nRows(), and size().

◆ uint8s_

std::vector<uint8_t> nanoaod::FlatTable::uint8s_
private

Definition at line 200 of file FlatTable.h.

nanoaod::FlatTable::ColumnType::Float
nanoaod::FlatTable::ints_
std::vector< int > ints_
Definition: FlatTable.h:199
mps_fire.i
i
Definition: mps_fire.py:428
SiPixelPI::one
Definition: SiPixelPayloadInspectorHelper.h:39
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
nanoaod::FlatTable::singleton_
bool singleton_
Definition: FlatTable.h:196
nanoaod::FlatTable::singleton
bool singleton() const
Definition: FlatTable.h:55
cuy.col
col
Definition: cuy.py:1010
Bool
int Bool
Definition: Types.h:100
hgcalConcentratorProducer_cfi.mantissaBits
mantissaBits
Definition: hgcalConcentratorProducer_cfi.py:67
mathSSE::return
return((rh ^ lh) &mask)
nanoaod::FlatTable::doc_
std::string doc_
Definition: FlatTable.h:195
nanoaod::FlatTable::row
RowView row(unsigned int row) const
Definition: FlatTable.h:107
nanoaod::FlatTable::doc
const std::string & doc() const
Definition: FlatTable.h:65
nanoaod::FlatTable::ColumnType
ColumnType
Definition: FlatTable.h:40
electrons_cff.docString
docString
Definition: electrons_cff.py:516
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
trackingPlots.other
other
Definition: trackingPlots.py:1467
nanoaod::FlatTable::ColumnType::UInt8
nanoaod::FlatTable::columnType
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:62
nanoaod::FlatTable::extension
bool extension() const
Definition: FlatTable.h:56
nanoaod::FlatTable::columnIndex
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
nanoaod::FlatTable::uint8s_
std::vector< uint8_t > uint8s_
Definition: FlatTable.h:200
Json::Int
int Int
Definition: forwards.h:16
nanoaod::FlatTable::size_
unsigned int size_
Definition: FlatTable.h:194
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
RowView
value
Definition: value.py:1
nanoaod::FlatTable::columns_
std::vector< Column > columns_
Definition: FlatTable.h:197
nanoaod::FlatTable::name
const std::string & name() const
Definition: FlatTable.h:57
nanoaod::FlatTable::name_
std::string name_
Definition: FlatTable.h:195
nanoaod::FlatTable::ColumnType::Int
nanoaod::FlatTable::floats_
std::vector< float > floats_
Definition: FlatTable.h:198
std
Definition: JetResolutionObject.h:76
nanoaod::FlatTable::nColumns
unsigned int nColumns() const
Definition: FlatTable.h:52
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:246
nanoaod::FlatTable::extension_
bool extension_
Definition: FlatTable.h:196
cms::Exception
Definition: Exception.h:70
TableParser.table
table
Definition: TableParser.py:111
nanoaod::FlatTable::ColumnType::Bool
edm::Span
Definition: Span.h:16
nanoaod::FlatTable::size
unsigned int size() const
Definition: FlatTable.h:54