]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PYTHIA8/pythia8130/include/Settings.h
pythia8130 distributed with AliRoot
[u/mrichter/AliRoot.git] / PYTHIA8 / pythia8130 / include / Settings.h
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.
5
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.
12
13 #ifndef Pythia8_Settings_H
14 #define Pythia8_Settings_H
15
16 #include "Info.h"
17 #include "PythiaStdlib.h"
18
19 namespace Pythia8 {
20
21 //**************************************************************************
22
23 // Class for bool flags.
24
25 class Flag {
26
27 public:
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
43 class Mode {
44
45 public:
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
65 class Parm {
66
67 public:
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
88 class Word {
89
90 public:
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
106 class Settings {
107
108 public:
109
110   // Constructor.
111   Settings() {}
112
113   // Initialize static pointer.
114   static void initPtr(Info* infoPtrIn) {infoPtr = infoPtrIn;}
115  
116   // Read in database from specific file.
117   static bool init(string startFile = "../xmldoc/Index.xml", 
118     bool append = false, ostream& os = cout) ;
119
120   // Overwrite existing database by reading from specific file.
121   static bool reInit(string startFile = "../xmldoc/Index.xml") ;
122
123   // Read in one update from a single line.
124   static bool readString(string line, bool warn = true, 
125     ostream& os = cout) ; 
126  
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) ;
130
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); } 
139
140   // Reset all values to their defaults.
141   static void resetAll() ;
142
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()); }
152  
153   // Add new entry.
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); }  
164
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); 
170   
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); 
176
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; }
182      
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 ; }
196
197 private:
198
199   // Pointer to various information on the generation.
200   static Info* infoPtr;
201
202   // Map for bool flags.
203   static map<string, Flag> flags;
204
205   // Map for integer modes.
206   static map<string, Mode> modes;
207
208   // Map for double parms.
209   static map<string, Parm> parms;
210
211   // Map for string words.
212   static map<string, Word> words;
213
214   // Flag that initialization has been performed.
215   static bool isInit;
216
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) ; 
220
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);
228
229 };
230
231 //**************************************************************************
232
233 } // end namespace Pythia8
234
235 #endif // Pythia8_Settings_H