1 #ifndef DataFormats_NanoAOD_FlatTable_h
2 #define DataFormats_NanoAOD_FlatTable_h
11 #include <type_traits>
15 namespace flatTableHelper {
20 template <
typename Span>
27 inline float one(
const float &
val)
const {
30 template <
typename Span>
74 auto begin = beginData<T>(column);
81 auto begin = beginData<T>(column);
89 throw cms::Exception(
"LogicError",
"columnValue works only for singleton tables");
90 return *beginData<T>(column);
112 template <
typename T,
typename C>
116 if (values.size() !=
size())
117 throw cms::Exception(
"LogicError",
"Mismatched size for " + name);
118 auto &vec = bigVector<T>();
119 columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
120 vec.insert(vec.end(), values.begin(), values.end());
124 template <
typename T,
typename C>
127 throw cms::Exception(
"LogicError",
"addColumnValue works only for singleton tables");
130 auto &vec = bigVector<T>();
131 columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
139 template <
typename T>
141 if constexpr (std::is_same<T, float>())
143 else if constexpr (std::is_same<T, int>())
145 else if constexpr (std::is_same<T, uint8_t>())
147 else if constexpr (std::is_same<T, int8_t>())
149 else if constexpr (std::is_same<T, bool>())
151 else if constexpr (std::is_same<T, uint32_t>())
153 else if constexpr (std::is_same<T, double>())
170 template <
typename T>
172 return bigVector<T>().cbegin() +
columns_[column].firstIndex;
174 template <
typename T>
179 template <
typename T>
181 return bigVectorImpl<T>(*this);
183 template <
typename T>
185 return bigVectorImpl<T>(*this);
188 template <
typename T,
class This>
191 if constexpr (std::is_same<T, float>())
192 return table.floats_;
193 else if constexpr (std::is_same<T, int>())
195 else if constexpr (std::is_same<T, uint8_t>())
196 return table.uint8s_;
197 else if constexpr (std::is_same<T, int8_t>())
199 else if constexpr (std::is_same<T, bool>())
200 return table.uint8s_;
201 else if constexpr (std::is_same<T, uint32_t>())
202 return table.uint32s_;
203 else if constexpr (std::is_same<T, double>())
204 return table.doubles_;
void addExtension(const FlatTable &extension)
RowView row(unsigned int row) const
void bulk(Span &&data) const
auto columnData(unsigned int column)
get a column by index (non-const)
int columnIndex(const std::string &name) const
float one(const float &val) 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_
static auto & bigVectorImpl(This &table)
std::vector< uint32_t > uint32s_
const std::string & doc() const
double getAnyValue(unsigned int column) const
auto columnData(unsigned int column) const
get a column by index (const)
void setDoc(const std::string &doc)
std::vector< float > floats_
MaybeMantissaReduce(int mantissaBits)
const FlatTable & table() const
auto beginData(unsigned int column)
T one(const T &val) const
unsigned int nRows() const
RowView(const FlatTable &table, unsigned int row)
const std::string & name() const
std::vector< int8_t > int8s_
const auto & columValue(unsigned int column) const
get a column value for singleton (const)
double getAnyValue(const std::string &column) const
auto const & bigVector() const
const std::string & columnName(unsigned int col) const
MaybeMantissaReduce(int mantissaBits)
void bulk(Span const &data) const
FlatTable(unsigned int size, const std::string &name, bool singleton, bool extension=false)
static ColumnType defaultColumnType()
static float reduceMantissaToNbitsRounding(const float &f)
unsigned int nColumns() const
unsigned int size() const
char data[epos_bytes_allocation]
void addColumn(const std::string &name, const C &values, const std::string &docString, int mantissaBits=-1)
auto beginData(unsigned int column) const
void addColumnValue(const std::string &name, const C &value, const std::string &docString, int mantissaBits=-1)
std::vector< double > doubles_
double getAnyValue(unsigned int row, unsigned int column) const
const std::string & columnDoc(unsigned int col) const