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