ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SqliteRecord Class Referencefinal

SqliteRecord is one record in the SqliteRecordset object. More...

#include <SqliteRecord.h>

Inheritance diagram for SqliteRecord:
Collaboration diagram for SqliteRecord:

Public Member Functions

 SqliteRecord (SqliteInpDef_ptr def)
 
 SqliteRecord ()=delete
 
 SqliteRecord (const SqliteRecord &)=delete
 
SqliteRecordoperator= (const SqliteRecord &)=delete
 
 ~SqliteRecord () override
 Destructor. More...
 
bool isFieldNull (const std::string &field) const override
 Check if the field value is NULL. More...
 
int getInt (const std::string &field) const override
 Get int field value. More...
 
long getLong (const std::string &field) const override
 Get long field value. More...
 
double getDouble (const std::string &field) const override
 Get double field value. More...
 
float getFloat (const std::string &field) const override
 Get float field value. More...
 
virtual const std::string & getString (const std::string &field) const override
 Get string field value. More...
 
int getInt (const std::string &field, unsigned int index) const override
 Get array int field value. More...
 
long getLong (const std::string &field, unsigned int index) const override
 Get array long field value. More...
 
double getDouble (const std::string &field, unsigned int index) const override
 Get array double field value. More...
 
float getFloat (const std::string &field, unsigned int index) const override
 Get array float field value. More...
 
virtual const std::string & getString (const std::string &field, unsigned int index) const override
 Get array string field value. More...
 
void dump () const
 Dump to cout. More...
 
void addValue (const std::string &field, SqliteInp value)
 

Private Types

enum  FieldCheckCode { FIELD_CHECK_OK, FIELD_CHECK_BAD_NAME, FIELD_CHECK_BAD_TYPE, FIELD_CHECK_NULL_VAL }
 
typedef std::map< std::string, SqliteInpRecord
 
typedef Record::const_iterator RecordCIterator
 
typedef std::tuple< RecordCIterator, FieldCheckCodeFieldCheckResult
 

Private Member Functions

FieldCheckResult checkField (const std::string &field, SqliteInpType fieldType) const
 
void handleError (const std::string &field, FieldCheckCode checkCode) const
 

Private Attributes

SqliteInpDef_ptr m_def
 
Record m_record
 

Detailed Description

SqliteRecord is one record in the SqliteRecordset object.

Definition at line 48 of file SqliteRecord.h.

Member Typedef Documentation

◆ FieldCheckResult

Definition at line 138 of file SqliteRecord.h.

◆ Record

typedef std::map<std::string,SqliteInp> SqliteRecord::Record
private

Definition at line 129 of file SqliteRecord.h.

◆ RecordCIterator

typedef Record::const_iterator SqliteRecord::RecordCIterator
private

Definition at line 130 of file SqliteRecord.h.

Member Enumeration Documentation

◆ FieldCheckCode

Enumerator
FIELD_CHECK_OK 
FIELD_CHECK_BAD_NAME 
FIELD_CHECK_BAD_TYPE 
FIELD_CHECK_NULL_VAL 

Definition at line 131 of file SqliteRecord.h.

132  {
137  };

Constructor & Destructor Documentation

◆ SqliteRecord() [1/3]

SqliteRecord::SqliteRecord ( SqliteInpDef_ptr  def)

Definition at line 19 of file SqliteRecord.cxx.

20  : m_def(def)
21 {
22 }

◆ SqliteRecord() [2/3]

SqliteRecord::SqliteRecord ( )
delete

◆ SqliteRecord() [3/3]

SqliteRecord::SqliteRecord ( const SqliteRecord )
delete

◆ ~SqliteRecord()

SqliteRecord::~SqliteRecord ( )
override

Destructor.

Definition at line 24 of file SqliteRecord.cxx.

25 {
26 }

Member Function Documentation

◆ addValue()

void SqliteRecord::addValue ( const std::string &  field,
SqliteInp  value 
)

Definition at line 102 of file SqliteRecord.cxx.

104 {
105  auto [it,result] = m_record.insert(std::pair(field,value));
106  if(!result) throw std::runtime_error("Unexpected error when adding new value for the field " +
107  field + ". Duplicate field name?");
108 }

◆ checkField()

SqliteRecord::FieldCheckResult SqliteRecord::checkField ( const std::string &  field,
SqliteInpType  fieldType 
) const
inlineprivate

Definition at line 149 of file SqliteRecord.h.

151 {
152  FieldCheckCode checkCode{FIELD_CHECK_OK};
153  RecordCIterator checkIt{m_record.end()};
154 
155  auto defIt = m_def->find(field);
156  if(defIt==m_def->end()) checkCode = FIELD_CHECK_BAD_NAME;
157  if(defIt->second!=fieldType) checkCode = FIELD_CHECK_BAD_TYPE;
158 
159  if(checkCode==FIELD_CHECK_OK) {
160  checkIt = m_record.find(field);
161  if(checkIt==m_record.end()) {
162  checkCode = FIELD_CHECK_NULL_VAL;
163  }
164  }
165  return std::make_tuple(checkIt,checkCode);
166 }

