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
 
class  RowView
 

Public Types

enum  ColumnType { FloatColumn, IntColumn, UInt8Column, BoolColumn }
 

Public Member Functions

template<typename T , typename C = std::vector<T>>
void addColumn (const std::string &name, const C &values, const std::string &docString, ColumnType type=defaultColumnType< T >(), int mantissaBits=-1)
 
template<typename T , typename C >
void addColumnValue (const std::string &name, const C &value, const std::string &docString, ColumnType type=defaultColumnType< T >(), int mantissaBits=-1)
 
void addExtension (const FlatTable &extension)
 
template<typename T >
boost::sub_range< std::vector< T > > columnData (unsigned int column)
 get a column by index (non-const) More...
 
template<typename T >
boost::sub_range< const std::vector< T > > 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 TcolumValue (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 >
std::vector< T >::iterator beginData (unsigned int column)
 
template<typename T >
std::vector< T >::const_iterator beginData (unsigned int column) const
 
template<typename T >
std::vector< T > & bigVector ()
 
template<>
std::vector< int > & bigVector ()
 
template<>
std::vector< float > & bigVector ()
 
template<>
std::vector< uint8_t > & bigVector ()
 
template<typename T >
const std::vector< T > & bigVector () const
 
template<>
const std::vector< float > & bigVector () const
 
template<>
const std::vector< uint8_t > & bigVector () const
 
template<>
const std::vector< int > & bigVector () const
 

Static Private Member Functions

template<typename T >
static void check_type (FlatTable::ColumnType type)
 
template<>
void check_type (FlatTable::ColumnType type)
 
template<>
void check_type (FlatTable::ColumnType type)
 
template<>
void check_type (FlatTable::ColumnType type)
 

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

Member Enumeration Documentation

◆ ColumnType

Enumerator
FloatColumn 
IntColumn 
UInt8Column 
BoolColumn 

Definition at line 38 of file FlatTable.h.

38  {
40  IntColumn,
43  }; // We could have other Float types with reduced mantissa, and similar

Constructor & Destructor Documentation

◆ FlatTable() [1/2]

nanoaod::FlatTable::FlatTable ( )
inline

Definition at line 45 of file FlatTable.h.

45 : size_(0) {}

◆ FlatTable() [2/2]

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

Definition at line 46 of file FlatTable.h.

◆ ~FlatTable()

nanoaod::FlatTable::~FlatTable ( )
inline

Definition at line 48 of file FlatTable.h.

48 {}

Member Function Documentation

◆ addColumn()

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

Definition at line 108 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  check_type<T>(type); // throws if type is wrong
118  auto &vec = bigVector<T>();
119  columns_.emplace_back(name, docString, type, vec.size());
120  vec.insert(vec.end(), values.begin(), values.end());
121  if (type == FloatColumn) {
122  flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).bulk(columnData<T>(columns_.size() - 1));
123  }
124  }

References nanoaod::flatTableHelper::MaybeMantissaReduce< T >::bulk(), columnIndex(), columns_, electrons_cff::docString, Exception, FloatColumn, 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,
ColumnType  type = defaultColumnType<T>(),
int  mantissaBits = -1 
)
inline

Definition at line 126 of file FlatTable.h.

130  {
131  if (!singleton())
132  throw cms::Exception("LogicError", "addColumnValue works only for singleton tables");
133  if (columnIndex(name) != -1)
134  throw cms::Exception("LogicError", "Duplicated column: " + name);
135  check_type<T>(type); // throws if type is wrong
136  auto &vec = bigVector<T>();
137  columns_.emplace_back(name, docString, type, vec.size());
138  if (type == FloatColumn) {
139  vec.push_back(flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).one(value));
140  } else {
141  vec.push_back(value);
142  }
143  }

References columnIndex(), columns_, electrons_cff::docString, Exception, FloatColumn, hgcalConcentratorProducer_cfi::mantissaBits, name(), 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 FloatColumn:
17  addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i), other.columnType(i));
18  break;
19  case IntColumn:
20  addColumn<int>(other.columnName(i), other.columnData<int>(i), other.columnDoc(i), other.columnType(i));
21  break;
22  case BoolColumn: // as UInt8
23  case UInt8Column:
24  addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i), other.columnType(i));
25  break;
26  }
27  }
28 }

References edmStreamStallGrapher::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 >
std::vector<T>::iterator nanoaod::FlatTable::beginData ( unsigned int  column)
inlineprivate

