Class MADInterpreter

java.lang.Object
org.scictrl.mp.orbitcorrect.accessories.AbstractParameterReader
org.scictrl.mp.orbitcorrect.accessories.MADInterpreter
All Implemented Interfaces:
IDataBushReader, IMultipleFileReader

public class MADInterpreter extends AbstractParameterReader implements IDataBushReader, IMultipleFileReader
MADInterpreter has the same functionality as DefaultDBReader. In addition to reading DataBush specific input can also read MAD input. Because DataBush is independent of MAD, or any other accelerator physics calculation program, can't write in MAD specific format. Gadgets like MADInterpreter perform interpretations to other envirements.
MADInterpreter also provides storing DataBush data in MAD format code.

MAD format does not include enough parameters for DataBush elements to initialize functional DataBush. I order to store all information for DataBush, part of data must be stored in DataBush specific format.

Input for MADInterpreter is assembled from two parts, MAD specific input and DataBush (abbreviated DB) specific input. Both kind of input must be stored in separate files.

Input for MADInterpreter points to MAD and DB files. This is sample of MADInterpreter input file:
 <DBINPUT
 "C:/DataBush/DBInput.txt"
 >
 <MADINPUT
 "C:/DataBush/MAD/MADInput 1.txt",
 "C:/DataBush/MAD/MADInput 2.txt"
 >
 
DataBush and MAD part is enclosed in-between brackets '<' and '>'. Code name "DBINPUT" and "MADINPUT" tells in which format style are input files inside brackets written. Separate files are closed inside '"'.

Files inside "DBINPUT" brackets are passed to DefaultDBReader.

Files Inside "MADINPUT" brackets are parsed by MADInterpreter. MADInterpreter writes and reads same format as MAD, only with few restrictions.
  • uses MAD comment sign '!', C and C++ comments
  • recognize only code for definitions of variables, elements and element's positions
  • does not support new element type defining. Only following MAD types may be used: MARKER, RFCAVITY, BPMH, BPMV, HKICK, VKICK, ECOLLIMATOR, RBEND, SBEND, QUADRUPOLE, SEXTUPOLE. Where BPMH and BPMV are: "BPMH: HMONITOR,TYPE=MM" and "BPMV: VMONITOR,TYPE=MM"
  • all elements, except MARKER, must be described in two parts, in definition and position part. In definition part element must be defined with default MAD type.
    In second part position of element must be defined with "INSTALL" expression. The order of parts is not important to MADInterpreter.
  • MARKER is defined with position expression "mymarker :MARKER, at=13.13"
  • variables must be defined, before they are used
  • MADInterpreter supports multiplication '*' and derivation '/' in numerical expressions
  • code word "TWOPI" is replaced with 2*Math.PI
DB specific input can store all information necessary to initialize DataBush, and MAD specific only part of it. It is possible, that same property is defined in this two places, even with different value. In this case last value read always overwrites any earlier value applied to same property.

IMPORTANT! Structure of data, stored in DataBush so differs from organization of data in MAD code, that can produce conflicts, if few simple rules are neglected.
Cause of conflict is:
  • DB format is case sensitive, MAD isn't. This is critical for recognition of element names. They must be unique, or DataBush won't initialize.
    possible conflict: If same element name, but in different, case is used in DB and MAD input, MADInterpreter recognizes it as two different elements, instead of applying all properties to same one.
  • transformation between DB and MAD elements is not bijective. This is transformation table. On left are element types, as used in MAD input. On right are class names of DataBush elements created by reader. The same names are used to declare element type in DB input format.
    MAD element DB element
    MARKERMarker
    RFCAVITYCavity
    BPMH,BPMVBPMonitor
    HKICKHorCorrector,Kicker
    VKICKVerCorrector
    ECOLLIMATORApperature
    RBENDRBending
    SBENDSBending
    QUADRUPOLEQuadrupole
    SEXTUPOLESextupole
    Element mapping
    Element with same name and type, defined in MAD and DB formated input, is recognized as same element.

    Beam position monitors and kickers are handled by MADInterpreter in special way:
    • MAD elements defined with BPMH type are recognized as BPMonitor. BPMV elements are ignored. String representation of DataBush in MAD format produces declaration of both types.
    • elements of HKICK type in MAD input are automatically recognized as HorCorrector elements. If you want to use HKICK element in MAD format as Kicker, a Kicker must be declared with same name in DB input before MAD declaration.
MADInterpreter is also able to store DataBush information in MAD format. Use saveToFiles and saveToStrings methods.
Author:
igor@scictrl.com
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Index of RBENDING and SBENDING elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    static final int
    Index of BPMV and BPMH elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    static final int
    Index of RFCAVITY elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    protected Map<String,Double>
    HashMap containing constants read from MAD input files.
    static final int
    Index of VerCorrector and HorCorrector elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    static final int
    Index of DB specific fromat, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    static final String[]
    String[] array of MAD commented string, describing contents of String[] array, returned by saveToFiles and saveToStrings methods.
    static final int
    Index of Kicker elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    static final int
    Index of MARKER elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    static final int
    Index of QUADRUPOLE elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.
    static final int
    Index of SEXTUPOLE elements in MAD formated string, stored in HEADER and String[] array, returned by saveToFiles and saveToStrings methods.

    Fields inherited from class org.scictrl.mp.orbitcorrect.accessories.AbstractParameterReader

    log, st, tok, uRL

    Fields inherited from interface org.scictrl.mp.orbitcorrect.IDataBushReader

    ST_FILE, ST_URL
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default MADInterpreter constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    addConstant(String name, double value)
    Puts new key name with value value to constant's HashMap.
    protected double
    Returnes value of constant with key name.
    Returns list of instances of DataBush elements created by read() method.
    void
    open(File[] files)
    Open files, specified by file array.
    void
    open(URL[] url)
    Open files, specified by URL array.
    Reads input and creates DataBush elements.
    Reads input and creates DataBush elements.
    static void
    saveToFiles(DataBush db, File inputFile, File dbFile, File madFile)
    Saves to files string representation of DataBush in MAD specific format, as is obtained with saveToStrings methods.
    static String[]
    Saves DataBush in to String[] array.
    static String[]
    Saves elements from ElementList in same way, as they are with saveToStrings(DataBush).

    Methods inherited from class org.scictrl.mp.orbitcorrect.accessories.AbstractParameterReader

    close, debugPrint, debugPrintln, getProperties, getSourceType, getURL, open, open, setProperties

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.scictrl.mp.orbitcorrect.IDataBushReader

    close, getProperties, getSourceType, open, open, setProperties