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,
  ColumnType::UInt32, ColumnType::Double, ColumnType::Int8
}
 

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) const
 get a column by index (const) More...
 
template<typename T >
auto columnData (unsigned int column)
 get a column by index (non-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) const
 
template<typename T >
auto beginData (unsigned int column)
 
template<typename T >
auto const & bigVector () const
 
template<typename T >
auto & bigVector ()
 

Static Private Member Functions

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

Private Attributes

std::vector< Columncolumns_
 
std::string doc_
 
std::vector< double > doubles_
 
bool extension_
 
std::vector< float > floats_
 
std::vector< int8_t > int8s_
 
std::vector< int > ints_
 
std::string name_
 
bool singleton_
 
unsigned int size_
 
std::vector< uint32_t > uint32s_
 
std::vector< uint8_t > uint8s_
 

Detailed Description

Definition at line 38 of file FlatTable.h.

Member Enumeration Documentation

◆ ColumnType

Enumerator
Float 
Int 
UInt8 
Bool 
UInt32 
Double 
Int8 

Definition at line 40 of file FlatTable.h.

40  {
41  Float,
42  Int,
43  UInt8,
44  Bool,
45  UInt32,
46  Double,
47  Int8
48  }; // We could have other Float types with reduced mantissa, and similar
int Bool
Definition: Types.h:100
unsigned int UInt32
Definition: Types.h:69
int Int
Definition: forwards.h:16

Constructor & Destructor Documentation

◆ FlatTable() [1/2]

nanoaod::FlatTable::FlatTable ( )
inline

Definition at line 50 of file FlatTable.h.

50 : size_(0) {}
unsigned int size_
Definition: FlatTable.h:209

◆ FlatTable() [2/2]

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

Definition at line 51 of file FlatTable.h.

unsigned int size_
Definition: FlatTable.h:209
bool extension() const
Definition: FlatTable.h:59
const std::string & name() const
Definition: FlatTable.h:60
std::string name_
Definition: FlatTable.h:210
bool singleton() const
Definition: FlatTable.h:58
unsigned int size() const
Definition: FlatTable.h:57

◆ ~FlatTable()

nanoaod::FlatTable::~FlatTable ( )
inline

Definition at line 53 of file FlatTable.h.

53 {}

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 113 of file FlatTable.h.

References columnIndex(), columns_, electrons_cff::docString, Exception, l1tHGCalConcentratorProducer_cfi::mantissaBits, name(), size(), and contentValuesCheck::values.

113  {
114  if (columnIndex(name) != -1)
115  throw cms::Exception("LogicError", "Duplicated column: " + name);
116  if (values.size() != size())
117  throw cms::Exception("LogicError", "Mismatched size for " + name);
118  auto &vec = bigVector<T>();
119  columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
120  vec.insert(vec.end(), values.begin(), values.end());
121  flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).bulk(columnData<T>(columns_.size() - 1));
122  }
std::vector< Column > columns_
Definition: FlatTable.h:212
const std::string & name() const
Definition: FlatTable.h:60
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
unsigned int size() const
Definition: FlatTable.h:57

◆ 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 125 of file FlatTable.h.

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

125  {
126  if (!singleton())
127  throw cms::Exception("LogicError", "addColumnValue works only for singleton tables");
128  if (columnIndex(name) != -1)
129  throw cms::Exception("LogicError", "Duplicated column: " + name);
130  auto &vec = bigVector<T>();
131  columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
132  vec.push_back(flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).one(value));
133  }
std::vector< Column > columns_
Definition: FlatTable.h:212
const std::string & name() const
Definition: FlatTable.h:60
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
Definition: value.py:1
bool singleton() const
Definition: FlatTable.h:58

◆ addExtension()

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

Definition at line 11 of file FlatTable.cc.

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

Referenced by NanoAODDQM::analyze().

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::Int8:
23  addColumn<int8_t>(other.columnName(i), other.columnData<int>(i), other.columnDoc(i));
24  break;
25  case ColumnType::Bool:
26  addColumn<bool>(other.columnName(i), other.columnData<bool>(i), other.columnDoc(i));
27  break;
28  case ColumnType::UInt8:
29  addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i));
30  break;
31  case ColumnType::UInt32:
32  addColumn<uint32_t>(other.columnName(i), other.columnData<uint32_t>(i), other.columnDoc(i));
33  break;
34  case ColumnType::Double:
35  addColumn<double>(other.columnName(i), other.columnData<double>(i), other.columnDoc(i));
36  break;
37  default:
38  throw cms::Exception("LogicError", "Unsupported type");
39  }
40  }
41 }
bool extension() const
Definition: FlatTable.h:59
const std::string & name() const
Definition: FlatTable.h:60
unsigned int size() const
Definition: FlatTable.h:57