Definition at line 170 of file FlatTable.h.

170  {
171  const Column &col = columns_[column];
172  check_type<T>(col.type); // throws if type is wrong
173  return bigVector<T>().begin() + col.firstIndex;
174  }

References cuy::col, and columns_.

◆ beginData() [2/2]

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

Definition at line 164 of file FlatTable.h.

164  {
165  const Column &col = columns_[column];
166  check_type<T>(col.type); // throws if type is wrong
167  return bigVector<T>().begin() + col.firstIndex;
168  }

References cuy::col, and columns_.

◆ bigVector() [1/8]

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

Definition at line 181 of file FlatTable.h.

181  {
182  throw cms::Exception("unsupported type");
183  }

References Exception.

◆ bigVector() [2/8]

template<>
std::vector<float>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 228 of file FlatTable.h.

228  {
229  return floats_;
230  }

References floats_.

◆ bigVector() [3/8]

template<>
std::vector<int>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 232 of file FlatTable.h.

232  {
233  return ints_;
234  }

References ints_.

◆ bigVector() [4/8]

template<>
std::vector<uint8_t>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 236 of file FlatTable.h.

236  {
237  return uint8s_;
238  }

References uint8s_.

◆ bigVector() [5/8]

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

Definition at line 177 of file FlatTable.h.

177  {
178  throw cms::Exception("unsupported type");
179  }

References Exception.

◆ bigVector() [6/8]

template<>
const std::vector<uint8_t>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 224 of file FlatTable.h.

224  {
225  return uint8s_;
226  }

References uint8s_.

◆ bigVector() [7/8]

template<>
const std::vector<float>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 216 of file FlatTable.h.

216  {
217  return floats_;
218  }

References floats_.

◆ bigVector() [8/8]

template<>
const std::vector<int>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 220 of file FlatTable.h.

220  {
221  return ints_;
222  }

References ints_.

◆ check_type() [1/4]

template<typename T >
static void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlinestaticprivate

Definition at line 194 of file FlatTable.h.

194  {
195  throw cms::Exception("unsupported type");
196  }

References Exception.

◆ check_type() [2/4]

template<>
void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlinestaticprivate

Definition at line 200 of file FlatTable.h.

200  {
202  throw cms::Exception("mismatched type");
203  }

References Exception, and FloatColumn.

◆ check_type() [3/4]

template<>
void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlinestaticprivate

Definition at line 205 of file FlatTable.h.

205  {
206  if (type != FlatTable::IntColumn)
207  throw cms::Exception("mismatched type");
208  }

References Exception, and IntColumn.

◆ check_type() [4/4]

template<>
void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlinestaticprivate

Definition at line 210 of file FlatTable.h.

210  {
212  throw cms::Exception("mismatched type");
213  }

References BoolColumn, Exception, and UInt8Column.

◆ columnData() [1/2]

template<typename T >
boost::sub_range<std::vector<T> > nanoaod::FlatTable::columnData ( unsigned int  column)
inline

get a column by index (non-const)

Definition at line 75 of file FlatTable.h.

75  {
76  auto begin = beginData<T>(column);
77  return boost::sub_range<std::vector<T>>(begin, begin + size_);
78  }

References begin, and size_.

◆ columnData() [2/2]

template<typename T >
boost::sub_range<const std::vector<T> > nanoaod::FlatTable::columnData ( unsigned int  column) const
inline

get a column by index (const)

Definition at line 68 of file FlatTable.h.

68  {
69  auto begin = beginData<T>(column);
70  return boost::sub_range<const std::vector<T>>(begin, begin + size_);
71  }

References begin, and size_.

Referenced by TableOutputBranches::fillColumn().

◆ columnDoc()

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

Definition at line 64 of file FlatTable.h.

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

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

60 { return columns_[col].type; }

References cuy::col, and columns_.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

◆ columValue()

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

get a column value for singleton (const)

Definition at line 82 of file FlatTable.h.

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

References Exception, and singleton().

◆ defaultColumnType()

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

Definition at line 148 of file FlatTable.h.

148  {
149  throw cms::Exception("unsupported type");
150  }

References Exception.

◆ doc()

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

Definition at line 63 of file FlatTable.h.

63 { return doc_; }

References doc_.

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

◆ extension()

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

Definition at line 54 of file FlatTable.h.

54 { return extension_; }

References extension_.

Referenced by TableOutputBranches::fill().

◆ getAnyValue()

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

Definition at line 30 of file FlatTable.cc.

30  {
31  if (column >= nColumns())
32  throw cms::Exception("LogicError", "Invalid column");
33  switch (columnType(column)) {
34  case FloatColumn:
35  return *(beginData<float>(column) + row);
36  case IntColumn:
37  return *(beginData<int>(column) + row);
38  case BoolColumn:
39  return *(beginData<uint8_t>(column) + row);
40  case UInt8Column:
41  return *(beginData<uint8_t>(column) + row);
42  }
43  throw cms::Exception("LogicError", "Unsupported type");
44 }

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

50 { return columns_.size(); };

References columns_.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

◆ nRows()

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

Definition at line 51 of file FlatTable.h.

51 { return size_; };

References size_.

◆ row()

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

Definition at line 105 of file FlatTable.h.

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

◆ setDoc()

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

Definition at line 62 of file FlatTable.h.

62 { doc_ = doc; }

References doc(), and doc_.

◆ singleton()

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

Definition at line 53 of file FlatTable.h.

53 { 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 186 of file FlatTable.h.

Referenced by doc(), and setDoc().

◆ extension_

bool nanoaod::FlatTable::extension_
private

Definition at line 187 of file FlatTable.h.

Referenced by extension().

◆ floats_

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

Definition at line 189 of file FlatTable.h.

Referenced by bigVector().

◆ ints_

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

Definition at line 190 of file FlatTable.h.

Referenced by bigVector().

◆ name_

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

Definition at line 186 of file FlatTable.h.

Referenced by name().

◆ singleton_

bool nanoaod::FlatTable::singleton_
private

Definition at line 187 of file FlatTable.h.

Referenced by singleton().

◆ size_

unsigned int nanoaod::FlatTable::size_
private

Definition at line 185 of file FlatTable.h.

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

◆ uint8s_

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

Definition at line 191 of file FlatTable.h.

Referenced by bigVector().

nanoaod::FlatTable::FloatColumn
Definition: FlatTable.h:39
nanoaod::FlatTable::ints_
std::vector< int > ints_
Definition: FlatTable.h:190
mps_fire.i
i
Definition: mps_fire.py:355
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
nanoaod::FlatTable::singleton_
bool singleton_
Definition: FlatTable.h:187
nanoaod::FlatTable::singleton
bool singleton() const
Definition: FlatTable.h:53
cuy.col
col
Definition: cuy.py:1010
hgcalConcentratorProducer_cfi.mantissaBits
mantissaBits
Definition: hgcalConcentratorProducer_cfi.py:67
nanoaod::FlatTable::doc_
std::string doc_
Definition: FlatTable.h:186
Column
nanoaod::FlatTable::row
RowView row(unsigned int row) const
Definition: FlatTable.h:105
nanoaod::FlatTable::doc
const std::string & doc() const
Definition: FlatTable.h:63
electrons_cff.docString
docString
Definition: electrons_cff.py:493
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
trackingPlots.other
other
Definition: trackingPlots.py:1465
nanoaod::FlatTable::columnType
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:60
nanoaod::FlatTable::extension
bool extension() const
Definition: FlatTable.h:54
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:191
nanoaod::FlatTable::size_
unsigned int size_
Definition: FlatTable.h:185
RowView
value
Definition: value.py:1
nanoaod::FlatTable::UInt8Column
Definition: FlatTable.h:41
nanoaod::FlatTable::columns_
std::vector< Column > columns_
Definition: FlatTable.h:188
nanoaod::FlatTable::name
const std::string & name() const
Definition: FlatTable.h:55
nanoaod::FlatTable::name_
std::string name_
Definition: FlatTable.h:186
nanoaod::FlatTable::floats_
std::vector< float > floats_
Definition: FlatTable.h:189
nanoaod::FlatTable::IntColumn
Definition: FlatTable.h:40
type
type
Definition: HCALResponse.h:21
nanoaod::FlatTable::nColumns
unsigned int nColumns() const
Definition: FlatTable.h:50
nanoaod::FlatTable::BoolColumn
Definition: FlatTable.h:42
Exception
Definition: hltDiff.cc:246
nanoaod::FlatTable::extension_
bool extension_
Definition: FlatTable.h:187
cms::Exception
Definition: Exception.h:70
begin
#define begin
Definition: vmac.h:32
nanoaod::FlatTable::size
unsigned int size() const
Definition: FlatTable.h:52