Package madgraph :: Package various :: Module misc
[hide private]
[frames] | no frames]

Module misc

source code

A set of functions performing routine administrative I/O tasks.

Classes [hide private]
  MuteLogger
mute_logger (designed to work as with statement), files allow to redirect the output of the log to a given file.
  BackRead
read a file returning the lines in reverse order for each call of readline() This actually just reads blocks (4096 bytes by default) of data from the end of the file and returns last line in an internal buffer.
  TMP_directory
create a temporary directory and ensure this one to be cleaned.
  TMP_variable
replace an attribute of a class with another value for the time of the context manager
  open_file
a convinient class to open a file
  OptionParser
Option Peaser which raise an error instead as calling exit
  chdir
  ProcessTimer
  Applenotification
  EasterEgg
Functions [hide private]
 
parse_info_str(fsock)
Parse a newline separated list of "param=value" as a dictionnary
source code
 
glob(name, path='')
call to glob.glob with automatic security on path
source code
 
mute_logger(names=['madgraph', 'ALOHA', 'cmdprint', 'madevent'], levels=[50, 50, 50, 50])
change the logger level and restore those at their initial value at the end of the function decorated.
source code
 
get_pkg_info(info_str=None)
Returns the current version information of the MadGraph5_aMC@NLO package, as written in the VERSION text file.
source code
 
get_time_info()
Returns the present time info for use in MG5 command history header.
source code
 
is_MA5_compatible_with_this_MG5(ma5path)
Returns None if compatible or, it not compatible, a string explaining why it is so.
source code
 
find_includes_path(start_path, extension)
Browse the subdirectories of the path 'start_path' and returns the first one found which contains at least one file ending with the string extension given in argument.
source code
 
get_ninja_quad_prec_support(ninja_lib_path)
Get whether ninja supports quad prec in different ways
source code
 
which(program) source code
 
has_f2py() source code
 
deactivate_dependence(dependency, cmd=None, log=None)
Make sure to turn off some dependency of MG5aMC.
source code
 
activate_dependence(dependency, cmd=None, log=None, MG5dir=None)
Checks whether the specfieid MG dependency can be activated if it was not turned off in MG5 options.
source code
 
which_lib(lib) source code
 
nice_representation(var, nb_space=0)
Return nice information on the current variable
source code
 
multiple_try(nb_try=5, sleep=20) source code
 
get_scan_name(first, last)
return a name of the type xxxx[A-B]yyy where xxx and yyy are the common part between the two names.
source code
 
compile(arg=[], cwd=None, mode='fortran', job_specs=True, nb_core=1, **opt)
compile a given directory
source code
 
get_gfortran_version(compiler='gfortran')
Returns the gfortran version as a string.
source code
 
mod_compilator(directory, new='gfortran', current=None, compiler_type='gfortran') source code
 
pid_exists(pid)
Check whether pid exists in the current process table.
source code
 
stdchannel_redirected(*args, **kwds)
A context manager to temporarily redirect stdout or stderr
source code
 
get_open_fds()
return the number of open file descriptors for current process
source code
 
detect_if_cpp_compiler_is_clang(cpp_compiler)
Detects whether the specified C++ compiler is clang.
source code
 
detect_cpp_std_lib_dependence(cpp_compiler)
Detects if the specified c++ compiler will normally link against the C++ standard library -lc++ or -libstdc++.
source code
 
detect_current_compiler(path, compiler_type='fortran')
find the current compiler for the current directory
source code
 
find_makefile_in_dir(directory)
return a list of all file starting with makefile in the given directory
source code
 
rm_old_compile_file() source code
 
format_time(n_secs) source code
 
rm_file_extension(ext, dirname, names) source code
 
multiple_replacer(*key_values) source code
 
multiple_replace(string, *key_values) source code
 
check_system_error(value=1) source code
 
call(arg, *args, **opt)
nice way to call an external program with nice error treatment
source code
 
Popen(arg, *args, **opt)
nice way to call an external program with nice error treatment
source code
 
call_stdout(arg, *args, **opt)
nice way to call an external program with nice error treatment
source code
 
mult_try_open(*args, **opt)
try to open a file with multiple try to ensure that filesystem is sync
source code
 
tail(f, n, offset=None)
Reads a n lines from f with an offset of offset lines.
source code
 
mkfifo(fifo_path)
makes a piping fifo (First-in First-out) file and nicely intercepts error in case the file format of the target drive doesn't suppor tit.
source code
 
get_last_line(fsock)
return the last line of a file
source code
 
write_PS_input(filePath, PS)
Write out in file filePath the PS point to be read by the MadLoop.
source code
 
format_timer(running_time)
return a nicely string representing the time elapsed.
source code
 
