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>
73 auto begin = beginData<T>(column);
80 auto begin = beginData<T>(column);
88 throw cms::Exception(
"LogicError",
"columnValue works only for singleton tables");
89 return *beginData<T>(column);
111 template <
typename T,
typename C>
115 if (values.size() !=
size())
116 throw cms::Exception(
"LogicError",
"Mismatched size for " + name);
117 auto &vec = bigVector<T>();
118 columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
119 vec.insert(vec.end(), values.begin(), values.end());
123 template <
typename T,
typename C>
126 throw cms::Exception(
"LogicError",
"addColumnValue works only for singleton tables");
129 auto &vec = bigVector<T>();
130 columns_.emplace_back(name, docString, defaultColumnType<T>(), vec.size());
138 template <
typename T>
140 if constexpr (std::is_same<T, float>())
142 else if constexpr (std::is_same<T, int>())
144 else if constexpr (std::is_same<T, uint8_t>())
146 else if constexpr (std::is_same<T, bool>())
148 else if constexpr (std::is_same<T, uint32_t>())
150 else if constexpr (std::is_same<T, double>())
167 template <
typename T>
169 return bigVector<T>().cbegin() +
columns_[column].firstIndex;
171 template <
typename T>
176 template <
typename T>
178 return bigVectorImpl<T>(*this);
180 template <
typename T>
182 return bigVectorImpl<T>(*this);
185 template <
typename T,
class This>
188 if constexpr (std::is_same<T, float>())
189 return table.floats_;
190 else if constexpr (std::is_same<T, int>())
192 else if constexpr (std::is_same<T, uint8_t>())
193 return table.uint8s_;
194 else if constexpr (std::is_same<T, bool>())
195 return table.uint8s_;
196 else if constexpr (std::is_same<T, uint32_t>())
197 return table.uint32s_;
198 else if constexpr (std::is_same<T, double>())
199 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
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