◆ dump()

void SqliteRecord::dump ( ) const

Dump to cout.

Definition at line 110 of file SqliteRecord.cxx.

111 {
112  bool first{true};
113  for(const auto& [colName,colType] : *m_def) {
114  if(first) {
115  first = false;
116  }
117  else {
118  std::cout << ", ";
119  }
120  auto recIt = m_record.find(colName);
121  bool fieldNull = (recIt==m_record.end());
122  std::cout << "[" << colName << " (";
123  switch(colType) {
124  case SQLITEINP_INT:
125  std::cout << "int) : " << (fieldNull? "NULL" : std::to_string(std::get<int>(recIt->second))) << "]";
126  break;
127  case SQLITEINP_LONG:
128  std::cout << "long) : " << (fieldNull? "NULL" : std::to_string(std::get<long>(recIt->second))) << "]";
129  break;
130  case SQLITEINP_FLOAT:
131  std::cout << "float) : ";
132  if (fieldNull) {
133  std::cout << "NULL";
134  }
135  else {
136  std::cout << std::setprecision(10) << std::get<float>(recIt->second) << "]";
137  }
138  break;
139  case SQLITEINP_DOUBLE:
140  std::cout << "double) : ";
141  if (fieldNull) {
142  std::cout << "NULL";
143  }
144  else {
145  std::cout << std::setprecision(10) << std::get<double>(recIt->second) << "]";
146  }
147  break;
148  case SQLITEINP_STRING:
149  std::cout << "string) : " << (fieldNull? "NULL" : ("\"" + std::get<std::string>(recIt->second)) + "\"") << "]";
150  break;
151  default:
152  std::cout << "ERROR) : ]";
153  }
154  }
155  std::cout << std::endl;
156 }

◆ getDouble() [1/2]

double SqliteRecord::getDouble ( const std::string &  field) const
overridevirtual

Get double field value.

