BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
xmlBase::IFile Class Reference

#include <IFile.h>

+ Inheritance diagram for xmlBase::IFile:

Public Types

typedef std::vector< int > intVector
 
typedef std::vector< double > doubleVector
 
typedef std::vector< int > intVector
 
typedef std::vector< double > doubleVector
 

Public Member Functions

 IFile (const char *filename)
 
 IFile (const DOMDocument *instrument)
 
 IFile (const DOMElement *instrument)
 
virtual ~IFile ()
 
virtual bool contains (const char *section, const char *item)
 
virtual int getInt (const char *section, const char *item)
 
virtual double getDouble (const char *section, const char *item)
 
virtual int getBool (const char *section, const char *item)
 
virtual const char * getString (const char *section, const char *item)
 
virtual intVector getIntVector (const char *section, const char *item)
 
virtual doubleVector getDoubleVector (const char *section, const char *item)
 
virtual int getInt (const char *section, const char *item, int defValue)
 
virtual double getDouble (const char *section, const char *item, double defValue)
 
virtual int getBool (const char *section, const char *item, int defValue)
 
virtual const char * getString (const char *section, const char *item, const char *defValue)
 
virtual intVector getIntVector (const char *section, const char *item, intVector defValues)
 
virtual doubleVector getDoubleVector (const char *section, const char *item, doubleVector defValues)
 
void setString (const char *section, const char *item, const char *newString)
 
void print ()
 
virtual void printOn (std::ostream &out=std::cout)
 
 IFile (const char *filename)
 
 IFile (const DOMDocument *instrument)
 
 IFile (const DOMElement *instrument)
 
virtual ~IFile ()
 
virtual bool contains (const char *section, const char *item)
 
virtual int getInt (const char *section, const char *item)
 
virtual double getDouble (const char *section, const char *item)
 
virtual int getBool (const char *section, const char *item)
 
virtual const char * getString (const char *section, const char *item)
 
virtual intVector getIntVector (const char *section, const char *item)
 
virtual doubleVector getDoubleVector (const char *section, const char *item)
 
virtual int getInt (const char *section, const char *item, int defValue)
 
virtual double getDouble (const char *section, const char *item, double defValue)
 
virtual int getBool (const char *section, const char *item, int defValue)
 
virtual const char * getString (const char *section, const char *item, const char *defValue)
 
virtual intVector getIntVector (const char *section, const char *item, intVector defValues)
 
virtual doubleVector getDoubleVector (const char *section, const char *item, doubleVector defValues)
 
void setString (const char *section, const char *item, const char *newString)
 
void print ()
 
virtual void printOn (std::ostream &out=std::cout)
 

Protected Member Functions

 IFile ()
 
 IFile ()
 

Static Protected Member Functions

static void stripBlanks (char *str1, const char *str2, int flags)
 
static int stricmp (const char *str1, const char *str2)
 
static void stripBlanks (char *str1, const char *str2, int flags)
 
static int stricmp (const char *str1, const char *str2)
 

Friends

class IFile_Section
 
class IFile_Item
 

Detailed Description

Member Typedef Documentation

◆ doubleVector [1/2]

typedef std::vector<double> xmlBase::IFile::doubleVector

◆ doubleVector [2/2]

typedef std::vector<double> xmlBase::IFile::doubleVector

Definition at line 95 of file InstallArea/include/xmlBase/xmlBase/IFile.h.

◆ intVector [1/2]

typedef std::vector<int> xmlBase::IFile::intVector

◆ intVector [2/2]

typedef std::vector<int> xmlBase::IFile::intVector

Definition at line 94 of file InstallArea/include/xmlBase/xmlBase/IFile.h.

Constructor & Destructor Documentation

◆ IFile() [1/8]

xmlBase::IFile::IFile ( const char *  filename)

Definition at line 136 of file IFile.cxx.

