TranslateCore Class Reference

This class contains the methods that are shared by all the MAD-like parsing classes. More...

#include <TranslateCore.hpp>

Inherited by AMLParser, BmadParser, MAD8Parser, MADXParser, SADParser, and XSIFParser.

Collaboration diagram for TranslateCore:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 TranslateCore ()
 Initializes internal variables.
bool ModifyIncludedFileNames (UAPNode *root, const Str &replacement_suffix)
 Searches for the file names specified in the <include> or <call> nodes in the given tree.
virtual UAPNodeXFileToAMLRep (const Str &file_name, UAPNode *uap_root=NULL)
 Reads in a X file (or files if there are include statements) and constructs the appropriate X representation tree and AML representation tree.
virtual UAPNodeXFileToXRep (const Str &file_name, UAPNode *uap_root=NULL)
 Reads in a X file (or files if there are include statements) and constructs the appropriate Representation tree.
virtual UAPNodeXRepToAMLRep (UAPNode *x_root, UAPNode *aml_root=NULL)
 Constructs from an X representation tree the corresponding AML representation tree.
virtual UAPNodeAMLRepToXFile (UAPNode *aml_root, const Str &file_name="", const Str &out_suffix="", bool one_file=false)
 Constructs a X file (or files) from a AML_representation tree.
virtual UAPNodeAMLRepToXRep (UAPNode *aml_root, UAPNode *x_root=NULL)
 Constructs from an AML representation tree the corresponding X representation tree.
virtual UAPNodeXRepToXFile (UAPNode *x_root, const Str &file_name="", const Str &out_suffix="", bool one_file=false)
 Creates a X file (or files if there are include statements) from a X_representation tree.

Protected Member Functions

virtual bool custom_x_statement_to_x (StrList word_list, Str comment, UAPNode *x_rep_root)
 Method to process statements read from an X-file that are unique to the particular language under consideration.
