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