gunzip(path, keep=False, stdout=None)
a standard replacement for os.system('gunzip -f %s.gz ' % event_path)
source code
 
gzip(path, stdout=None, error=True, forceexternal=False)
a standard replacement for os.system('gzip %s ' % path)
source code
 
get_HEPTools_location_setter(HEPToolsDir, type)
Checks whether mg5dir/HEPTools/<type> (which is 'lib', 'bin' or 'include') is in the environment paths of the user.
source code
 
get_shell_type()
Try and guess what shell type does the user use.
source code
 
is_executable(path)
check if a path is executable
source code
 
sprint(*args, **opt)
Returns the current line number in our program.
source code
 
equal(a, b, sig_fig=6, zero_limit=True)
function to check if two float are approximatively equal
source code
 
timeout(func, args=(), kwargs={}, timeout_duration=1, default=None)
This function will spwan a thread and run the given function using the args, kwargs and return the given default value if the timeout_duration is exceeded
source code
 
digest(text)
using mg5 for the hash
source code
 
get_older_version(v1, v2)
return v2 if v1>v2 return v1 if v1<v2 return v1 if v1=v2 return v1 if v2 is not in 1.2.3.4.5 format return v2 if v1 is not in 1.2.3.4.5 format
source code
 
is_plugin_supported(obj) source code
 
set_global(loop=False, unitary=True, mp=False, cms=False) source code
 
plugin_import(module, error_msg, fcts=[])
convenient way to import a plugin file/function
source code
 
from_plugin_import(plugin_path, target_type, keyname=None, warning=False, info=None)
return the class associated with keyname for a given plugin class if keyname is None, return all the name associated
source code
 
import_python_lhapdf(lhapdfconfig)
load the python module of lhapdf return None if it can not be loaded
source code
 
newtonmethod(f, df, x0, error=1e-10, maxiter=10000)
implement newton method for solving f(x)=0, df is the derivate
source code
 
wget(http, path, *args, **opt)
a wget function for both unix and mac
source code
Variables [hide private]
  MADEVENT = False
  logger = logging.getLogger('cmdprint.ext_program')
  logger_stderr = logging.getLogger('madevent.misc')
  PACKAGE_INFO = {}
  wait_once = False
  nb_open = 0
  apple_notify = Applenotification()
  username = 'omattelaer'
  plugin_support = {}
  python_lhapdf = None
hash(x)
  __package__ = 'madgraph.various'
Function Details [hide private]

get_pkg_info(info_str=None)

source code 

Returns the current version information of the MadGraph5_aMC@NLO package, as written in the VERSION text file. If the file cannot be found, a dictionary with empty values is returned. As an option, an info string can be passed to be read instead of the file content.

get_gfortran_version(compiler='gfortran')

source code 

Returns the gfortran version as a string. Returns '0' if it failed.

pid_exists(pid)

source code 

Check whether pid exists in the current process table. UNIX only. https://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid-in-python

stdchannel_redirected(*args, **kwds)

source code 

A context manager to temporarily redirect stdout or stderr                                                                                                                                              
                                                                                                                                                                                                        
e.g.:                                                                                                                                                                                                   
                                                                                                                                                                                                        
                                                                                                                                                                                                        
with stdchannel_redirected(sys.stderr, os.devnull):                                                                                                                                                     
    if compiler.has_function('clock_gettime', libraries=['rt']):                                                                                                                                        
        libraries.append('rt')                                                                                                                                                                          

Decorators:
  • @contextlib.contextmanager

get_open_fds()

source code 

return the number of open file descriptors for current process

.. warning: will only work on UNIX-like os-es.

call(arg, *args, **opt)

source code 

nice way to call an external program with nice error treatment

Decorators:
  • @check_system_error()

Popen(arg, *args, **opt)

source code 

nice way to call an external program with nice error treatment

Decorators:
  • @check_system_error()

call_stdout(arg, *args, **opt)

source code 

nice way to call an external program with nice error treatment

Decorators:
  • @check_system_error()

mult_try_open(*args, **opt)

source code 

try to open a file with multiple try to ensure that filesystem is sync

Decorators:
  • @multiple_try()

tail(f, n, offset=None)

source code 

Reads a n lines from f with an offset of offset lines. The return value is a tuple in the form ``lines``.

get_HEPTools_location_setter(HEPToolsDir, type)

source code 
Checks whether mg5dir/HEPTools/<type> (which is 'lib', 'bin' or 'include')
is in the environment paths of the user. If not, it returns a preamble that
sets it before calling the exectuable, for example:
   <preamble> ./my_exe
with <preamble> -> DYLD_LIBRARY_PATH=blabla:$DYLD_LIBRARY_PATH