~maddevelopers/mg5amcnlo/PY8meetsMG5aMC

« back to all changes in this revision

Viewing changes to madgraph/various/shower_card.py

  • Committer: Rikkert Frederix
  • Date: 2019-05-20 08:54:08 UTC
  • mfrom: (272.16.43 2.6.6)
  • Revision ID: frederix@physik.uzh.ch-20190520085408-0neo63eae31efec5
merge with 2.6.6 revision 322 which includes the fix in genps_fks for the p_i_fks

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import re
19
19
import os
20
20
import logging
21
 
 
 
21
try:
 
22
    import madgraph
 
23
except ImportError:
 
24
    import internal.misc as misc
 
25
    import internal.banner as banner
 
26
    from internal import InvalidCmd
 
27
else:
 
28
    import madgraph.various.misc as misc
 
29
    import madgraph.various.banner as banner
 
30
    from madgraph import InvalidCmd
 
31
    
22
32
logger = logging.getLogger('madgraph.shower_card') 
23
33
 
24
34
pjoin = os.path.join
92
102
        lines = content.split('\n')
93
103
        list_dm = []
94
104
        for l in lines:
95
 
          if '#' in l:
96
 
             l = l.split('#',1)[0]
97
 
          if '=' not in l:
98
 
             continue
99
 
          args = l.split('=',1) # here the 1 is important in case of string passed
100
 
          key = args[0].strip().lower()
101
 
          value = args[1].strip()
102
 
          self.set_param(key, value)
103
 
          if str(key).upper().startswith('DM'):
104
 
              list_dm.append(int(key.split('_',1)[1]))
105
 
          #special case for DM_*
106
 
          for i in range(1,100):
107
 
              if not i in list_dm: 
108
 
                  self['dm_'+str(i)] = ''
 
105
            if '#' in l:
 
106
                l = l.split('#',1)[0]
 
107
            if '=' not in l:
 
108
                continue
 
109
            args = l.split('=',1) # here the 1 is important in case of string passed
 
110
            key = args[0].strip().lower()
 
111
            value = args[1].strip()
 
112
            self.set_param(key, value)
 
113
            if str(key).upper().startswith('DM'):
 
114
                list_dm.append(int(key.split('_',1)[1]))
 
115
            #special case for DM_*
 
116
            for i in range(1,100):
 
117
                if not i in list_dm: 
 
118
                    self['dm_'+str(i)] = ''
109
119
 
 
120
        misc.sprint(self['nsplit_jobs'])
110
121
        self.text=content
111
122
 
112
123
 
116
127
        if not testing write_to is an input path, if testing the text is
117
128
        returned by the function
118
129
        """
 
130
        
119
131
        if key in self.logical_vars:
120
 
            if str(value).lower() in self.true:
121
 
                self[key] = True
122
 
            elif str(value).lower() in self.false:
123
 
                self[key] = False
124
 
            else:
125
 
                raise ShowerCardError('%s is not a valid value for %s' % \
126
 
                        (value, key))
 
132
            try:
 
133
                self[key] = banner.ConfigFile.format_variable(value, bool, key)
 
134
            except InvalidCmd, error:
 
135
                raise ShowerCardError(str(error))
127
136
        elif key in self.string_vars:
128
137
            if value.lower() == 'none':
129
138
                self[key] = ''
131
140
                self[key] = value
132
141
        elif key in self.int_vars:
133
142
            try:
134
 
                self[key] = int(value)
135
 
            except ValueError:
136
 
                raise ShowerCardError('%s is not a valid value for %s. An integer number is expected' % \
137
 
                        (value, key))
 
143
                self[key] = banner.ConfigFile.format_variable(value, int, key)
 
144
            except InvalidCmd, error:
 
145
                raise ShowerCardError(str(error))
138
146
        elif key in self.float_vars:
139
147
            try:
140
 
                self[key] = float(value)
141
 
            except ValueError:
142
 
                raise ShowerCardError('%s is not a valid value for %s. A floating point number is expected' % \
143
 
                        (value, key))
 
148
                self[key] =  banner.ConfigFile.format_variable(value, float, key)
 
149
            except InvalidCmd, error:
 
150
                raise ShowerCardError(str(error))
144
151
        else:
145
152
            raise ShowerCardError('Unknown entry: %s = %s' % (key, value))
146
153
        self.keylist.append(key)
160
167
                    if key not in self.logical_vars:
161
168
                        newlines.append('%s = %s #%s' % (key, value, comment))
162
169
                    else:
163
 
                        if key:
 
170
 
 
171
                        if self[key]:
164
172
                            newlines.append('%s = %s #%s' % (key, 'T', comment))
165
173
                        else:
166
174
                            newlines.append('%s = %s #%s' % (key, 'F', comment))