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:
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.
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:
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
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 MARKER Marker RFCAVITY Cavity BPMH,BPMV BPMonitor HKICK HorCorrector,Kicker VKICK VerCorrector ECOLLIMATOR Apperature RBEND RBending SBEND SBending QUADRUPOLE Quadrupole SEXTUPOLE Sextupole Element mapping
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.
saveToFiles
and saveToStrings
methods.- Author:
- igor@scictrl.com
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Index of RBENDING and SBENDING elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final int
Index of BPMV and BPMH elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final int
Index of RFCAVITY elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.HashMap containing constants read from MAD input files.static final int
Index of VerCorrector and HorCorrector elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final int
Index of DB specific fromat, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final String[]
String[]
array of MAD commented string, describing contents ofString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final int
Index of Kicker elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final int
Index of MARKER elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final int
Index of QUADRUPOLE elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.static final int
Index of SEXTUPOLE elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addConstant
(String name, double value) Puts new keyname
with valuevalue
to constant's HashMap.protected double
getConstant
(String name) Returnes value of constant with keyname
.getList()
Returns list of instances of DataBush elements created byread()
method.void
Open files, specified by file array.void
Open files, specified by URL array.read()
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 withsaveToStrings
methods.static String[]
Saves DataBush in toString[]
array.static String[]
Saves elements fromElementList
in same way, as they are withsaveToStrings(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
-
Field Details
-
consts
HashMap containing constants read from MAD input files. HashMap object is created, whenread
method is called. Constant definition in MAD looks like thisconstant_name=some_double_value
.- See Also:
-
DB
public static final int DBIndex of DB specific fromat, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
MARK
public static final int MARKIndex of MARKER elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
BPM
public static final int BPMIndex of BPMV and BPMH elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
CAV
public static final int CAVIndex of RFCAVITY elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
SE
public static final int SEIndex of SEXTUPOLE elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
QU
public static final int QUIndex of QUADRUPOLE elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
BE
public static final int BEIndex of RBENDING and SBENDING elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
COR
public static final int CORIndex of VerCorrector and HorCorrector elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
KICK
public static final int KICKIndex of Kicker elements in MAD formated string, stored in HEADER andString[]
array, returned bysaveToFiles
andsaveToStrings
methods.- See Also:
-
HEADER
String[]
array of MAD commented string, describing contents ofString[]
array, returned bysaveToFiles
andsaveToStrings
methods. Correspondent description in header (HEADER[index]
) and contents (saveToStrings()[index]
) mach in index.- See Also:
-
-
Constructor Details
-
MADInterpreter
public MADInterpreter()Default MADInterpreter constructor.
-
-
Method Details
-
addConstant
Puts new keyname
with valuevalue
to constant's HashMap.- Parameters:
name
- java.lang.String constant's namevalue
- double constant's value- See Also:
-
getConstant
Returnes value of constant with keyname
. If key is not found, return value is 0.0.- Parameters:
name
- java.lang.String constant name- Returns:
- double value of
name
key - See Also:
-
getList
Returns list of instances of DataBush elements created byread()
method. Returns elements created by MADInterpreter. Elements are stored inElementList
list. List is created and filled after call toread()
method.- Specified by:
getList
in interfaceIDataBushReader
- Returns:
ElementList
list of read elements
-
open
Open files, specified by file array. Openes files.- Specified by:
open
in interfaceIMultipleFileReader
- Parameters:
files
- java.io.File[]- Throws:
DataBushException
- if any.
-
open
Open files, specified by URL array. Openes URL.- Specified by:
open
in interfaceIMultipleFileReader
- Parameters:
url
- java.net.URL[]- Throws:
DataBushException
- if any.
-
read
Reads input and creates DataBush elements. Input must be opened with one ofParameterReader.openInStream
methods. Created elements are stored and returned inElementList
. Reads input and creates DataBush elements. Input must be opened with one ofParameterReader.openInStream
methods. Created elements are stored and returned inElementList
. Call read only once per new opened stream.- Specified by:
read
in interfaceIDataBushReader
- Returns:
ElementList
list of created elements- Throws:
DataBushException
- if any.
-
read
public ElementList<AbstractDataBushElement> read(ElementList<AbstractDataBushElement> l) throws DataBushException Reads input and creates DataBush elements. Input must be opened with one ofParameterReader.openInStream
methods. Created elements are stored and returned inElementList
. Reads input and creates DataBush elements. Input must be opened with one ofParameterReader.openInStream
methods. Created elements are stored and returned inElementList
. Call read only once per new opened stream.- Specified by:
read
in interfaceIDataBushReader
- Parameters:
l
- aElementList
object- Returns:
ElementList
list of created elements- Throws:
DataBushException
- if any.
-
saveToFiles
public static void saveToFiles(DataBush db, File inputFile, File dbFile, File madFile) throws IOException Saves to files string representation of DataBush in MAD specific format, as is obtained withsaveToStrings
methods. Three files must be specified to save DataBush.- inputFile is input file for MADInterpreter.
- dbFile is file with DataBush represented in its specific format. inputFile points to this file in DBINPUT part of code. dbFile may be used as input for DefaultDBReader.
- madInput is file with MAD specific representation of DataBush. This is only naked data with no MAD command lines.
- Parameters:
db
- theDataBush
to be savedinputFile
-java.io.File
with input for MADInterpreterdbFile
-java.io.File
with DB specific DataBush representationmadFile
-java.io.File
with MAD specific DataBush representation- Throws:
IOException
- signals problems during writing to files.
-
saveToStrings
Saves DataBush in toString[]
array. At 0 index,returnedArray[0]
, is saved DB specific representation of DataBush. At further indexes are saved MAD specific representations of each group of elements (markers, bendings,...) separately. Each group is saved on two consecutive positions in array. In one definition of element from group, in other description of position. Only MARKER is describe under one array index, since its enough to define marker with position only.
Strings in array may be accessed with use of static fields, declared in MADInterpreter.
EXAMPLEString[] st= MADInterpreter.saveToStrings(myDataBush);
//this prints out header and description of all elements from myDataBush in DB specific code. System.out.println(HEADER[DB]); System.out.println(st[DB]);
//this prints out header and MAD description of markers //do not use MARK+1, markers are described only under MARK position System.out.println(HEADER[MARK]); System.out.println(st[MARK]);
//this prints out header and MAD coded string with definition of quadrupoles System.out.println(HEADER[QU]); System.out.println(st[QU]);
//this prints out header and MAD coded string with positions of quadrupoles System.out.println(HEADER[QU+1]); System.out.println(st[QU+1]);- Parameters:
db
- theDataBush
to be represented in strings- Returns:
- an
java.lang.String[]
array with description of elements in DataBush
-
saveToStrings
Saves elements fromElementList
in same way, as they are withsaveToStrings(DataBush)
. Difference is, that elements taken from list are not initialized and do not guarantee to be able to initialize DataBush.- Parameters:
l
- aElementList
object- Returns:
- an
java.lang.String[]
array with description of elements in DataBush - See Also:
-