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::Int8, ColumnType::UInt8, ColumnType::Int16, ColumnType::UInt16,
  ColumnType::Int32, ColumnType::UInt32, ColumnType::Bool, ColumnType::Float,
  ColumnType::Double
}
 

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< int16_t > int16s_
 
std::vector< int32_t > int32s_
 
std::vector< int8_t > int8s_
 
std::string name_
 
bool singleton_
 
unsigned int size_
 
std::vector< uint16_t > uint16s_
 
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
Int8 
UInt8 
Int16 
UInt16 
Int32 
UInt32 
Bool 
Float 
Double 

Definition at line 40 of file FlatTable.h.

40  {
41  Int8,
42  UInt8,
43  Int16,
44  UInt16,
45  Int32,
46  UInt32,
47  Bool,
48  Float,
49  Double,
50  }; // We could have other Float types with reduced mantissa, and similar
int Bool
Definition: Types.h:100
unsigned int UInt32
Definition: Types.h:69
unsigned short UInt16
Definition: Types.h:62
short Int16
Definition: Types.h:61
int Int32
Definition: Types.h:68

Constructor & Destructor Documentation

◆ FlatTable() [1/2]

nanoaod::FlatTable::FlatTable ( )
inline

Definition at line 52 of file FlatTable.h.

52 : size_(0) {}
unsigned int size_
Definition: FlatTable.h:219

◆ FlatTable() [2/2]

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

Definition at line 53 of file FlatTable.h.

unsigned int size_
Definition: FlatTable.h:219
bool extension() const
Definition: FlatTable.h:61
const std::string & name() const
Definition: FlatTable.h:62
std::string name_
Definition: FlatTable.h:220
bool singleton() const
Definition: FlatTable.h:60
unsigned int size() const
Definition: FlatTable.h:59

◆ ~FlatTable()

nanoaod::FlatTable::~FlatTable ( )
inline

Definition at line 55 of file FlatTable.h.

55 {}

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

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

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

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

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

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

◆ 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::Int8:
17  addColumn<int8_t>(other.columnName(i), other.columnData<int8_t>(i), other.columnDoc(i));
18  break;
19  case ColumnType::UInt8:
20  addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i));
21  break;
22  case ColumnType::Int16:
23  addColumn<int16_t>(other.columnName(i), other.columnData<int16_t>(i), other.columnDoc(i));
24  break;
25  case ColumnType::UInt16:
26  addColumn<uint16_t>(other.columnName(i), other.columnData<uint16_t>(i), other.columnDoc(i));
27  break;
28  case ColumnType::Int32:
29  addColumn<int32_t>(other.columnName(i), other.columnData<int32_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::Bool:
35  addColumn<bool>(other.columnName(i), other.columnData<bool>(i), other.columnDoc(i));
36  break;
37  case ColumnType::Float:
38  addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i));
39  break;
40  case ColumnType::Double:
41  addColumn<double>(other.columnName(i), other.columnData<double>(i), other.columnDoc(i));
42  break;
43  default:
44  throw cms::Exception("LogicError", "Unsupported type");
45  }
46  }
47 }
bool extension() const
Definition: FlatTable.h:61
const std::string & name() const
Definition: FlatTable.h:62
unsigned int size() const
Definition: FlatTable.h:59

◆ beginData() [1/2]

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

Definition at line 177 of file FlatTable.h.

References columns_.

177  {
178  return bigVector<T>().cbegin() + columns_[column].firstIndex;
179  }
std::vector< Column > columns_
Definition: FlatTable.h:222

◆ beginData() [2/2]

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

Definition at line 181 of file FlatTable.h.

References columns_.

181  {
182  return bigVector<T>().begin() + columns_[column].firstIndex;
183  }
std::vector< Column > columns_
Definition: FlatTable.h:222

◆ bigVector() [1/2]

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

Definition at line 186 of file FlatTable.h.

186  {
187  return bigVectorImpl<T>(*this);
188  }

◆ bigVector() [2/2]

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

Definition at line 190 of file FlatTable.h.

190  {
191  return bigVectorImpl<T>(*this);
192  }

◆ bigVectorImpl()

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

Definition at line 195 of file FlatTable.h.

References TableParser::table.

195  {
196  // helper function to avoid code duplication, for the two accessor functions that differ only in const-ness
197  if constexpr (std::is_same<T, int8_t>())
199  else if constexpr (std::is_same<T, uint8_t>())
201  else if constexpr (std::is_same<T, int16_t>())
203  else if constexpr (std::is_same<T, uint16_t>())
205  else if constexpr (std::is_same<T, int32_t>())
207  else if constexpr (std::is_same<T, uint32_t>())
209  else if constexpr (std::is_same<T, bool>())
210  return table.uint8s_; // special case: bool stored as vector of uint8
211  else if constexpr (std::is_same<T, float>())
213  else if constexpr (std::is_same<T, double>())
215  else
216  static_assert(dependent_false<T>::value, "unsupported type");
217  }
return((rh ^ lh) &mask)
std::vector< uint8_t > uint8s_
Definition: FlatTable.h:224
std::vector< int16_t > int16s_
Definition: FlatTable.h:225
std::vector< uint32_t > uint32s_
Definition: FlatTable.h:228
std::vector< float > floats_
Definition: FlatTable.h:229
std::vector< int32_t > int32s_
Definition: FlatTable.h:227
std::vector< uint16_t > uint16s_
Definition: FlatTable.h:226
Definition: value.py:1
std::vector< int8_t > int8s_
Definition: FlatTable.h:223
std::vector< double > doubles_
Definition: FlatTable.h:230
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 75 of file FlatTable.h.

References size_.

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

