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  import sys 
 18  import re 
 19  import os 
 20  import logging 
 21  pjoin = os.path.join 
 22   
 23  logger = logging.getLogger('madgraph.stdout') 
 24   
25 -class FOAnalyseCardError(Exception):
26 pass
27
28 -class FOAnalyseCard(dict):
29 """A simple handler for the fixed-order analyse card """ 30 31 string_vars = ['fo_extralibs', 'fo_extrapaths', 'fo_includepaths', 32 'fo_analyse', 'fo_analysis_format', 'fo_lhe_min_weight', 33 'fo_lhe_weight_ratio', 34 'fo_lhe_postprocessing'] 35 36
37 - def __init__(self, card=None, testing=False):
38 """ if testing, card is the content""" 39 self.testing = testing 40 dict.__init__(self) 41 self.keylist = self.keys() 42 43 if card: 44 self.read_card(card)
45 46
47 - def read_card(self, card_path):
48 """read the FO_analyse_card, if testing card_path is the content""" 49 fo_analysis_formats = ['topdrawer','hwu','root','none', 'lhe'] 50 if not self.testing: 51 content = open(card_path).read() 52 else: 53 content = card_path 54 lines = [l for l in content.split('\n') \ 55 if '=' in l and not l.startswith('#')] 56 for l in lines: 57 args = l.split('#')[0].split('=') 58 key = args[0].strip().lower() 59 value = args[1].strip() 60 if key in self.string_vars: 61 # special treatment for libs: remove lib and .a 62 # (i.e. libfastjet.a -> fastjet) 63 if key == 'fo_extralibs': 64 value = value.replace('lib', '').replace('.a', '') 65 elif key == 'fo_analysis_format' and value.lower() not in fo_analysis_formats: 66 raise FOAnalyseCardError('Unknown FO_ANALYSIS_FORMAT: %s' % value) 67 if value.lower() == 'none': 68 self[key] = '' 69 else: 70 self[key] = value 71 else: 72 raise FOAnalyseCardError('Unknown entry: %s = %s' % (key, value)) 73 self.keylist.append(key)
74 75
76 - def write_card(self, card_path):
77 """write the parsed FO_analyse.dat (to be included in the Makefile) 78 in side card_path. 79 if self.testing, the function returns its content""" 80 81 if 'fo_analysis_format' in self and self['fo_analysis_format'].lower() in ['lhe','none']: 82 if self['fo_analyse']: 83 logger.warning('FO_ANALYSE parameter of the FO_analyse card should be empty for this analysis format. Removing this information.') 84 self['fo_analyse'] = '' 85 86 lines = [] 87 to_add = '' 88 for key in self.keylist: 89 value = self[key].lower() 90 if key in self.string_vars: 91 if key == 'fo_analysis_format': 92 if value == 'topdrawer': 93 to_add = 'dbook.o open_output_files_dummy.o HwU_dummy.o' 94 elif value == 'hwu': 95 to_add = 'HwU.o open_output_files_dummy.o' 96 elif value == 'root': 97 to_add = 'rbook_fe8.o rbook_be8.o HwU_dummy.o' 98 elif value == 'lhe': 99 to_add = 'analysis_lhe.o open_output_files_dummy.o write_event.o' 100 else: 101 to_add = 'analysis_dummy.o dbook.o open_output_files_dummy.o HwU_dummy.o' 102 103 104 105 for key in self.keylist: 106 value = self[key] 107 if key in self.string_vars: 108 if key == 'fo_extrapaths': 109 # add the -L flag 110 line = '%s=%s' % (key.upper(), 111 ' '.join(['-Wl,-rpath,' + path for path in value.split()])+' '+' '.join(['-L' + path for path in value.split()])) 112 elif key == 'fo_includepaths': 113 # add the -I flag 114 line = '%s=%s' % (key.upper(), 115 ' '.join(['-I' + path for path in value.split()])) 116 elif key == 'fo_extralibs': 117 # add the -l flag 118 line = '%s=%s' % (key.upper(), 119 ' '.join(['-l' + lib for lib in value.split()])) 120 elif key == 'fo_analyse': 121 line = '%s=%s '% (key.upper(), value) 122 line = line + to_add 123 else: 124 line = '' 125 lines.append(line) 126 else: 127 raise FOAnalyseCardError('Unknown key: %s = %s' % (key, value)) 128 129 if self.testing: 130 return ('\n'.join(lines) + '\n') 131 else: 132 open(card_path, 'w').write(('\n'.join(lines) + '\n'))
133