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

Definition at line 41 of file FlatTable.h.

41  {
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 119 of file FlatTable.h.

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

119  {
120  if (columnIndex(name) != -1)
121  throw cms::Exception("LogicError", "Duplicated column: " + name);
122  if (values.size() != size())
123  throw cms::Exception("LogicError", "Mismatched size for " + name);
124  auto &vec = bigVector<T>();
125  columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
126  vec.insert(vec.end(), values.begin(), values.end());
127  flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).bulk(columnData<T>(columns_.size() - 1));
128  }
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 131 of file FlatTable.h.

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

131  {
132  if (!singleton())
133  throw cms::Exception("LogicError", "addColumnValue works only for singleton tables");
134  if (columnIndex(name) != -1)
135  throw cms::Exception("LogicError", "Duplicated column: " + name);
136  auto &vec = bigVector<T>();
137  columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
138  vec.push_back(flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).one(value));
139  }
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, and trackingPlots::other.

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::UInt8:
17  addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i));
18  break;
19  case ColumnType::Int16:
20  addColumn<int16_t>(other.columnName(i), other.columnData<int16_t>(i), other.columnDoc(i));
21  break;
22  case ColumnType::UInt16:
23  addColumn<uint16_t>(other.columnName(i), other.columnData<uint16_t>(i), other.columnDoc(i));
24  break;
25  case ColumnType::Int32:
26  addColumn<int32_t>(other.columnName(i), other.columnData<int32_t>(i), other.columnDoc(i));
27  break;
28  case ColumnType::UInt32:
29  addColumn<uint32_t>(other.columnName(i), other.columnData<uint32_t>(i), other.columnDoc(i));
30  break;
31  case ColumnType::Bool:
32  addColumn<bool>(other.columnName(i), other.columnData<bool>(i), other.columnDoc(i));
33  break;
34  case ColumnType::Float:
35  addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i));
36  break;
37  case ColumnType::Double:
38  addColumn<double>(other.columnName(i), other.columnData<double>(i), other.columnDoc(i));
39  break;
40  default:
41  throw cms::Exception("LogicError", "Unsupported type");
42  }
43  }
44 }
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 179 of file FlatTable.h.

References columns_.

179  {
180  return bigVector<T>().cbegin() + columns_[column].firstIndex;
181  }
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 183 of file FlatTable.h.

References columns_.

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

◆ bigVector() [1/2]

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

Definition at line 188 of file FlatTable.h.

188  {
189  return bigVectorImpl<T>(*this);
190  }

◆ bigVector() [2/2]

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

Definition at line 192 of file FlatTable.h.

192  {
193  return bigVectorImpl<T>(*this);
194  }

◆ bigVectorImpl()

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

Definition at line 197 of file FlatTable.h.

References ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), and TableParser::table.

197  {
198  // helper function to avoid code duplication, for the two accessor functions that differ only in const-ness
199  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:223
std::vector< int16_t > int16s_
Definition: FlatTable.h:224
std::vector< uint32_t > uint32s_
Definition: FlatTable.h:227
std::vector< float > floats_
Definition: FlatTable.h:228
std::vector< int32_t > int32s_
Definition: FlatTable.h:226
std::vector< uint16_t > uint16s_
Definition: FlatTable.h:225
Definition: value.py:1
std::vector< double > doubles_
Definition: FlatTable.h:229
long double T
if(threadIdxLocalY==0 &&threadIdxLocalX==0)

◆ 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 TableOutputBranches::fillColumn(), and LumiOutputBranches::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(), TableOutputBranches::fillColumn(), LumiOutputBranches::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 146 of file FlatTable.h.

References Bool, ALPAKA_ACCELERATOR_NAMESPACE::brokenline::constexpr(), Double, Float, Int16, Int32, UInt16, UInt32, and UInt8.

146  {
147  if constexpr (std::is_same<T, uint8_t>())
148  return ColumnType::UInt8;
149  else if constexpr (std::is_same<T, int16_t>())
151  else if constexpr (std::is_same<T, uint16_t>())
153  else if constexpr (std::is_same<T, int32_t>())
155  else if constexpr (std::is_same<T, uint32_t>())
157  else if constexpr (std::is_same<T, bool>())
159  else if constexpr (std::is_same<T, float>())
160  return ColumnType::Float;
161  else if constexpr (std::is_same<T, double>())
162  return ColumnType::Double;
163  else
164  static_assert(dependent_false<T>::value, "unsupported type");
165  }
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
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
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 46 of file FlatTable.cc.

References Exception.

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

46  {
47  if (column >= nColumns())
48  throw cms::Exception("LogicError", "Invalid column");
49  switch (columnType(column)) {
50  case ColumnType::UInt8:
51  return *(beginData<uint8_t>(column) + row);
52  case ColumnType::Int16:
53  return *(beginData<int16_t>(column) + row);
54  case ColumnType::UInt16:
55  return *(beginData<uint16_t>(column) + row);
56  case ColumnType::Int32:
57  return *(beginData<int32_t>(column) + row);
58  case ColumnType::UInt32:
59  return *(beginData<uint32_t>(column) + row);
60  case ColumnType::Bool:
61  return *(beginData<bool>(column) + row);
62  case ColumnType::Float:
63  return *(beginData<float>(column) + row);
64  case ColumnType::Double:
65  return *(beginData<double>(column) + row);
66  }
67  throw cms::Exception("LogicError", "Unsupported type");
68 }
RowView row(unsigned int row) const
Definition: FlatTable.h:116
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 116 of file FlatTable.h.

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

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

◆ int16s_

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

Definition at line 224 of file FlatTable.h.

◆ int32s_

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

Definition at line 226 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 225 of file FlatTable.h.

◆ uint32s_

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

Definition at line 227 of file FlatTable.h.

◆ uint8s_

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

Definition at line 223 of file FlatTable.h.