ATLAS Offline Software
Loading...
Searching...
No Matches
RDBRecord Class Referencefinal

RDBRecord is one record in the RDBRecordset object. More...

#include <RDBRecord.h>

Inheritance diagram for RDBRecord:
Collaboration diagram for RDBRecord:

Public Member Functions

 RDBRecord (const RDBRecord &)=delete
RDBRecordoperator= (const RDBRecord &)=delete
 ~RDBRecord () override
 Destructor.
bool isFieldNull (std::string_view fieldName) const override
 Check if the field value is NULL.
int getInt (std::string_view fieldName) const override
 Get int field value.
long getLong (std::string_view fieldName) const override
 Get long field value.
double getDouble (std::string_view fieldName) const override
 Get double field value.
float getFloat (std::string_view fieldName) const override
 Get float field value.
virtual const std::string & getString (std::string_view string_view) const override
 Get string field value.
int getInt (std::string_view fieldName, unsigned int index) const override
 Get array int field value.
long getLong (std::string_view fieldName, unsigned int index) const override
 Get array long field value.
double getDouble (std::string_view fieldName, unsigned int index) const override
 Get array double field value.
float getFloat (std::string_view fieldName, unsigned int index) const override
 Get array float field value.
virtual const std::string & getString (std::string_view fieldName, unsigned int index) const override
 Get array string field value.
bool operator!= (const RDBRecord &rhs) const
std::ostream & toOutputStream (std::ostream &os) const

Protected Member Functions

 RDBRecord (const coral::AttributeList &attList, const std::string &tableName)
 Constructor used by RDBRecordset class.

Private Types

typedef std::map< std::string, unsigned int, std::less<> > FieldName2ListIndex

Private Member Functions

 RDBRecord ()
 Empty private constructor.
template<typename T>
const T & getGeneric (std::string_view fieldName) const
FieldName2ListIndex::const_iterator getItr (std::string_view fieldName) const
FieldName2ListIndex::const_iterator getItr (std::string_view fieldName, int) const

Private Attributes

FieldName2ListIndex m_name2Index
coral::AttributeList *m_values ATLAS_THREAD_SAFE
std::string m_tableName

Friends

class RDBRecordset

Detailed Description

RDBRecord is one record in the RDBRecordset object.

Definition at line 36 of file RDBRecord.h.

Member Typedef Documentation

◆ FieldName2ListIndex

typedef std::map<std::string, unsigned int, std::less<> > RDBRecord::FieldName2ListIndex
private

Definition at line 125 of file RDBRecord.h.

Constructor & Destructor Documentation

◆ RDBRecord() [1/3]

RDBRecord::RDBRecord ( const RDBRecord & )
delete

◆ ~RDBRecord()

RDBRecord::~RDBRecord ( )
override

Destructor.

Definition at line 41 of file RDBRecord.cxx.

42{
43 delete m_values;
44}

◆ RDBRecord() [2/3]

RDBRecord::RDBRecord ( const coral::AttributeList & attList,
const std::string & tableName )
protected

Constructor used by RDBRecordset class.

Parameters
attList[IN] pointer to the attribute list, source of the Record object
cursor[IN] need to check if the field values are NULL
tableName[IN] data table name in the database

Definition at line 26 of file RDBRecord.cxx.

28 : m_values(0)
29 , m_tableName(tableName)
30{
31 // Copy attList. Try to avoid sharing, for thread-safety.
32 m_values = new coral::AttributeList(attList.specification(), false);
33 m_values->fastCopyData (attList);
34
35 for(unsigned int i=0; i<m_values->size(); i++) {
36 std::string key = (*m_values)[i].specification().name();
38 }
39}
std::string m_tableName
Definition RDBRecord.h:133
FieldName2ListIndex m_name2Index
Definition RDBRecord.h:130

◆ RDBRecord() [3/3]

RDBRecord::RDBRecord ( )
inlineprivate

Empty private constructor.

Definition at line 128 of file RDBRecord.h.

128{}

Member Function Documentation

◆ getDouble() [1/2]

double RDBRecord::getDouble ( std::string_view fieldName) const
overridevirtual

Get double field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 128 of file RDBRecord.cxx.

129{
130 return getGeneric<double>(fieldName);
131}
const T & getGeneric(std::string_view fieldName) const
Definition RDBRecord.cxx:47

◆ getDouble() [2/2]

double RDBRecord::getDouble ( std::string_view fieldName,
unsigned int index ) const
overridevirtual

Get array double field value.

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

Implements IRDBRecord.

Definition at line 175 of file RDBRecord.cxx.

