- Update to pythia8140
[u/mrichter/AliRoot.git] / PYTHIA8 / pythia8140 / include / Settings.h
CommitLineData
b584e2f5 1// Settings.h is a part of the PYTHIA event generator.
2// Copyright (C) 2010 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// Settings: maps of flags, modes, parms and words with input/output.
12
13#ifndef Pythia8_Settings_H
14#define Pythia8_Settings_H
15
16#include "Info.h"
17#include "PythiaStdlib.h"
18
19namespace Pythia8 {
20
21//==========================================================================
22
23// Class for bool flags.
24
25class Flag {
26
27public:
28
29 // Constructor
30 Flag(string nameIn = " ", bool defaultIn = false) : name(nameIn),
31 valNow(defaultIn) , valDefault(defaultIn) { }
32
33 // Data members.
34 string name;
35 bool valNow, valDefault;
36
37};
38
39//==========================================================================
40
41// Class for integer modes.
42
43class Mode {
44
45public:
46
47 // Constructor
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) { }
52
53 // Data members.
54 string name;
55 int valNow, valDefault;
56 bool hasMin, hasMax;
57 int valMin, valMax;
58
59};
60
61//==========================================================================
62
63// Class for double parms (where parm is shorthand for parameter).
64
65class Parm {
66
67public:
68
69 // Constructor
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) { }
75
76 // Data members.
77 string name;
78 double valNow, valDefault;
79 bool hasMin, hasMax;
80 double valMin, valMax;
81
82};
83
84//==========================================================================
85
86// Class for string words.
87
88class Word {
89
90public:
91
92 // Constructor
93 Word(string nameIn = " ", string defaultIn = " ") : name(nameIn),
94 valNow(defaultIn) , valDefault(defaultIn) { }
95
96 // Data members.
97 string name, valNow, valDefault;
98
99};
100
101//==========================================================================
102
103// This class holds info on flags (bool), modes (int),
104// parms (double) and words (string).
105
106class Settings {
107
108public:
109
110 // Constructor.
111 Settings() : isInit(false) {}
112
113 // Initialize Info pointer.
114 void initPtr(Info* infoPtrIn) {infoPtr = infoPtrIn;}
115
116 // Read in database from specific file.
117 bool init(string startFile = "../xmldoc/Index.xml", bool append = false,
118 ostream& os = cout) ;
119
120 // Overwrite existing database by reading from specific file.
121 bool reInit(string startFile = "../xmldoc/Index.xml", ostream& os = cout) ;
122
123 // Read in one update from a single line.
124 bool readString(string line, bool warn = true, ostream& os = cout) ;
125
126 // Write updates or everything to user-defined file.
127 bool writeFile(string toFile, bool writeAll = false) ;
128 bool writeFile(ostream& os = cout, bool writeAll = false) ;
129
130 // Print out table of database, either all or only changed ones,
131 // or ones containing a given string.
132 void listAll(ostream& os = cout) {
133 list( true, false, " ", os); }
134 void listChanged(ostream& os = cout) {
135 list (false, false, " ", os); }
136 void list(string match, ostream& os = cout) {
137 list (false, true, match, os); }
138
139 // Reset all values to their defaults.
140 void resetAll() ;
141
142 // Query existence of an entry.
143 bool isFlag(string keyIn) {
144 return (flags.find(toLower(keyIn)) != flags.end()); }
145 bool isMode(string keyIn) {
146 return (modes.find(toLower(keyIn)) != modes.end()); }
147 bool isParm(string keyIn) {
148 return (parms.find(toLower(keyIn)) != parms.end()); }
149 bool isWord(string keyIn) {
150 return (words.find(toLower(keyIn)) != words.end()); }
151
152 // Add new entry.
153 void addFlag(string keyIn, bool defaultIn) {
154 flags[toLower(keyIn)] = Flag(keyIn, defaultIn); }
155 void addMode(string keyIn, int defaultIn, bool hasMinIn,
156 bool hasMaxIn, int minIn, int maxIn) { modes[toLower(keyIn)]
157 = Mode(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
158 void addParm(string keyIn, double defaultIn, bool hasMinIn,
159 bool hasMaxIn, double minIn, double maxIn) { parms[toLower(keyIn)]
160 = Parm(keyIn, defaultIn, hasMinIn, hasMaxIn, minIn, maxIn); }
161 void addWord(string keyIn, string defaultIn) {
162 words[toLower(keyIn)] = Word(keyIn, defaultIn); }
163
164 // Give back current value, with check that key exists.
165 bool flag(string keyIn);
166 int mode(string keyIn);
167 double parm(string keyIn);
168 string word(string keyIn);
169
170 // Change current value, respecting limits.
171 void flag(string keyIn, bool nowIn);
172 void mode(string keyIn, int nowIn);
173 void parm(string keyIn, double nowIn);
174 void word(string keyIn, string nowIn);
175
176 // Change current value, disregarding limits.
177 void forceMode(string keyIn, int nowIn) {
178 if (isMode(keyIn)) modes[toLower(keyIn)].valNow = nowIn; }
179 void forceParm(string keyIn, double nowIn) {
180 if (isParm(keyIn)) parms[toLower(keyIn)].valNow = nowIn; }
181
182 // Restore current value to default.
183 void resetFlag(string keyIn) {
184 if (isFlag(keyIn)) flags[toLower(keyIn)].valNow
185 = flags[toLower(keyIn)].valDefault ; }
186 void resetMode(string keyIn) {
187 if (isMode(keyIn)) modes[toLower(keyIn)].valNow
188 = modes[toLower(keyIn)].valDefault ; }
189 void resetParm(string keyIn) {
190 if (isParm(keyIn)) parms[toLower(keyIn)].valNow
191 = parms[toLower(keyIn)].valDefault ; }
192 void resetWord(string keyIn) {
193 if (isWord(keyIn)) words[toLower(keyIn)].valNow
194 = words[toLower(keyIn)].valDefault ; }
195
196private:
197
198 // Pointer to various information on the generation.
199 Info* infoPtr;
200
201 // Map for bool flags.
202 map<string, Flag> flags;
203
204 // Map for integer modes.
205 map<string, Mode> modes;
206
207 // Map for double parms.
208 map<string, Parm> parms;
209
210 // Map for string words.
211 map<string, Word> words;
212
213 // Flag that initialization has been performed.
214 bool isInit;
215
216 // Print out table of database, called from listAll and listChanged.
217 void list(bool doListAll, bool doListString, string match,
218 ostream& os = cout);
219
220 // Useful functions for string handling.
221 string toLower(const string& name);
222 bool boolString(string tag);
223 string attributeValue(string line, string attribute);
224 bool boolAttributeValue(string line, string attribute);
225 int intAttributeValue(string line, string attribute);
226 double doubleAttributeValue(string line, string attribute);
227
228};
229
230//==========================================================================
231
232} // end namespace Pythia8
233
234#endif // Pythia8_Settings_H