1 // Settings.h is a part of the PYTHIA event generator.
2 // Copyright (C) 2008 Torbjorn Sjostrand.
3 // PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
4 // Please respect the MCnet Guidelines, see GUIDELINES for details.
6 // Header file for the settings database; and for error statistics.
7 // Flag: helper class with bool flags.
8 // Mode: helper class with int modes.
9 // Parm: (short for parameter) helper class with double parameters.
10 // Word: helper class with string words.
11 // Settings: maps of flags, modes, parms and words with input/output.
13 #ifndef Pythia8_Settings_H
14 #define Pythia8_Settings_H
17 #include "PythiaStdlib.h"
21 //**************************************************************************
23 // Class for bool flags.
30 Flag(string nameIn = " ", bool defaultIn = false) : name(nameIn),
31 valNow(defaultIn) , valDefault(defaultIn) { }
35 bool valNow, valDefault;
39 //**************************************************************************
41 // Class for integer modes.
48 Mode(string nameIn = " ", int defaultIn = 0, bool hasMinIn = false,
49 bool hasMaxIn = false, int minIn = 0, int maxIn = 0) : name(nameIn),
50 valNow(defaultIn), valDefault(defaultIn), hasMin(hasMinIn),
51 hasMax(hasMaxIn), valMin(minIn), valMax(maxIn) { }
55 int valNow, valDefault;
61 //**************************************************************************
63 // Class for double parms (where parm is shorthand for parameter).
70 Parm(string nameIn = " ", double defaultIn = 0.,
71 bool hasMinIn = false, bool hasMaxIn = false, double minIn = 0.,
72 double maxIn = 0.) : name(nameIn), valNow(defaultIn),
73 valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
74 valMin(minIn), valMax(maxIn) { }
78 double valNow, valDefault;
80 double valMin, valMax;
84 //**************************************************************************
86 // Class for string words.
93 Word(string nameIn = " ", string defaultIn = " ") : name(nameIn),
94 valNow(defaultIn) , valDefault(defaultIn) { }
97 string name, valNow, valDefault;
101 //**************************************************************************
103 // This class holds info on flags (bool), modes (int),
104 // parms (double) and words (string).
113 // Initialize static pointer.
114 static void initPtr(Info* infoPtrIn) {infoPtr = infoPtrIn;}
116 // Read in database from specific file.
117 static bool init(string startFile = "../xmldoc/Index.xml",
118 bool append = false, ostream& os = cout) ;
120 // Overwrite existing database by reading from specific file.
121 static bool reInit(string startFile = "../xmldoc/Index.xml") ;
123 // Read in one update from a single line.
124 static bool readString(string line, bool warn = true,
125 ostream& os = cout) ;
127 // Write updates or everything to user-defined file.
128 static bool writeFile(ostream& os = cout, bool writeAll = false) ;
129 static bool writeFile(string toFile, bool writeAll = false) ;
131 // Print out table of database, either all or only changed ones,
132 // or ones containing a given string.
133 static void listAll(ostream& os = cout) {
134 list( true, false, " ", os); }
135 static void listChanged(ostream& os = cout) {
136 list (false, false, " ", os); }
137 static void list(string match, ostream& os = cout) {
138 list (false, true, match, os); }
140 // Reset all values to their defaults.
141 static void resetAll() ;
143 // Query existence of an entry.
144 static bool isFlag(string keyIn) {
145 return (flags.find(toLower(keyIn)) != flags.end()); }
146 static bool isMode(string keyIn) {
147 return (modes.find(toLower(keyIn)) != modes.end()); }
148 static bool isParm(string keyIn) {
149 return (parms.find(toLower(keyIn)) != parms.end()); }
150 static bool isWord(string keyIn) {
151 return (words.find(toLower(keyIn)) != words.end()); }
154 static void addFlag(string keyIn, bool defaultIn) {
155 flags[toLower(keyIn)] = Flag(keyIn, defaultIn); }
156 static void addMode(string keyIn, int defaultIn, bool hasMinIn,
157 bool hasMaxIn, int minIn, int maxIn) { modes[toLower(keyIn)]
158 = Mode(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
159 static void addParm(string keyIn, double defaultIn, bool hasMinIn,
160 bool hasMaxIn, double minIn, double maxIn) { parms[toLower(keyIn)]
161 = Parm(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
162 static void addWord(string keyIn, string defaultIn) {
163 words[toLower(keyIn)] = Word(keyIn, defaultIn); }
165 // Give back current value, with check that key exists.
166 static bool flag(string keyIn);
167 static int mode(string keyIn);
168 static double parm(string keyIn);
169 static string word(string keyIn);
171 // Change current value, respecting limits.
172 static void flag(string keyIn, bool nowIn);
173 static void mode(string keyIn, int nowIn);
174 static void parm(string keyIn, double nowIn);
175 static void word(string keyIn, string nowIn);
177 // Change current value, disregarding limits.
178 static void forceMode(string keyIn, int nowIn) {
179 if (isMode(keyIn)) modes[toLower(keyIn)].valNow = nowIn; }
180 static void forceParm(string keyIn, double nowIn) {
181 if (isParm(keyIn)) parms[toLower(keyIn)].valNow = nowIn; }
183 // Restore current value to default.
184 static void resetFlag(string keyIn) {
185 if (isFlag(keyIn)) flags[toLower(keyIn)].valNow
186 = flags[toLower(keyIn)].valDefault ; }
187 static void resetMode(string keyIn) {
188 if (isMode(keyIn)) modes[toLower(keyIn)].valNow
189 = modes[toLower(keyIn)].valDefault ; }
190 static void resetParm(string keyIn) {
191 if (isParm(keyIn)) parms[toLower(keyIn)].valNow
192 = parms[toLower(keyIn)].valDefault ; }
193 static void resetWord(string keyIn) {
194 if (isWord(keyIn)) words[toLower(keyIn)].valNow
195 = words[toLower(keyIn)].valDefault ; }
199 // Pointer to various information on the generation.
200 static Info* infoPtr;
202 // Map for bool flags.
203 static map<string, Flag> flags;
205 // Map for integer modes.
206 static map<string, Mode> modes;
208 // Map for double parms.
209 static map<string, Parm> parms;
211 // Map for string words.
212 static map<string, Word> words;
214 // Flag that initialization has been performed.
217 // Print out table of database, called from listAll and listChanged.
218 static void list(bool listAll, bool listString, string match,
219 ostream& os = cout) ;
221 // Useful functions for string handling.
222 static string toLower(const string& name);
223 static bool boolString(string tag);
224 static string attributeValue(string line, string attribute);
225 static bool boolAttributeValue(string line, string attribute);
226 static int intAttributeValue(string line, string attribute);
227 static double doubleAttributeValue(string line, string attribute);
231 //**************************************************************************
233 } // end namespace Pythia8
235 #endif // Pythia8_Settings_H