Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParameterReader.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParameterReader.h
1 /***********************************************************************
2 ParameterReader class is used to simplify the process of reading parameters from an input file and/or from the command line.
3 Version 1.01 (09-20-2011) Zhi Qiu
4 ***********************************************************************/
5 
6 #ifndef _ParameterReaderHeader
7 #define _ParameterReaderHeader
8 
9 #include <vector>
10 #include <string>
11 
12 // using namespace std;
13 using std::string;
14 using std::vector;
15 using std::ofstream;
16 using std::ifstream;
17 using std::ostream;
18 using std::istream;
19 using std::abs;
20 
22 {
23  private:
24  vector<string>* names; vector<double>* values; // store all parameter names and values
25  string removeComments(string str, string commentSymbol); // all substring after "symbol" in "str" will be removed
26  void phraseEquationWithoutComments(string equation); // phrase an equation like "x=1", assume string has no comments
27  long find(string name); // give the index of parameter with "name", or -1 if it does not exist
28  public:
31  void phraseOneLine(string str, string commentSymbol=(string)("#")); // read and phrase one setting string like "x=1"
32  void readFromFile(string filename, string commentSymbol=(string)("#")); // read in parameters from a file
33  void readFromArguments(long argc, char * argv[], string commentSymbol=(string)("#"), long start_from=1); // read in parameter from argument list. The process starts with index="start_from".
34  bool exist(string name); // check if parameter with "name" exists
35  void setVal(string name, double value); // set the parameter with "name" to value "value"
36  double getVal(string name); // return the value for parameter with "name"
37  void echo(); // print out all parameters to the screen
38 };
39 
40 
41 #endif
42 
43 /***********************************************************************
44 Changelog:
45 09-20-2011: Ver1.01
46  -- Bug fix: If the parameter file that is passed to the readFromFile function does not exist, the program stops instead of going into infinite loops.
47 
48 ***********************************************************************/