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< const std::vector< T > > columnData (unsigned int column) const
 get a column by index (const) More...
 
template<typename T >
boost::sub_range< std::vector< T > > 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 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 >::const_iterator beginData (unsigned int column) const
 
template<typename T >
std::vector< T >::iterator beginData (unsigned int column)
 
template<typename T >
const std::vector< T > & bigVector () const
 
template<typename T >
std::vector< T > & bigVector ()
 
template<>
const std::vector< float > & bigVector () const
 
template<>
const std::vector< int > & bigVector () const
 
template<>
std::vector< float > & bigVector ()
 
template<>
std::vector< uint8_t > & bigVector ()
 
template<>
const std::vector< uint8_t > & bigVector () const
 
template<>
std::vector< int > & bigVector ()
 
template<>
void check_type (FlatTable::ColumnType type)
 
template<>
void check_type (FlatTable::ColumnType type)
 
template<>
void check_type (FlatTable::ColumnType type)
 

Static Private Member Functions

template<typename T >
static 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 27 of file FlatTable.h.

Member Enumeration Documentation

Enumerator
FloatColumn 
IntColumn 
UInt8Column 
BoolColumn 

Definition at line 29 of file FlatTable.h.

Constructor & Destructor Documentation

nanoaod::FlatTable::FlatTable ( )
inline

Definition at line 31 of file FlatTable.h.

31 : size_(0) {}
unsigned int size_
Definition: FlatTable.h:148
nanoaod::FlatTable::FlatTable ( unsigned int  size,
const std::string &  name,
bool  singleton,
bool  extension = false 
)
inline

Definition at line 32 of file FlatTable.h.

unsigned int size_
Definition: FlatTable.h:148
bool extension() const
Definition: FlatTable.h:39
const std::string & name() const
Definition: FlatTable.h:40
std::string name_
Definition: FlatTable.h:149
unsigned int size() const
Definition: FlatTable.h:37
bool singleton() const
Definition: FlatTable.h:38
nanoaod::FlatTable::~FlatTable ( )
inline

Definition at line 33 of file FlatTable.h.

33 {}

Member Function Documentation

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

References nanoaod::flatTableHelper::MaybeMantissaReduce< T >::bulk(), Exception, and findQualityFiles::size.

89  {
90  if (columnIndex(name) != -1) throw cms::Exception("LogicError", "Duplicated column: "+name);
91  if (values.size() != size()) throw cms::Exception("LogicError", "Mismatched size for "+name);
92  check_type<T>(type); // throws if type is wrong
93  auto & vec = bigVector<T>();
94  columns_.emplace_back(name,docString,type,vec.size());
95  vec.insert(vec.end(), values.begin(), values.end());
96  if (type == FloatColumn) {
97  flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).bulk(columnData<T>(columns_.size()-1));
98  }
99  }
type
Definition: HCALResponse.h:21
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
std::vector< Column > columns_
Definition: FlatTable.h:151
const std::string & name() const
Definition: FlatTable.h:40
unsigned int size() const
Definition: FlatTable.h:37
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 101 of file FlatTable.h.

References Exception, electrons_cff::extension, nanoaod::flatTableHelper::MaybeMantissaReduce< T >::one(), and electrons_cff::singleton.

Referenced by LHETablesProducer::fillLHEObjectTable(), and NPUTablesProducer::fillNPUObjectTable().

101  {
102  if (!singleton()) throw cms::Exception("LogicError", "addColumnValue works only for singleton tables");
103  if (columnIndex(name) != -1) throw cms::Exception("LogicError", "Duplicated column: "+name);
104  check_type<T>(type); // throws if type is wrong
105  auto & vec = bigVector<T>();
106  columns_.emplace_back(name,docString,type,vec.size());
107  if (type == FloatColumn) {
108  vec.push_back( flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).one(value) );
109  } else {
110  vec.push_back( value );
111  }
112  }
type
Definition: HCALResponse.h:21
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
std::vector< Column > columns_
Definition: FlatTable.h:151
Definition: value.py:1
const std::string & name() const
Definition: FlatTable.h:40
bool singleton() const
Definition: FlatTable.h:38
void nanoaod::FlatTable::addExtension ( const FlatTable extension)

