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
 

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)
 
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)
 
const std::string & name () const
 
unsigned int nColumns () const
 
unsigned int nRows () 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:130
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:130
bool extension() const
Definition: FlatTable.h:39
const std::string & name() const
Definition: FlatTable.h:40
std::string name_
Definition: FlatTable.h:131
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 73 of file FlatTable.h.

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

73  {
74  if (columnIndex(name) != -1) throw cms::Exception("LogicError", "Duplicated column: "+name);
75  if (values.size() != size()) throw cms::Exception("LogicError", "Mismatched size for "+name);
76  check_type<T>(type); // throws if type is wrong
77  auto & vec = bigVector<T>();
78  columns_.emplace_back(name,docString,type,vec.size());
79  vec.insert(vec.end(), values.begin(), values.end());
80  if (type == FloatColumn) {
81  flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).bulk(columnData<T>(columns_.size()-1));
82  }
83  }
type
Definition: HCALResponse.h:21
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
std::vector< Column > columns_
Definition: FlatTable.h:133
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 85 of file FlatTable.h.

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

Referenced by LHETablesProducer::fillLHEObjectTable().

85  {
86  if (!singleton()) throw cms::Exception("LogicError", "addColumnValue works only for singleton tables");
87  if (columnIndex(name) != -1) throw cms::Exception("LogicError", "Duplicated column: "+name);
88  check_type<T>(type); // throws if type is wrong
89  auto & vec = bigVector<T>();
90  columns_.emplace_back(name,docString,type,vec.size());
91  if (type == FloatColumn) {
92  vec.push_back( flatTableHelper::MaybeMantissaReduce<T>(mantissaBits).one(value) );
93  } else {
94  vec.push_back( value );
95  }
96  }
type
Definition: HCALResponse.h:21
int columnIndex(const std::string &name) const
Definition: FlatTable.cc:3
std::vector< Column > columns_
Definition: FlatTable.h:133
Definition: value.py:1
const std::string & name() const
Definition: FlatTable.h:40
bool singleton() const
Definition: FlatTable.h:38
template<typename T >
std::vector<T>::const_iterator nanoaod::FlatTable::beginData ( unsigned int  column) const
inlineprivate

Definition at line 112 of file FlatTable.h.

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

112  {
113  const Column & col = columns_[column];
114  check_type<T>(col.type); // throws if type is wrong
115  return bigVector<T>().begin() + col.firstIndex;
116  }
std::vector< Column > columns_
Definition: FlatTable.h:133
#define begin
Definition: vmac.h:30
col
Definition: cuy.py:1008
template<typename T >
std::vector<T>::iterator nanoaod::FlatTable::beginData ( unsigned int  column)
inlineprivate

Definition at line 118 of file FlatTable.h.

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

118  {
119  const Column & col = columns_[column];
120  check_type<T>(col.type); // throws if type is wrong
121  return bigVector<T>().begin() + col.firstIndex;
122  }
std::vector< Column > columns_
Definition: FlatTable.h:133
#define begin
Definition: vmac.h:30
col
Definition: cuy.py:1008
template<typename T >
const std::vector<T>& nanoaod::FlatTable::bigVector ( ) const
inlineprivate

Definition at line 125 of file FlatTable.h.

References Exception.

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

Definition at line 127 of file FlatTable.h.

References Exception.

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

Definition at line 154 of file FlatTable.h.

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

Definition at line 155 of file FlatTable.h.

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

Definition at line 159 of file FlatTable.h.

159 { return uint8s_; }
std::vector< uint8_t > uint8s_
Definition: FlatTable.h:136
template<>
std::vector<int>& nanoaod::FlatTable::bigVector ( )
inlineprivate

Definition at line 158 of file FlatTable.h.

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

Definition at line 156 of file FlatTable.h.

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

Definition at line 157 of file FlatTable.h.

157 { return floats_; }
std::vector< float > floats_
Definition: FlatTable.h:134
template<typename T >
static void nanoaod::FlatTable::check_type ( FlatTable::ColumnType  type)
inlinestaticprivate

Definition at line 139 of file FlatTable.h.

References Exception.

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

Definition at line 142 of file FlatTable.h.

References Exception, and FloatColumn.

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

Definition at line 145 of file FlatTable.h.

References Exception, and IntColumn.

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

Definition at line 148 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 TableOutputBranches::fillColumn().

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:130
#define begin
Definition: vmac.h:30
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:130
#define begin
Definition: vmac.h:30
const std::string& nanoaod::FlatTable::columnDoc ( unsigned int  col) const
inline

Definition at line 49 of file FlatTable.h.

References cuy::col.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

49 { return columns_[col].doc; }
std::vector< Column > columns_
Definition: FlatTable.h:133
col
Definition: cuy.py:1008
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 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:133
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 TableOutputBranches::defineBranchesFromFirstEvent().

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

Definition at line 45 of file FlatTable.h.

References cuy::col.

Referenced by TableOutputBranches::defineBranchesFromFirstEvent().

45 { return columns_[col].type; }
std::vector< Column > columns_
Definition: FlatTable.h:133
col
Definition: cuy.py:1008
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 98 of file FlatTable.h.

References Exception.

98 { 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:131
bool nanoaod::FlatTable::extension ( ) const
inline

Definition at line 39 of file FlatTable.h.

Referenced by TableOutputBranches::fill().

39 { return extension_; }
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 TableOutputBranches::defineBranchesFromFirstEvent().

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

Definition at line 36 of file FlatTable.h.

36 { return size_; };
unsigned int size_
Definition: FlatTable.h:130
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:131
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 133 of file FlatTable.h.

Referenced by columnIndex().

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

Definition at line 131 of file FlatTable.h.

bool nanoaod::FlatTable::extension_
private

Definition at line 132 of file FlatTable.h.

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

Definition at line 134 of file FlatTable.h.

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

Definition at line 135 of file FlatTable.h.

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

Definition at line 131 of file FlatTable.h.

bool nanoaod::FlatTable::singleton_
private

Definition at line 132 of file FlatTable.h.

unsigned int nanoaod::FlatTable::size_
private

Definition at line 130 of file FlatTable.h.

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

Definition at line 136 of file FlatTable.h.