virtual bool aml_ele_to_x_class (UAPNode *aml_ele, Str &x_class)
 Finds the Bmad class (Eg: sol_quad, rfcavity, etc.
void multipole_to_k_tilt (Str k_in, Str ks_in, Str tilt_in, Str n, Str &k, Str &tilt)
 Translates a multipole component given by k_in, ks_in, and tilt_in and eliminates ks_in to give the multipole solely in terms of k and tilt.
void multipole_to_k_ks (Str k_in, Str ks_in, Str tilt_in, Str n, Str &k, Str &ks)
 Translates a multipole component given by k_in, ks_in, and tilt_in and eliminates tilt_in to give the multipole solely in terms of k and ks.
void required_multipole_transfer (const Str &odd_man_out, const Str &k_base, const Str &ks_base, const Str &tilt_base, Str &k_ele, Str &ks_ele, Str &tilt_ele)
 Translation of multipole parameters, either from a multipole, quadrupole, sextupole, & or octupole, from AML to X is tricky since in AML you can specify (k, ks, tilt) while in X you generally specify (k, ks) or (k, tilt).


Detailed Description

This class contains the methods that are shared by all the MAD-like parsing classes.

Currently: MAD-8, MAD-X, and Bmad.

Definition at line 99 of file TranslateCore.hpp.


Member Function Documentation

bool TranslateCore::aml_ele_to_x_class ( UAPNode aml_ele,
Str &  x_class 
) [protected, virtual]

Finds the Bmad class (Eg: sol_quad, rfcavity, etc.

) of an element.

Parameters:
aml_ele Element node
x_class Class of element
Returns:
True if a class is found. False otherwise

Definition at line 3564 of file TranslateCore.cpp.

UAPNode * TranslateCore::AMLRepToXFile ( UAPNode aml_root,
const Str &  file_name = "",
const Str &  out_suffix = "",
bool  one_file = false 
) [virtual]

Constructs a X file (or files) from a AML_representation tree.

Also the intermediate X representation tree is constructed. If the argument one_file is set false, then the file names used for each included file are obtained from the href attribute of the <xi:include> node. See the ModifyIncludedFileNames routine.

Parameters:
aml_root May be a <AML_representation> node or a <UAP_root> node.
file_name The root X file to create. If not present or "" then the present file name will be used. If "*" then use the out_suffix to replace the current suffix.
out_suffix The suffix to use for include files in place of the current suffix. The file suffix is defined as everything after and including the last ".". If not present or "" then the present files name will be used.
one_file If true then concatinate everything into one file. Default is false.
Returns:
X <X_representation> node.

Reimplemented in AMLParser.

Definition at line 2471 of file TranslateCore.cpp.

UAPNode * TranslateCore::AMLRepToXRep ( UAPNode aml_root,
UAPNode x_root = NULL 
) [virtual]

Constructs from an AML representation tree the corresponding X representation tree.

Parameters:
aml_root May be a <AML_representation> node or a <UAP_root> node.
x_root May be a <X_representation> node or a <UAP_root> node, or NULL. If it is a <UAP_root> node then all existing <X_representation> children are deleted. If it is NULL (the default) then, if the aml_root is a <UAP_root> or has a a <UAP_root> parent, a <X_representation> child is created. Otherwise if x_root is NULL a new <X_representation> node is created.
Returns:
X <X_representation> node.

Reimplemented in AMLParser.

Definition at line 2483 of file TranslateCore.cpp.

bool TranslateCore::custom_x_statement_to_x ( StrList  word_list,
Str  comment,
UAPNode x_rep_root 
) [protected, virtual]

Method to process statements read from an X-file that are unique to the particular language under consideration.

Parameters:
word_list List of words that make up the x-statement.
comment Possible comment that went with the statement.
x_rep_root Root node of the x-representation sub-tree.
recognized True if the statement is recognized. False otherwise.

Definition at line 4605 of file TranslateCore.cpp.

bool TranslateCore::ModifyIncludedFileNames ( UAPNode root,
const Str &  replacement_suffix 
)

Searches for the file names specified in the <include> or <call> nodes in the given tree.

The ending suffix (everything after the last dot "." in the name) of these names are then replaced by replacement_suffix.

Parameters:
root Root of tree.
replacement_suffix text to replace with.
Returns:
true if everything OK. false otherwise.

Definition at line 39 of file TranslateCore.cpp.

void TranslateCore::multipole_to_k_ks ( Str  k_in,
Str  ks_in,
Str  tilt_in,
Str  n,
Str &  k,
Str &  ks 
) [protected]

Translates a multipole component given by k_in, ks_in, and tilt_in and eliminates tilt_in to give the multipole solely in terms of k and ks.

Note: If k is zero the output string is blank (""). Similarly with tilt.

Parameters:
k_in Input normal component.
ks_in Input skew component.
tilt_in Input multipole tilt.
n Input multipole order.
k Output normal component.
ks Output ks.

Definition at line 4532 of file TranslateCore.cpp.

void TranslateCore::multipole_to_k_tilt ( Str  k_in,
Str  ks_in,
Str  tilt_in,
Str  n,
Str &  k,
Str &  tilt 
) [protected]

Translates a multipole component given by k_in, ks_in, and tilt_in and eliminates ks_in to give the multipole solely in terms of k and tilt.

Note: If k is zero the output string is blank (""). Similarly with tilt.

Parameters:
k_in Input normal component.
ks_in Input skew component.
tilt_in Input multipole tilt.
n Input multipole order.
k Output normal component.
tilt Output tilt.

Definition at line 4495 of file TranslateCore.cpp.

void TranslateCore::required_multipole_transfer ( const Str &  odd_man_out,
const Str &  k_base,
const Str &  ks_base,
const Str &  tilt_base,
Str &  k_ele,
Str &  ks_ele,
Str &  tilt_ele 
) [protected]

Translation of multipole parameters, either from a multipole, quadrupole, sextupole, & or octupole, from AML to X is tricky since in AML you can specify (k, ks, tilt) while in X you generally specify (k, ks) or (k, tilt).

Now given values for (k, ks, tilt) for an element, there are standard formula that can be used to convert to (k, tilt) or (k, ks) as given in the AML manual.

However, there is an additional complication in that elements can inherit parameters from other elements and the setting of parameters can happen after an element has been defined. To see why this is a problem, consider the following example: A base element, call it q0, specifies a tilt which will be called it q0::tilt. Another element, call it q1, inherits from q0 and additionally specifies a k1 (called q1:k1). Assume that the X representation wants to see things specified by (k, ks). When the parameters from q0 are converted to X, we have q0::k(X) = 0 and q0::ks(X) = 0! When the parameters from q1 are converted we have q1::k1(X) = q1::k1(AML) and q1::ks(X) = 0. Thus in the X rep, q1 does not have a skew component but in AML there is one (since it will inherit a tilt from q0).

The solution involves some bookkeeping: First, the (k, ks, tilt) parameters are saved For each element. For quadrupoles, sextupoles, and octupoles the storage is in: aml_k_map[ele_name] -> k value string aml_ks_map[ele_name] -> ks value string aml_tilt_map[ele_name] -> tilt value string ele_name is the name of the element. For multipoles this is in: aml_multi_kl_map[ele_name] -> kl value string vector aml_multi_ksl_map[ele_name] -> ksl value string vector aml_multi_tilt_map[ele_name] -> tilt value string vector ele_name is the name of the multipole element.

[It is important to note here that if q1 inherits from q0, then q0 must be defined first, also sets must be done after an element is defined.]

As the elements are precessed in order, if the element does not inherit from a base element then the conversion from AML (k, ks, tilt) to X values is straight forward.

If an element does inherit from a base element, the following procedure is used:

If it is "required" (defined below), the (k, ks, tilt) values from the base element are transfered to the current element for each k, ks, or tilt that is defined in the base element but not defined in the current element. The conversion from (k, ks, tilt) to X is now done.

If it is not "required", the AML (k, ks, tilt) values are converted to X ignoring the base element.

After the conversion to X, in both required and non-required cases, the values from the base element are transferred to the maps that save the parameters. This is done in case a future element inherits from the current element.

Note that even in the non-required case it would be technically OK to transfer the base values to the current element. That is, the correct X parameters would be produced. There are several reasons not to, for one, the transfer can potentially be confusing to someone looking at the output.

Now to define "required": It is required to transfer when the multipole in the X representation and the multipole in the AML representation are not equivalent. Specifically, when the X representation is (k, ks), it is required if all of the following conditions apply: 1) At least one of the k, ks or tilt is defined in the current element, and 2) The element tilt or the base tilt is defined. When the X representation is (k, tilt), substitute "ks' for "tilt" in condition (2) above.

