6#ifndef FRAMEWORK_SIMPLETABLECONDITION_H_
7#define FRAMEWORK_SIMPLETABLECONDITION_H_
14#include "Framework/Exception/Exception.h"
26 const std::vector<std::string>& columns)
29 idMask_{0xFFFFFFFFu} {
30 columnCount_ = (
unsigned int)(columns.size());
37 for (
unsigned int i = 0; i < columnCount_; i++)
38 if (colname == columns_[i])
return i;
51 if (icol >= columnCount_) {
52 EXCEPTION_RAISE(
"ConditionsException",
53 std::string(
"Column index out of range in ") +
getName());
55 return columns_[icol];
61 unsigned int getRowId(
unsigned int irow)
const {
63 EXCEPTION_RAISE(
"ConditionsException",
64 "Row out of range: " + std::to_string(irow));
94 virtual std::ostream&
streamRow(std::ostream& s,
int irow)
const {
95 return s << keys_[irow];
94 virtual std::ostream&
streamRow(std::ostream& s,
int irow)
const {
…}
99 std::size_t findKey(
unsigned int id)
const;
101 std::size_t findKeyInsert(
unsigned int id)
const;
103 std::vector<std::string> columns_;
104 unsigned int columnCount_;
105 std::vector<uint32_t> keys_;
106 unsigned int idMask_;
113 const std::vector<std::string>& columns)
127 void add(
unsigned int id,
const std::vector<T>& values) {
128 if (values.size() != columnCount_) {
129 EXCEPTION_RAISE(
"ConditionsException",
130 getName() +
": Attempted to insert a row with " +
131 std::to_string(values.size()) +
132 " columns into a table with " +
133 std::to_string(columnCount_) +
" columns");
135 std::size_t loc = findKey(
id);
137 EXCEPTION_RAISE(
"ConditionsException",
138 "Attempted to add condition in " +
getName() +
139 " for existing id " + std::to_string(
id));
141 loc = findKeyInsert(
id);
144 keys_.insert(keys_.begin() + loc,
id);
146 values_.insert(values_.begin() + loc * columnCount_, values.begin(),
127 void add(
unsigned int id,
const std::vector<T>& values) {
…}
154 T
get(
unsigned int id,
unsigned int col)
const {
155 std::size_t irow = findKey(
id);
156 if (col >= columnCount_ || irow ==
getRowCount()) {
157 EXCEPTION_RAISE(
"ConditionsException",
158 "No such column " + std::to_string(col) +
" or id " +
161 return values_[irow * columnCount_ + col];
154 T
get(
unsigned int id,
unsigned int col)
const {
…}
168 std::pair<unsigned int, std::vector<T> >
getRow(
unsigned int irow)
const {
170 EXCEPTION_RAISE(
"ConditionsException",
171 "Row out of range: " + std::to_string(irow));
173 std::vector<T> rv(&(values_[irow * columnCount_]),
174 &(values_[(irow + 1) * columnCount_]));
175 return std::pair<unsigned int, std::vector<T> >(keys_[irow], rv);
168 std::pair<unsigned int, std::vector<T> >
getRow(
unsigned int irow)
const {
…}
184 T
getByName(
unsigned int id,
const std::string& colname)
const {
184 T
getByName(
unsigned int id,
const std::string& colname)
const {
…}
191 virtual std::ostream&
streamRow(std::ostream& s,
int irow)
const {
193 EXCEPTION_RAISE(
"ConditionsException",
194 "Row out of range: " + std::to_string(irow));
197 for (
int i = 0; i < columnCount_; i++)
198 s <<
',' << values_[irow * columnCount_ + i];
199 return s << std::endl;
191 virtual std::ostream&
streamRow(std::ostream& s,
int irow)
const {
…}
203 std::vector<T> values_;
213 const std::vector<std::string>& columns)
226 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.