Definition at line 10 of file FlatTable.cc.

References BoolColumn, columnData(), columnDoc(), columnName(), columnType(), extension(), FloatColumn, mps_fire::i, IntColumn, gen::n, name(), nColumns(), size(), and UInt8Column.

Referenced by NanoAODDQM::analyze().

10  {
11  if (extension() || !other.extension() || name() != other.name() || size() != other.size()) throw cms::Exception("LogicError", "Mismatch in adding extension");
12  for (unsigned int i = 0, n = other.nColumns(); i < n; ++i) {
13  switch(other.columnType(i)) {
14  case FloatColumn:
15  addColumn<float>(other.columnName(i), other.columnData<float>(i), other.columnDoc(i), other.columnType(i));
16  break;
17  case IntColumn:
18  addColumn<int>(other.columnName(i), other.columnData<int>(i), other.columnDoc(i), other.columnType(i));
19  break;
20  case BoolColumn: // as UInt8
21  case UInt8Column:
22  addColumn<uint8_t>(other.columnName(i), other.columnData<uint8_t>(i), other.columnDoc(i), other.columnType(i));
23  break;
24  }
25  }
26 }
bool extension() const
Definition: FlatTable.h:39
const std::string & name() const
Definition: FlatTable.h:40
unsigned int size() const
Definition: FlatTable.h:37
template<typename T >
std::vector<T>::const_iterator nanoaod::FlatTable::beginData ( unsigned int  column) const
inlineprivate

Definition at line 130 of file FlatTable.h.

References begin, cuy::col, nanoaod::FlatTable::Column::firstIndex, and nanoaod::FlatTable::Column::type.

130  {
131  const Column & col = columns_[column];
132  check_type<T>(col.type); // throws if type is wrong
133  return bigVector<T>().begin() + col.firstIndex;
134  }
std::vector< Column > columns_
Definition: FlatTable.h:151
#define begin
Definition: vmac.h:32
col
Definition: cuy.py:1010
template<typename T >
std::vector<T>::iterator nanoaod::FlatTable::beginData ( unsigned int  column)
inlineprivate

Definition at line 136 of file FlatTable.h.

References begin, cuy::col, nanoaod::FlatTable::Column::firstIndex, and nanoaod::FlatTable::Column::type.

136  {
137  const Column & col = columns_[column];
138  check_type<T>(col.type); // throws if type is wrong
139  return bigVector<T>().begin() + col.firstIndex;
140  }
std::vector< Column > columns_
Definition: FlatTable.h:151
#define begin
Definition: vmac.h:32
col
Definition: cuy.py:1010
template<typename T >
const std::vector<T>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 143 of file FlatTable.h.

References Exception.

143 { throw cms::Exception("unsupported type"); }
template<typename T >
std::vector<T>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 145 of file FlatTable.h.

References Exception.

145 { throw cms::Exception("unsupported type"); }
template<>
const std::vector<float>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 172 of file FlatTable.h.

172 { return floats_; }
std::vector< float > floats_
Definition: FlatTable.h:152
template<>
const std::vector<int>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 173 of file FlatTable.h.

173 { return ints_; }
std::vector< int > ints_
Definition: FlatTable.h:153
template<>
const std::vector<uint8_t>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 174 of file FlatTable.h.

174 { return uint8s_; }
std::vector< uint8_t > uint8s_
Definition: FlatTable.h:154
template<>
std::vector<float>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 175 of file FlatTable.h.

175 { return floats_; }
std::vector< float > floats_
Definition: FlatTable.h:152
template<>
std::vector<int>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 176 of file FlatTable.h.

