Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:19:44

0001 /***********************************************************************
0002 ParameterReader class is used to simplify the process of reading parameters from an input file and/or from the command line.
0003 Version 1.01 (09-20-2011) Zhi Qiu
0004 ***********************************************************************/
0005 
0006 #ifndef _ParameterReaderHeader
0007 #define _ParameterReaderHeader
0008 
0009 #include <vector>
0010 #include <string>
0011 
0012 // using namespace std;
0013 using std::string;
0014 using std::vector;
0015 using std::ofstream;
0016 using std::ifstream;
0017 using std::ostream;
0018 using std::istream;
0019 using std::abs;
0020 
0021 class ParameterReader
0022 {
0023   private:
0024     vector<string>* names; vector<double>* values; // store all parameter names and values
0025     string removeComments(string str, string commentSymbol); // all substring after "symbol" in "str" will be removed
0026     void phraseEquationWithoutComments(string equation); // phrase an equation like "x=1", assume string has no comments
0027     long find(string name); // give the index of parameter with "name", or -1 if it does not exist
0028   public:
0029     ParameterReader();
0030     ~ParameterReader();
0031     void phraseOneLine(string str, string commentSymbol=(string)("#")); // read and phrase one setting string like "x=1"
0032     void readFromFile(string filename, string commentSymbol=(string)("#")); // read in parameters from a file
0033     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".
0034     bool exist(string name); // check if parameter with "name" exists
0035     void setVal(string name, double value); // set the parameter with "name" to value "value"
0036     double getVal(string name); // return the value for parameter with "name"
0037     void echo(); // print out all parameters to the screen
0038 };
0039 
0040 
0041 #endif
0042 
0043 /***********************************************************************
0044 Changelog:
0045 09-20-2011: Ver1.01
0046  -- 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.
0047 
0048 ***********************************************************************/