1 #ifndef DataFormats_NanoAOD_FlatTable_h 2 #define DataFormats_NanoAOD_FlatTable_h 7 #include <boost/range/sub_range.hpp> 13 namespace flatTableHelper {
17 inline void bulk(boost::sub_range<std::vector<T>>
data)
const { }
35 unsigned int nColumns()
const {
return columns_.size(); };
36 unsigned int nRows()
const {
return size_; };
37 unsigned int size()
const {
return size_; }
53 boost::sub_range<const std::vector<T>>
columnData(
unsigned int column)
const {
54 auto begin = beginData<T>(column);
55 return boost::sub_range<const std::vector<T>>(
begin, begin+size_);
60 boost::sub_range<std::vector<T>>
columnData(
unsigned int column) {
61 auto begin = beginData<T>(column);
62 return boost::sub_range<std::vector<T>>(
begin, begin+size_);
69 return * beginData<T>(column);
72 double getAnyValue(
unsigned int row,
unsigned int column)
const ;
81 unsigned int row()
const {
return row_; }
88 template<
typename T,
typename C = std::vector<T>>
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);
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) {
100 template<
typename T,
typename C>
103 if (columnIndex(name) != -1)
throw cms::Exception(
"LogicError",
"Duplicated column: "+name);
105 auto & vec = bigVector<T>();
106 columns_.emplace_back(name,docString,
type,vec.size());
107 if (
type == FloatColumn) {
110 vec.push_back( value );
130 typename std::vector<T>::const_iterator
beginData(
unsigned int column)
const {
132 check_type<T>(col.
type);
136 typename std::vector<T>::iterator
beginData(
unsigned int column) {
138 check_type<T>(col.
type);
172 template<>
inline const std::vector<float> & FlatTable::bigVector<float>()
const {
return floats_; }
173 template<>
inline const std::vector<int> & FlatTable::bigVector<int>()
const {
return ints_; }
174 template<>
inline const std::vector<uint8_t> & FlatTable::bigVector<uint8_t>()
const {
return uint8s_; }
175 template<>
inline std::vector<float> & FlatTable::bigVector<float>() {
return floats_; }
176 template<>
inline std::vector<int> & FlatTable::bigVector<int>() {
return ints_; }
177 template<>
inline std::vector<uint8_t> & FlatTable::bigVector<uint8_t>() {
return uint8s_; }
boost::sub_range< const std::vector< T > > columnData(unsigned int column) const
get a column by index (const)
RowView row(unsigned int row) const
std::vector< T > & bigVector()
float one(const float &val) const
void bulk(boost::sub_range< std::vector< float >> data) const
const std::vector< T > & bigVector() const
Column(const std::string &aname, const std::string &docString, ColumnType atype, unsigned int anIndex)
std::vector< Column > columns_
ColumnType columnType(unsigned int col) const
std::vector< uint8_t > uint8s_
void addColumn(const std::string &name, const C &values, const std::string &docString, ColumnType type=defaultColumnType< T >(), int mantissaBits=-1)
const std::string & doc() const
double getAnyValue(unsigned int column) const
void setDoc(const std::string &doc)
std::vector< float > floats_
MaybeMantissaReduce(int mantissaBits)
std::vector< T >::iterator beginData(unsigned int column)
const FlatTable & table() const
T one(const T &val) const
void bulk(boost::sub_range< std::vector< T >> data) const
unsigned int nRows() const
RowView(const FlatTable &table, unsigned int row)
void addColumnValue(const std::string &name, const C &value, const std::string &docString, ColumnType type=defaultColumnType< T >(), int mantissaBits=-1)
const std::string & name() const
const T & columValue(unsigned int column) const
get a column value for singleton (const)
double getAnyValue(const std::string &column) const
const std::string & columnName(unsigned int col) const
MaybeMantissaReduce(int mantissaBits)
boost::sub_range< std::vector< T > > columnData(unsigned int column)
get a column by index (non-const)
FlatTable(unsigned int size, const std::string &name, bool singleton, bool extension=false)
static void check_type(FlatTable::ColumnType type)
static ColumnType defaultColumnType()
static float reduceMantissaToNbitsRounding(const float &f)
unsigned int nColumns() const
unsigned int size() const
char data[epos_bytes_allocation]
std::vector< T >::const_iterator beginData(unsigned int column) const
const std::string & columnDoc(unsigned int col) const