ATLAS Offline Software
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
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. More...
 
bool isFieldNull (const std::string &fieldName) const override
 Check if the field value is NULL. More...
 
int getInt (const std::string &fieldName) const override
 Get int field value. More...
 
long getLong (const std::string &fieldName) const override
 Get long field value. More...
 
double getDouble (const std::string &fieldName) const override
 Get double field value. More...
 
float getFloat (const std::string &fieldName) const override
 Get float field value. More...
 
virtual const std::string & getString (const std::string &fieldName) const override
 Get string field value. More...
 
int getInt (const std::string &fieldName, unsigned int index) const override
 Get array int field value. More...
 
long getLong (const std::string &fieldName, unsigned int index) const override
 Get array long field value. More...
 
double getDouble (const std::string &fieldName, unsigned int index) const override
 Get array double field value. More...
 
float getFloat (const std::string &fieldName, unsigned int index) const override
 Get array float field value. More...
 
virtual const std::string & getString (const std::string &fieldName, unsigned int index) const override
 Get array string field value. More...
 
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. More...
 

Private Types

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

Private Member Functions

 RDBRecord ()
 Empty private constructor. More...
 

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 34 of file RDBRecord.h.

Member Typedef Documentation

◆ FieldName2ListIndex

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

Definition at line 123 of file RDBRecord.h.

Constructor & Destructor Documentation

◆ RDBRecord() [1/3]

RDBRecord::RDBRecord ( const RDBRecord )
delete

◆ ~RDBRecord()

RDBRecord::~RDBRecord ( )
override

Destructor.

Definition at line 42 of file RDBRecord.cxx.

43 {
44  delete m_values;
45 }

◆ 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 27 of file RDBRecord.cxx.

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

◆ RDBRecord() [3/3]

RDBRecord::RDBRecord ( )
inlineprivate

Empty private constructor.

Definition at line 126 of file RDBRecord.h.

126 {}

Member Function Documentation

◆ getDouble() [1/2]

double RDBRecord::getDouble ( const std::string &  fieldName) const
overridevirtual

Get double field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 99 of file RDBRecord.cxx.

100 {
101  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName);
102  if(it==m_name2Index.end()) {
103  throw std::runtime_error( "Wrong name for the field " + m_tableName+"."+fieldName);
104  }
105 
106  const coral::AttributeList& values = *m_values;
107  if(values[it->second].specification().type()==typeid(double)) {
108  return values[it->second].data<double>();
109  }
110  else {
111  throw std::runtime_error( "Field " + fieldName + " is NOT of double type");
112  }
113 }

◆ getDouble() [2/2]

double RDBRecord::getDouble ( const std::string &  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 185 of file RDBRecord.cxx.

186 {
187  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName + "_" + std::to_string(index));
188  if(it==m_name2Index.end()) {
189  throw std::runtime_error("Wrong name for the array field " + m_tableName+"."+fieldName + " or index=" + std::to_string(index) + " is out of range");
190  }
191 
192  const coral::AttributeList& values = *m_values;
193  if(values[it->second].specification().type()==typeid(double)) {
194  return values[it->second].data<double>();
195  }
196  else {
197  throw std::runtime_error( "Field " + fieldName + " is NOT of double type");
198  }
199 }

◆ getFloat() [1/2]

float RDBRecord::getFloat ( const std::string &  fieldName) const
overridevirtual

Get float field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 115 of file RDBRecord.cxx.

116 {
117  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName);
118  if(it==m_name2Index.end()) {
119  throw std::runtime_error( "Wrong name for the field " + m_tableName+"."+fieldName);
120  }
121 
122  const coral::AttributeList& values = *m_values;
123  if(values[it->second].specification().type()==typeid(float)) {
124  return values[it->second].data<float>();
125  }
126  else {
127  throw std::runtime_error( "Field " + fieldName + " is NOT of float type");
128  }
129 }

◆ getFloat() [2/2]