Parameters
field[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 51 of file SqliteRecord.cxx.

52 {
53  auto [recIt,checkCode] = checkField(field,SQLITEINP_DOUBLE);
54  if(checkCode==FIELD_CHECK_OK) {
55  return std::get<double>(recIt->second);
56  }
57  handleError(field,checkCode);
58  return 0.;
59 }

◆ getDouble() [2/2]

double SqliteRecord::getDouble ( const std::string &  field,
unsigned int  index 
) const
overridevirtual

Get array double field value.

Parameters
field[IN] field name
index[IN] index in the array
Returns
field value

Implements IRDBRecord.

Definition at line 87 of file SqliteRecord.cxx.

88 {
89  return getDouble(field + "_" + std::to_string(index));
90 }

◆ getFloat() [1/2]

float SqliteRecord::getFloat ( const std::string &  field) const
overridevirtual

Get float field value.

Parameters
field[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 61 of file SqliteRecord.cxx.

62 {
63  // SQLite stores REAL as double
64  return (float)getDouble(field);
65 }

◆ getFloat() [2/2]

float SqliteRecord::getFloat ( const std::string &  field,
unsigned int  index 
) const
overridevirtual

Get array float field value.

Parameters
field[IN] field name
index[IN] index in the array
Returns
field value

Implements IRDBRecord.

Definition at line 92 of file SqliteRecord.cxx.

93 {
94  return getFloat(field + "_" + std::to_string(index));
95 }

◆ getInt() [1/2]

int SqliteRecord::getInt ( const std::string &  field) const
overridevirtual

Get int field value.

Parameters
field[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 35 of file SqliteRecord.cxx.

36 {
37  auto [recIt,checkCode] = checkField(field,SQLITEINP_INT);
38  if(checkCode==FIELD_CHECK_OK) {
39  return std::get<int>(recIt->second);
40  }
41  handleError(field,checkCode);
42  return 0;
43 }

◆ getInt() [2/2]

int SqliteRecord::getInt ( const std::string &  field,
unsigned int  index 
) const
overridevirtual

Get array int field value.

Parameters
field[IN] field name
index[IN] index in the array
Returns
field value

Implements IRDBRecord.

Definition at line 77 of file SqliteRecord.cxx.

78 {
79  return getInt(field + "_" + std::to_string(index));
80 }

◆ getLong() [1/2]

long SqliteRecord::getLong ( const std::string &  field) const
overridevirtual

Get long field value.

Parameters
field[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 45 of file SqliteRecord.cxx.

46 {
47  // Our database does not support LONG data types at this moment
48  return (long)getInt(field);
49 }

◆ getLong() [2/2]

long SqliteRecord::getLong ( const std::string &  field,
unsigned int  index 
) const
overridevirtual

Get array long field value.

Parameters
field[IN] field name
index[IN] index in the array
Returns
field value

Implements IRDBRecord.

Definition at line 82 of file SqliteRecord.cxx.

83 {
84  return getLong(field + "_" + std::to_string(index));
85 }

◆ getString() [1/2]

const std::string & SqliteRecord::getString ( const std::string &  field) const
overridevirtual

Get string field value.

Parameters
field[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 67 of file SqliteRecord.cxx.

68 {
69  auto [recIt,checkCode] = checkField(field,SQLITEINP_STRING);
70  if(checkCode==FIELD_CHECK_OK) {
71  return std::get<std::string>(recIt->second);
72  }
73  handleError(field,checkCode);
74  throw std::runtime_error("Unexpected error in SqliteRecord::getString()");
75 }

◆ getString() [2/2]

const std::string & SqliteRecord::getString ( const std::string &  field,
unsigned int  index 
) const
overridevirtual

Get array string field value.

Parameters
field[IN] field name
index[IN] index in the array
Returns
field value

Implements IRDBRecord.

Definition at line 97 of file SqliteRecord.cxx.

98 {
99  return getString(field + "_" + std::to_string(index));
100 }

◆ handleError()

void SqliteRecord::handleError ( const std::string &  field,
FieldCheckCode  checkCode 
) const
inlineprivate

Definition at line 168 of file SqliteRecord.h.

170 {
171  switch(checkCode) {
173  throw std::runtime_error( "Wrong name for the field " + field);
175  throw std::runtime_error( "Wrong data type requested for the field " + field);
177  throw std::runtime_error( field + " is NULL");
178  default:
179  break;
180  }
181  return;
182 }

◆ isFieldNull()

bool SqliteRecord::isFieldNull ( const std::string &  field) const
overridevirtual

Check if the field value is NULL.

Parameters
field[IN] field name @retun TRUE if the field is NULL, FALSE otherwise

Implements IRDBRecord.

Definition at line 28 of file SqliteRecord.cxx.

29 {
30  if(m_record.find(field)!=m_record.end()) return false;
31  if(m_def->find(field)==m_def->end()) throw std::runtime_error( "Wrong name for the field "+ field);
32  return true;
33 }

◆ operator=()

SqliteRecord& SqliteRecord::operator= ( const SqliteRecord )
delete

Member Data Documentation

◆ m_def

SqliteInpDef_ptr SqliteRecord::m_def
private

Definition at line 140 of file SqliteRecord.h.

◆ m_record

Record SqliteRecord::m_record
private

Definition at line 141 of file SqliteRecord.h.


The documentation for this class was generated from the following files:
get_generator_info.result
result
Definition: get_generator_info.py:21
index
Definition: index.py:1
skel.it
it
Definition: skel.GENtoEVGEN.py:396
athena.value
value
Definition: athena.py:124
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
SQLITEINP_LONG
@ SQLITEINP_LONG
Definition: SqliteRecord.h:26
SQLITEINP_INT
@ SQLITEINP_INT
Definition: SqliteRecord.h:25
SqliteRecord::getFloat
float getFloat(const std::string &field) const override
Get float field value.
Definition: SqliteRecord.cxx:61
SqliteRecord::FIELD_CHECK_BAD_NAME
@ FIELD_CHECK_BAD_NAME
Definition: SqliteRecord.h:134
SQLITEINP_DOUBLE
@ SQLITEINP_DOUBLE
Definition: SqliteRecord.h:28
SqliteRecord::FIELD_CHECK_BAD_TYPE
@ FIELD_CHECK_BAD_TYPE
Definition: SqliteRecord.h:135
SqliteRecord::FIELD_CHECK_OK
@ FIELD_CHECK_OK
Definition: SqliteRecord.h:133
SqliteRecord::getInt
int getInt(const std::string &field) const override
Get int field value.
Definition: SqliteRecord.cxx:35
SQLITEINP_STRING
@ SQLITEINP_STRING
Definition: SqliteRecord.h:29
SqliteRecord::FieldCheckCode
FieldCheckCode
Definition: SqliteRecord.h:132
SqliteRecord::handleError
void handleError(const std::string &field, FieldCheckCode checkCode) const
Definition: SqliteRecord.h:168
SQLITEINP_FLOAT
@ SQLITEINP_FLOAT
Definition: SqliteRecord.h:27
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
SqliteRecord::getLong
long getLong(const std::string &field) const override
Get long field value.
Definition: SqliteRecord.cxx:45
DeMoScan.first
bool first
Definition: DeMoScan.py:536
SqliteRecord::m_def
SqliteInpDef_ptr m_def
Definition: SqliteRecord.h:140
SqliteRecord::checkField
FieldCheckResult checkField(const std::string &field, SqliteInpType fieldType) const
Definition: SqliteRecord.h:149
SqliteRecord::m_record
Record m_record
Definition: SqliteRecord.h:141
SqliteRecord::getString
virtual const std::string & getString(const std::string &field) const override
Get string field value.
Definition: SqliteRecord.cxx:67
SqliteRecord::getDouble
double getDouble(const std::string &field) const override
Get double field value.
Definition: SqliteRecord.cxx:51
SqliteRecord::RecordCIterator
Record::const_iterator RecordCIterator
Definition: SqliteRecord.h:130
SqliteRecord::FIELD_CHECK_NULL_VAL
@ FIELD_CHECK_NULL_VAL
Definition: SqliteRecord.h:136