176 { return ints_; }
std::vector< int > ints_
Definition: FlatTable.h:153
template<>
std::vector<uint8_t>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 177 of file FlatTable.h.

177 { return uint8s_; }
std::vector< uint8_t > uint8s_
Definition: FlatTable.h:154
template<typename T >
static void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlinestaticprivate

Definition at line 157 of file FlatTable.h.

References Exception.

157 { throw cms::Exception("unsupported type"); }
template<>
void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlineprivate

Definition at line 160 of file FlatTable.h.

References Exception, and FloatColumn.

160  {
161  if (type != FlatTable::FloatColumn) throw cms::Exception("mismatched type");
162 }
type
Definition: HCALResponse.h:21
template<>
void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlineprivate

Definition at line 163 of file FlatTable.h.

References Exception, and IntColumn.

163  {
164  if (type != FlatTable::IntColumn) throw cms::Exception("mismatched type");
165 }
type
Definition: HCALResponse.h:21
template<>
void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlineprivate

Definition at line 166 of file FlatTable.h.

References BoolColumn, Exception, and UInt8Column.

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

References begin.

Referenced by addExtension(), TableOutputBranches::fillColumn(), and NanoAODDQM::Plot1D::vfill().

53  {
54  auto begin = beginData<T>(column);
55  return boost::sub_range<const std::vector<T>>(begin, begin+size_);
56  }
unsigned int size_
Definition: FlatTable.h:148
#define begin
Definition: vmac.h:32
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 60 of file FlatTable.h.

References begin.

60  {
61  auto begin = beginData<T>(column);
62  return boost::sub_range<std::vector<T>>(begin, begin+size_);
63  }
unsigned int size_
Definition: FlatTable.h:148
#define begin
Definition: vmac.h:32
const std::string& nanoaod::FlatTable::columnDoc ( unsigned int  col) const
inline

Definition at line 49 of file FlatTable.h.

References cuy::col.

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

49 { return columns_[col].doc; }
std::vector< Column > columns_
Definition: FlatTable.h:151
col
Definition: cuy.py:1010
int nanoaod::FlatTable::columnIndex ( const std::string &  name) const

Definition at line 3 of file FlatTable.cc.

References columns_, mps_fire::i, and gen::n.

Referenced by NanoAODDQM::Plot1D::fill(), NanoAODDQM::Profile1D::fill(), and TableOutputBranches::fillColumn().

3  {
4  for (unsigned int i = 0, n = columns_.size(); i < n; ++i) {
5  if (columns_[i].name == name) return i;
6  }
7  return -1;
8 }
std::vector< Column > columns_
Definition: FlatTable.h:151
const std::string & name() const
Definition: FlatTable.h:40
const std::string& nanoaod::FlatTable::columnName ( unsigned int  col) const
inline

Definition at line 42 of file FlatTable.h.

References cuy::col, dataset::name, and AlCaHLTBitMon_QueryRunRegistry::string.

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

42 { return columns_[col].name; }
std::vector< Column > columns_
Definition: FlatTable.h:151
col
Definition: cuy.py:1010
ColumnType nanoaod::FlatTable::columnType ( unsigned int  col) const
inline

Definition at line 45 of file FlatTable.h.

References cuy::col.

Referenced by addExtension(), TableOutputBranches::defineBranchesFromFirstEvent(), NanoAODDQM::Plot1D::fill(), and getAnyValue().

45 { return columns_[col].type; }
std::vector< Column > columns_
Definition: FlatTable.h:151
col
Definition: cuy.py:1010
template<typename T >
const T& nanoaod::FlatTable::columValue ( unsigned int  column) const
inline

get a column value for singleton (const)

Definition at line 67 of file FlatTable.h.

References Exception, and electrons_cff::singleton.

67  {
68  if (!singleton()) throw cms::Exception("LogicError", "columnValue works only for singleton tables");
69  return * beginData<T>(column);
70  }
bool singleton() const
Definition: FlatTable.h:38
template<typename T >
static ColumnType nanoaod::FlatTable::defaultColumnType ( )
inlinestatic

