Concrete class for interface to geometry database with possibility to override entries from a text file.
More...
#include <GeometryDBSvc.h>
|
| | 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 §ion="") 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 §ion="") const |
| | Print paramaters from text file which are not used. If section is supplied only consider the parameters in that section.
|
|
| 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 |
Concrete class for interface to geometry database with possibility to override entries from a text file.
Definition at line 25 of file GeometryDBSvc.h.
◆ 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 |
◆ finalize()
| StatusCode GeometryDBSvc::finalize |
( |
| ) |
|
|
virtual |
Service finalize.
Definition at line 67 of file GeometryDBSvc.cxx.
68{
69
72
73 msg(MSG::INFO) <<
"The following parameters were not used:" <<
endmsg;
75 } else {
76
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;
82 } else {
83
84
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;
90 printedUnnamed = true;
91 }
92 }
93 }
94 }
95 }
96 return StatusCode::SUCCESS;
97}
◆ 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
◆ 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 {
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()) {
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
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]
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
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
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;
374 std::ostringstream
key;
375 key <<
"TableSize:" << recordSetName;
377
378 std::istringstream istr(result);
380 if (!istr.eof()) {
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{
251
252 if (
getValue(recordSetName, name, index, result)) {
253 std::istringstream istr(result);
255 if (!istr.eof()) {
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{
269
270 if (
getValue(recordSetName, name, index, result)) {
271 std::istringstream istr(result);
273 if (!istr.eof()) {
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 }
234 std::string lookupKey =
parameterKey(recordSetName,name,index);
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;
241 }
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
38
39 msg(MSG::INFO) <<
"Parameters from text file:" <<
endmsg;
41 } else {
42
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;
48 } else {
49
50
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;
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 {
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.
◆ 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.
◆ setParameterFileName()
| void GeometryDBSvc::setParameterFileName |
( |
const std::string & | filename | ) |
|
|
private |
Definition at line 101 of file GeometryDBSvc.cxx.
102{
105 msg(MSG::WARNING) <<
"Overriding from a text file is NOT recommended for production use." <<
endmsg;
108 if (!status) {
110 }
111 }
112}
◆ 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 }
298 if (index < (
int)recordSet->
size()) {
299 try {
301 }
302 catch(std::runtime_error& ex) {
303 if (msgLvl(MSG::VERBOSE))
msg(MSG::VERBOSE) <<
"Exception caught: " << ex.what() <<
endmsg;
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 }
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 |
◆ m_printNotUsed
| bool GeometryDBSvc::m_printNotUsed |
|
private |
◆ m_printParameters
| bool GeometryDBSvc::m_printParameters |
|
private |
◆ m_sections
| std::vector<std::string> GeometryDBSvc::m_sections |
|
private |
◆ m_textFileName
| std::string GeometryDBSvc::m_textFileName |
|
private |
◆ m_textParameters
The documentation for this class was generated from the following files: