Tidying

Tue, 07 May 2013 22:32:39 +0200

author
Andy Buckley <andy@insectnation.org>
date
Tue, 07 May 2013 22:32:39 +0200
changeset 223
a37f9686a5ff
parent 222
3c65cf35a5b5
child 224
ae148391c467

Tidying

ChangeLog file | annotate | diff | comparison | revisions
pyslha.py file | annotate | diff | comparison | revisions
     1.1 --- a/ChangeLog	Tue May 07 22:22:22 2013 +0200
     1.2 +++ b/ChangeLog	Tue May 07 22:32:39 2013 +0200
     1.3 @@ -1,3 +1,7 @@
     1.4 +2013-05-07  Andy Buckley  <andy.buckley@cern.ch>
     1.5 +
     1.6 +	* Adding multi-value support and refactoring Block value setting.
     1.7 +
     1.8  2013-04-29  Andy Buckley  <andy.buckley@cern.ch>
     1.9  
    1.10  	* Version 2.0.0 with new Block API.
     2.1 --- a/pyslha.py	Tue May 07 22:22:22 2013 +0200
     2.2 +++ b/pyslha.py	Tue May 07 22:32:39 2013 +0200
     2.3 @@ -35,13 +35,9 @@
     2.4  
     2.5  TODOs:
     2.6  
     2.7 -  For 2.1.0:
     2.8 -   * Only allow integers to be used as block entry indices, to allow multiple
     2.9 -     values (request, if possible, from Anders & Are).
    2.10 -
    2.11    For 2.2.0:
    2.12     * Preserve comments from read -> write (needs full-line/inline comment
    2.13 -     separation?). Can use separate comment dicts in Block and Decay, and
    2.14 +     separation). Can use separate comment dicts in Block and Decay, and
    2.15       attach a multiline .comment attr to the returned/written dicts.
    2.16  
    2.17    Later/maybe:
    2.18 @@ -49,10 +45,14 @@
    2.19     * Handle RPV SUSY in ISAWIG
    2.20  """
    2.21  
    2.22 -__author__ = "Andy Buckley <andy.buckley@cern.ch"
    2.23 +__author__ = "Andy Buckley <andy.buckley@cern.ch>"
    2.24  __version__ = "2.1.0"
    2.25  
    2.26  
    2.27 +
    2.28 +###############################################################################
    2.29 +## Private utility functions
    2.30 +
    2.31  def _mkdict():
    2.32      """Try to return an empty ordered dict, but fall back to normal dict if necessary"""
    2.33      try:
    2.34 @@ -90,6 +90,10 @@
    2.35      return tuple(a)
    2.36  
    2.37  
    2.38 +
    2.39 +###############################################################################
    2.40 +## Exceptions
    2.41 +
    2.42  class AccessError(Exception):
    2.43      "Exception object to be raised when a SLHA block is accessed in an invalid way"
    2.44      def __init__(self, errmsg):
    2.45 @@ -106,6 +110,9 @@
    2.46  
    2.47  
    2.48  
    2.49 +###############################################################################
    2.50 +## The data block, decay and particle classes
    2.51 +
    2.52  class Block(object):
    2.53      """
    2.54      Object representation of any BLOCK elements read from an SLHA file.
    2.55 @@ -121,10 +128,11 @@
    2.56      methods for iteration. Purely iterating over the object behaves like keys(),
    2.57      as for an ordinary dict.
    2.58  
    2.59 -    Multiple indices are possible, especially for entries in mixing matrix
    2.60 -    blocks. These are now implemented in the natural way, e.g. for access to the
    2.61 -    (1,2) element of a mxing matrix block, use bmix[1,2] = 0.123 and print
    2.62 -    bmix[1,2]. The value() and set_value() functions behave similarly.
    2.63 +    Multiple (integer) indices are possible, especially for entries in mixing
    2.64 +    matrix blocks. These are now implemented in the natural way, e.g. for access
    2.65 +    to the (1,2) element of a mixing matrix block, use bmix[1,2] = 0.123 and
    2.66 +    print bmix[1,2]. The value() and set_value() functions behave
    2.67 +    similarly. Multi-element values are also permitted.
    2.68  
    2.69      It is possible, although not usual, to store unindexed values in a
    2.70      block. This is only supported when that entry is the only one in the block,
    2.71 @@ -148,7 +156,8 @@
    2.72  
    2.73          This method is just for convenience: it splits the single string
    2.74          argument if necessary and converts the list of strings into numeric
    2.75 -        types when possible.
    2.76 +        types when possible. For the treatment of the resulting iterable see the
    2.77 +        set_value method.
    2.78          """
    2.79          ## If the argument is a single string, split it and proceed
    2.80          if type(args) is str:
    2.81 @@ -320,6 +329,10 @@
    2.82          return s
    2.83  
    2.84  
    2.85 +
    2.86 +###############################################################################
    2.87 +## SLHA parsing and writing functions
    2.88 +
    2.89  def readSLHA(spcstr, ignorenobr=False):
    2.90      """
    2.91      Read an SLHA definition from a string, returning dictionaries of blocks and
    2.92 @@ -647,7 +660,6 @@
    2.93  ###############################################################################
    2.94  ## ISAWIG format reading/writing
    2.95  
    2.96 -
    2.97  def readISAWIG(isastr, ignorenobr=False):
    2.98      """
    2.99      Read a spectrum definition from a string in the ISAWIG format, returning
   2.100 @@ -1035,9 +1047,9 @@
   2.101      return out
   2.102  
   2.103  
   2.104 +
   2.105  ###############################################################################
   2.106 -## File-level functions
   2.107 -
   2.108 +## File-level read/write functions
   2.109  
   2.110  def readSLHAFile(spcfilename, **kwargs):
   2.111      """
   2.112 @@ -1103,7 +1115,6 @@
   2.113  ###############################################################################
   2.114  ## Main function for module testing
   2.115  
   2.116 -
   2.117  if __name__ == "__main__":
   2.118      import sys
   2.119      for a in sys.argv[1:]:

mercurial