6#ifndef FRAMEWORK_SIMPLETABLECONDITION_H_
7#define FRAMEWORK_SIMPLETABLECONDITION_H_
13#include "Framework/Exception/Exception.h"
25 const std::vector<std::string>& columns)
28 idMask_{0xFFFFFFFFu} {
29 columnCount_ = (
unsigned int)(columns.size());
36 for (
unsigned int i = 0; i < columnCount_; i++)
37 if (colname == columns_[i])
return i;
50 if (icol >= columnCount_) {
51 EXCEPTION_RAISE(
"ConditionsException",
52 std::string(
"Column index out of range in ") +
getName());
54 return columns_[icol];
60 unsigned int getRowId(
unsigned int irow)
const {
62 EXCEPTION_RAISE(
"ConditionsException",
63 "Row out of range: " + std::to_string(irow));
93 virtual std::ostream&
streamRow(std::ostream& s,
int irow)
const {
94 return s << keys_[irow];
98 std::size_t findKey(
unsigned int id)
const;
100 std::size_t findKeyInsert(
unsigned int id)
const;
102 std::vector<std::string> columns_;
103 unsigned int columnCount_;
104 std::vector<uint32_t> keys_;
105 unsigned int idMask_;
112 const std::vector<std::string>& columns)
126 void add(
unsigned int id,
const std::vector<T>& values) {
127 if (values.size() != columnCount_) {
128 EXCEPTION_RAISE(
"ConditionsException",
129 getName() +
": Attempted to insert a row with " +
130 std::to_string(values.size()) +
131 " columns into a table with " +
132 std::to_string(columnCount_) +
" columns");
134 std::size_t loc = findKey(
id);
136 EXCEPTION_RAISE(
"ConditionsException",
137 "Attempted to add condition in " +
getName() +
138 " for existing id " + std::to_string(
id));
140 loc = findKeyInsert(
id);
143 keys_.insert(keys_.begin() + loc,
id);
145 values_.insert(values_.begin() + loc * columnCount_, values.begin(),
153 T
get(
unsigned int id,
unsigned int col)
const {
154 std::size_t irow = findKey(
id);
155 if (col >= columnCount_ || irow ==
getRowCount()) {
156 EXCEPTION_RAISE(
"ConditionsException",
157 "No such column " + std::to_string(col) +
" or id " +
160 return values_[irow * columnCount_ + col];
167 std::pair<unsigned int, std::vector<T> >
getRow(
unsigned int irow)
const {
169 EXCEPTION_RAISE(
"ConditionsException",
170 "Row out of range: " + std::to_string(irow));
172 std::vector<T> rv(&(values_[irow * columnCount_]),
173 &(values_[(irow + 1) * columnCount_]));
174 return std::pair<unsigned int, std::vector<T> >(keys_[irow], rv);
183 T
getByName(
unsigned int id,
const std::string& colname)
const {
190 virtual std::ostream&
streamRow(std::ostream& s,
int irow)
const {
192 EXCEPTION_RAISE(
"ConditionsException",
193 "Row out of range: " + std::to_string(irow));
196 for (
int i = 0; i < columnCount_; i++)
197 s <<
',' << values_[irow * columnCount_ + i];
198 return s << std::endl;
202 std::vector<T> values_;
212 const std::vector<std::string>& columns)
225 const std::vector<std::string>& columns)
Base class for conditions information like pedestals, gains, electronics maps, etc.
unsigned int getColumnNumber(const std::string &colname) const
Get a the column number for the given column name.
void setIdMask(unsigned int mask)
Set an AND mask to be applied to the id.
virtual std::ostream & streamRow(std::ostream &s, int irow) const
Streams a given row of this table.
unsigned int getIdMask() const
Get the AND mask to be applied to the id.
unsigned int getColumnCount() const
Get the number of columns.
const std::string & getColumnName(unsigned int icol) const
Get the name of the given column.
std::size_t getRowCount() const
Get the number of rows.
const std::vector< std::string > & getColumnNames() const
Get the names of the columns.
unsigned int getRowId(unsigned int irow) const
Get the id for the given row.
BaseTableCondition(const std::string &name, const std::vector< std::string > &columns)
Create table with given set of columns.
T get(unsigned int id, unsigned int col) const
Get an entry by DetectorId and number.
std::pair< unsigned int, std::vector< T > > getRow(unsigned int irow) const
Get a row by number Used primarily for persisting the SimpleTableCondition.
virtual std::ostream & streamRow(std::ostream &s, int irow) const
Streams a given row of this table.
T getByName(unsigned int id, const std::string &colname) const
Get a column by DetectorId and name Throws an exception when.
void add(unsigned int id, const std::vector< T > &values)
Add an entry to the table.
void clear()
Clear the contents.
Base class for all conditions objects, very simple.
ConditionsObject(const std::string &name)
Class constructor.
std::string getName() const
Get the name of this object.
All classes in the ldmx-sw project use this namespace.