Note: for multipoles the procedure is the same as the above with each order n being processed separately.

Definition at line 4576 of file TranslateCore.cpp.

UAPNode * TranslateCore::XFileToAMLRep ( const Str &  file_name,
UAPNode uap_root = NULL 
) [virtual]

Reads in a X file (or files if there are include statements) and constructs the appropriate X representation tree and AML representation tree.

The constructed trees have the root <UAP_Root>.

Parameters:
file_name The root X file to use.
uap_root The root of the UAP tree. If not present then a new tree will be formed with the root called <UAP_Root>,
Returns:
The AML representation subtree root.

Reimplemented in AMLParser.

Definition at line 93 of file TranslateCore.cpp.

UAPNode * TranslateCore::XFileToXRep ( const Str &  file_name,
UAPNode uap_root = NULL 
) [virtual]

Reads in a X file (or files if there are include statements) and constructs the appropriate Representation tree.

The constructed UAP tree has the root <_representation>.

Parameters:
file_name The root X file to use.
uap_root The root of the subtree (typeically <UAP_Root>)
Returns:
The child of root that is the <_representation>.

Reimplemented in AMLParser.

Definition at line 115 of file TranslateCore.cpp.

UAPNode * TranslateCore::XRepToAMLRep ( UAPNode x_root,
UAPNode aml_root = NULL 
) [virtual]

Constructs from an X representation tree the corresponding AML representation tree.

Parameters:
x_root May be a <X_representation> node or a <UAP_root> node.
aml_root May be a <AML_representation> node or a <UAP_root> node, or NULL. If it is a <UAP_root> node then all existing <AML_representation> children are deleted. If it is NULL (the default) then, if the x_root is a <UAP_root> or has a a <UAP_root> parent, a <AML_representation> child is created. Otherwise if x_root is NULL a new <AML_representation> node is created.
Returns:
<AML_representation> node.

Reimplemented in AMLParser.

Definition at line 1181 of file TranslateCore.cpp.

UAPNode * TranslateCore::XRepToXFile ( UAPNode x_root,
const Str &  file_name = "",
const Str &  out_suffix = "",
bool  one_file = false 
) [virtual]

Creates a X file (or files if there are include statements) from a X_representation tree.

If the argument one_file is set false, then the file names used for each included file are obtained from the href attribute of the <xi:include> node. See the ModifyIncludedFileNames routine.

Parameters:
x_root May be a <X_representation> node or a <UAP_root> node.
file_name The root X file to create. If not present or "" then the present file name will be used. If "*" then use the out_suffix to replace the current suffix.
out_suffix The suffix to use for include files in place of the current suffix. The file suffix is defined as everything after and including the last ".". If not present or "" then the present files name will be used.
one_file If true then concatinate everything into one file. Default is false.
Returns:
X <X_representation> node.

Reimplemented in AMLParser.

Definition at line 3839 of file TranslateCore.cpp.


Generated on Fri Feb 12 15:47:57 2010 for Universal Accelerator Parser by  doxygen 1.5.7