137 {
138 using facilities::Util;
139
140 XmlParser parser;
141
142 parser.doSchema(true);
143
144 std::string filenameStr = filename;
145 Util::expandEnvVar(&filenameStr);
146
147 // What if this fails (e.g., file doesn't exist or is not
148 // well-formed)?? How to report it?
149 DOMDocument* doc = parser.parse(filenameStr.c_str());
150
151 // Check it's a good doc.
152 if (doc == 0) {
153 std::cerr << "Attempt to construct IFile from null DOMDocument"
154 << std::endl;
155 std::cerr.flush();
156 exit(1);
157 // FATAL_MACRO("Attempt to construct IFile from null DomDocument");
158 }
159
160 // If so, initialize IFile from it
161 domToIni(doc);
162 }

◆ IFile() [2/8]

xmlBase::IFile::IFile ( const DOMDocument *  instrument)

Definition at line 106 of file IFile.cxx.

107 {
108 // check that argument is non-null
109 if (doc == 0) {
110 // FATAL_MACRO("Attempt to construct IFile from null DOMDocument");
111 std::cerr << "Attempt to construct IFile from null DOMDocument"
112 << std::endl;
113 std::cerr.flush();
114 exit(1);
115 }
116 // If so, call service to do the actual work
117 domToIni(doc);
118 }

◆ IFile() [3/8]

xmlBase::IFile::IFile ( const DOMElement *  instrument)

Definition at line 120 of file IFile.cxx.

121 {
122 // check that argument is non-null
123 if (doc == 0) {
124 // FATAL_MACRO("Attempt to construct IFile from null DOMElement");
125 std::cerr << "Attempt to construct IFile from null DOMDocument"
126 << std::endl;
127 std::cerr.flush();
128 exit(1);
129 }
130 // If so, call service to do the actual work
131 domToIni(doc);
132 }

◆ ~IFile() [1/2]

xmlBase::IFile::~IFile ( )
virtual

Definition at line 90 of file IFile.cxx.

91 {
92 iterator it = begin();
93 while (it != end())
94 delete (*it++).second;
95
96 }

◆ IFile() [4/8]

xmlBase::IFile::IFile ( )
inlineprotected

Definition at line 146 of file Calibration/xmlBase/xmlBase-00-00-03/xmlBase/IFile.h.

146{};

◆ IFile() [5/8]

xmlBase::IFile::IFile ( const char *  filename)

◆ IFile() [6/8]

xmlBase::IFile::IFile ( const DOMDocument *  instrument)

◆ IFile() [7/8]

xmlBase::IFile::IFile ( const DOMElement *  instrument)

◆ ~IFile() [2/2]

virtual xmlBase::IFile::~IFile ( )
virtual

◆ IFile() [8/8]

xmlBase::IFile::IFile ( )
inlineprotected

Definition at line 146 of file InstallArea/include/xmlBase/xmlBase/IFile.h.

146{};

Member Function Documentation

◆ contains() [1/2]

bool xmlBase::IFile::contains ( const char *  section,
const char *  item 
)
virtual

Definition at line 231 of file IFile.cxx.

232 {
233 return (IFile::_getstring (section, item, 0) != 0);
234 }

Referenced by getBool(), getDouble(), getDoubleVector(), getInt(), getIntVector(), getString(), and lookFor().

◆ contains() [2/2]

virtual bool xmlBase::IFile::contains ( const char *  section,
const char *  item 
)
virtual

◆ getBool() [1/4]

int xmlBase::IFile::getBool ( const char *  section,
const char *  item 
)
virtual

Definition at line 351 of file IFile.cxx.

352 {
353 std::string hilf (IFile::_getstring (section, item));
354
355 if (hilf == "yes")
356 return (1);
357 else if (hilf == "true")
358 return (1);
359 else if (hilf == "1")
360 return (1);
361 else if (hilf == "no")
362 return (0);
363 else if (hilf == "false")
364 return (0);
365 else if (hilf == "0")
366 return (0);
367 else {
368 std::string errorString("[");
369 errorString += section + std::string("]") + item + " = \'" + hilf
370 + "\' is not boolean";
371 FATAL_MACRO (errorString);
372 return (0);
373 }
374 }

Referenced by getBool().

◆ getBool() [2/4]

