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
}
 

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_
 
std::vector< double > doubles_
 
bool extension_
 
std::vector< float > floats_
 
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 

Definition at line 40 of file FlatTable.h.

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

Constructor & Destructor Documentation

◆ FlatTable() [1/2]

nanoaod::FlatTable::FlatTable ( )
inline

Definition at line 49 of file FlatTable.h.

49 : size_(0) {}

◆ FlatTable() [2/2]

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

Definition at line 50 of file FlatTable.h.

◆ ~FlatTable()

nanoaod::FlatTable::~FlatTable ( )
inline

Definition at line 52 of file FlatTable.h.

52 {}

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

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

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

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

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  case ColumnType::UInt32:
29  addColumn<uint32_t>(other.columnName(i), other.columnData<uint32_t>(i), other.columnDoc(i));
30  break;
31  case ColumnType::Double:
32  addColumn<double>(other.columnName(i), other.columnData<double>(i), other.columnDoc(i));
33  break;
34  default:
35  throw cms::Exception("LogicError", "Unsupported type");
36  }
37  }
38 }

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

172  {
173  return bigVector<T>().begin() + columns_[column].firstIndex;
174  }

References columns_.

◆ beginData() [2/2]

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

Definition at line 168 of file FlatTable.h.

168  {
169  return bigVector<T>().cbegin() + columns_[column].firstIndex;
170  }

References columns_.

◆ bigVector() [1/2]

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

Definition at line 181 of file FlatTable.h.

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

◆ bigVector() [2/2]

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

Definition at line 177 of file FlatTable.h.

177  {
178  return bigVectorImpl<T>(*this);
179  }

◆ bigVectorImpl()

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

Definition at line 186 of file FlatTable.h.

186  {
187  // helper function to avoid code duplication, for the two accessor functions that differ only in const-ness
188  if constexpr (std::is_same<T, float>())
190  else if constexpr (std::is_same<T, int>())
192  else if constexpr (std::is_same<T, uint8_t>())
194  else if constexpr (std::is_same<T, bool>())
196  else if constexpr (std::is_same<T, uint32_t>())
198  else if constexpr (std::is_same<T, double>())
200  else
201  static_assert(dependent_false<T>::value, "unsupported type");
202  }

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

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

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

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

References size_.

Referenced by TableOutputBranches::fillColumn().

◆ columnDoc()

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

Definition at line 68 of file FlatTable.h.

68 { 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 61 of file FlatTable.h.

61 { 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 64 of file FlatTable.h.

64 { 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 86 of file FlatTable.h.

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

References Exception, and singleton().

◆ defaultColumnType()

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

Definition at line 139 of file FlatTable.h.

139  {
140  if constexpr (std::is_same<T, float>())
141  return ColumnType::Float;
142  else if constexpr (std::is_same<T, int>())
144  else if constexpr (std::is_same<T, uint8_t>())
145  return ColumnType::UInt8;
146  else if constexpr (std::is_same<T, bool>())
148  else if constexpr (std::is_same<T, uint32_t>())
150  else if constexpr (std::is_same<T, double>())
151  return ColumnType::Double;
152  else
153  static_assert(dependent_false<T>::value, "unsupported type");
154  }

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

◆ doc()

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

Definition at line 67 of file FlatTable.h.

67 { return doc_; }

References doc_.

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

◆ extension()

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

Definition at line 58 of file FlatTable.h.

58 { return extension_; }

References extension_.

Referenced by TableOutputBranches::fill().

◆ getAnyValue()

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

Definition at line 40 of file FlatTable.cc.

40  {
41  if (column >= nColumns())
42  throw cms::Exception("LogicError", "Invalid column");
43  switch (columnType(column)) {
44  case ColumnType::Float:
45  return *(beginData<float>(column) + row);
46  case ColumnType::Int:
47  return *(beginData<int>(column) + row);
48  case ColumnType::Bool:
49  return *(beginData<bool>(column) + row);
50  case ColumnType::UInt8:
51  return *(beginData<uint8_t>(column) + row);
52  case ColumnType::UInt32:
53  return *(beginData<uint32_t>(column) + row);
54  case ColumnType::Double:
55  return *(beginData<double>(column) + row);
56  }
57  throw cms::Exception("LogicError", "Unsupported type");
58 }

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

54 { return columns_.size(); };

References columns_.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

◆ nRows()

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

Definition at line 55 of file FlatTable.h.

55 { return size_; };

References size_.

◆ row()

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

Definition at line 109 of file FlatTable.h.

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

◆ setDoc()

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

Definition at line 66 of file FlatTable.h.

66 { doc_ = doc; }

References doc(), and doc_.

◆ singleton()

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

Definition at line 57 of file FlatTable.h.

57 { 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 205 of file FlatTable.h.

Referenced by doc(), and setDoc().

◆ doubles_

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

Definition at line 212 of file FlatTable.h.

◆ extension_

bool nanoaod::FlatTable::extension_
private

Definition at line 206 of file FlatTable.h.

Referenced by extension().

◆ floats_

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

Definition at line 208 of file FlatTable.h.

◆ ints_

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

Definition at line 209 of file FlatTable.h.

◆ name_

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

Definition at line 205 of file FlatTable.h.

Referenced by name().

◆ singleton_

bool nanoaod::FlatTable::singleton_
private

Definition at line 206 of file FlatTable.h.

Referenced by singleton().

◆ size_

unsigned int nanoaod::FlatTable::size_
private

Definition at line 204 of file FlatTable.h.

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

◆ uint32s_

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

Definition at line 211 of file FlatTable.h.

◆ uint8s_

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

Definition at line 210 of file FlatTable.h.

nanoaod::FlatTable::ColumnType::Float
nanoaod::FlatTable::ints_
std::vector< int > ints_
Definition: FlatTable.h:209
mps_fire.i
i
Definition: mps_fire.py:428
SiPixelPI::one
Definition: SiPixelPayloadInspectorHelper.h:39
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
nanoaod::FlatTable::uint32s_
std::vector< uint32_t > uint32s_
Definition: FlatTable.h:211
nanoaod::FlatTable::singleton_
bool singleton_
Definition: FlatTable.h:206
nanoaod::FlatTable::singleton
bool singleton() const
Definition: FlatTable.h:57
cuy.col
col
Definition: cuy.py:1009
Bool
int Bool
Definition: Types.h:100
hgcalConcentratorProducer_cfi.mantissaBits
mantissaBits
Definition: hgcalConcentratorProducer_cfi.py:68
nanoaod::FlatTable::ColumnType::UInt32
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
mathSSE::return
return((rh ^ lh) &mask)
nanoaod::FlatTable::doc_
std::string doc_
Definition: FlatTable.h:205
nanoaod::FlatTable::row
RowView row(unsigned int row) const
Definition: FlatTable.h:109
nanoaod::FlatTable::doc
const std::string & doc() const
Definition: FlatTable.h:67
nanoaod::FlatTable::ColumnType
ColumnType
Definition: FlatTable.h:40
electrons_cff.docString
docString
Definition: electrons_cff.py:521
UInt32
unsigned int UInt32
Definition: Types.h:69
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
trackingPlots.other
other
Definition: trackingPlots.py:1464
nanoaod::FlatTable::ColumnType::UInt8
nanoaod::FlatTable::columnType
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:64
nanoaod::FlatTable::extension
bool extension() const
Definition: FlatTable.h:58
nanoaod::FlatTable::ColumnType::Double
nanoaod::FlatTable::columnIndex
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
nanoaod::FlatTable::doubles_
std::vector< double > doubles_
Definition: FlatTable.h:212
nanoaod::FlatTable::uint8s_
std::vector< uint8_t > uint8s_
Definition: FlatTable.h:210
Json::Int
int Int
Definition: forwards.h:16
nanoaod::FlatTable::size_
unsigned int size_
Definition: FlatTable.h:204
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
RowView
hgcal_conditions::positions::HeterogeneousHGCalPositionsType::Float
value
Definition: value.py:1
nanoaod::FlatTable::columns_
std::vector< Column > columns_
Definition: FlatTable.h:207
nanoaod::FlatTable::name
const std::string & name() const
Definition: FlatTable.h:59
nanoaod::FlatTable::name_
std::string name_
Definition: FlatTable.h:205
nanoaod::FlatTable::ColumnType::Int
nanoaod::FlatTable::floats_
std::vector< float > floats_
Definition: FlatTable.h:208
std
Definition: JetResolutionObject.h:76
nanoaod::FlatTable::nColumns
unsigned int nColumns() const
Definition: FlatTable.h:54
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:245
nanoaod::FlatTable::extension_
bool extension_
Definition: FlatTable.h:206
cms::Exception
Definition: Exception.h:70
hgcal_conditions::parameters::HeterogeneousHGCalEEParametersType::Double
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:56