float RDBRecord::getFloat ( const std::string &  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 201 of file RDBRecord.cxx.

202 {
203  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName + "_" + std::to_string(index));
204  if(it==m_name2Index.end()) {
205  throw std::runtime_error("Wrong name for the array field " + m_tableName+"."+fieldName + " or index=" + std::to_string(index) + " is out of range");
206  }
207 
208  const coral::AttributeList& values = *m_values;
209  if(values[it->second].specification().type()==typeid(float)) {
210  return values[it->second].data<float>();
211  }
212  else {
213  throw std::runtime_error( "Field " + fieldName + " is NOT of float type");
214  }
215 }

◆ getInt() [1/2]

int RDBRecord::getInt ( const std::string &  fieldName) const
overridevirtual

Get int field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 58 of file RDBRecord.cxx.

59 {
60  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName);
61  if(it==m_name2Index.end()) {
62  throw std::runtime_error( "Wrong name for the field " + m_tableName+"."+fieldName);
63  }
64 
65  const coral::AttributeList& values = *m_values;
66  if(values[it->second].specification().type()==typeid(int)) {
67  return values[it->second].data<int>();
68  }
69  else if(values[it->second].specification().type()==typeid(long)) {
70  return (int)values[it->second].data<long>();
71  }
72  else {
73  throw std::runtime_error( "Field " + fieldName + " is NOT of integer type\n");
74  }
75 }

◆ getInt() [2/2]

int RDBRecord::getInt ( const std::string &  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 147 of file RDBRecord.cxx.

148 {
149  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName + "_" + std::to_string(index));
150  if(it==m_name2Index.end()) {
151  throw std::runtime_error("Wrong name for the array field " + m_tableName+"."+fieldName + " or index=" + std::to_string(index) + " is out of range");
152  }
153 
154  const coral::AttributeList& values = *m_values;
155  if(values[it->second].specification().type()==typeid(int)) {
156  return values[it->second].data<int>();
157  }
158  else if(values[it->second].specification().type()==typeid(long)) {
159  return (int)values[it->second].data<long>();
160  }
161  else {
162  throw std::runtime_error( "Field " + fieldName + " is NOT of integer type\n");
163  }
164 }

◆ getLong() [1/2]

long RDBRecord::getLong ( const std::string &  fieldName) const
overridevirtual

Get long field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 77 of file RDBRecord.cxx.

78 {
79  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName);
80  if(it==m_name2Index.end()) {
81  throw std::runtime_error( "Wrong name for the field " + m_tableName+"."+fieldName);
82  }
83 
84  const coral::AttributeList& values = *m_values;
85  if(values[it->second].specification().type()==typeid(long)) {
86  return values[it->second].data<long>();
87  }
88  else if(values[it->second].specification().type()==typeid(int)) {
89  return (long)values[it->second].data<int>();
90  }
91  else if(values[it->second].specification().type()==typeid(long long)) {
92  return (long)values[it->second].data<long long>();
93  }
94  else {
95  throw std::runtime_error( "Field " + fieldName + " is NOT of long type");
96  }
97 }

◆ getLong() [2/2]

long RDBRecord::getLong ( const std::string &  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 166 of file RDBRecord.cxx.

167 {
168  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName + "_" + std::to_string(index));
169  if(it==m_name2Index.end()) {
170  throw std::runtime_error("Wrong name for the array field " + m_tableName+"."+fieldName + " or index=" + std::to_string(index) + " is out of range");
171  }
172 
173  const coral::AttributeList& values = *m_values;
174  if(values[it->second].specification().type()==typeid(long)) {
175  return values[it->second].data<long>();
176  }
177  else if(values[it->second].specification().type()==typeid(int)) {
178  return (long)values[it->second].data<int>();
179  }
180  else {
181  throw std::runtime_error( "Field " + fieldName + " is NOT of long type");
182  }
183 }

◆ getString() [1/2]

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

Get string field value.

Parameters
fieldName[IN] field name
Returns
field value

Implements IRDBRecord.

Definition at line 131 of file RDBRecord.cxx.