176{
177 auto it = getItr(fieldName, index);
178 const coral::AttributeList& values = *m_values;
179 const auto &item = values[it->second];
180 if(item.specification().type()==typeid(double)) {
181 return item.data<double>();
182 }
183 else {
184 throw std::runtime_error( std::format("Field {} is NOT of double type",fieldName));
185 }
186}
FieldName2ListIndex::const_iterator getItr(std::string_view fieldName) const
Definition RDBRecord.cxx:64

◆ getFloat() [1/2]

float RDBRecord::getFloat ( std::string_view fieldName) const
overridevirtual

Get float field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 133 of file RDBRecord.cxx.

134{
135 return getGeneric<float>(fieldName);
136}

◆ getFloat() [2/2]

float RDBRecord::getFloat ( std::string_view fieldName,
unsigned int index ) const
overridevirtual

Get array float field value.

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

Implements IRDBRecord.

Definition at line 188 of file RDBRecord.cxx.

189{
190 auto it = getItr(fieldName, index);
191 const coral::AttributeList& values = *m_values;
192 const auto &item = values[it->second];
193 if(item.specification().type()==typeid(float)) {
194 return item.data<float>();
195 }
196 else {
197 throw std::runtime_error( std::format("Field {} is NOT of float type", fieldName));
198 }
199}

◆ getGeneric()

template<typename T>
const T & RDBRecord::getGeneric ( std::string_view fieldName) const
private

Definition at line 47 of file RDBRecord.cxx.

48{
49 std::string name =std::format("{}.{}", m_tableName, fieldName);
50 FieldName2ListIndex::const_iterator it = m_name2Index.find(name);
51 if(it==m_name2Index.end()) {
52 throw std::runtime_error(std::format("Wrong name for the field {}", name));
53 }
54
55 const coral::AttributeList& values = *m_values;
56 const auto &itr = values[it->second];
57 if(itr.specification().type()==typeid(T)) {
58 return itr.data<T>();
59 } else {
60 throw std::runtime_error(std::format("Field {} is NOT a type of {}", fieldName, typeid(T).name()));
61 }
62}
unsigned long long T

◆ getInt() [1/2]

int RDBRecord::getInt ( std::string_view fieldName) const
overridevirtual

Get int field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 93 of file RDBRecord.cxx.

94{
95 auto it = getItr(fieldName);
96 const coral::AttributeList& values = *m_values;
97 const auto& item = values[it->second];
98 if(item.specification().type()==typeid(int)) {
99 return item.data<int>();
100 }
101 else if(item.specification().type()==typeid(long)) {
102 return (int)item.data<long>();
103 }
104 else {
105 throw std::runtime_error( std::format("Field {} is NOT of integer type", fieldName));
106 }
107}

◆ getInt() [2/2]

int RDBRecord::getInt ( std::string_view fieldName,
unsigned int index ) const
overridevirtual

Get array int field value.

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

Implements IRDBRecord.

Definition at line 143 of file RDBRecord.cxx.

144{
145 auto it = getItr(fieldName, index);
146 const coral::AttributeList& values = *m_values;
147 const auto &item = values[it->second];
148 if(item.specification().type()==typeid(int)) {
149 return item.data<int>();
150 }
151 else if(item.specification().type()==typeid(long)) {
152 return (int)item.data<long>();
153 }
154 else {
155 throw std::runtime_error( std::format("Field {} is NOT of integer type", fieldName));
156 }
157}

◆ getItr() [1/2]

RDBRecord::FieldName2ListIndex::const_iterator RDBRecord::getItr ( std::string_view fieldName) const
private

Definition at line 64 of file RDBRecord.cxx.

65{
66 const std::string name = std::format("{}.{}", m_tableName, fieldName);
67 FieldName2ListIndex::const_iterator it = m_name2Index.find(name);
68 if(it==m_name2Index.end()) {
69 throw std::runtime_error( "Wrong name for the field " + name);
70 }
71 return it;
72}

◆ getItr() [2/2]

RDBRecord::FieldName2ListIndex::const_iterator RDBRecord::getItr ( std::string_view fieldName,
int index ) const
private

Definition at line 74 of file RDBRecord.cxx.

75{
76 const std::string name =std::format("{}.{}_{}", m_tableName, fieldName, index);
77 FieldName2ListIndex::const_iterator it = m_name2Index.find(name);
78 if(it==m_name2Index.end()) {
79 throw std::runtime_error(std::format("Wrong name for the array field {}.{} or index={} is out of range.",m_tableName,fieldName,index));
80 }
81 return it;
82}

