1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from __future__ import absolute_import
17 import random
18 from six.moves import range
19 if __name__=='__main__':
20
21 import os
22 import sys
23 root_path = os.path.split(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))[0]
24 sys.path.insert(0, root_path)
25
26 import madgraph.various.misc as misc
27 from madgraph import MadGraph5Error
33 """ A container class to specify all banner styles. """
34
35 ordered_style_keys = ['classic','classic2','classic3','big','funky',
36 'curly','bubbles','mario','wiggly',
37 'printed','fast','isometric']
38 styles = {}
39 styles['classic'] = \
40 r"""
41 __ __ _ _
42 | \/ | | | |
43 | \ / | __ _ __| | | ___ ___ _ __
44 | |\/| |/ _` |/ _` | | / _ \ / _ \| '_ \
45 | | | | (_| | (_| | |___| (_) | (_) | |_) |
46 |_| |_|\__,_|\__,_|______\___/ \___/| .__/
47 | |
48 |_|
49 %(version)s
50 %(ref)s
51 """
52
53 styles['classic2'] = \
54 r"""
55 ,,
56 `7MMM. ,MMF' `7MM `7MMF'
57 MMMb dPMM MM MM
58 M YM ,M MM ,6"Yb. ,M""bMM MM ,pW"Wq. ,pW"Wq.`7MMpdMAo.
59 M Mb M' MM 8) MM ,AP MM MM 6W' `Wb 6W' `Wb MM `Wb
60 M YM.P' MM ,pm9MM 8MI MM MM , 8M M8 8M M8 MM M8
61 M `YM' MM 8M MM `Mb MM MM ,M YA. ,A9 YA. ,A9 MM ,AP
62 .JML. `' .JMML.`Moo9^Yo.`Wbmd"MML..JMMmmmmMMM `Ybmd9' `Ybmd9' MMbmmd'
63 MM
64 .JMML.
65 %(versionref)s
66 """
67
68 styles['classic3'] = \
69 r"""
70 __ __ _ _
71 | \/ | __ _ __| | | ___ ___ _ __
72 | |\/| |/ _` |/ _` | | / _ \ / _ \| '_ \
73 | | | | (_| | (_| | |__| (_) | (_) | |_) |
74 |_| |_|\__,_|\__,_|_____\___/ \___/| .__/
75 |_|
76
77 %(version)s
78 %(ref)s
79 """
80
81 styles['big'] = \
82 r"""
83 88b d88 88 88
84 888b d888 88 88
85 88`8b d8'88 88 88
86 88 `8b d8' 88 ,adPPYYba, ,adPPYb,88 88 ,adPPYba, ,adPPYba, 8b,dPPYba,
87 88 `8b d8' 88 "" `Y8 a8" `Y88 88 a8" "8a a8" "8a 88P' "8a
88 88 `8b d8' 88 ,adPPPPP88 8b 88 88 8b d8 8b d8 88 d8
89 88 `888' 88 88, ,88 "8a, ,d88 88 "8a, ,a8" "8a, ,a8" 88b, ,a8"
90 88 `8' 88 `"8bbdP"Y8 `"8bbdP"Y8 88888888888 `"YbbdP"' `"YbbdP"' 88`YbbdP"'
91 88
92 88
93 %(versionref)s
94 """
95
96 styles['funky'] = \
97 r"""
98 .-'''-. .-'''-.
99 _______ .---. ' _ \ ' _ \
100 __ __ ___ \ ___ `'. | | / /` '. \ / /` '. \_________ _...._
101 | |/ `.' `. ' |--.\ \ | |. | \ ' . | \ '\ |.' '-.
102 | .-. .-. ' | | \ ' | || ' | '| ' | '\ .'```'. '.
103 | | | | | | __ | | | '| |\ \ / / \ \ / / \ | \ \
104 | | | | | | .:--.'. | | | || | `. ` ..' / `. ` ..' / | | | |
105 | | | | | |/ | \ | | | ' .'| | '-...-'` '-...-'` | \ / ;
106 | | | | | |`" __ | | | |___.' /' | | | |\`----' .'
107 |__| |__| |__| .'.''| | /_______.'/ | | | | '-....-'`
108 / / | |_\_______|/ '---' .' '.
109 \ \._,\ '/ '-----------'
110 `--' `"
111
112
113 %(versionref)s
114 """
115
116 styles['curly'] = \
117 r"""
118 __ __) _
119 (, /| /| /) ___/__)
120 / | / | _ _(/ (, / ________
121 ) / |/ |_(_(_(_(_ / (_)(_) /_)_
122 (_/ ' (_____ .-/
123 )(_/
124
125 %(version)s
126 %(ref)s
127 """
128
129
130 styles['keyboard'] = \
131 r"""
132 ____ ____ ____ ____ ____ ____ ____
133 ||M |||a |||d |||L |||o |||o |||p ||
134 ||__|||__|||__|||__|||__|||__|||__||
135 |/__\|/__\|/__\|/__\|/__\|/__\|/__\|
136
137 %(version)s
138 %(ref)s
139 """
140
141 styles['bubbles'] = \
142 r"""
143 Oo oO o o
144 O O o o O O
145 o o O O o o
146 O Oo O o o
147 O o .oOoO' .oOoO O .oOo. .oOo. .oOo.
148 o O O o o O O O o O o O o
149 o O o O O o o . o O o O o O
150 O o `OoO'o `OoO'o OOoOooO `OoO' `OoO' oOoO'
151 O
152 o'
153 %(version)s
154 %(ref)s
155 """
156
157 styles['mario'] = \
158 r"""
159 _ __
160 /\/\ __ _ __| | / / ___ ___ _ __
161 / \ / _` |/ _` |/ / / _ \ / _ \| '_ \
162 / /\/\ \ (_| | (_| / /__| (_) | (_) | |_) |
163 \/ \/\__,_|\__,_\____/\___/ \___/| .__/
164 |_|
165 %(version)s
166 %(ref)s
167 """
168
169 styles['wiggly'] = \
170 r"""
171 __ __ ____ ______ _____ ____ ____ _____
172 \ \ / / ( ) (_ __ \ (_ _) / __ \ / __ \ ( __ \
173 () \/ () / /\ \ ) ) \ \ | | / / \ \ / / \ \ ) )_) )
174 / _ _ \ ( (__) ) ( ( ) ) | | ( () () ) ( () () ) ( ___/
175 / / \/ \ \ ) ( ) ) ) ) | | __ ( () () ) ( () () ) ) )
176 /_/ \_\ / /\ \ / /__/ / __| |___) ) \ \__/ / \ \__/ / ( (
177 (/ \) /__( )__\ (______/ \________/ \____/ \____/ /__\
178
179 %(versionref)s
180 """
181
182 styles['printed'] = \
183 r"""
184 __/\\\\____________/\\\\________________________/\\\___/\\\_______________________________________________________
185 _\/\\\\\\________/\\\\\\_______________________\/\\\__\/\\\_______________________________________________________
186 _\/\\\//\\\____/\\\//\\\_______________________\/\\\__\/\\\___________________________________________/\\\\\\\\\__
187 _\/\\\\///\\\/\\\/_\/\\\__/\\\\\\\\\___________\/\\\__\/\\\_________________/\\\\\________/\\\\\_____/\\\/////\\\_
188 _\/\\\__\///\\\/___\/\\\_\////////\\\_____/\\\\\\\\\__\/\\\_______________/\\\///\\\____/\\\///\\\__\/\\\\\\\\\\__
189 _\/\\\____\///_____\/\\\___/\\\\\\\\\\___/\\\////\\\__\/\\\______________/\\\__\//\\\__/\\\__\//\\\_\/\\\//////___
190 _\/\\\_____________\/\\\__/\\\/////\\\__\/\\\__\/\\\__\/\\\_____________\//\\\__/\\\__\//\\\__/\\\__\/\\\_________
191 _\/\\\_____________\/\\\_\//\\\\\\\\/\\_\//\\\\\\\/\\_\/\\\\\\\\\\\\\\\__\///\\\\\/____\///\\\\\/___\/\\\_________
192 _\///______________\///___\////////\//___\///////\//__\///////////////_____\/////________\/////_____\///__________
193
194 %(versionref)s
195 """
196
197 styles['fast'] = \
198 r"""
199 __ ___ ____
200 / |/ /___ _____/ / / ____ ____ ____
201 / /|_/ / __ `/ __ / / / __ \/ __ \/ __ \
202 / / / / /_/ / /_/ / /___/ /_/ / /_/ / /_/ /
203 /_/ /_/\__,_/\__,_/_____/\____/\____/ .___/
204 /_/
205 %(version)s
206 %(ref)s
207 """
208
209 styles['isometric'] = \
210 r"""
211 ___ ___ _____ ___ ___ ___
212 /__/\ / /\ / /::\ / /\ / /\ / /\
213 | |::\ / /::\ / /:/\:\ / /::\ / /::\ / /::\
214 | |:|:\ / /:/\:\ / /:/ \:\ ___ ___ / /:/\:\ / /:/\:\ / /:/\:\
215 __|__|:|\:\ / /:/~/::\ /__/:/ \__\:| /__/\ / /\ / /:/ \:\ / /:/ \:\ / /:/~/:/
216 /__/::::| \:\ /__/:/ /:/\:\ \ \:\ / /:/ \ \:\ / /:/ /__/:/ \__\:\ /__/:/ \__\:\ /__/:/ /:/
217 \ \:\~~\__\/ \ \:\/:/__\/ \ \:\ /:/ \ \:\ /:/ \ \:\ / /:/ \ \:\ / /:/ \ \:\/:/
218 \ \:\ \ \::/ \ \:\/:/ \ \:\/:/ \ \:\ /:/ \ \:\ /:/ \ \::/
219 \ \:\ \ \:\ \ \::/ \ \::/ \ \:\/:/ \ \:\/:/ \ \:\
220 \ \:\ \ \:\ \__\/ \__\/ \ \::/ \ \::/ \ \:\
221 \__\/ \__\/ \__\/ \__\/ \__\/
222
223 %(versionref)s
224 """
225
226 @classmethod
228 if style.lower()=='random':
229 chosen = random.choice(cls.get_style_keys())
230 return cls.styles[chosen]
231 else:
232 return cls.styles[style]
233
234 @classmethod
237
238 @classmethod
239 - def get_MadLoop_Banner(cls, style='classic', color='blue',
240 top_frame_char = '=', bottom_frame_char = '=',
241 left_frame_char = '{',right_frame_char = '}',
242 print_frame=True, side_margin = 7, up_margin = 1):
243 """ Writes out MadLoop banner."""
244
245 colors = {'black':30,'red':31,'green':32,'yellow':33,
246 'blue':34,'magenta':35,'cyan':36,'lightred':91,'lightgreen':92,
247 'lightyellow':93,'lightblue':94,'lightmagenta':95,'lightcyan':96,
248 'white':97,'none':-1}
249
250 if style.lower()=='random':
251 color = random.choice(['blue','green','red'])
252
253 reference = "Ref: arXiv:1103.0621v2, arXiv:1405.0301"
254 version = "v%(version)s (%(date)s)"%misc.get_pkg_info()
255 versionref = "%s, %s"%(version,reference)
256 if style.lower() not in cls.get_style_keys()+['random']:
257 raise MadGraph5Error('Incorrect style in MadLoopBanner. Must be'+\
258 ' one of the following: %s'%str(cls.get_style_keys()+['random']))
259
260 if isinstance(color,int):
261 color_start ="char(27)//'[%im"%int
262 color_end = "char(27)//'[0m"
263 elif color.lower() in colors:
264 if color.lower()=='none':
265 color_start = ""
266 color_end = ""
267 else:
268 color_start ="char(27)//'[%im"%colors[color.lower()]
269 color_end = "char(27)//'[0m"
270 else:
271 raise MadGraph5Error('Incorrect color in MadLoopBanner. Must be and'+\
272 ' intenger or one of the following: %s'%str(list(colors.keys())))
273
274 def format_banner(banner):
275 """ Format the raw banner text to give it a frame, colors and a
276 margin."""
277
278 def fw(*args):
279 """Fortran write line"""
280 elems = []
281 for arg in args:
282 if arg.startswith('char('):
283 elems.append("%s'"%arg)
284 continue
285
286
287 arg = arg.replace("'","'//char(39)//'")
288 arg = arg.replace('"',"'//char(34)//'")
289 if len(arg)>0:
290 elems.append("'%s'"%arg)
291 return "write(*,*) %s"%("//".join(elems))
292
293 banner_lines = banner.split('\n')
294 formatted_lines = []
295
296
297 width = side_margin*2 + max(len(line) for line in banner_lines)
298 if print_frame:
299 width += 2
300
301
302 if print_frame:
303 formatted_lines.append(fw(" %s "%(top_frame_char*(width-2))))
304
305
306 for i in range(up_margin):
307 formatted_lines.append(fw("%(lside)s%(width)s%(rside)s"%
308 {'lside':left_frame_char if print_frame else '',
309 'rside':right_frame_char if print_frame else '',
310 'width':' '*(width-2)}))
311
312
313 for line in banner_lines:
314 line_elements = []
315 line_elements.append((left_frame_char if
316 print_frame else '')+' '*side_margin)
317
318 line_elements.append(color_start)
319
320 found = False
321 for tag in [versionref, reference, version]:
322 if tag in line:
323 line_elements.extend([line[:line.index(tag)],
324 color_end,tag,color_start,
325 line[line.index(tag)+len(tag):]+
326 ' '*(width-2*(side_margin+1)-len(line))])
327 found = True
328 break
329 if not found:
330 line_elements.append(line+
331 ' '*(width-2*(side_margin+1)-len(line)))
332 line_elements.append(color_end)
333 line_elements.append(' '*side_margin+(right_frame_char
334 if print_frame else ''))
335 formatted_lines.append(fw(*line_elements))
336
337
338 for i in range(up_margin):
339 formatted_lines.append(fw("%(lside)s%(width)s%(rside)s"%
340 {'lside':left_frame_char if print_frame else '',
341 'rside':right_frame_char if print_frame else '',
342 'width':' '*(width-2)}))
343
344
345 if print_frame:
346 formatted_lines.append(fw(" %s "%(bottom_frame_char*(width-2))))
347
348 return '\n'.join(formatted_lines)
349
350
351
352 return format_banner(
353 cls.get_raw_banner(style.lower())
354 %{'versionref':versionref, 'ref':reference, 'version':version})
355
356
357 if __name__=='__main__':
358 import madgraph.iolibs.file_writers as writers
359 import os
360 import copy
361 pjoin = os.path.join
362 writer = writers.FortranWriter('test_ML_banner.f')
363
364 styles = copy.copy(MadLoopBannerStyles.get_style_keys())
365 styles.append('random')
366
367
368
369
370
371
372
373 f_code = ""
374 for style in styles:
375 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s with default options.'\n"%style
376 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style)
377
378 for style in styles:
379 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s in red.'\n"%style
380 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style, color='red')
381
382 for style in styles:
383 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s in green.'\n"%style
384 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style, color='green')
385
386 for style in styles:
387 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s without frame.'\n"%style
388 f_code += MadLoopBannerStyles.get_MadLoop_Banner(style=style, print_frame=False)
389
390 for style in styles:
391 f_code += "\nwrite(*,*) ''\nwrite(*,*) 'Style %s with a different frame.'\n"%style
392 f_code += MadLoopBannerStyles.get_MadLoop_Banner(
393 side_margin=10, up_margin=3,
394 top_frame_char = '-',
395 bottom_frame_char = '-',
396 left_frame_char = '*',
397 right_frame_char = '*',
398 style=style)
399
400 writer.writelines("program testMLBanner\n%s\nend\n"%f_code)
401 writer.close()
402
403 if os.path.isfile(pjoin(os.getcwd(),'test_ML_banner')):
404 os.remove(pjoin(os.getcwd(),'test_ML_banner'))
405 misc.call('gfortran -o test_ML_banner test_ML_banner.f',
406 cwd=os.getcwd(),shell=True)
407 misc.call('./test_ML_banner',cwd=os.getcwd(),shell=True)
408