Package madgraph :: Package various :: Module FO_analyse_card
[hide private]
[frames] | no frames]

Source Code for Module madgraph.various.FO_analyse_card

  1  ################################################################################ 
  2  # 
  3  # Copyright (c) 2011 The MadGraph Development team and Contributors 
  4  # 
  5  # This file is a part of the MadGraph 5 project, an application which  
  6  # automatically generates Feynman diagrams and matrix elements for arbitrary 
  7  # high-energy processes in the Standard Model and beyond. 
  8  # 
  9  # It is subject to the MadGraph license which should accompany this  
 10  # distribution. 
 11  # 
 12  # For more information, please visit: http://madgraph.phys.ucl.ac.be 
 13  # 
 14  ################################################################################ 
 15  """A File for splitting""" 
 16   
 17  from __future__ import absolute_import 
 18  import sys 
 19  import re 
 20  import os 
 21  import logging 
 22  pjoin = os.path.join 
 23   
 24  logger = logging.getLogger('madgraph.stdout') 
 25   
26 -class FOAnalyseCardError(Exception):
27 pass
28
29 -class FOAnalyseCard(dict):
30 """A simple handler for the fixed-order analyse card """ 31 32 string_vars = ['fo_extralibs', 'fo_extrapaths', 'fo_includepaths', 33 'fo_analyse', 'fo_analysis_format', 'fo_lhe_min_weight', 34 'fo_lhe_weight_ratio', 35 'fo_lhe_postprocessing'] 36 37
38 - def __init__(self, card=None, testing=False):
39 """ if testing, card is the content""" 40 self.testing = testing 41 dict.__init__(self) 42 self.keylist = list(self.keys()) 43 44 if card: 45 self.read_card(card)
46 47
48 - def read_card(self, card_path):
49 """read the FO_analyse_card, if testing card_path is the content""" 50 fo_analysis_formats = ['topdrawer','hwu','root','none', 'lhe'] 51 if not self.testing: 52 content = open(card_path).read() 53 else: 54 content = card_path 55 lines = [l for l in content.split('\n') \ 56 if '=' in l and not l.startswith('#')] 57 for l in lines: 58 args = l.split('#')[0].split('=') 59 key = args[0].strip().lower() 60 value = args[1].strip() 61 if key in self.string_vars: 62 # special treatment for libs: remove lib and .a 63 # (i.e. libfastjet.a -> fastjet) 64 if key == 'fo_extralibs': 65 value = value.replace('lib', '').replace('.a', '') 66 elif key == 'fo_analysis_format' and value.lower() not in fo_analysis_formats: 67 raise FOAnalyseCardError('Unknown FO_ANALYSIS_FORMAT: %s' % value) 68 if value.lower() == 'none': 69 self[key] = '' 70 else: 71 self[key] = value 72 else: 73 raise FOAnalyseCardError('Unknown entry: %s = %s' % (key, value)) 74 self.keylist.append(key)
75 76
77 - def write_card(self, card_path):
78 """write the parsed FO_analyse.dat (to be included in the Makefile) 79 in side card_path. 80 if self.testing, the function returns its content""" 81 82 if 'fo_analysis_format' in self and self['fo_analysis_format'].lower() in ['lhe','none']: 83 if self['fo_analyse']: 84 logger.warning('FO_ANALYSE parameter of the FO_analyse card should be empty for this analysis format. Removing this information.') 85 self['fo_analyse'] = '' 86 87 lines = [] 88 to_add = '' 89 for key in self.keylist: 90 value = self[key].lower() 91 if key in self.string_vars: 92 if key == 'fo_analysis_format': 93 if value == 'topdrawer': 94 to_add = 'dbook.o open_output_files_dummy.o HwU_dummy.o' 95 elif value == 'hwu': 96 to_add = 'HwU.o open_output_files_dummy.o' 97 elif value == 'root': 98 to_add = 'rbook_fe8.o rbook_be8.o HwU_dummy.o' 99 elif value == 'lhe': 100 to_add = 'analysis_lhe.o open_output_files_dummy.o write_event.o' 101 else: 102 to_add = 'analysis_dummy.o dbook.o open_output_files_dummy.o HwU_dummy.o' 103 104 105 106 for key in self.keylist: 107 value = self[key] 108 if key in self.string_vars: 109 if key == 'fo_extrapaths': 110 # add the -L flag 111 line = '%s=%s' % (key.upper(), 112 ' '.join(['-Wl,-rpath,' + path for path in value.split()])+' '+' '.join(['-L' + path for path in value.split()])) 113 elif key == 'fo_includepaths': 114 # add the -I flag 115 line = '%s=%s' % (key.upper(), 116 ' '.join(['-I' + path for path in value.split()])) 117 elif key == 'fo_extralibs': 118 # add the -l flag 119 line = '%s=%s' % (key.upper(), 120 ' '.join(['-l' + lib for lib in value.split()])) 121 elif key == 'fo_analyse': 122 line = '%s=%s '% (key.upper(), value) 123 line = line + to_add 124 else: 125 line = '' 126 lines.append(line) 127 else: 128 raise FOAnalyseCardError('Unknown key: %s = %s' % (key, value)) 129 130 if self.testing: 131 return ('\n'.join(lines) + '\n') 132 else: 133 open(card_path, 'w').write(('\n'.join(lines) + '\n'))
134