Package madgraph :: Package interface :: Module master_interface
[hide private]
[frames] | no frames]

Source Code for Module madgraph.interface.master_interface

  1  ################################################################################ 
  2  # 
  3  # Copyright (c) 2009 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 user friendly command line interface to access all MadGraph features. 
 16     Uses the cmd package for command interpretation and tab completion. 
 17  """ 
 18   
 19   
 20  import atexit 
 21  import logging 
 22  import optparse 
 23  import os 
 24  import pydoc 
 25  import re 
 26  import subprocess 
 27  import sys 
 28  import traceback 
 29  import time 
 30   
 31  root_path = os.path.split(os.path.dirname(os.path.realpath( __file__ )))[0] 
 32  root_path = os.path.split(root_path)[0] 
 33  sys.path.insert(0, root_path) 
 34   
 35  #usefull shortcut 
 36  pjoin = os.path.join 
 37   
 38  import madgraph 
 39  import madgraph.interface.extended_cmd as cmd 
 40  import madgraph.interface.madgraph_interface as MGcmd 
 41  import madgraph.iolibs.files as files 
 42   
 43  from madgraph import MG4DIR, MG5DIR, MadGraph5Error 
 44   
 45  logger = logging.getLogger('cmdprint') # -> stdout 
 46   
 47   
48 -class Switcher(object):
49 """ Helping class containing all the switching routine """ 50
51 - def __init__(self, main='MadGraph', *args, **opt):
52 53 # define the interface 54 self.change_principal_cmd(main) 55 self.cmd.__init__(self, *args, **opt)
56 57 58 59 135 136 137 138 139
140 - def check_add(self, *args, **opts):
141 return self.cmd.check_add(self, *args, **opts)
142
143 - def check_answer_in_input_file(self, *args, **opts):
144 return self.cmd.check_answer_in_input_file(self, *args, **opts)
145
146 - def check_check(self, *args, **opts):
147 return self.cmd.check_check(self, *args, **opts)
148
149 - def check_define(self, *args, **opts):
150 return self.cmd.check_define(self, *args, **opts)
151
152 - def check_display(self, *args, **opts):
153 return self.cmd.check_display(self, *args, **opts)
154
155 - def check_draw(self, *args, **opts):
156 return self.cmd.check_draw(self, *args, **opts)
157
158 - def check_for_export_dir(self, *args, **opts):
159 return self.cmd.check_for_export_dir(self, *args, **opts)
160
161 - def check_generate(self, *args, **opts):
162 return self.cmd.check_generate(self, *args, **opts)
163
164 - def check_history(self, *args, **opts):
165 return self.cmd.check_history(self, *args, **opts)
166
167 - def check_import(self, *args, **opts):
168 return self.cmd.check_import(self, *args, **opts)
169
170 - def check_install(self, *args, **opts):
171 return self.cmd.check_install(self, *args, **opts)
172
173 - def check_launch(self, *args, **opts):
174 return self.cmd.check_launch(self, *args, **opts)
175
176 - def check_load(self, *args, **opts):
177 return self.cmd.check_load(self, *args, **opts)
178
179 - def check_open(self, *args, **opts):
180 return self.cmd.check_open(self, *args, **opts)
181
182 - def check_output(self, *args, **opts):
183 return self.cmd.check_output(self, *args, **opts)
184
185 - def check_process_format(self, *args, **opts):
186 return self.cmd.check_process_format(self, *args, **opts)
187
188 - def check_save(self, *args, **opts):
189 return self.cmd.check_save(self, *args, **opts)
190
191 - def check_set(self, *args, **opts):
192 return self.cmd.check_set(self, *args, **opts)
193
194 - def check_stored_line(self, *args, **opts):
195 return self.cmd.check_stored_line(self, *args, **opts)
196
197 - def complete_add(self, *args, **opts):
198 return self.cmd.complete_add(self, *args, **opts)
199
200 - def complete_check(self, *args, **opts):
201 return self.cmd.complete_check(self, *args, **opts)
202
203 - def complete_define(self, *args, **opts):
204 return self.cmd.complete_define(self, *args, **opts)
205
206 - def complete_display(self, *args, **opts):
207 return self.cmd.complete_display(self, *args, **opts)
208
209 - def complete_draw(self, *args, **opts):
210 return self.cmd.complete_draw(self, *args, **opts)
211
212 - def complete_generate(self, *args, **opts):
213 return self.cmd.complete_generate(self, *args, **opts)
214
215 - def complete_help(self, *args, **opts):
216 return self.cmd.complete_help(self, *args, **opts)
217
218 - def complete_history(self, *args, **opts):
219 return self.cmd.complete_history(self, *args, **opts)
220
221 - def complete_import(self, *args, **opts):
222 return self.cmd.complete_import(self, *args, **opts)
223
224 - def complete_install(self, *args, **opts):
225 return self.cmd.complete_install(self, *args, **opts)
226
227 - def complete_launch(self, *args, **opts):
228 return self.cmd.complete_launch(self, *args, **opts)
229
230 - def complete_load(self, *args, **opts):
231 return self.cmd.complete_load(self, *args, **opts)
232
233 - def complete_open(self, *args, **opts):
234 return self.cmd.complete_open(self, *args, **opts)
235
236 - def complete_output(self, *args, **opts):
237 return self.cmd.complete_output(self, *args, **opts)
238
239 - def complete_save(self, *args, **opts):
240 return self.cmd.complete_save(self, *args, **opts)
241
242 - def complete_set(self, *args, **opts):
243 return self.cmd.complete_set(self, *args, **opts)
244
245 - def complete_tutorial(self, *args, **opts):
246 return self.cmd.complete_tutorial(self, *args, **opts)
247
248 - def do_EOF(self, *args, **opts):
249 return self.cmd.do_EOF(self, *args, **opts)
250
251 - def do_add(self, *args, **opts):
252 return self.cmd.do_add(self, *args, **opts)
253
254 - def do_check(self, *args, **opts):
255 return self.cmd.do_check(self, *args, **opts)
256
257 - def do_define(self, *args, **opts):
258 return self.cmd.do_define(self, *args, **opts)
259
260 - def do_display(self, *args, **opts):
261 return self.cmd.do_display(self, *args, **opts)
262
263 - def do_exit(self, *args, **opts):
264 return self.cmd.do_exit(self, *args, **opts)
265
266 - def do_generate(self, *args, **opts):
267 return self.cmd.do_generate(self, *args, **opts)
268
269 - def do_help(self, *args, **opts):
270 return self.cmd.do_help(self, *args, **opts)
271
272 - def do_history(self, *args, **opts):
273 return self.cmd.do_history(self, *args, **opts)
274
275 - def do_import(self, *args, **opts):
276 return self.cmd.do_import(self, *args, **opts)
277
278 - def do_install(self, *args, **opts):
279 return self.cmd.do_install(self, *args, **opts)
280
281 - def do_launch(self, *args, **opts):
282 return self.cmd.do_launch(self, *args, **opts)
283
284 - def do_load(self, *args, **opts):
285 return self.cmd.do_load(self, *args, **opts)
286
287 - def do_open(self, *args, **opts):
288 return self.cmd.do_open(self, *args, **opts)
289
290 - def do_output(self, *args, **opts):
291 return self.cmd.do_output(self, *args, **opts)
292
293 - def do_quit(self, *args, **opts):
294 return self.cmd.do_quit(self, *args, **opts)
295
296 - def do_save(self, *args, **opts):
297 return self.cmd.do_save(self, *args, **opts)
298
299 - def do_set(self, *args, **opts):
300 return self.cmd.do_set(self, *args, **opts)
301
302 - def do_tutorial(self, *args, **opts):
303 return self.cmd.do_tutorial(self, *args, **opts)
304
305 - def help_EOF(self, *args, **opts):
306 return self.cmd.help_EOF(self, *args, **opts)
307
308 - def help_add(self, *args, **opts):
309 return self.cmd.help_add(self, *args, **opts)
310
311 - def help_check(self, *args, **opts):
312 return self.cmd.help_check(self, *args, **opts)
313
314 - def help_define(self, *args, **opts):
315 return self.cmd.help_define(self, *args, **opts)
316
317 - def help_display(self, *args, **opts):
318 return self.cmd.help_display(self, *args, **opts)
319
320 - def help_generate(self, *args, **opts):
321 return self.cmd.help_generate(self, *args, **opts)
322
323 - def help_help(self, *args, **opts):
324 return self.cmd.help_help(self, *args, **opts)
325
326 - def help_history(self, *args, **opts):
327 return self.cmd.help_history(self, *args, **opts)
328
329 - def help_import(self, *args, **opts):
330 return self.cmd.help_import(self, *args, **opts)
331
332 - def help_install(self, *args, **opts):
333 return self.cmd.help_install(self, *args, **opts)
334
335 - def help_launch(self, *args, **opts):
336 return self.cmd.help_launch(self, *args, **opts)
337
338 - def help_load(self, *args, **opts):
339 return self.cmd.help_load(self, *args, **opts)
340
341 - def help_open(self, *args, **opts):
342 return self.cmd.help_open(self, *args, **opts)
343
344 - def help_output(self, *args, **opts):
345 return self.cmd.help_output(self, *args, **opts)
346
347 - def help_quit(self, *args, **opts):
348 return self.cmd.help_quit(self, *args, **opts)
349
350 - def help_save(self, *args, **opts):
351 return self.cmd.help_save(self, *args, **opts)
352
353 - def help_set(self, *args, **opts):
354 return self.cmd.help_set(self, *args, **opts)
355
356 - def help_tutorial(self, *args, **opts):
357 return self.cmd.help_tutorial(self, *args, **opts)
358
359 - def test_interface(self, *args, **opts):
360 return self.cmd.test_interface(self, *args, **opts)
361
362 - def set_configuration(self, *args, **opts):
363 return self.cmd.set_configuration(self, *args, **opts)
364 365
366 -class MasterCmd(Switcher, MGcmd.MadGraphCmd, cmd.CmdShell):
367 368
369 - def change_principal_cmd(self, name):
370 if name == 'MadGraph': 371 self.cmd = MGcmd.MadGraphCmd 372 else: 373 raise MadGraph5Error, 'Type of interface not valid' 374 375 if __debug__: 376 self.debug_link_to_command()
377
378 -class MasterCmdWeb(Switcher, MGcmd.MadGraphCmdWeb):
379
380 - def __init__(self, *arg, **opt):
381 382 if os.environ.has_key('_CONDOR_SCRATCH_DIR'): 383 self.writing_dir = pjoin(os.environ['_CONDOR_SCRATCH_DIR'], \ 384 os.path.pardir) 385 else: 386 self.writing_dir = pjoin(os.environ['MADGRAPH_DATA'], 387 os.environ['REMOTE_USER']) 388 389 390 #standard initialization 391 Switcher.__init__(self, mgme_dir = '', *arg, **opt) 392 393 self.options['timeout'] = 1 # time authorize to answer question [0 is no time limit]
394
395 - def change_principal_cmd(self, name):
396 if name == 'MadGraph': 397 self.cmd = MGcmd.MadGraphCmdWeb 398 # elif name == 'Loop': 399 # self.cmd = NLOcmd.LoopInterfaceWeb 400 else: 401 raise MadGraph5Error, 'Type of interface not valid' 402 403 if __debug__: 404 self.debug_link_to_command()
405
406 - def finalize(self, nojpeg):
407 """Finalize web generation""" 408 409 self.cmd.finalize(self, nojpeg, online = True)
410 411 # Generate a new amplitude
412 - def do_generate(self, line):
413 """Generate an amplitude for a given process""" 414 415 try: 416 Switcher.do_generate(self, line) 417 except: 418 # put the stop logo on the web 419 files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg') 420 raise
421 422 # Add a process to the existing multiprocess definition
423 - def do_add(self, line):
424 """Generate an amplitude for a given process and add to 425 existing amplitudes 426 syntax: 427 """ 428 try: 429 Switcher.do_add(self, line) 430 except: 431 # put the stop logo on the web 432 files.cp(self._export_dir+'/HTML/stop.jpg',self._export_dir+'/HTML/card.jpg') 433 raise
434 435 # Use the cluster file for the configuration
436 - def set_configuration(self, config_path=None):
437 438 """Force to use the web configuration file only""" 439 config_path = pjoin(os.environ['MADGRAPH_BASE'], 'mg5_configuration.txt') 440 return Switcher.set_configuration(self, config_path=config_path)
441 442
443 - def do_save(self, line, check=True):
444 """Save information to file""" 445 446 if check: 447 self.check_save([]) 448 raise #useless but full security 449 450 args = self.split_arg(line) 451 if args[0] != 'options': 452 Switcher.do_save(self, line,check) 453 else: 454 # put default options since 455 # in the web the local file is not used 456 # in download the default file is more usefull 457 files.cp(pjoin(MG5DIR,'input','mg5_configuration.txt'), args[1])
458