virtual int xmlBase::IFile::getBool ( const char *  section,
const char *  item 
)
virtual

◆ getBool() [3/4]

int xmlBase::IFile::getBool ( const char *  section,
const char *  item,
int  defValue 
)
virtual

Definition at line 444 of file IFile.cxx.

445 {
446 return ( contains(section, item) )? getBool( section, item ):defValue;
447 }
virtual bool contains(const char *section, const char *item)
Definition: IFile.cxx:231
virtual int getBool(const char *section, const char *item)
Definition: IFile.cxx:351

◆ getBool() [4/4]

virtual int xmlBase::IFile::getBool ( const char *  section,
const char *  item,
int  defValue 
)
virtual

◆ getDouble() [1/4]

double xmlBase::IFile::getDouble ( const char *  section,
const char *  item 
)
virtual

Definition at line 316 of file IFile.cxx.

317 {
318 // double hf;
319 std::string hilf (IFile::_getstring (section, item));
320
321 try {
323 }
324 catch (facilities::WrongType ex) {
325 std::cerr << ("from xmlBase::IFile::getDouble ") << std::endl;
326 // FATAL_MACRO
327 std::cerr << ex.getMsg() << std::endl;
328 throw(IFileException(" "));
329 }
330 }
static double stringToDouble(const std::string &InStr)
Exception class used when converting from string to numeric type.

Referenced by getDouble(), and lookFor().

◆ getDouble() [2/4]

virtual double xmlBase::IFile::getDouble ( const char *  section,
const char *  item 
)
virtual

◆ getDouble() [3/4]

double xmlBase::IFile::getDouble ( const char *  section,
const char *  item,
double  defValue 
)
virtual

Definition at line 449 of file IFile.cxx.

450 {
451 return ( contains(section, item) )? getDouble( section, item ):defValue;
452 }
virtual double getDouble(const char *section, const char *item)
Definition: IFile.cxx:316

◆ getDouble() [4/4]

virtual double xmlBase::IFile::getDouble ( const char *  section,
const char *  item,
double  defValue 
)
virtual

◆ getDoubleVector() [1/4]

IFile::doubleVector xmlBase::IFile::getDoubleVector ( const char *  section,
const char *  item 
)
virtual

Definition at line 409 of file IFile.cxx.

411 {
412 doubleVector dv;
413 char buffer[1024];
414
415 strncpy(buffer, IFile::_getstring(section,item), sizeof(buffer) );
416 if (strlen(buffer) >= sizeof(buffer) ) {
417 FATAL_MACRO("string from _getstring() too long");
418 return dv;
419 }
420 char *vString = strtok(buffer,"}");
421 vString = strtok(buffer,"{");
422
423 char *test = strtok(vString,",");
424 while (test != NULL) {
425 dv.push_back(atof(test));
426 test = strtok((char*)NULL,",");
427 }
428 if (dv.size() <= 0) {
429 std::string hilf (buffer);
430 std::string errorString("[");
431 errorString += section + std::string("]") + item + " = \'"
432 + hilf + "\' is not an double vector";
433 FATAL_MACRO (errorString);
434 }
435 return (dv);
436 }
std::string test
Definition: CalibModel.cxx:43

Referenced by getDoubleVector().

◆ getDoubleVector() [2/4]

virtual doubleVector xmlBase::IFile::getDoubleVector ( const char *  section,
const char *  item 
)
virtual

◆ getDoubleVector() [3/4]

IFile::doubleVector xmlBase::IFile::getDoubleVector ( const char *  section,
const char *  item,
doubleVector  defValues 
)
virtual

Definition at line 465 of file IFile.cxx.

467 {
468 return (contains(section, item))? getDoubleVector(section, item):defValues;
469 }
virtual doubleVector getDoubleVector(const char *section, const char *item)
Definition: IFile.cxx:409

◆ getDoubleVector() [4/4]

virtual doubleVector xmlBase::IFile::getDoubleVector ( const char *  section,
const char *  item,
doubleVector  defValues 
)
virtual

◆ getInt() [1/4]

int xmlBase::IFile::getInt ( const char *  section,
const char *  item 
)
virtual

Definition at line 334 of file IFile.cxx.

335 {
336 // int hf;
337 std::string hilf (IFile::_getstring (section, item));
338
339 try {
341 }
342 catch (facilities::WrongType ex) {
343 std::cerr << ("from xmlBase::IFile::getInt ") << std::endl;
344 std::cerr << ex.getMsg() << std::endl;
345 throw(IFileException(" "));
346 }
347 }
static int stringToInt(const std::string &InStr)

Referenced by getInt(), and lookFor().

◆ getInt() [2/4]

virtual int xmlBase::IFile::getInt ( const char *  section,
const char *  item 
)
virtual

◆ getInt() [3/4]

int xmlBase::IFile::getInt ( const char *  section,
const char *  item,
int  defValue 
)
virtual

Definition at line 440 of file IFile.cxx.

440 {
441 return ( contains(section, item) )? getInt( section, item ):defValue;
442 }
virtual int getInt(const char *section, const char *item)
Definition: IFile.cxx:334

◆ getInt() [4/4]

virtual int xmlBase::IFile::getInt ( const char *  section,
const char *  item,
int  defValue 
)
virtual

◆ getIntVector() [1/4]

IFile::intVector xmlBase::IFile::getIntVector ( const char *  section,
const char *  item 
)
virtual

Definition at line 378 of file IFile.cxx.

379 {
380 intVector iv;
381 char buffer[1024];
382
383 strncpy(buffer, IFile::_getstring(section,item), sizeof(buffer) -1);
384 if ( strlen(buffer) >= sizeof(buffer) ) {
385 FATAL_MACRO("string returned from _getstring is too long");
386 return iv;
387 }
388
389 char *vString = strtok(buffer,"}");
390 vString = strtok(buffer,"{");
391
392 char *test = strtok(vString,",");
393 while (test != NULL) {
394 iv.push_back(atoi(test));
395 test = strtok((char*)NULL,",");
396 }
397 if (iv.size() <= 0) {
398 std::string hilf (buffer);
399 std::string errorString("[");
400 errorString += section + std::string("]") + item + " = \'"
401 + hilf + "\' is not an integer vector";
402 FATAL_MACRO (errorString);
403
404 }
405 return (iv);
406 }

Referenced by getIntVector().

◆ getIntVector() [2/4]

virtual intVector xmlBase::IFile::getIntVector ( const char *  section,
const char *  item 
)
virtual

◆ getIntVector() [3/4]

IFile::intVector xmlBase::IFile::getIntVector ( const char *  section,
const char *  item,
intVector  defValues 
)
virtual

Definition at line 459 of file IFile.cxx.

460 {
461 return (contains(section, item))? getIntVector(section, item)
462 : defValues;
463 }
virtual intVector getIntVector(const char *section, const char *item)
Definition: IFile.cxx:378

◆ getIntVector() [4/4]

virtual intVector xmlBase::IFile::getIntVector ( const char *  section,
const char *  item,
intVector  defValues 
)
virtual

◆ getString() [1/4]

const char * xmlBase::IFile::getString ( const char *  section,
const char *  item 
)
virtual

Definition at line 286 of file IFile.cxx.

287 {
288 return _getstring(section, item);
289 }

Referenced by getString(), and lookFor().

◆ getString() [2/4]

virtual const char * xmlBase::IFile::getString ( const char *  section,
const char *  item 
)
virtual

◆ getString() [3/4]

const char * xmlBase::IFile::getString ( const char *  section,
const char *  item,
const char *  defValue 
)
virtual

Definition at line 454 of file IFile.cxx.

455 {
456 return ( contains(section, item) )? getString( section, item ):defValue;
457 }
virtual const char * getString(const char *section, const char *item)
Definition: IFile.cxx:286

◆ getString() [4/4]

virtual const char * xmlBase::IFile::getString ( const char *  section,
const char *  item,
const char *  defValue 
)
virtual

◆ print() [1/2]

void xmlBase::IFile::print ( )

Definition at line 43 of file IFile.cxx.

43{printOn(std::cout); std::cout.flush();}
virtual void printOn(std::ostream &out=std::cout)
Definition: IFile.cxx:30

◆ print() [2/2]

void xmlBase::IFile::print ( )

◆ printOn() [1/2]

void xmlBase::IFile::printOn ( std::ostream &  out = std::cout)
virtual

Definition at line 30 of file IFile.cxx.

30 {
31 for (iterator section_map=begin(); section_map!=end(); ++section_map) {
32 IFile_Section& section = *(*section_map).second;
33 out << "\n[" << (*section_map).first << "]\n";
34
35 for( IFile_Section::iterator item_map = section.begin();
36 item_map != section.end(); ++item_map){
37 IFile_Item& item = *(*item_map).second;
38 out << (*item_map).first << " = " << (item.mystring()) << "\n";
39 }
40 }
41 }

Referenced by print().

◆ printOn() [2/2]

virtual void xmlBase::IFile::printOn ( std::ostream &  out = std::cout)
virtual

◆ setString() [1/2]

void xmlBase::IFile::setString ( const char *  section,
const char *  item,
const char *  newString 
)

Definition at line 293 of file IFile.cxx.

295 {
296 char hitem[1000], hsection[1000];
297 IFile_Item *item =0;
298 IFile_Section *section=0;
299
300 stripBlanks (hitem, itemname, ALL);
301 stripBlanks (hsection, sectionname, ALL);
302
303 iterator it = find(std::string(hsection));
304
305 if ( it != end() ) {
306 section = (*it).second;
307
308 if (section->contains(hitem) )
309 item = section->lookUp(hitem);
310 }
311
312 if (item) item->mystring()=newString;
313 }
#define ALL
Definition: IFile.cxx:25
static void stripBlanks(char *str1, const char *str2, int flags)
Definition: IFile.cxx:58

◆ setString() [2/2]

void xmlBase::IFile::setString ( const char *  section,
const char *  item,
const char *  newString 
)

◆ stricmp() [1/2]

int xmlBase::IFile::stricmp ( const char *  str1,
const char *  str2 
)
staticprotected

Definition at line 46 of file IFile.cxx.

47 {
48 while ( *str1 && *str2 && toupper(*str1)==toupper(*str2) )
49 {
50 str1++;
51 str2++;
52 }
53
54 return (toupper(*str1) - toupper(*str2));
55 }

◆ stricmp() [2/2]

static int xmlBase::IFile::stricmp ( const char *  str1,
const char *  str2 
)
staticprotected

◆ stripBlanks() [1/2]

void xmlBase::IFile::stripBlanks ( char *  str1,
const char *  str2,
int  flags 
)
staticprotected

Definition at line 58 of file IFile.cxx.

59 {
60 if (flags & ALL)
61 {
62 while ( *str2 )
63 {
64 if (*str2==' ' || *str2=='\t')
65 str2++;
66 else
67 *str1++ = *str2++;
68 }
69 *str1=0;
70 }
71 else
72 {
73 if (flags & LEADING)
74 while ( *str2 && (*str2==' ' || *str2=='\t'))
75 str2++;
76
77 strcpy (str1, str2);
78
79 if (flags & TRAILING)
80 {
81 str1 += strlen (str1);
82
83 do str1--; while (*str1==' ' || *str1=='\t');
84 *++str1 = 0;
85 }
86 }
87 }
#define LEADING
Definition: IFile.cxx:24
#define TRAILING
Definition: IFile.cxx:26

Referenced by setString().

◆ stripBlanks() [2/2]

static void xmlBase::IFile::stripBlanks ( char *  str1,
const char *  str2,
int  flags 
)
staticprotected

Friends And Related Function Documentation

◆ IFile_Item

◆ IFile_Section

IFile_Section
friend

check for and replace an environment variable within a string Soon to become obsolete – maybe is by now

Definition at line 137 of file Calibration/xmlBase/xmlBase-00-00-03/xmlBase/IFile.h.


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