Definition at line 116 of file FlatTable.h.

References Exception.

116 { throw cms::Exception("unsupported type"); }
const std::string& nanoaod::FlatTable::doc ( ) const
inline

Definition at line 48 of file FlatTable.h.

Referenced by TableOutputBranches::fill().

48 { return doc_; }
std::string doc_
Definition: FlatTable.h:149
bool nanoaod::FlatTable::extension ( ) const
inline

Definition at line 39 of file FlatTable.h.

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

39 { return extension_; }
double nanoaod::FlatTable::getAnyValue ( unsigned int  row,
unsigned int  column 
) const

Definition at line 28 of file FlatTable.cc.

References BoolColumn, columnType(), Exception, FloatColumn, IntColumn, nColumns(), and UInt8Column.

Referenced by NanoAODDQM::Profile1D::fill().

28  {
29  if (column >= nColumns()) throw cms::Exception("LogicError","Invalid column");
30  switch(columnType(column)) {
31  case FloatColumn: return *(beginData<float>(column)+row);
32  case IntColumn: return *(beginData<int>(column)+row);
33  case BoolColumn: return *(beginData<uint8_t>(column)+row);
34  case UInt8Column: return *(beginData<uint8_t>(column)+row);
35  }
36  throw cms::Exception("LogicError", "Unsupported type");
37 }
RowView row(unsigned int row) const
Definition: FlatTable.h:86
ColumnType columnType(unsigned int col) const
Definition: FlatTable.h:45
unsigned int nColumns() const
Definition: FlatTable.h:35
const std::string& nanoaod::FlatTable::name ( ) const
inline
unsigned int nanoaod::FlatTable::nColumns ( ) const
inline

Definition at line 35 of file FlatTable.h.

Referenced by addExtension(), TableOutputBranches::defineBranchesFromFirstEvent(), and getAnyValue().

35 { return columns_.size(); };
std::vector< Column > columns_
Definition: FlatTable.h:151
unsigned int nanoaod::FlatTable::nRows ( ) const
inline

Definition at line 36 of file FlatTable.h.

36 { return size_; };
unsigned int size_
Definition: FlatTable.h:148
RowView nanoaod::FlatTable::row ( unsigned int  row) const
inline

Definition at line 86 of file FlatTable.h.

Referenced by NanoAODDQM::SelGroupConfig::fillSel().

86 { return RowView(*this, row); }
RowView row(unsigned int row) const
Definition: FlatTable.h:86
void nanoaod::FlatTable::setDoc ( const std::string &  doc)
inline

Definition at line 47 of file FlatTable.h.

References common_cff::doc.

47 { doc_ = doc; }
const std::string & doc() const
Definition: FlatTable.h:48
std::string doc_
Definition: FlatTable.h:149
bool nanoaod::FlatTable::singleton ( ) const
inline

Definition at line 38 of file FlatTable.h.

Referenced by TableOutputBranches::fill().

38 { return singleton_; }
unsigned int nanoaod::FlatTable::size ( void  ) const
inline

Member Data Documentation

std::vector<Column> nanoaod::FlatTable::columns_
private

Definition at line 151 of file FlatTable.h.

Referenced by columnIndex().

std::string nanoaod::FlatTable::doc_
private

Definition at line 149 of file FlatTable.h.

bool nanoaod::FlatTable::extension_
private

Definition at line 150 of file FlatTable.h.

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

Definition at line 152 of file FlatTable.h.

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

Definition at line 153 of file FlatTable.h.

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

Definition at line 149 of file FlatTable.h.

bool nanoaod::FlatTable::singleton_
private

Definition at line 150 of file FlatTable.h.

unsigned int nanoaod::FlatTable::size_
private

Definition at line 148 of file FlatTable.h.

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

Definition at line 154 of file FlatTable.h.