ATLAS Offline Software
Loading...
Searching...
No Matches
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
17typedef long long int64;
18
19
20class GenericDbTable: public DataObject {
21
22 public:
23
24
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
89
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
117
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
150
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
306
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
435
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
643
650template <class TYPE>
651std::string ToString( const TYPE & t ) const {
652 //CONDDBTABLESTREAM os;
653 std::ostringstream os;
654 os << t;
655 return os.str();
656}
657
658
662
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
long long int64
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static const std::vector< std::string > types
#define TYPE(CODE, TYP, IOTYP)
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...
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.
int setNull(unsigned n_column, const float &null)
Set Null value for column.
void verifyInitialization()
Verifies if all columns are initialized.
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.
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.
int getTypes(std::vector< dataTypes > &types) const
This method gets a vector containing the data types of all columns in the table.
int setColumndata(unsigned n_column, const std::vector< float > &data)
Insert a subset in a column of floats.
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.
int setName(unsigned n_column, const std::string &name)
This method defines the name for a specified column.
int getNames(std::vector< std::string > &names) const
This method gets a vector containing the names of all columns in the table.
int __getNull(T &data, COLUMN *tmpColumn) const
Templated method for handling the null values.
unsigned getNumColumns() const
Returns the number of columns in the table.
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...
std::string ToString(const TYPE &t) const
Auxiliary function to convert any value to string.
int setType(unsigned n_column, dataTypes type)
This method defines the data type for a specified column.
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.
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...
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)
int setColumndata(unsigned n_column, const std::vector< std::vector< float > > &data)
Insert a subset in a column of vectors of floats.
int setColumndata(unsigned n_column, const std::vector< short int > &data)
The following methods allow to insert in the columns a group of values.
GenericDbTable()
Default constructor.
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...
int setCell(unsigned n_column, unsigned n_row, const short int ndata)
set data methods
int getNull(unsigned n_column, float &null) const
Get Null value for column.
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...
~GenericDbTable()
Object destructor.
int getRowID(std::string &pID) const
This method returns, for a given ID, the row number.
std::vector< CondDBColumn * > m_conddbtable
int setColumndata(unsigned n_column, const std::vector< std::vector< double > > &data)
Insert a subset in a column of vectors of doubles.
void resize(int num_rows)
Reserves more rows on the table.
int setColumndata(unsigned n_column, const std::vector< double > &data)
Insert a subset in a column of doubles.
unsigned getNumRows() const
Returns the number of rows RESERVED in the table.
std::vector< std::vector< short int > > column
std::vector< std::vector< double > > column
std::vector< std::vector< float > > column
std::vector< std::vector< long int > > column
std::vector< std::vector< int64 > > column
std::vector< std::vector< std::string > > column
std::vector< short int > column
std::vector< long int > column
std::vector< std::string > column
Definition of the columns.