◆ beginData() [1/2]

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

Definition at line 171 of file FlatTable.h.

References columns_.

171  {
172  return bigVector<T>().cbegin() + columns_[column].firstIndex;
173  }
std::vector< Column > columns_
Definition: FlatTable.h:212

◆ beginData() [2/2]

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

Definition at line 175 of file FlatTable.h.

References columns_.

175  {
176  return bigVector<T>().begin() + columns_[column].firstIndex;
177  }
std::vector< Column > columns_
Definition: FlatTable.h:212

◆ bigVector() [1/2]

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

Definition at line 180 of file FlatTable.h.

180  {
181  return bigVectorImpl<T>(*this);
182  }

◆ bigVector() [2/2]

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

Definition at line 184 of file FlatTable.h.

184  {
185  return bigVectorImpl<T>(*this);
186  }

◆ bigVectorImpl()

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

Definition at line 189 of file FlatTable.h.

References TableParser::table.

189  {
190  // helper function to avoid code duplication, for the two accessor functions that differ only in const-ness
191  if constexpr (std::is_same<T, float>())
193  else if constexpr (std::is_same<T, int>())
195  else if constexpr (std::is_same<T, uint8_t>())
197  else if constexpr (std::is_same<T, int8_t>())
199  else if constexpr (std::is_same<T, bool>())
201  else if constexpr (std::is_same<T, uint32_t>())
203  else if constexpr (std::is_same<T, double>())
205  else
206  static_assert(dependent_false<T>::value, "unsupported type");
207  }
std::vector< int > ints_
Definition: FlatTable.h:214
return((rh ^ lh) &mask)
std::vector< uint8_t > uint8s_
Definition: FlatTable.h:215
std::vector< uint32_t > uint32s_
Definition: FlatTable.h:217
std::vector< float > floats_
Definition: FlatTable.h:213
Definition: value.py:1
std::vector< int8_t > int8s_
Definition: FlatTable.h:216
std::vector< double > doubles_
Definition: FlatTable.h:218
long double T

◆ columnData() [1/2]

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

get a column by index (const)

Definition at line 73 of file FlatTable.h.

References size_.

Referenced by LumiOutputBranches::fillColumn(), and TableOutputBranches::fillColumn().

73  {
74  auto begin = beginData<T>(column);
75  return edm::Span(begin, begin + size_);
76  }
unsigned int size_
Definition: FlatTable.h:209
Definition: Span.h:16

◆ columnData() [2/2]

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

get a column by index (non-const)

Definition at line 80 of file FlatTable.h.

References size_.

80  {
81  auto begin = beginData<T>(column);
82  return edm::Span(begin, begin + size_);
83  }
unsigned int size_
Definition: FlatTable.h:209
Definition: Span.h:16

◆ columnDoc()

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

Definition at line 69 of file FlatTable.h.

References cuy::col, and columns_.

Referenced by LumiOutputBranches::defineBranchesFromFirstEvent(), and TableOutputBranches::defineBranchesFromFirstEvent().

69 { return columns_[col].doc; }
std::vector< Column > columns_
Definition: FlatTable.h:212
col
Definition: cuy.py:1009

◆ columnIndex()

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

Definition at line 3 of file FlatTable.cc.

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

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

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 }
std::vector< Column > columns_
Definition: FlatTable.h:212
const std::string & name() const
Definition: FlatTable.h:60

◆ columnName()

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

Definition at line 62 of file FlatTable.h.

References cuy::col, and columns_.

Referenced by LumiOutputBranches::defineBranchesFromFirstEvent(), and TableOutputBranches::defineBranchesFromFirstEvent().

62 { return columns_[col].name; }
std::vector< Column > columns_
Definition: FlatTable.h:212
col
Definition: cuy.py:1009

◆ columnType()

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

Definition at line 65 of file FlatTable.h.

References cuy::col, and columns_.

Referenced by LumiOutputBranches::defineBranchesFromFirstEvent(), and TableOutputBranches::defineBranchesFromFirstEvent().

65 { return columns_[col].type; }
std::vector< Column > columns_
Definition: FlatTable.h:212
col
Definition: cuy.py:1009

◆ columValue()

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

get a column value for singleton (const)

Definition at line 87 of file FlatTable.h.

References Exception, and singleton().

87  {
88  if (!singleton())
89  throw cms::Exception("LogicError", "columnValue works only for singleton tables");
90  return *beginData<T>(column);
91  }
bool singleton() const
Definition: FlatTable.h:58

