ATLAS Offline Software
Loading...
Searching...
No Matches
GeometryDBSvc Class Reference

Concrete class for interface to geometry database with possibility to override entries from a text file. More...

#include <GeometryDBSvc.h>

Inheritance diagram for GeometryDBSvc:
Collaboration diagram for GeometryDBSvc:

Public Member Functions

 GeometryDBSvc (const std::string &name, ISvcLocator *sl)
virtual ~GeometryDBSvc ()
virtual StatusCode initialize ()
 Service init.
virtual StatusCode finalize ()
 Service finalize.
virtual double getDouble (IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const
virtual int getInt (IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const
virtual std::string getString (IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const
virtual bool testField (IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const
virtual bool testFieldTxt (IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const
virtual unsigned int getTableSize (IRDBRecordset_ptr recordSet) const
virtual double getDouble (const std::string &recordSetName, const std::string &name, int index=0) const
virtual int getInt (const std::string &recordSetName, const std::string &name, int index=0) const
virtual std::string getString (const std::string &recordSetName, const std::string &name, int index=0) const
virtual bool testField (const std::string &recordSetName, const std::string &name, int index=0) const
virtual unsigned int getTableSize (const std::string &recordSetName) const
virtual void printParameters (const std::string &section="") const
 Print paramaters read in from text file. If section is supplied only consider the parameters in that section.
virtual void printNotUsed (const std::string &section="") const
 Print paramaters from text file which are not used. If section is supplied only consider the parameters in that section.

Private Member Functions

void setParameterFileName (const std::string &filename)
std::string parameterKey (const std::string &recordSetName, const std::string &name, int index) const
bool getValue (const std::string &recordSetName, const std::string &name, int index, std::string &var) const
bool getValue (const std::string &recordSetName, const std::string &name, int index, double &var) const
bool getValue (const std::string &recordSetName, const std::string &name, int index, int &var) const
bool getTableSizeFromTextFile (const std::string &recordSetName, int &var) const

Private Attributes

TextFileDBReaderm_textParameters
std::string m_textFileName
bool m_printParameters
bool m_printNotUsed
std::vector< std::string > m_sections

Detailed Description

Concrete class for interface to geometry database with possibility to override entries from a text file.

Definition at line 25 of file GeometryDBSvc.h.

Constructor & Destructor Documentation

◆ GeometryDBSvc()

GeometryDBSvc::GeometryDBSvc ( const std::string & name,
ISvcLocator * sl )

Definition at line 14 of file GeometryDBSvc.cxx.

14 :
15 base_class(name, pSvcLocator),
17{
18 declareProperty("TextFileName",m_textFileName, "Text file name for overriding database.");
19 declareProperty("PrintParameters",m_printParameters = true, "Print parameters read in from text file.");
20 declareProperty("PrintNotUsed", m_printNotUsed = true, "Print parameters not used.");
21 declareProperty("Sections", m_sections, "Sections considered for logging. Empty list means all.");
22}
TextFileDBReader * m_textParameters
std::string m_textFileName
std::vector< std::string > m_sections

◆ ~GeometryDBSvc()

GeometryDBSvc::~GeometryDBSvc ( )
virtual

Definition at line 24 of file GeometryDBSvc.cxx.

25{
26 delete m_textParameters;
27}

Member Function Documentation

◆ finalize()

StatusCode GeometryDBSvc::finalize ( )
virtual

Service finalize.

Definition at line 67 of file GeometryDBSvc.cxx.

68{
69
70 if (m_textParameters && m_printNotUsed && msgLvl(MSG::INFO)) {
71 if (m_sections.empty()) {
72 // Consider all parameters if no sections are requested.
73 msg(MSG::INFO) << "The following parameters were not used:" << endmsg;
74 m_textParameters->printNotUsed();
75 } else {
76 // Otherwise consider only those parameters that belong to sections requested.
77 bool printedUnnamed = false;
78 for (std::vector<std::string>::const_iterator iter = m_sections.begin(); iter != m_sections.end(); ++iter) {
79 msg(MSG::INFO) << "The following parameters were not used from section: " << *iter <<endmsg;
80 if (m_textParameters->sectionPresent(*iter)) {
81 m_textParameters->printNotUsed(*iter);
82 } else {
83 // If section not present consider those in unnamed section (passing a section name that is not present will do this)
84 // If we already printed those in the unnamed section don't do so again.
85 if (printedUnnamed) {
86 msg(MSG::INFO) << " Section not present. Parameters from text file from unnamed section already printed above." << endmsg;
87 } else {
88 msg(MSG::INFO) << " Section not present. Parameters from text file from unnamed section will be printed." << endmsg;
89 m_textParameters->printNotUsed(*iter);
90 printedUnnamed = true;
91 }
92 }
93 }
94 }
95 }
96 return StatusCode::SUCCESS;
97}
#define endmsg
MsgStream & msg
Definition testRead.cxx:32

◆ getDouble() [1/2]

double GeometryDBSvc::getDouble ( const std::string & recordSetName,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 148 of file GeometryDBSvc.cxx.

149{
150 double tmpPar = 0;
151 if (getValue(recordSetName,name,index,tmpPar)) {
152 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Parameter " << parameterKey(recordSetName,name,index) << " from text file: " << tmpPar << endmsg;
153 return tmpPar;
154 } else {
155 msg(MSG::ERROR) << "Parameter " << parameterKey(recordSetName,name,index) << " not found." << endmsg;
156 return 0;
157 }
158}
bool getValue(const std::string &recordSetName, const std::string &name, int index, std::string &var) const
std::string parameterKey(const std::string &recordSetName, const std::string &name, int index) const

◆ getDouble() [2/2]

double GeometryDBSvc::getDouble ( IRDBRecordset_ptr recordSet,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 129 of file GeometryDBSvc.cxx.

130{
131 if (!recordSet.get()) return getDouble("",name,index);
132 double tmpPar = 0;
133 std::string recordSetName = recordSet->nodeName();
134 if (getValue(recordSetName,name,index,tmpPar)) {
135 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Parameter " << parameterKey(recordSetName,name,index) << " from text file: " << tmpPar << endmsg;
136 } else {
137 if (index >= (int)recordSet->size()) {
138 msg(MSG::ERROR) << "Parameter " << parameterKey(recordSetName,name,index) << " not found. " << endmsg;
139 } else {
140 tmpPar = (*recordSet)[index]->getDouble(name);
141 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Parameter " << parameterKey(recordSetName,name,index) << " from database: " << tmpPar << endmsg;
142 }
143 }
144 return tmpPar;
145}
virtual double getDouble(IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const
virtual std::string nodeName() const =0
virtual unsigned int size() const =0
str index
Definition DeMoScan.py:362

◆ getInt() [1/2]

int GeometryDBSvc::getInt ( const std::string & recordSetName,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 180 of file GeometryDBSvc.cxx.

181{
182 int tmpPar = 0;
183 if (getValue(recordSetName,name,index,tmpPar)) {
184 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Parameter " << parameterKey(recordSetName,name,index) << " from text file: " << tmpPar << endmsg;
185 return tmpPar;
186 } else {
187 msg(MSG::ERROR) << "Parameter " << parameterKey(recordSetName,name,index) << index << " not found." << endmsg;
188 return 0;
189 }
190}

◆ getInt() [2/2]

int GeometryDBSvc::getInt ( IRDBRecordset_ptr recordSet,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 161 of file GeometryDBSvc.cxx.

162{
163 if (!recordSet.get()) return getInt("",name,index);
164 int tmpPar = 0;
165 std::string recordSetName = recordSet->nodeName();
166 if (getValue(recordSetName,name,index,tmpPar)) {
167 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Parameter " << parameterKey(recordSetName,name,index) << " from text file: " << tmpPar << endmsg;
168 } else {
169 if (index >= (int)recordSet->size()) {
170 msg(MSG::ERROR) << "Parameter " << parameterKey(recordSetName,name,index) << " not found. " << endmsg;
171 } else {
172 tmpPar = (*recordSet)[index]->getInt(name);
173 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Parameter " << parameterKey(recordSetName,name,index) << " from database: " << tmpPar << endmsg;
174 }
175 }
176 return tmpPar;
177}
virtual int getInt(IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const

◆ getString() [1/2]

std::string GeometryDBSvc::getString ( const std::string & recordSetName,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 212 of file GeometryDBSvc.cxx.

213{
214 std::string tmpPar;
215 if (getValue(recordSetName,name,index,tmpPar)) {
216 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Parameter " << parameterKey(recordSetName,name,index) << " from text file: " << tmpPar << endmsg;
217 return tmpPar;
218 } else {
219 msg(MSG::ERROR) << "Parameter " << parameterKey(recordSetName,name,index) << " not found." << endmsg;
220 return "";
221 }
222}

◆ getString() [2/2]

std::string GeometryDBSvc::getString ( IRDBRecordset_ptr recordSet,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 193 of file GeometryDBSvc.cxx.

194{
195 if (!recordSet.get()) return getString("",name,index);
196 std::string tmpPar;
197 std::string recordSetName = recordSet->nodeName();
198 if (getValue(recordSetName,name,index,tmpPar)) {
199 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Parameter " << parameterKey(recordSetName,name,index) << " from text file: " << tmpPar << endmsg;
200 } else {
201 if (index >= (int)recordSet->size()) {
202 msg(MSG::ERROR) << "Parameter " << parameterKey(recordSetName,name,index) << index << " not found. " << endmsg;
203 } else {
204 tmpPar = (*recordSet)[index]->getString(name);
205 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Parameter " << parameterKey(recordSetName,name,index) << " from database: " << tmpPar << endmsg;
206 }
207 }
208 return tmpPar;
209}
virtual std::string getString(IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const

◆ getTableSize() [1/2]

unsigned int GeometryDBSvc::getTableSize ( const std::string & recordSetName) const
virtual

Definition at line 347 of file GeometryDBSvc.cxx.

348{
349 int tmpPar = 0;
350 unsigned int tmpParUnsigned = 0;
351 // Table size stored with key of form TableSize:TableName
352 if (getTableSizeFromTextFile(recordSetName,tmpPar)) {
353 if (tmpPar < 0) {
354 msg(MSG::ERROR) << "Table " << recordSetName << " size from text file is negative: " << tmpPar << endmsg;
355 tmpPar = 0;
356 } else {
357 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Table " << recordSetName << " size from text file: " << tmpPar << endmsg;
358 }
359 tmpParUnsigned = static_cast<unsigned int>(tmpPar);
360 } else {
361 msg(MSG::ERROR) << "getTableSize: Table " << recordSetName << " does not exist in text file." << endmsg;
362 }
363 return tmpParUnsigned;
364}
bool getTableSizeFromTextFile(const std::string &recordSetName, int &var) const

◆ getTableSize() [2/2]

unsigned int GeometryDBSvc::getTableSize ( IRDBRecordset_ptr recordSet) const
virtual

Definition at line 324 of file GeometryDBSvc.cxx.

325{
326 int tmpPar = 0;
327 unsigned int tmpParUnsigned = 0;
328 std::string recordSetName = recordSet->nodeName();
329 // Table size stored with key of form TableSize:TableName
330 if (getTableSizeFromTextFile(recordSetName,tmpPar)) {
331 if (tmpPar < 0) {
332 msg(MSG::ERROR) << "Table " << recordSetName << " size from text file is negative: " << tmpPar << endmsg;
333 tmpPar = 0;
334 } else {
335 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "TEXTFILE: Table " << recordSetName << " size from text file: " << tmpPar << endmsg;
336 }
337 tmpParUnsigned = static_cast<unsigned int>(tmpPar);
338 } else {
339 // Get from database
340 tmpParUnsigned = recordSet->size();
341 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Table " << recordSetName << " size from database: " << tmpParUnsigned << endmsg;
342 }
343 return tmpParUnsigned;
344}

◆ getTableSizeFromTextFile()

bool GeometryDBSvc::getTableSizeFromTextFile ( const std::string & recordSetName,
int & var ) const
private

Definition at line 368 of file GeometryDBSvc.cxx.

369{
370 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Looking for TableSize for " << recordSetName << endmsg;
371 std::string result;
372 var = -1;
373 if (!m_textParameters) return false;
374 std::ostringstream key;
375 key << "TableSize:" << recordSetName;
376 if (m_textParameters->find(key.str(),result)) {
377 // Convert to int
378 std::istringstream istr(result);
379 istr >> var;
380 if (!istr.eof()) { // Should have read the whole stream
381 msg(MSG::ERROR) << "Error retrieving parameter TableSize:" << recordSetName << " as an int: " << result << endmsg;
382 return false;
383 }
384 return true;
385 }
386 return false;
387}

◆ getValue() [1/3]

bool GeometryDBSvc::getValue ( const std::string & recordSetName,
const std::string & name,
int index,
double & var ) const
private

Definition at line 247 of file GeometryDBSvc.cxx.

248{
249 std::string result;
250 var = 0;
251 // Get the parameter as a string first
252 if (getValue(recordSetName, name, index, result)) {
253 std::istringstream istr(result);
254 istr >> var;
255 if (!istr.eof()) { // Should have read the whole stream
256 msg(MSG::ERROR) << "Error retrieving parameter " << parameterKey(recordSetName,name,index) << " as a double: " << result << endmsg;
257 return false;
258 }
259 return true;
260 }
261 return false;
262}

◆ getValue() [2/3]

bool GeometryDBSvc::getValue ( const std::string & recordSetName,
const std::string & name,
int index,
int & var ) const
private

Definition at line 265 of file GeometryDBSvc.cxx.

266{
267 std::string result;
268 var = 0;
269 // Get the parameter as a string first
270 if (getValue(recordSetName, name, index, result)) {
271 std::istringstream istr(result);
272 istr >> var;
273 if (!istr.eof()) { // Should have read the whole stream
274 msg(MSG::ERROR) << "Error retrieving parameter " << parameterKey(recordSetName,name,index) << " as an int: " << result << endmsg;
275 return false;
276 }
277 return true;
278 }
279 return false;
280}

◆ getValue() [3/3]

bool GeometryDBSvc::getValue ( const std::string & recordSetName,
const std::string & name,
int index,
std::string & var ) const
private

Definition at line 226 of file GeometryDBSvc.cxx.

227{
228 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Looking for Parameter " << parameterKey(recordSetName,name,index) << endmsg;
229 if (recordSetName.empty() && index) {
230 msg(MSG::WARNING) << "Non zero index for parameter with empry record set. Index will be ignored: " << index << endmsg;
231 }
232 var = "";
233 if (!m_textParameters) return false;
234 std::string lookupKey = parameterKey(recordSetName,name,index);
235 bool result = m_textParameters->find(parameterKey(recordSetName,name,index),var);
236 if (!result && !recordSetName.empty()) {
237 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Not found. Looking for default entry with #ALL" << endmsg;
238 std::ostringstream keyalt;
239 keyalt << recordSetName << "#ALL:" << name;
240 result = m_textParameters->find(keyalt.str(),var);
241 }
242 return result;
243}

◆ initialize()

StatusCode GeometryDBSvc::initialize ( )
virtual

Service init.

Definition at line 30 of file GeometryDBSvc.cxx.

31{
32 msg(MSG::INFO) << "GeometryDBSvc Initialized" << endmsg;
34
35 // Some printout
36 if (m_textParameters && m_printParameters && msgLvl(MSG::INFO)) {
37 if (m_sections.empty()) {
38 // Print all parameters if no sections are requested
39 msg(MSG::INFO) << "Parameters from text file:" << endmsg;
40 m_textParameters->printParameters();
41 } else {
42 // Otherwise print only those parameters that belong to sections requested.
43 bool printedUnnamed = false;
44 for (std::vector<std::string>::const_iterator iter = m_sections.begin(); iter != m_sections.end(); ++iter) {
45 msg(MSG::INFO) << "Parameters from text file from section: " << *iter << endmsg;
46 if (m_textParameters->sectionPresent(*iter)) {
47 m_textParameters->printParameters(*iter);
48 } else {
49 // If section not present print those in unnamed section (passing a section name that is not present will do this)
50 // If we already printed those in the unnamed section don't do so again.
51 if (printedUnnamed) {
52 msg(MSG::INFO) << " Section not present. Parameters from text file from unnamed section already printed above." << endmsg;
53 } else {
54 msg(MSG::INFO) << " Section not present. Parameters from text file from unnamed section will be printed." << endmsg;
55 m_textParameters->printParameters(*iter);
56 printedUnnamed = true;
57 }
58 }
59 }
60 }
61 }
62 return StatusCode::SUCCESS;
63}
void setParameterFileName(const std::string &filename)

◆ parameterKey()

std::string GeometryDBSvc::parameterKey ( const std::string & recordSetName,
const std::string & name,
int index ) const
private

Definition at line 117 of file GeometryDBSvc.cxx.

118{
119 std::ostringstream ostr;
120 if (!recordSetName.empty()) {
121 ostr << recordSetName << "#" << index << ":" << name;
122 } else {
123 ostr << name;
124 }
125 return ostr.str();
126}

◆ printNotUsed()

void GeometryDBSvc::printNotUsed ( const std::string & section = "") const
virtual

Print paramaters from text file which are not used. If section is supplied only consider the parameters in that section.

Definition at line 396 of file GeometryDBSvc.cxx.

397{
398 m_textParameters->printNotUsed(section);
399}
void section(const std::string &sec)

◆ printParameters()

void GeometryDBSvc::printParameters ( const std::string & section = "") const
virtual

Print paramaters read in from text file. If section is supplied only consider the parameters in that section.

Definition at line 390 of file GeometryDBSvc.cxx.

391{
392 m_textParameters->printParameters(section);
393}

◆ setParameterFileName()

void GeometryDBSvc::setParameterFileName ( const std::string & filename)
private

Definition at line 101 of file GeometryDBSvc.cxx.

102{
103 if (!filename.empty()) {
104 msg(MSG::INFO) << "Parameters overriden from text file: " << filename << endmsg;
105 msg(MSG::WARNING) << "Overriding from a text file is NOT recommended for production use." << endmsg;
106 if (!m_textParameters) m_textParameters = new TextFileDBReader;
107 bool status = m_textParameters->readFile(filename);
108 if (!status) {
109 msg(MSG::ERROR) << "Problem reading text file: " << filename << endmsg;
110 }
111 }
112}
status
Definition merge.py:16

◆ testField() [1/2]

bool GeometryDBSvc::testField ( const std::string & recordSetName,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 316 of file GeometryDBSvc.cxx.

317{
318 std::string tmpStr;
319 return getValue(recordSetName, name, index, tmpStr);
320}

◆ testField() [2/2]

bool GeometryDBSvc::testField ( IRDBRecordset_ptr recordSet,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 290 of file GeometryDBSvc.cxx.

291{
292 std::string recordSetName = recordSet->nodeName();
293 if (testField(recordSetName, name, index)) {
294 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Parameter " << parameterKey(recordSetName,name,index) << " found in text file. " << endmsg;
295 return true;
296 }
297 bool result = false;
298 if (index < (int)recordSet->size()) {
299 try {
300 result = !(*recordSet)[index]->isFieldNull(name);
301 }
302 catch(std::runtime_error& ex) {
303 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Exception caught: " << ex.what() << endmsg;
304 result = false;
305 }
306 }
307 if (result){
308 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Parameter " << parameterKey(recordSetName,name,index) << " found in database. " << endmsg;
309 } else {
310 if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Parameter " << parameterKey(recordSetName,name,index) << " not found. " << endmsg;
311 }
312 return result;
313}
virtual bool testField(IRDBRecordset_ptr recordSet, const std::string &name, int index=0) const

◆ testFieldTxt()

bool GeometryDBSvc::testFieldTxt ( IRDBRecordset_ptr recordSet,
const std::string & name,
int index = 0 ) const
virtual

Definition at line 283 of file GeometryDBSvc.cxx.

284{
285 std::string recordSetName = recordSet->nodeName();
286 return testField(recordSetName, name, index);
287}

Member Data Documentation

◆ m_printNotUsed

bool GeometryDBSvc::m_printNotUsed
private

Definition at line 69 of file GeometryDBSvc.h.

◆ m_printParameters

bool GeometryDBSvc::m_printParameters
private

Definition at line 68 of file GeometryDBSvc.h.

◆ m_sections

std::vector<std::string> GeometryDBSvc::m_sections
private

Definition at line 70 of file GeometryDBSvc.h.

◆ m_textFileName

std::string GeometryDBSvc::m_textFileName
private

Definition at line 67 of file GeometryDBSvc.h.

◆ m_textParameters

TextFileDBReader* GeometryDBSvc::m_textParameters
private

Definition at line 64 of file GeometryDBSvc.h.


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