◆ getLong() [1/2]

long RDBRecord::getLong ( std::string_view fieldName) const
overridevirtual

Get long field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 109 of file RDBRecord.cxx.

110{
111 auto it = getItr(fieldName);
112 const coral::AttributeList& values = *m_values;
113 const auto& item = values[it->second];
114 if(item.specification().type()==typeid(long)) {
115 return item.data<long>();
116 }
117 else if(item.specification().type()==typeid(int)) {
118 return (long)item.data<int>();
119 }
120 else if(item.specification().type()==typeid(long long)) {
121 return (long)item.data<long long>();
122 }
123 else {
124 throw std::runtime_error( std::format("Field {} is NOT of long type",fieldName));
125 }
126}

◆ getLong() [2/2]

long RDBRecord::getLong ( std::string_view fieldName,
unsigned int index ) const
overridevirtual

Get array long field value.

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

Implements IRDBRecord.

Definition at line 159 of file RDBRecord.cxx.

160{
161 auto it = getItr(fieldName, index);
162 const coral::AttributeList& values = *m_values;
163 const auto &item = values[it->second];
164 if(item.specification().type()==typeid(long)) {
165 return item.data<long>();
166 }
167 else if(item.specification().type()==typeid(int)) {
168 return (long)item.data<int>();
169 }
170 else {
171 throw std::runtime_error( std::format("Field {} is NOT of long type", fieldName));
172 }
173}

◆ getString() [1/2]

const std::string & RDBRecord::getString ( std::string_view fieldName,
unsigned int index ) const
overridevirtual

Get array string field value.

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

Implements IRDBRecord.

Definition at line 201 of file RDBRecord.cxx.

202{
203 auto it = getItr(fieldName, index);
204 const coral::AttributeList& values = *m_values;
205 const auto &item = values[it->second];
206 if(item.specification().type()==typeid(std::string)) {
207 return item.data<std::string>();
208 }
209 else {
210 throw std::runtime_error( std::format("Field {} is NOT of string type", fieldName));
211 }
212}

◆ getString() [2/2]

const std::string & RDBRecord::getString ( std::string_view string_view) const
overridevirtual

Get string field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 138 of file RDBRecord.cxx.

139{
140 return getGeneric<std::string>(fieldName);
141}

◆ isFieldNull()

bool RDBRecord::isFieldNull ( std::string_view fieldName) const
overridevirtual

Check if the field value is NULL.

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

Implements IRDBRecord.

Definition at line 85 of file RDBRecord.cxx.

86{
87 auto it = getItr(fieldName);
88
89 const coral::AttributeList& values = *m_values;
90 return values[it->second].isNull();
91}

◆ operator!=()

bool RDBRecord::operator!= ( const RDBRecord & rhs) const

Definition at line 214 of file RDBRecord.cxx.

215{
216 const coral::AttributeList& myAttList = *m_values;
217 const coral::AttributeList& rhsAttList = *rhs.m_values;
218
219 if(myAttList.size()!=rhsAttList.size()) return true;
220
221 for(size_t i(0); i<myAttList.size(); ++i) {
222 const coral::Attribute& myAtt = myAttList[i];
223 const std::string name = myAtt.specification().name();
224 bool exists(false);
225 for(size_t j(0); j<rhsAttList.size(); ++j) {
226 const coral::Attribute& rhsAtt = rhsAttList[j];
227 if(rhsAtt.specification().name()==name) {
228 if(myAtt!=rhsAtt) {
229 return true;
230 }
231 exists = true;
232 break;
233 }
234 }// Go through the attributes in the RHS list
235 if(!exists)
236 return true;
237 }
238 return false;
239}
bool exists(const std::string &filename)
does a file exist
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ operator=()

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

◆ toOutputStream()

std::ostream & RDBRecord::toOutputStream ( std::ostream & os) const

Definition at line 241 of file RDBRecord.cxx.

242{
243 m_values->toOutputStream(os);
244 return os;
245}

◆ RDBRecordset

friend class RDBRecordset
friend

Definition at line 38 of file RDBRecord.h.

Member Data Documentation

◆ ATLAS_THREAD_SAFE

coral::AttributeList* m_values RDBRecord::ATLAS_THREAD_SAFE
private

Definition at line 131 of file RDBRecord.h.

◆ m_name2Index

FieldName2ListIndex RDBRecord::m_name2Index
private

Definition at line 130 of file RDBRecord.h.

◆ m_tableName

std::string RDBRecord::m_tableName
private

Definition at line 133 of file RDBRecord.h.


The documentation for this class was generated from the following files: