Line data Source code
1 : // Settings.h is a part of the PYTHIA event generator.
2 : // Copyright (C) 2015 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.
5 :
6 : // Header file for the settings database.
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 : // MVec: vector of Modes (integers).
12 : // PVec: vector of Parms (doubles).
13 : // Settings: maps of flags, modes, parms and words with input/output.
14 :
15 : #ifndef Pythia8_Settings_H
16 : #define Pythia8_Settings_H
17 :
18 : #include "Pythia8/Info.h"
19 : #include "Pythia8/PythiaStdlib.h"
20 :
21 : namespace Pythia8 {
22 :
23 : //==========================================================================
24 :
25 : // Class for bool flags.
26 :
27 0 : class Flag {
28 :
29 : public:
30 :
31 : // Constructor
32 0 : Flag(string nameIn = " ", bool defaultIn = false) : name(nameIn),
33 0 : valNow(defaultIn) , valDefault(defaultIn) { }
34 :
35 : // Data members.
36 : string name;
37 : bool valNow, valDefault;
38 :
39 : };
40 :
41 : //==========================================================================
42 :
43 : // Class for integer modes.
44 :
45 0 : class Mode {
46 :
47 : public:
48 :
49 : // Constructor
50 : Mode(string nameIn = " ", int defaultIn = 0, bool hasMinIn = false,
51 : bool hasMaxIn = false, int minIn = 0, int maxIn = 0,
52 0 : bool optOnlyIn = false) : name(nameIn), valNow(defaultIn),
53 0 : valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
54 0 : valMin(minIn), valMax(maxIn), optOnly(optOnlyIn) { }
55 :
56 : // Data members.
57 : string name;
58 : int valNow, valDefault;
59 : bool hasMin, hasMax;
60 : int valMin, valMax;
61 : bool optOnly;
62 :
63 : };
64 :
65 : //==========================================================================
66 :
67 : // Class for double parms (where parm is shorthand for parameter).
68 :
69 0 : class Parm {
70 :
71 : public:
72 :
73 : // Constructor
74 : Parm(string nameIn = " ", double defaultIn = 0.,
75 : bool hasMinIn = false, bool hasMaxIn = false, double minIn = 0.,
76 0 : double maxIn = 0.) : name(nameIn), valNow(defaultIn),
77 0 : valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
78 0 : valMin(minIn), valMax(maxIn) { }
79 :
80 : // Data members.
81 : string name;
82 : double valNow, valDefault;
83 : bool hasMin, hasMax;
84 : double valMin, valMax;
85 :
86 : };
87 :
88 : //==========================================================================
89 :
90 : // Class for string words.
91 :
92 0 : class Word {
93 :
94 : public:
95 :
96 : // Constructor
97 0 : Word(string nameIn = " ", string defaultIn = " ") : name(nameIn),
98 0 : valNow(defaultIn) , valDefault(defaultIn) { }
99 :
100 : // Data members.
101 : string name, valNow, valDefault;
102 :
103 : };
104 :
105 : //==========================================================================
106 :
107 : // Class for vector of bool flags.
108 :
109 0 : class FVec {
110 :
111 : public:
112 :
113 : // Constructor
114 : FVec(string nameIn = " ", vector<bool> defaultIn = vector<bool>(1, false)) :
115 0 : name(nameIn), valNow(defaultIn) , valDefault(defaultIn) { }
116 :
117 : // Data members.
118 : string name;
119 : vector<bool> valNow, valDefault;
120 :
121 : };
122 :
123 : //==========================================================================
124 :
125 : // Class for vector of integers.
126 :
127 0 : class MVec {
128 :
129 : public:
130 :
131 : // Constructor
132 : MVec(string nameIn = " ", vector<int> defaultIn = vector<int>(1, 0),
133 : bool hasMinIn = false, bool hasMaxIn = false, int minIn = 0,
134 0 : int maxIn = 0) : name(nameIn), valNow(defaultIn),
135 0 : valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
136 0 : valMin(minIn), valMax(maxIn) { }
137 :
138 : // Data members.
139 : string name;
140 : vector<int> valNow, valDefault;
141 : bool hasMin, hasMax;
142 : int valMin, valMax;
143 :
144 : };
145 :
146 : //==========================================================================
147 :
148 : // Class for vector of doubles.
149 :
150 0 : class PVec {
151 :
152 : public:
153 :
154 : // Constructor
155 : PVec(string nameIn = " ", vector<double> defaultIn = vector<double>(1, 0.),
156 : bool hasMinIn = false, bool hasMaxIn = false, double minIn = 0.,
157 0 : double maxIn = 0.) : name(nameIn), valNow(defaultIn),
158 0 : valDefault(defaultIn), hasMin(hasMinIn), hasMax(hasMaxIn),
159 0 : valMin(minIn), valMax(maxIn) { }
160 :
161 : // Data members.
162 : string name;
163 : vector<double> valNow, valDefault;
164 : bool hasMin, hasMax;
165 : double valMin, valMax;
166 :
167 : };
168 :
169 : //==========================================================================
170 :
171 : // This class holds info on flags (bool), modes (int), parms (double),
172 : // words (string), fvecs (vector of bool), mvecs (vector of int) and pvecs
173 : // (vector of double).
174 :
175 0 : class Settings {
176 :
177 : public:
178 :
179 : // Constructor.
180 0 : Settings() : isInit(false), readingFailedSave(false) {}
181 :
182 : // Initialize Info pointer.
183 0 : void initPtr(Info* infoPtrIn) {infoPtr = infoPtrIn;}
184 :
185 : // Read in database from specific file.
186 : bool init(string startFile = "../xmldoc/Index.xml", bool append = false,
187 : ostream& os = cout) ;
188 :
189 : // Overwrite existing database by reading from specific file.
190 : bool reInit(string startFile = "../xmldoc/Index.xml", ostream& os = cout) ;
191 :
192 : // Read in one update from a single line.
193 : bool readString(string line, bool warn = true, ostream& os = cout) ;
194 :
195 : // Keep track whether any readings have failed, invalidating run setup.
196 0 : bool readingFailed() {return readingFailedSave;}
197 :
198 : // Write updates or everything to user-defined file.
199 : bool writeFile(string toFile, bool writeAll = false) ;
200 : bool writeFile(ostream& os = cout, bool writeAll = false) ;
201 :
202 : // Print out table of database, either all or only changed ones,
203 : // or ones containing a given string.
204 : void listAll(ostream& os = cout) {
205 0 : list( true, false, " ", os); }
206 : void listChanged(ostream& os = cout) {
207 0 : list (false, false, " ", os); }
208 : void list(string match, ostream& os = cout) {
209 : list (false, true, match, os); }
210 :
211 : // Give back current value(s) as a string, whatever the type.
212 : string output(string keyIn, bool fullLine = true);
213 :
214 : // Reset all values to their defaults.
215 : void resetAll() ;
216 :
217 : // Query existence of an entry.
218 : bool isFlag(string keyIn) {
219 0 : return (flags.find(toLower(keyIn)) != flags.end()); }
220 : bool isMode(string keyIn) {
221 0 : return (modes.find(toLower(keyIn)) != modes.end()); }
222 : bool isParm(string keyIn) {
223 0 : return (parms.find(toLower(keyIn)) != parms.end()); }
224 : bool isWord(string keyIn) {
225 0 : return (words.find(toLower(keyIn)) != words.end()); }
226 : bool isFVec(string keyIn) {
227 0 : return (fvecs.find(toLower(keyIn)) != fvecs.end()); }
228 : bool isMVec(string keyIn) {
229 0 : return (mvecs.find(toLower(keyIn)) != mvecs.end()); }
230 : bool isPVec(string keyIn) {
231 0 : return (pvecs.find(toLower(keyIn)) != pvecs.end()); }
232 :
233 : // Add new entry.
234 : void addFlag(string keyIn, bool defaultIn) {
235 0 : flags[toLower(keyIn)] = Flag(keyIn, defaultIn); }
236 : void addMode(string keyIn, int defaultIn, bool hasMinIn,
237 : bool hasMaxIn, int minIn, int maxIn, bool optOnlyIn = false) {
238 0 : modes[toLower(keyIn)] = Mode(keyIn, defaultIn, hasMinIn, hasMaxIn,
239 0 : minIn, maxIn, optOnlyIn); }
240 : void addParm(string keyIn, double defaultIn, bool hasMinIn,
241 0 : bool hasMaxIn, double minIn, double maxIn) { parms[toLower(keyIn)]
242 0 : = Parm(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
243 : void addWord(string keyIn, string defaultIn) {
244 0 : words[toLower(keyIn)] = Word(keyIn, defaultIn); }
245 : void addFVec(string keyIn, vector<bool> defaultIn) {
246 0 : fvecs[toLower(keyIn)] = FVec(keyIn, defaultIn); }
247 : void addMVec(string keyIn, vector<int> defaultIn, bool hasMinIn,
248 0 : bool hasMaxIn, int minIn, int maxIn) { mvecs[toLower(keyIn)]
249 0 : = MVec(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
250 : void addPVec(string keyIn, vector<double> defaultIn, bool hasMinIn,
251 0 : bool hasMaxIn, double minIn, double maxIn) { pvecs[toLower(keyIn)]
252 0 : = PVec(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
253 :
254 : // Give back current value, with check that key exists.
255 : bool flag(string keyIn);
256 : int mode(string keyIn);
257 : double parm(string keyIn);
258 : string word(string keyIn);
259 : vector<bool> fvec(string keyIn);
260 : vector<int> mvec(string keyIn);
261 : vector<double> pvec(string keyIn);
262 :
263 : // Give back default value, with check that key exists.
264 : bool flagDefault(string keyIn);
265 : int modeDefault(string keyIn);
266 : double parmDefault(string keyIn);
267 : string wordDefault(string keyIn);
268 : vector<bool> fvecDefault(string keyIn);
269 : vector<int> mvecDefault(string keyIn);
270 : vector<double> pvecDefault(string keyIn);
271 :
272 : // Give back a map of all entries whose names match the string "match".
273 : map<string, Flag> getFlagMap(string match);
274 : map<string, Mode> getModeMap(string match);
275 : map<string, Parm> getParmMap(string match);
276 : map<string, Word> getWordMap(string match);
277 : map<string, FVec> getFVecMap(string match);
278 : map<string, MVec> getMVecMap(string match);
279 : map<string, PVec> getPVecMap(string match);
280 :
281 : // Change current value, respecting limits.
282 : void flag(string keyIn, bool nowIn);
283 : bool mode(string keyIn, int nowIn);
284 : void parm(string keyIn, double nowIn);
285 : void word(string keyIn, string nowIn);
286 : void fvec(string keyIn, vector<bool> nowIn);
287 : void mvec(string keyIn, vector<int> nowIn);
288 : void pvec(string keyIn, vector<double> nowIn);
289 :
290 : // Change current value, disregarding limits.
291 : void forceMode(string keyIn, int nowIn);
292 : void forceParm(string keyIn, double nowIn);
293 : void forceMVec(string keyIn, vector<int> nowIn);
294 : void forcePVec(string keyIn, vector<double> nowIn);
295 :
296 : // Restore current value to default.
297 : void resetFlag(string keyIn);
298 : void resetMode(string keyIn);
299 : void resetParm(string keyIn);
300 : void resetWord(string keyIn);
301 : void resetFVec(string keyIn);
302 : void resetMVec(string keyIn);
303 : void resetPVec(string keyIn);
304 :
305 : private:
306 :
307 : // Pointer to various information on the generation.
308 : Info* infoPtr;
309 :
310 : // Map for bool flags.
311 : map<string, Flag> flags;
312 :
313 : // Map for integer modes.
314 : map<string, Mode> modes;
315 :
316 : // Map for double parms.
317 : map<string, Parm> parms;
318 :
319 : // Map for string words.
320 : map<string, Word> words;
321 :
322 : // Map for vectors of bool.
323 : map<string, FVec> fvecs;
324 :
325 : // Map for vectors of int.
326 : map<string, MVec> mvecs;
327 :
328 : // Map for vectors of double.
329 : map<string, PVec> pvecs;
330 :
331 : // Flags that initialization has been performed; whether any failures.
332 : bool isInit, readingFailedSave;
333 :
334 : // Print out table of database, called from listAll and listChanged.
335 : void list(bool doListAll, bool doListString, string match,
336 : ostream& os = cout);
337 :
338 : // Master switch for program printout.
339 : void printQuiet(bool quiet);
340 :
341 : // Restore settings used in tunes to e+e- and pp/ppbar data.
342 : void resetTuneEE();
343 : void resetTunePP();
344 :
345 : // Initialize tunes to e+e- and pp/ppbar data.
346 : void initTuneEE(int eeTune);
347 : void initTunePP(int ppTune);
348 :
349 : // Useful functions for string handling.
350 : string toLower(const string& name);
351 : bool boolString(string tag);
352 : string attributeValue(string line, string attribute);
353 : bool boolAttributeValue(string line, string attribute);
354 : int intAttributeValue(string line, string attribute);
355 : double doubleAttributeValue(string line, string attribute);
356 : vector<bool> boolVectorAttributeValue(string line, string attribute);
357 : vector<int> intVectorAttributeValue(string line, string attribute);
358 : vector<double> doubleVectorAttributeValue(string line, string attribute);
359 :
360 : };
361 :
362 : //==========================================================================
363 :
364 : } // end namespace Pythia8
365 :
366 : #endif // Pythia8_Settings_H
|