132 {
133  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName);
134  if(it==m_name2Index.end()) {
135  throw std::runtime_error( "Wrong name for the field " + m_tableName+"."+fieldName);
136  }
137 
138  const coral::AttributeList& values = *m_values;
139  if(values[it->second].specification().type()==typeid(std::string)) {
140  return values[it->second].data<std::string>();
141  }
142  else {
143  throw std::runtime_error( "Field " + fieldName + " is NOT of string type");
144  }
145 }

◆ getString() [2/2]

const std::string & RDBRecord::getString ( const std::string &  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 217 of file RDBRecord.cxx.

218 {
219  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName + "_" + std::to_string(index));
220  if(it==m_name2Index.end()) {
221  throw std::runtime_error("Wrong name for the array field " + m_tableName+"."+fieldName + " or index=" + std::to_string(index) + " is out of range");
222  }
223 
224  const coral::AttributeList& values = *m_values;
225  if(values[it->second].specification().type()==typeid(std::string)) {
226  return values[it->second].data<std::string>();
227  }
228  else {
229  throw std::runtime_error( "Field " + fieldName + " is NOT of string type");
230  }
231 }

◆ isFieldNull()

bool RDBRecord::isFieldNull ( const std::string &  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 47 of file RDBRecord.cxx.

48 {
49  FieldName2ListIndex::const_iterator it = m_name2Index.find(m_tableName+"."+fieldName);
50  if(it==m_name2Index.end()) {
51  throw std::runtime_error( "Wrong name for the field " + m_tableName+"."+fieldName);
52  }
53 
54  const coral::AttributeList& values = *m_values;
55  return values[it->second].isNull();
56 }

◆ operator!=()

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

Definition at line 233 of file RDBRecord.cxx.

234 {
235  const coral::AttributeList& myAttList = *m_values;
236  const coral::AttributeList& rhsAttList = *rhs.m_values;
237 
238  if(myAttList.size()!=rhsAttList.size()) return true;
239 
240  for(size_t i(0); i<myAttList.size(); ++i) {
241  const coral::Attribute& myAtt = myAttList[i];
242  const std::string name = myAtt.specification().name();
243  bool exists(false);
244  for(size_t j(0); j<rhsAttList.size(); ++j) {
245  const coral::Attribute& rhsAtt = rhsAttList[j];
246  if(rhsAtt.specification().name()==name) {
247  if(myAtt!=rhsAtt) {
248  return true;
249  }
250  exists = true;
251  break;
252  }
253  }// Go through the attributes in the RHS list
254  if(!exists)
255  return true;
256  }
257  return false;
258 }

◆ operator=()

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

◆ toOutputStream()

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

Definition at line 260 of file RDBRecord.cxx.

261 {
262  m_values->toOutputStream(os);
263  return os;
264 }

Friends And Related Function Documentation

◆ RDBRecordset

friend class RDBRecordset
friend

Definition at line 36 of file RDBRecord.h.

Member Data Documentation

◆ ATLAS_THREAD_SAFE

coral::AttributeList* m_values RDBRecord::ATLAS_THREAD_SAFE
private

Definition at line 129 of file RDBRecord.h.

◆ m_name2Index

FieldName2ListIndex RDBRecord::m_name2Index
private

Definition at line 128 of file RDBRecord.h.

◆ m_tableName

std::string RDBRecord::m_tableName
private

Definition at line 131 of file RDBRecord.h.


The documentation for this class was generated from the following files:
RDBRecord::m_tableName
std::string m_tableName
Definition: RDBRecord.h:131
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
index
Definition: index.py:1
RDBRecord::m_name2Index
FieldName2ListIndex m_name2Index
Definition: RDBRecord.h:128
skel.it
it
Definition: skel.GENtoEVGEN.py:396
python.PyKernel.AttributeList
AttributeList
Definition: PyKernel.py:36
python.Bindings.values
values
Definition: Control/AthenaPython/python/Bindings.py:805
lumiFormat.i
int i
Definition: lumiFormat.py:85
taskman.fieldName
fieldName
Definition: taskman.py:492
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.dummyaccess.exists
def exists(filename)
Definition: dummyaccess.py:9
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37