=== Plugin idea === init file: {{{ ## import the required files # example: import maddm_interface as maddm_interface # Three types of functionality are allowed in a plugin # 1. new output mode # 2. new cluster support # 3. new interface # 1. Define new output mode # example: new_output = {'myformat': MYCLASS} # madgraph will then allow the command "output myformat PATH" # MYCLASS should inherated of the class madgraph.iolibs.export_v4.VirtualExporter new_output = {} # 2. Define new way to handle the cluster. # example new_cluster = {'mycluster': MYCLUSTERCLASS} # allow "set cluster_type mycluster" in madgraph # MYCLUSTERCLASSshould inherated from madgraph.various.cluster.Cluster new_cluster = {} # 3. Define a new interface (allow to add/modify MG5 command) # This can be activated via ./bin/mg5_aMC --mode=PLUGINNAME ## Put None if no dedicated command are required new_interface = None ########################## CONTROL VARIABLE #################################### __author__ = '' __email__ = '' __version__ = (1,0,0) minimal_mg5amcnlo_version = (2,3,4) maximal_mg5amcnlo_version = (1000,1000,1000) latest_validated_version = (2,4,0) }}} === Example 1: hello world (adding command to the interface) __init__.py file {{{ ## import the required files import helloworld as helloworld ## Does it define a new interface (will be avaible with ./bin/mg5_aMC --mode=maddm ## Put None if no dedicated command are required new_interface = helloworld.NewInterface ## Does it define a new output mode. Need to be define new_output = {} ## The test/code have been validated up to this version latest_validated_version = '2.3.4' }}} helloworld.py file {{{ class Newinterface(master_interface.MasterCmd): def do_helloworld(self, line): """print hello world""" print "hello world" }}} === Example 2: New Exporter __init__.py file {{{ ## import the required files import output as output ## Define a typical error for the plugin class EVTDECONS_Error(Exception): pass ## Does it define a new interface (will be avaible with ./bin/mg5_aMC --mode=maddm ## Put None if no dedicated command are required new_interface = False ## Does it define a new output mode. Need to be define new_output = {'madweight2': output.My_MW_Exporter, 'standalone_lib': output.MY_CPP_Standalone} ## The test/code have been validated up to this version latest_validated_version = '2.5.0' minimal_version_required = '2.5.0' maximal_version_required = None }}} output.py file {{{ import madgraph.iolibs.export_cpp as export_cpp import madgraph.iolibs.export_v4 as export_v4 import madgraph.various.misc as misc class My_MW_Exporter(export_v4.ProcessExporterFortranMWGroup): check = True # check status of the directory. Remove it if already exists # Language type: 'v4' for f77/ 'cpp' for C++ output exporter = 'v4' # Output type: #[Template/dir/None] copy the Template, just create dir or do nothing output = 'Template' # Decide which type of merging to used [madevent/madweight] grouped_mode = 'madweight' # if no grouping on can decide to merge uu~ and u~u anyway: sa_symmetry = True nb_done = 0 def __init__(self, *args, **opts): misc.sprint("Initialise the exporter") return super(My_MW_Exporter, self).__init__(*args, **opts) def copy_template(self, *args, **opts): misc.sprint("copy the associate template") return super(My_MW_Exporter, self).copy_template(*args, **opts) def generate_subprocess_directory(self, subproc_group, fortran_model, me=None): misc.sprint(me) if me is None: MyExporter.nb_done +=1 current_generated = MyExporter.nb_done else: current_generated = me return super(My_MW_Exporter, self).generate_subprocess_directory(subproc_group, fortran_model, current_generated) class MY_CPP_Standalone(export_cpp.ProcessExporterPythia8): # check status of the directory. Remove it if already exists check = True # Language type: 'v4' for f77/ 'cpp' for C++ output exporter = 'cpp' # Output type: #[Template/dir/None] copy the Template, just create dir or do nothing output = 'Template' # Decide which type of merging if used [madevent/madweight] grouped_mode = False # if no grouping on can decide to merge uu~ and u~u anyway: sa_symmetry = True def __init__(self, *args, **opts): misc.sprint("Initialise the exporter") return super(MY_CPP_Standalone, self).__init__(*args, **opts) def copy_template(self, model): misc.sprint("initialise the directory") return super(MY_CPP_Standalone, self).copy_template(model) def generate_subprocess_directory(self, subproc_group, fortran_model, me=None): misc.sprint('create the directory') return super(MY_CPP_Standalone, self).generate_subprocess_directory(subproc_group, fortran_model, me) def convert_model(self, model, wanted_lorentz=[], wanted_coupling=[]): misc.sprint('create the model') return super(MY_CPP_Standalone, self).convert_model(model, wanted_lorentz, wanted_coupling) def finalize(self, matrix_element, cmdhistory, MG5options, outputflag): """typically creating jpeg/HTML output/ compilation/... cmdhistory is the list of command used so far. MG5options are all the options of the main interface outputflags is a list of options provided when doing the output command""" misc.sprint("pass here") return super(MY_CPP_Standalone, self).finalize(matrix_element, cmdhistory, MG5options, outputflag) def modify_grouping(self, matrix_element): """allow to modify the grouping (if grouping is in place) return two value: - True/False if the matrix_element was modified - the new(or old) matrix element""" #irrelevant here since group_mode=False so this function is never called return False, matrix_element }}} === List of function that need to be defined in the exporter For Fortran/CPP output: Note: All of them are defined in ProcessExporterFortran. So you need to define them only if you start a class from scratch. This list correspond to the call to the exporter performed outside the class itself. 1. __init__(self, dir_path = "", opt=None) 2. copy_template(self, modelname) 3. generate_subprocess_directory(self, subproc_group, helicity_model, me=None) [for grouped] 4. generate_subprocess_directory(self, matrix_element, helicity_model, me_number) [for ungrouped] 4. convert_model(model, wanted_lorentz=[], wanted_coupling=[]) 5. finalize(self,matrix_element, cmdhistory, MG5options, outputflag) 6. modify_grouping(self, matrix_element) 7. export_model_files(self, model_v4_path) [only if you want to support old model format] 8. export_helas(self, HELAS_PATH) [only if you want to support old model format] === List of class variable that need to be defined in the exporter: Note: All of them are defined in ProcessExporterFortran/ProcessExporterCPP. So you need to define them only if you start a class from scratch. This list correspond to the attribute of the exporter called outside the exporter class. 1. '''grouped_mode''' This variable changes the type of object called within 'generate_subprocess_directory' functions. a. '''False''' to avoid grouping (only identical matrix element are merged) b. ''' 'madevent' ''' group the massless quark and massless lepton c. ''' 'madweight' ''' group the gluon with the massless quark 2. '''sa_symmetry''' If no grouped_mode=False, uu~ and u~u will be called independently. Putting sa_symmetry generates only one of the two matrix-element. (might not work for cpp output. 3. '''check''' Ask madgraph to check if the directory already exists and propose to the user to remove it first if this is the case 4. '''output''' [Template, None, dir] a. ''''Template'''', madgraph will call copy_template b. ''''dir'''', madgraph will just create an empty directory for initialisation c. '''None''', madgraph do nothing for initialisation 5. '''exporter''' ['v4'/'cpp'] language of the output 'v4' for Fortran output, 'cpp' for C++ output === Base class which can be use to create a new exporter from scratch: at the beginning of madgraph/various/iolibs/export_v4.py. A virtual class "VirtualExporter" is defined all exporter class should derive from that class. That virtual class list all the functions called by the interface that you can define (that class in itself does nothing)