GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
Public Member Functions | Static Public Member Functions
GGSInputParser Class Reference

Class needed to parse configuration file. More...

#include <GGSInputParser.h>

Public Member Functions

void ReadInput (std::string fileName, int *argc, std::string *argv)
 Reads configuration file. More...
 
void ReadInput (std::string fileName)
 Reads configuration file. More...
 
const std::string & GetParameter (std::string parameterName)
 
bool GetFlag (std::string flagName)
 
void Report ()
 

Static Public Member Functions

static GGSInputParserGetInstance ()
 Get instance of the singleton. More...
 

Detailed Description

Class needed to parse configuration file.

This class reads a data card file and returns a pointer to char with the list of inputs and the number of arguments. This class creates a singleton.

Definition at line 26 of file GGSInputParser.h.

Member Function Documentation

GGSInputParser & GGSInputParser::GetInstance ( )
static

Get instance of the singleton.

Method to access the pointer to the class

Returns
the reference to GGSInputParser

Definition at line 21 of file GGSInputParser.cpp.

21  {
22  static GGSInputParser parserInstance;
23  return parserInstance;
24 }
Class needed to parse configuration file.
void GGSInputParser::ReadInput ( std::string  fileName,
int *  argc,
std::string *  argv 
)

Reads configuration file.

This method reads configuration file and put contents in memory and in an array of chars, returning also the length of the array ("main" style)

Definition at line 36 of file GGSInputParser.cpp.

36  {
37  static const std::string routineName("GGSInputParser::ReadInput");
38 
39  _configFileName = fileName;
40 
41  std::ifstream inputFile(fileName.c_str());
42  if (!inputFile.is_open())
43  return;
44  argv[0] = "Exec";
45  int pargc = 1;
46 
47  if (inputFile.fail()) {
48  COUT(ERROR) << "Error in reading configuration file. No parameter has been loaded." << ENDL;
49  } else {
50  std::string lineData, lineBuffer;
51  while (!(inputFile.eof())) {
52  getline(inputFile, lineBuffer);
53  std::stringstream streamBuffer(lineBuffer, std::ios_base::in);
54  getline(streamBuffer, lineData, '#');
55  if (lineData.length() > 0) {
56  // Search for parameter name
57  std::string::iterator startWord = lineData.begin(), endWord = lineData.begin();
58  while (*startWord == ' ' && startWord != lineData.end())
59  startWord++;
60  endWord = startWord;
61  while (*endWord != ' ' && endWord != lineData.end())
62  endWord++;
63 
64  // Found the parameter name.
65  std::string parName(startWord, endWord);
66  boost::trim(parName);
67 
68  // Search for parameter value
69  startWord = endWord;
70  while (*startWord == ' ' && startWord != lineData.end())
71  startWord++;
72  endWord = startWord;
73  while (*endWord != ' ' && endWord != lineData.end())
74  endWord++;
75 
76  // Found the parameter value.
77  std::string parValue(startWord, endWord);
78  boost::trim(parValue);
79 
80  // Put the name and the value in te parameters vector
81  if (strcmp(parName.c_str(), "")) {
82  argv[pargc] = "";
83  argv[pargc] = parName;
84  pargc++;
85  }
86  if (strcmp(parValue.c_str(), "")) {
87  argv[pargc] = "";
88  argv[pargc] = parValue;
89  pargc++;
90  }
91  _parameters.push_back(std::pair<std::string, std::string>(parName, parValue));
92  }
93  }
94  }
95 
96  *argc = pargc;
97 }
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
void GGSInputParser::ReadInput ( std::string  fileName)

Reads configuration file.

This method reads configuration file and put contents in memory (this method calls ReadInput(string fileName, int* argc, string* argv))

Definition at line 30 of file GGSInputParser.cpp.

30  {
31  int argc = 0;
32  std::string mych[1000];
33  ReadInput(fileName, &argc, (std::string *)mych);
34 }
void ReadInput(std::string fileName, int *argc, std::string *argv)
Reads configuration file.

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