◆ defaultColumnType()

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

Definition at line 140 of file FlatTable.h.

References Bool, Double, Float, Int, Int8, UInt32, and UInt8.

140  {
141  if constexpr (std::is_same<T, float>())
142  return ColumnType::Float;
143  else if constexpr (std::is_same<T, int>())
145  else if constexpr (std::is_same<T, uint8_t>())
146  return ColumnType::UInt8;
147  else if constexpr (std::is_same<T, int8_t>())
148  return ColumnType::Int8;
149  else if constexpr (std::is_same<T, bool>())
151  else if constexpr (std::is_same<T, uint32_t>())
153  else if constexpr (std::is_same<T, double>())
154  return ColumnType::Double;
155  else
156  static_assert(dependent_false<T>::value, "unsupported type");
157  }
return((rh ^ lh) &mask)
int Bool
Definition: Types.h:100
unsigned int UInt32
Definition: Types.h:69
Definition: value.py:1
int Int
Definition: forwards.h:16
long double T

◆ doc()

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

Definition at line 68 of file FlatTable.h.

References doc_.

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

68 { return doc_; }
std::string doc_
Definition: FlatTable.h:210

◆ extension()

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

Definition at line 59 of file FlatTable.h.

References extension_.

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

59 { return extension_; }

◆ getAnyValue()

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

Definition at line 43 of file FlatTable.cc.

References Exception.

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

43  {
44  if (column >= nColumns())
45  throw cms::Exception("LogicError", "Invalid column");
46  switch (columnType(column)) {
47  case ColumnType::Float:
48  return *(beginData<float>(column) + row);
49  case ColumnType::Int:
50  return *(beginData<int>(column) + row);
51  case ColumnType::Int8:
52  return *(beginData<int8_t>(column) + row);
53  case ColumnType::Bool:
54  return *(beginData<bool>(column) + row);
55  case ColumnType::UInt8:
56  return *(beginData<uint8_t>(column) + row);
57  case ColumnType::UInt32:
58  return *(beginData<uint32_t>(column) + row);
59  case ColumnType::Double:
60  return *(beginData<double>(column) + row);
61  }
62  throw cms::Exception("LogicError", "Unsupported type");
63 }
RowView row(unsigned int row) const
Definition: FlatTable.h:110
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:65
unsigned int nColumns() const
Definition: FlatTable.h:55

◆ name()

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

◆ nColumns()

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

Definition at line 55 of file FlatTable.h.

References columns_.

Referenced by LumiOutputBranches::defineBranchesFromFirstEvent(), and TableOutputBranches::defineBranchesFromFirstEvent().

55 { return columns_.size(); };
std::vector< Column > columns_
Definition: FlatTable.h:212

◆ nRows()

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

Definition at line 56 of file FlatTable.h.

References size_.

56 { return size_; };
unsigned int size_
Definition: FlatTable.h:209

◆ row()

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

Definition at line 110 of file FlatTable.h.

110 { return RowView(*this, row); }
RowView row(unsigned int row) const
Definition: FlatTable.h:110

◆ setDoc()

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

Definition at line 67 of file FlatTable.h.

References doc(), and doc_.

67 { doc_ = doc; }
const std::string & doc() const
Definition: FlatTable.h:68
std::string doc_
Definition: FlatTable.h:210

◆ singleton()

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

Definition at line 58 of file FlatTable.h.

References singleton_.

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

58 { return singleton_; }

◆ 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 210 of file FlatTable.h.

Referenced by doc(), and setDoc().

◆ doubles_

std::vector<double> nanoaod::FlatTable::doubles_
private

Definition at line 218 of file FlatTable.h.

◆ extension_

bool nanoaod::FlatTable::extension_
private

Definition at line 211 of file FlatTable.h.

Referenced by extension().

◆ floats_

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

Definition at line 213 of file FlatTable.h.

◆ int8s_

std::vector<int8_t> nanoaod::FlatTable::int8s_
private

Definition at line 216 of file FlatTable.h.

◆ ints_

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

Definition at line 214 of file FlatTable.h.

◆ name_

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

Definition at line 210 of file FlatTable.h.

Referenced by name().

◆ singleton_

bool nanoaod::FlatTable::singleton_
private

Definition at line 211 of file FlatTable.h.

Referenced by singleton().

◆ size_

unsigned int nanoaod::FlatTable::size_
private

Definition at line 209 of file FlatTable.h.

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

◆ uint32s_

std::vector<uint32_t> nanoaod::FlatTable::uint32s_
private

Definition at line 217 of file FlatTable.h.

◆ uint8s_

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

Definition at line 215 of file FlatTable.h.