[1] | 1 | // Settings.h is a part of the PYTHIA event generator. |
---|
| 2 | // Copyright (C) 2012 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 | |
---|
| 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() : 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 | // Give back a map of all entries whose names match the string "match". |
---|
| 171 | map<string, Flag> getFlagMap(string match); |
---|
| 172 | map<string, Mode> getModeMap(string match); |
---|
| 173 | map<string, Parm> getParmMap(string match); |
---|
| 174 | map<string, Word> getWordMap(string match); |
---|
| 175 | |
---|
| 176 | // Change current value, respecting limits. |
---|
| 177 | void flag(string keyIn, bool nowIn); |
---|
| 178 | void mode(string keyIn, int nowIn); |
---|
| 179 | void parm(string keyIn, double nowIn); |
---|
| 180 | void word(string keyIn, string nowIn); |
---|
| 181 | |
---|
| 182 | // Change current value, disregarding limits. |
---|
| 183 | void forceMode(string keyIn, int nowIn); |
---|
| 184 | void forceParm(string keyIn, double nowIn); |
---|
| 185 | |
---|
| 186 | // Restore current value to default. |
---|
| 187 | void resetFlag(string keyIn); |
---|
| 188 | void resetMode(string keyIn); |
---|
| 189 | void resetParm(string keyIn); |
---|
| 190 | void resetWord(string keyIn); |
---|
| 191 | |
---|
| 192 | private: |
---|
| 193 | |
---|
| 194 | // Pointer to various information on the generation. |
---|
| 195 | Info* infoPtr; |
---|
| 196 | |
---|
| 197 | // Map for bool flags. |
---|
| 198 | map<string, Flag> flags; |
---|
| 199 | |
---|
| 200 | // Map for integer modes. |
---|
| 201 | map<string, Mode> modes; |
---|
| 202 | |
---|
| 203 | // Map for double parms. |
---|
| 204 | map<string, Parm> parms; |
---|
| 205 | |
---|
| 206 | // Map for string words. |
---|
| 207 | map<string, Word> words; |
---|
| 208 | |
---|
| 209 | // Flag that initialization has been performed. |
---|
| 210 | bool isInit; |
---|
| 211 | |
---|
| 212 | // Print out table of database, called from listAll and listChanged. |
---|
| 213 | void list(bool doListAll, bool doListString, string match, |
---|
| 214 | ostream& os = cout); |
---|
| 215 | |
---|
| 216 | // Initialize tunes to e+e- and pp/ppbar data. |
---|
| 217 | void initTuneEE(int eeTune); |
---|
| 218 | void initTunePP(int ppTune); |
---|
| 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 |
---|