ATLAS Offline Software
GenericDbTable.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef CONDDBOBJECTS_GENERICDBTABLE_H
6 #define CONDDBOBJECTS_GENERICDBTABLE_H
7 
8 
9 #include <iostream>
10 #include <vector>
11 #include <string>
12 #include <sstream>
13 
14 
15 #include "GaudiKernel/DataObject.h"
16 
17 typedef long long int64;
18 
19 
20 class GenericDbTable: public DataObject {
21 
22  public:
23 
24 
25  enum dataTypes {kNull=0,
27  kInt,
38  };
39 
40 
41 
48 
56 
63  GenericDbTable(unsigned n_columns, int n_rows = 0);
64 
68  /* virtual*/ ~GenericDbTable();
69 
76  /* virtual */ int getNames(std::vector<std::string> &names) const;
77 
84  /* virtual */ int getTypes(std::vector<dataTypes> &types) const;
85 
90  /* virtual */ int getNull(unsigned n_column, float &null) const;
91  /* virtual */ int getNull(unsigned n_column, long int &null) const;
92  /* virtual */ int getNull(unsigned n_column, int64 &null) const;
93  /* virtual */ int getNull(unsigned n_column, double &null) const;
94  /* virtual */ int getNull(unsigned n_column, std::string &null) const;
95 
103  /* virtual */ int setName(unsigned n_column, const std::string& name);
104 
112  /* virtual */ int setType(unsigned n_column, dataTypes type);
113 
118  /* virtual */ int setNull(unsigned n_column, const float &null);
119  /* virtual */ int setNull(unsigned n_column, const long int &null);
120  /* virtual */ int setNull(unsigned n_column, const int64 &null);
121  /* virtual */ int setNull(unsigned n_column, const double &null);
122  /* virtual */ int setNull(unsigned n_column, const std::string &null);
123 
131  /* virtual */ void Initialize(unsigned n_columns, int n_rows=0);
132 
133 
142  /* virtual */ int getRow(unsigned rowNumber, std::vector<std::string> &values) const;
143 
151  int getRowID(std::string &pID) const;
152 
154 // The following methods get the value of a specified cell
156 
165  /* virtual */ int getCell(unsigned n_column, unsigned n_row, short int &ndata) const;
166 
175  /* virtual */ int getCell(unsigned n_column, unsigned n_row, long int &ndata) const ;
176 
185  /* virtual */ int getCell(unsigned n_column, unsigned n_row, int64 &ndata) const ;
186 
195  /* virtual */ int getCell(unsigned n_column, unsigned n_row, float &ndata) const;
196 
205  /* virtual */ int getCell(unsigned n_column, unsigned n_row, std::string &ndata) const;
206 
215  /* virtual */ int getCell(unsigned n_column, unsigned n_row, double &ndata) const;
216 
225  /* virtual */ int getCell(unsigned n_column, unsigned n_row, std::vector<short int> &ndata) const;
226 
235  /* virtual */ int getCell(unsigned n_column, unsigned n_row, std::vector<long int> &ndata) const;
236 
245  /* virtual */ int getCell(unsigned n_column, unsigned n_row, std::vector<int64> &ndata) const;
246 
255  /* virtual */ int getCell(unsigned n_column, unsigned n_row, std::vector<float> &ndata) const;
256 
265  /* virtual */ int getCell(unsigned n_column, unsigned n_row, std::vector<std::string> &ndata) const;
266 
275  /* virtual */ int getCell(unsigned n_column, unsigned n_row, std::vector<double> &ndata) const;
276 
277 
286  int getCell(const std::string& colName, unsigned int n_row, short int &data) const;
287  int getCell(const std::string& colName, unsigned int n_row, long int &data) const;
288  int getCell(const std::string& colName, unsigned int n_row, int64 &data) const;
289  int getCell(const std::string& colName, unsigned int n_row, float &data) const;
290  int getCell(const std::string& colName, unsigned int n_row, double &data) const;
291  int getCell(const std::string& colName, unsigned int n_row, std::string &data) const;
292  int getCell(const std::string& colName, unsigned int n_row, std::vector<short int> &data) const;
293  int getCell(const std::string& colName, unsigned int n_row, std::vector<long int> &data) const;
294  int getCell(const std::string& colName, unsigned int n_row, std::vector<int64> &data) const;
295  int getCell(const std::string& colName, unsigned int n_row, std::vector<float> &data) const;
296  int getCell(const std::string& colName, unsigned int n_row, std::vector<double> &data) const;
297  int getCell(const std::string& colName, unsigned int n_row, std::vector<std::string> &data) const;
298 
299 
300 
302 
315  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const short int ndata);
316 
325  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const long int ndata);
326 
335  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const int64 ndata);
336 
345  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const float ndata);
346 
355  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const std::string& ndata);
356 
365  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const double ndata);
366 
375  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const std::vector<short int> &ndata);
376 
385  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const std::vector<long int> &ndata);
386 
395  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const std::vector<int64> &ndata);
396 
405  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const std::vector<float> &ndata);
406 
415  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const std::vector<std::string> &ndata);
416 
425  /* virtual */ int setCell(unsigned n_column, unsigned n_row, const std::vector<double> &ndata);
426 
427 
444  /* virtual */ int setColumndata(unsigned n_column, const std::vector<short int> &data);
445 
454  /* virtual */ int setColumndata(unsigned n_column, const std::vector<long int> &data);
455 
464  /* virtual */ int setColumndata(unsigned n_column, const std::vector<int64> &data);
465 
474  /* virtual */ int setColumndata(unsigned n_column, const std::vector<float> &data);
475 
484  /* virtual */ int setColumndata(unsigned n_column, const std::vector<std::string> &data);
485 
494  /* virtual */ int setColumndata(unsigned n_column, const std::vector<double> &data);
495 
504  /* virtual */ int setColumndata(unsigned n_column, const std::vector<std::vector<short int> > &data);
505 
514  /* virtual */ int setColumndata(unsigned n_column, const std::vector<std::vector<long int> > &data);
515 
524  /* virtual */ int setColumndata(unsigned n_column, const std::vector<std::vector<int64> > &data);
525 
534  /* virtual */ int setColumndata(unsigned n_column, const std::vector<std::vector<float> > &data);
535 
544  /* virtual */ int setColumndata(unsigned n_column, const std::vector<std::vector<std::string> > &data);
545 
554  /* virtual */ int setColumndata(unsigned n_column, const std::vector<std::vector<double> > &data);
555 
556 
563  /* virtual */ void resize(int num_rows);
564 
571  /* virtual */ unsigned getNumRows() const {return m_numRows;}
572 
579  /* virtual */ unsigned getNumColumns() const {return m_conddbtable.size();}
580 
581 
582  private:
583 
584 
585 
594  template <typename T, typename COLUMN>
595  int __getNull(T &data, COLUMN *tmpColumn) const
596  {
597  data = tmpColumn->column[0];
598  return CDB_SUCCESS;
599  }
600 
601 
608  template <typename T, typename COLUMN>
609  int __getCell(unsigned n_column, unsigned n_row, T &ndata, dataTypes type, COLUMN *tmpColumn) const;
610 
617  template <typename T, typename COLUMN>
618  int __setCell(unsigned n_column, unsigned n_row, const T &ndata, dataTypes type, COLUMN *tmpColumn);
619 
626  template <typename T, typename COLUMN>
627  int __setColumnData(unsigned n_column, T &data, dataTypes type, COLUMN *tmpColumn);
628 
635  template <typename T>
636  int __getCellByName(const std::string& colName, unsigned int n_row, T &data) const;
637 
638 
642  void verifyInitialization();
643 
650 template <class TYPE>
651 std::string ToString( const TYPE & t ) const {
652  //CONDDBTABLESTREAM os;
653  std::ostringstream os;
654  os << t;
655  return os.str();
656 }
657 
658 
663  struct CondDBColumn{
664  virtual ~CondDBColumn() {}
666  std::string name;
668 
669  };
670 
672  {
673  std::vector<short int> column;
674  };
675 
677  {
678  std::vector<int64> column;
679  };
680 
681 
683  {
684  std::vector<long int> column;
685  };
686 
688  {
689  std::vector<float> column;
690  };
691 
693  {
694  std::vector<std::string> column;
695  };
696 
698  {
699  std::vector<double> column;
700  };
701 
703  {
704  std::vector<std::vector<short int> > column;
705  };
706 
708  {
709  std::vector<std::vector<int64> > column;
710  };
711 
713  {
714  std::vector<std::vector<long int> > column;
715  };
716 
718  {
719  std::vector<std::vector<float> > column;
720  };
721 
723  {
724  std::vector<std::vector<std::string> > column;
725  };
726 
728  {
729  std::vector<std::vector<double> > column;
730  };
731 
732 
734  std::vector<CondDBColumn*> m_conddbtable;
735  unsigned m_numRows;
736 
737 };
738 
739 #endif /*CONDDBOBJECTS_GENERICDBTABLE_H*/
740 
741 
742 
GenericDbTable::CondDBColumn
Definition of the columns.
Definition: GenericDbTable.h:663
GenericDbTable::CondDBColumn::type
dataTypes type
Definition: GenericDbTable.h:667
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
GenericDbTable::CondDBColumnArrayString::column
std::vector< std::vector< std::string > > column
Definition: GenericDbTable.h:724
GenericDbTable::__getCell
int __getCell(unsigned n_column, unsigned n_row, T &ndata, dataTypes type, COLUMN *tmpColumn) const
Templated method that get's the data from a specified cell This is the method that does the real work...
Definition: GenericDbTable.cxx:1781
GenericDbTable::setColumndata
int setColumndata(unsigned n_column, const std::vector< double > &data)
Insert a subset in a column of doubles.
GenericDbTable::~GenericDbTable
~GenericDbTable()
Object destructor.
Definition: GenericDbTable.cxx:53
GenericDbTable::CondDBColumnFloat
Definition: GenericDbTable.h:688
GenericDbTable::CondDBColumnArrayFloat
Definition: GenericDbTable.h:718
GenericDbTable::CondDBColumnArrayBool
Definition: GenericDbTable.h:703
GenericDbTable::__setCell
int __setCell(unsigned n_column, unsigned n_row, const T &ndata, dataTypes type, COLUMN *tmpColumn)
Templated method that set's the data in a specified cell This is the method that does the real work.
Definition: GenericDbTable.cxx:1807
GenericDbTable::CondDBColumnLong::column
std::vector< int64 > column
Definition: GenericDbTable.h:678
GenericDbTable::__getCellByName
int __getCellByName(const std::string &colName, unsigned int n_row, T &data) const
Templated method that get's column data using the column name This method get's the desired column nu...
Definition: GenericDbTable.cxx:1870
GenericDbTable::CDB_ALLOC_ERROR
@ CDB_ALLOC_ERROR
Definition: GenericDbTable.h:46
GenericDbTable::kArrayBool
@ kArrayBool
Definition: GenericDbTable.h:32
GenericDbTable::CondDBColumn::~CondDBColumn
virtual ~CondDBColumn()
Definition: GenericDbTable.h:664
GenericDbTable::getCell
int getCell(unsigned n_column, unsigned n_row, std::vector< float > &ndata) const
This method gets a value from a cell in a column of vectors of floats.
GenericDbTable::CondDBColumnBool
Definition: GenericDbTable.h:672
GenericDbTable::CondDBColumnArrayDouble::column
std::vector< std::vector< double > > column
Definition: GenericDbTable.h:729
GenericDbTable::CondDBColumnBool::column
std::vector< short int > column
Definition: GenericDbTable.h:673
GenericDbTable::__getNull
int __getNull(T &data, COLUMN *tmpColumn) const
Templated method for handling the null values.
Definition: GenericDbTable.h:595
int64
long long int64
Definition: GenericDbTable.h:17
GenericDbTable::CondDBColumnFloat::column
std::vector< float > column
Definition: GenericDbTable.h:689
GenericDbTable::CondDBErrorCode
CondDBErrorCode
Definition: GenericDbTable.h:42
GenericDbTable::ToString
std::string ToString(const TYPE &t) const
Auxiliary function to convert any value to string.
Definition: GenericDbTable.h:651
GenericDbTable::kLongLong
@ kLongLong
Definition: GenericDbTable.h:31
GenericDbTable::CondDBColumnString::column
std::vector< std::string > column
Definition: GenericDbTable.h:694
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
GenericDbTable::CondDBColumnArrayDouble
Definition: GenericDbTable.h:728
GenericDbTable::setNull
int setNull(unsigned n_column, const float &null)
Set Null value for column.
Definition: GenericDbTable.cxx:651
GenericDbTable::kArrayInt
@ kArrayInt
Definition: GenericDbTable.h:34
GenericDbTable::m_conddbtable
std::vector< CondDBColumn * > m_conddbtable
Definition: GenericDbTable.h:734
GenericDbTable::getNames
int getNames(std::vector< std::string > &names) const
This method gets a vector containing the names of all columns in the table.
Definition: GenericDbTable.cxx:85
GenericDbTable::CondDBColumnInt::column
std::vector< long int > column
Definition: GenericDbTable.h:684
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
GenericDbTable::Initialize
void Initialize(unsigned n_columns, int n_rows=0)
This method initializes a table created by the default constructor If the table had the number of col...
Definition: GenericDbTable.cxx:61
GenericDbTable::kArrayLongLong
@ kArrayLongLong
Definition: GenericDbTable.h:37
GenericDbTable::kArrayFloat
@ kArrayFloat
Definition: GenericDbTable.h:33
GenericDbTable::resize
void resize(int num_rows)
Reserves more rows on the table.
Definition: GenericDbTable.cxx:1606
GenericDbTable::setName
int setName(unsigned n_column, const std::string &name)
This method defines the name for a specified column.
Definition: GenericDbTable.cxx:337
GenericDbTable::m_numRows
unsigned m_numRows
Definition: GenericDbTable.h:735
GenericDbTable::setColumndata
int setColumndata(unsigned n_column, const std::vector< std::vector< double > > &data)
Insert a subset in a column of vectors of doubles.
GenericDbTable::getRow
int getRow(unsigned rowNumber, std::vector< std::string > &values) const
This method returns a vector of strings with allelements in a row In case the cell has an array the f...
Definition: GenericDbTable.cxx:1616
GenericDbTable::CondDBColumnArrayLong::column
std::vector< std::vector< int64 > > column
Definition: GenericDbTable.h:709
GenericDbTable::CondDBColumnArrayFloat::column
std::vector< std::vector< float > > column
Definition: GenericDbTable.h:719
python.subdetectors.mmg.names
names
Definition: mmg.py:8
GenericDbTable::setType
int setType(unsigned n_column, dataTypes type)
This method defines the data type for a specified column.
Definition: GenericDbTable.cxx:356
GenericDbTable::getRowID
int getRowID(std::string &pID) const
This method returns, for a given ID, the row number.
Definition: GenericDbTable.cxx:111
GenericDbTable::CDB_SUCCESS
@ CDB_SUCCESS
Definition: GenericDbTable.h:45
GenericDbTable::kString
@ kString
Definition: GenericDbTable.h:29
GenericDbTable::__setColumnData
int __setColumnData(unsigned n_column, T &data, dataTypes type, COLUMN *tmpColumn)
Templated method that set's portions of data in a specified column This method is deprecated and henc...
Definition: GenericDbTable.cxx:1844
GenericDbTable::getTypes
int getTypes(std::vector< dataTypes > &types) const
This method gets a vector containing the data types of all columns in the table.
Definition: GenericDbTable.cxx:98
GenericDbTable::kArrayDouble
@ kArrayDouble
Definition: GenericDbTable.h:36
GenericDbTable::setCell
int setCell(unsigned n_column, unsigned n_row, const short int ndata)
set data methods
Definition: GenericDbTable.cxx:909
GenericDbTable::m_isInitialized
bool m_isInitialized
Definition: GenericDbTable.h:733
GenericDbTable::CondDBColumnLong
Definition: GenericDbTable.h:677
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
GenericDbTable
Definition: GenericDbTable.h:20
GenericDbTable::CondDBColumnDouble::column
std::vector< double > column
Definition: GenericDbTable.h:699
GenericDbTable::getNumRows
unsigned getNumRows() const
Returns the number of rows RESERVED in the table.
Definition: GenericDbTable.h:571
GenericDbTable::setColumndata
int setColumndata(unsigned n_column, const std::vector< float > &data)
Insert a subset in a column of floats.
TYPE
#define TYPE(CODE, TYP, IOTYP)
GenericDbTable::CondDBColumnArrayLong
Definition: GenericDbTable.h:708
GenericDbTable::CondDBColumn::name
std::string name
Definition: GenericDbTable.h:666
GenericDbTable::kFloat
@ kFloat
Definition: GenericDbTable.h:28
GenericDbTable::getCell
int getCell(unsigned n_column, unsigned n_row, short int &ndata) const
This method gets a value from a cell in a column of long ints (int in MySQL)
Definition: GenericDbTable.cxx:706
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
GenericDbTable::kInt
@ kInt
Definition: GenericDbTable.h:27
GenericDbTable::CondDBColumnString
Definition: GenericDbTable.h:693
GenericDbTable::CDB_RANGE_ERROR
@ CDB_RANGE_ERROR
Definition: GenericDbTable.h:43
GenericDbTable::CDB_TYPE_ERROR
@ CDB_TYPE_ERROR
Definition: GenericDbTable.h:44
GenericDbTable::dataTypes
dataTypes
Definition: GenericDbTable.h:25
GenericDbTable::kDouble
@ kDouble
Definition: GenericDbTable.h:30
GenericDbTable::setColumndata
int setColumndata(unsigned n_column, const std::vector< std::vector< float > > &data)
Insert a subset in a column of vectors of floats.
GenericDbTable::verifyInitialization
void verifyInitialization()
Verifies if all columns are initialized.
Definition: GenericDbTable.cxx:1763
GenericDbTable::getNull
int getNull(unsigned n_column, float &null) const
Get Null value for column.
Definition: GenericDbTable.cxx:237
GenericDbTable::CondDBColumnArrayBool::column
std::vector< std::vector< short int > > column
Definition: GenericDbTable.h:704
GenericDbTable::CondDBColumn::initialized
bool initialized
Definition: GenericDbTable.h:665
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
GenericDbTable::getCell
int getCell(unsigned n_column, unsigned n_row, std::vector< double > &ndata) const
This method gets a value from a cell in a column of vector of doubles.
GenericDbTable::CDB_NOT_INITIALIZED
@ CDB_NOT_INITIALIZED
Definition: GenericDbTable.h:42
GenericDbTable::setColumndata
int setColumndata(unsigned n_column, const std::vector< short int > &data)
The following methods allow to insert in the columns a group of values.
Definition: GenericDbTable.cxx:1203
GenericDbTable::getNumColumns
unsigned getNumColumns() const
Returns the number of columns in the table.
Definition: GenericDbTable.h:579
GenericDbTable::CondDBColumnInt
Definition: GenericDbTable.h:683
GenericDbTable::kArrayString
@ kArrayString
Definition: GenericDbTable.h:35
GenericDbTable::GenericDbTable
GenericDbTable()
Default constructor.
Definition: GenericDbTable.h:55
GenericDbTable::kBool
@ kBool
Definition: GenericDbTable.h:26
GenericDbTable::kNull
@ kNull
Definition: GenericDbTable.h:25
GenericDbTable::CondDBColumnArrayInt
Definition: GenericDbTable.h:713
GenericDbTable::CDB_STRTOARRAY_ERROR
@ CDB_STRTOARRAY_ERROR
Definition: GenericDbTable.h:47
GenericDbTable::setCell
int setCell(unsigned n_column, unsigned n_row, const std::vector< float > &ndata)
This method changes a value from a cell in a column of vectors of floats.
GenericDbTable::setCell
int setCell(unsigned n_column, unsigned n_row, const std::vector< double > &ndata)
This method changes a value from a cell in a column of vectors of doubles.
GenericDbTable::CondDBColumnArrayString
Definition: GenericDbTable.h:723
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
GenericDbTable::CondDBColumnArrayInt::column
std::vector< std::vector< long int > > column
Definition: GenericDbTable.h:714
GenericDbTable::CondDBColumnDouble
Definition: GenericDbTable.h:698