75  {
76  auto begin = beginData<T>(column);
77  return edm::Span(begin, begin + size_);
78  }
unsigned int size_
Definition: FlatTable.h:219
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 82 of file FlatTable.h.

References size_.

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

◆ columnDoc()

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

Definition at line 71 of file FlatTable.h.

References cuy::col, and columns_.

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

71 { return columns_[col].doc; }
std::vector< Column > columns_
Definition: FlatTable.h:222
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:222
const std::string & name() const
Definition: FlatTable.h:62

◆ columnName()

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

Definition at line 64 of file FlatTable.h.

References cuy::col, and columns_.

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

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

◆ columnType()

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

Definition at line 67 of file FlatTable.h.

References cuy::col, and columns_.

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

67 { return columns_[col].type; }
std::vector< Column > columns_
Definition: FlatTable.h:222
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 89 of file FlatTable.h.

References Exception, and singleton().

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

◆ defaultColumnType()

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

Definition at line 142 of file FlatTable.h.

References Bool, Double, Float, Int16, Int32, Int8, UInt16, UInt32, and UInt8.

142  {
143  if constexpr (std::is_same<T, int8_t>())
144  return ColumnType::Int8;
145  else if constexpr (std::is_same<T, uint8_t>())
146  return ColumnType::UInt8;
147  else if constexpr (std::is_same<T, int16_t>())
149  else if constexpr (std::is_same<T, uint16_t>())
151  else if constexpr (std::is_same<T, int32_t>())
153  else if constexpr (std::is_same<T, uint32_t>())
155  else if constexpr (std::is_same<T, bool>())
157  else if constexpr (std::is_same<T, float>())
158  return ColumnType::Float;
159  else if constexpr (std::is_same<T, double>())
160  return ColumnType::Double;
161  else
162  static_assert(dependent_false<T>::value, "unsupported type");
163  }
return((rh ^ lh) &mask)
int Bool
Definition: Types.h:100
unsigned int UInt32
Definition: Types.h:69
Definition: value.py:1
unsigned short UInt16
Definition: Types.h:62
short Int16
Definition: Types.h:61
long double T
int Int32
Definition: Types.h:68

◆ doc()

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

Definition at line 70 of file FlatTable.h.

References doc_.

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

70 { return doc_; }
std::string doc_
Definition: FlatTable.h:220

◆ extension()

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

Definition at line 61 of file FlatTable.h.

References extension_.

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

61 { return extension_; }

◆ getAnyValue()

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

Definition at line 49 of file FlatTable.cc.

References Exception.

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

49  {
50  if (column >= nColumns())
51  throw cms::Exception("LogicError", "Invalid column");
52  switch (columnType(column)) {
53  case ColumnType::Int8:
54  return *(beginData<int8_t>(column) + row);
55  case ColumnType::UInt8:
56  return *(beginData<uint8_t>(column) + row);
57  case ColumnType::Int16:
58  return *(beginData<int16_t>(column) + row);
59  case ColumnType::UInt16:
60  return *(beginData<uint16_t>(column) + row);
61  case ColumnType::Int32:
62  return *(beginData<int32_t>(column) + row);
63  case ColumnType::UInt32:
64  return *(beginData<uint32_t>(column) + row);
65  case ColumnType::Bool:
66  return *(beginData<bool>(column) + row);
67  case ColumnType::Float:
68  return *(beginData<float>(column) + row);
69  case ColumnType::Double:
70  return *(beginData<double>(column) + row);
71  }
72  throw cms::Exception("LogicError", "Unsupported type");
73 }
RowView row(unsigned int row) const
Definition: FlatTable.h:112
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:67
unsigned int nColumns() const
Definition: FlatTable.h:57

◆ name()

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

◆ nColumns()

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

Definition at line 57 of file FlatTable.h.

References columns_.

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

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

◆ nRows()

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

Definition at line 58 of file FlatTable.h.

References size_.

58 { return size_; };
unsigned int size_
Definition: FlatTable.h:219

◆ row()

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

Definition at line 112 of file FlatTable.h.

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

◆ setDoc()

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

Definition at line 69 of file FlatTable.h.

References doc(), and doc_.

69 { doc_ = doc; }
const std::string & doc() const
Definition: FlatTable.h:70
std::string doc_
Definition: FlatTable.h:220

◆ singleton()

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

Definition at line 60 of file FlatTable.h.

References singleton_.

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

60 { 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 220 of file FlatTable.h.

Referenced by doc(), and setDoc().

◆ doubles_

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

Definition at line 230 of file FlatTable.h.

◆ extension_

bool nanoaod::FlatTable::extension_
private

Definition at line 221 of file FlatTable.h.

Referenced by extension().

◆ floats_

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

Definition at line 229 of file FlatTable.h.

◆ int16s_

std::vector<int16_t> nanoaod::FlatTable::int16s_
private

Definition at line 225 of file FlatTable.h.

◆ int32s_

std::vector<int32_t> nanoaod::FlatTable::int32s_
private

Definition at line 227 of file FlatTable.h.

◆ int8s_

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

Definition at line 223 of file FlatTable.h.

◆ name_

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

Definition at line 220 of file FlatTable.h.

Referenced by name().

◆ singleton_

bool nanoaod::FlatTable::singleton_
private

Definition at line 221 of file FlatTable.h.

Referenced by singleton().

◆ size_

unsigned int nanoaod::FlatTable::size_
private

Definition at line 219 of file FlatTable.h.

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

◆ uint16s_

std::vector<uint16_t> nanoaod::FlatTable::uint16s_
private

Definition at line 226 of file FlatTable.h.

◆ uint32s_

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

Definition at line 228 of file FlatTable.h.

◆ uint8s_

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

Definition at line 224 of file FlatTable.h.