5 from AthenaCommon
import Logging
6 mglog = Logging.logging.getLogger(
'MadGraphUtils')
9 MADGRAPH_GRIDPACK_LOCATION=
'madevent'
11 MADGRAPH_CATCH_ERRORS=
True
12 MADGRAPH_COMMAND_STACK = []
17 for line
in iter(card):
18 if not line.strip().startswith(
'#'):
19 command = line.split(
'!', 1)[0]
21 setting = command.split(
'=')[-1].strip()
22 value =
'='.
join(command.split(
'=')[:-1]).strip()
25 setting=setting.lower()
31 if setting.replace(
"'",
'').
replace(
'"',
'').
replace(
'.',
'').lower()
in [
't',
'true']:
36 y=
str(x).lower().strip()
38 while len(y)>0
and (y[0]==
'"' or y[0]==
"'"):
40 while len(y)>0
and (y[-1]==
'"' or y[-1]==
"'"):
50 return key
in mydict
and mydict[key]==value
57 return key
in mydict
and mydict[key]
in [
't',
'true']
70 version_file =
open(os.environ[
'MADPATH']+
'/VERSION',
'r')
72 for line
in version_file:
74 version=line.split(
'=')[1].strip()
78 raise RuntimeError(
'Failed to find MadGraph/MadGraph5_aMC@NLO version in '+version_file)
80 vs=[
int(v)
for v
in version.split(
'.')]
83 y=
int(100**
max(len(vs),len(args)))
89 y=
int(100**
max(len(vs),len(args)))
94 return versionnumber>=testnumber
97 f =
open(run_card,
'r')
98 if "parton_shower" in f.read().lower():
107 raise RuntimeError(
'runArgs must be provided!')
108 if hasattr(runArgs,
'ecmEnergy'):
109 beamEnergy = runArgs.ecmEnergy / 2.
111 raise RuntimeError(
"No center of mass energy found in runArgs.")
112 if hasattr(runArgs,
'randomSeed'):
113 random_seed = runArgs.randomSeed
115 raise RuntimeError(
"No random seed found in runArgs.")
116 return beamEnergy,random_seed
120 global MADGRAPH_CATCH_ERRORS
121 if not MADGRAPH_CATCH_ERRORS:
123 unmasked_error =
False
128 if type(errors)==bytes:
129 errors = errors.decode(
'utf-8')
131 mglog.info(
'Some errors detected by MadGraphControl - checking for serious errors')
132 for err
in errors.split(
'\n'):
133 if len(err.strip())==0:
136 if 'Inappropriate ioctl for device' in err:
139 if 'stty: standard input: Invalid argument' in err:
143 if 'PDF already installed' in err:
146 if 'Read-only file system' in err:
153 if 'impossible to set default multiparticles' in err:
157 if 'More information is found in' in err:
158 my_debug_file = err.split(
"'")[1]
159 if err.startswith(
'tar'):
162 if 'python2 support will be removed' in err:
165 if 'python3.12 support is still experimental' in err:
169 if 'required by /lib64/libfontconfig.so' in err
or\
170 'required by /lib64/libgs.so' in err:
173 if 'Error: Symbol' in err
and 'has no IMPLICIT type' in err:
174 bad_variables += [ err.split(
'Symbol ')[1].
split(
' at ')[0] ]
180 unmasked_error =
True
182 if my_debug_file
is None:
183 debug_files = glob.glob(
'*debug.log')+glob.glob(
'*/*debug.log')
184 for debug_file
in debug_files:
186 has_subproc = os.access(os.path.join(os.path.dirname(debug_file),
'SubProcesses'),os.R_OK)
188 my_debug_file = debug_file
191 if my_debug_file
is not None:
192 if not unmasked_error:
193 mglog.warning(
'Found a debug file at '+my_debug_file+
' but no apparent error. Will terminate.')
194 mglog.error(
'MadGraph5_aMC@NLO appears to have crashed. Debug file output follows.')
195 with open(my_debug_file,
'r')
as error_output:
196 for l
in error_output:
197 mglog.error(l.replace(
'\n',
''))
198 mglog.error(
'End of debug file output')
201 mglog.warning(
'Appeared to detect variables in your run card that MadGraph did not understand:')
202 mglog.warning(
' Check your run card / JO settings for %s',bad_variables)
206 mglog.error(f
'Detected a bad return code: {return_code}')
207 unmasked_error =
True
210 if unmasked_error
or my_debug_file
is not None:
212 raise RuntimeError(
'Error detected in MadGraphControl process')
218 mglog.info(
'Will write a stand-alone debugging script.')
219 mglog.info(
'This is an attempt to provide you commands that you can use')
220 mglog.info(
'to reproduce the error locally. If you make additional')
221 mglog.info(
'modifications by hand (not using MadGraphControl) in your JO,')
222 mglog.info(
'make sure that you check and modify the script as needed.\n\n')
223 global MADGRAPH_COMMAND_STACK
224 mglog.info(
'# Script start; trim off columns left of the "#"')
226 with open(
'standalone_script.sh',
'w')
as standalone_script:
227 for command
in MADGRAPH_COMMAND_STACK:
228 for line
in command.split(
'\n'):
230 standalone_script.write(line+
'\n')
231 mglog.info(
'# Script end')
232 mglog.info(
'Script also written to %s/standalone_script.sh',os.getcwd())
236 global MADGRAPH_COMMAND_STACK
237 if 'PYTHONPATH' in os.environ:
238 if not any( [(
'Generators/madgraph/models' in x
and 'shutil_patch' not in x)
for x
in os.environ[
'PYTHONPATH'].
split(
':') ]):
239 os.environ[
'PYTHONPATH'] +=
':/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest'
240 MADGRAPH_COMMAND_STACK += [
'export PYTHONPATH=${PYTHONPATH}:/cvmfs/atlas.cern.ch/repo/sw/Generators/madgraph/models/latest']
242 if 'GFORTRAN_TMPDIR' in os.environ:
244 if 'TMPDIR' in os.environ:
245 os.environ[
'GFORTRAN_TMPDIR']=os.environ[
'TMPDIR']
246 MADGRAPH_COMMAND_STACK += [
'export GFORTRAN_TMPDIR=${TMPDIR}']
248 if 'TMP' in os.environ:
249 os.environ[
'GFORTRAN_TMPDIR']=os.environ[
'TMP']
250 MADGRAPH_COMMAND_STACK += [
'export GFORTRAN_TMPDIR=${TMP}']
255 lo_config_card=process_dir+
'/Cards/me5_configuration.txt'
256 nlo_config_card=process_dir+
'/Cards/amcatnlo_configuration.txt'
258 if os.access(lo_config_card,os.R_OK)
and not os.access(nlo_config_card,os.R_OK):
259 return lo_config_card
260 elif os.access(nlo_config_card,os.R_OK)
and not os.access(lo_config_card,os.R_OK):
261 return nlo_config_card
262 elif os.access(nlo_config_card,os.R_OK)
and os.access(lo_config_card,os.R_OK):
263 mglog.error(
'Found both types of config card in '+process_dir)
265 mglog.error(
'No config card in '+process_dir)
266 raise RuntimeError(
'Unable to locate configuration card')