00001 #include "Translate/MADXParser.hpp"
00002
00003 using namespace std;
00004 using namespace BasicUtilities;
00005
00006
00007
00008
00009 MADXParser::MADXParser() : TranslateCore() {
00010
00011 language = "MADX";
00012 include_file_string = "call:filename";
00013 continuation_char = "";
00014 knl_tn_style_multipoles = false;
00015 c_style_format = true;
00016 abbreviations_permitted = false;
00017
00018 x_attributes_to_upper_case << "apertype";
00019
00020 init_lists_madx();
00021 init_lists_mad();
00022 init_lists_core();
00023 }
00024
00025
00026
00027
00028 bool MADXParser::custom_x_statement_to_x (StrList word_list, string comment,
00029 UAPNode* x_rep_root) {
00030
00031
00032
00033 if (word_list.size() < 3) return false;
00034
00035
00036
00037 string word1 = next_word(word_list);
00038
00039 while (true) {
00040 if (word1 == "const" || word1 == "real" || word1 == "int") {
00041 word1 = next_word(word_list);
00042 continue;
00043 }
00044 break;
00045 }
00046
00047
00048
00049 if (word_list.size() < 2) return false;
00050
00051 string word2 = next_word(word_list);
00052 string word3 = next_word(word_list);
00053
00054
00055
00056 if (word2 == "=") {
00057 UAPNode* node = x_rep_root->addChild("constant");
00058 node->addAttribute("name", word1);
00059 while (word_list.size() != 0) word3 += next_word(word_list);
00060 node->addAttribute("design", word3);
00061 if (comment != "") node->addAttribute("comment", comment);
00062 return true;
00063 }
00064
00065
00066
00067 if (word1 == "use") {
00068 UAPNode* node = x_rep_root->addChild(word1);
00069 while (true) {
00070 if (word_list.size() < 2 || word2 != "," || next_word(word_list) != "=") {
00071 info_out.error ("Malformed USE Statement");
00072 return true;
00073 }
00074 if (word3 == "period")
00075 node->addAttribute("line", next_word(word_list));
00076 else if (word3 == "range")
00077 node->addAttribute("range", next_word(word_list));
00078 else {
00079 info_out.error ("Unknown USE argument: " + word3);
00080 return true;
00081 }
00082 if (word_list.size() == 0) break;
00083 word2 = next_word(word_list);
00084 word3 = next_word(word_list);
00085 }
00086 return true;
00087 }
00088
00089
00090
00091
00092 string value;
00093 if (word2 == "->") {
00094 value = next_word(word_list);
00095 if (value == ":") value = next_word(word_list);
00096 if (value != "=") {
00097 info_out.error ("Missing or misplaced \"=\"");
00098 return true;
00099 }
00100 value = next_word(word_list);
00101 while (word_list.size() != 0) value += next_word(word_list);
00102
00103 if (word1 == "parameter" || word1 == "beginning" || word1 == "beam_start") {
00104 UAPNode* node = x_rep_root->addChild(word1);
00105 node->addAttribute(word3, value);
00106 } else {
00107 UAPNode* node = x_rep_root->addChild("set");
00108 node->addAttribute("element", word1);
00109 node->addAttribute("attribute", word3);
00110 node->addAttribute("value", value);
00111 }
00112 return true;
00113 }
00114
00115
00116
00117 return false;
00118
00119 }
00120
00121
00122
00123
00124 bool MADXParser::custom_x_add_attributes (StrList& word_list, string ele_class,
00125 string& attrib_name, UAPNode* x_ele_root) {
00126
00127
00128
00129
00130 if (attrib_name == "aperture" ||
00131 (ele_class == "multipole" && (attrib_name == "knl" || attrib_name == "ksl"))) {
00132
00133 if (word_list.size() < 4 ||
00134 (next_word(word_list) != "=" || next_word(word_list) != "{")) {
00135 info_out.error ("MALFORMED " + attrib_name + " ATTRIBUTE.");
00136 return true;
00137 }
00138
00139 string value;
00140 while (true) {
00141 if (word_list.size() == 0) {
00142 info_out.error ("NO CLOSING \"}\" FOUND IN ATTRIBUTE: " + attrib_name);
00143 return true;
00144 }
00145 string word = next_word(word_list);
00146 if (word == "}") break;
00147 value += word;
00148 if (word == ",") value += " ";
00149 }
00150
00151 x_ele_root->addAttribute(attrib_name, value);
00152 return true;
00153 }
00154
00155
00156
00157 return false;
00158 }
00159
00160
00161
00162
00163 bool MADXParser::custom_x_node_to_aml (UAPNode* x_node, UAPNode* aml_root, UAPNode* aml_ele) {
00164
00165
00166
00167 if (x_node->getName() == "set") {
00168 string attrib = x_node->getAttributeString("attribute");
00169 string value = x_node->getAttributeString("value");
00170 string val1;
00171 if (attrib == "knl" || attrib == "ksl") {
00172 for (int n = 0;; n++) {
00173 size_t ix_comma = value.find(",");
00174 if (ix_comma == string::npos) {
00175 val1 = value;
00176 value = "";
00177 } else {
00178 val1 = trim(value.substr(0,ix_comma));
00179 value.erase(0,++ix_comma);
00180 }
00181 if (val1.find_first_not_of("0. ") != string::npos) {
00182 UAPNode* aml_node = aml_ele->addChild("set");
00183 string n_str = int_to_string(n);
00184 string name = x_node->getAttributeString("element");
00185 if (attrib == "knl") {
00186 aml_node->addAttribute("attribute", name + "[multipole:kl(n=" + n_str + ")]");
00187 } else {
00188 aml_node->addAttribute("attribute", name + "[multipole:ksl(n=" + n_str + ")]");
00189 }
00190 aml_node->addAttribute("value", val1);
00191 }
00192 if (value == "") break;
00193 }
00194
00195 return true;
00196 }
00197 }
00198
00199
00200
00201 return false;
00202
00203 }
00204
00205
00206
00207
00208 bool MADXParser::custom_x_element_attribute_to_aml (UAPNode* x_node, string x_class,
00209 UAPAttribute ia, UAPNode* aml_node) {
00210
00211 string attrib_name = ia.getName();
00212 string attrib_value = ia.getValue();
00213
00214
00215
00216 if (x_class == "multipole" && (attrib_name == "knl" || attrib_name == "ksl")) {
00217 return true;
00218 }
00219
00220
00221
00222 if (attrib_name == "aperture") {
00223 size_t ix_comma = attrib_value.find(",");
00224 if (ix_comma == string::npos) {
00225 aml_node->getChildByName("aperture", true)->
00226 addChild("xy_limit")->addAttribute("design", attrib_value);
00227 } else {
00228 string val_x = trim(attrib_value.substr(0,ix_comma));
00229 attrib_value.erase(0,++ix_comma);
00230 ix_comma = attrib_value.find(",");
00231 if (ix_comma != string::npos) {
00232 info_out.error ("TOO MANY APERTURE VALUES. NO CORRESPONDING AML TRANSLATION",
00233 "FOR: " + x_node->toString());
00234
00235 return true;
00236 }
00237 UAPNode* aper_node = aml_node->getChildByName("aperture", true);
00238 aper_node->addChild("x_limit")->addAttribute("design", val_x);
00239 aper_node->addChild("y_limit")->addAttribute("design", trim(attrib_value));
00240 }
00241 return true;
00242 }
00243
00244
00245
00246 if (attrib_name == "apertype") {
00247 if (attrib_value != "CIRCLE" && attrib_value != "ELLIPSE" &&
00248 attrib_value != "RECTANGLE") {
00249 info_out.error ("NO CORRESPONDING APERTURE TYPE OF: " + attrib_value,
00250 "FOR: " + x_node->toString());
00251 }
00252 return false;
00253 }
00254
00255
00256
00257 return false;
00258
00259 }
00260
00261
00262
00263
00264 void MADXParser::custom2_x_element_attribute_to_aml (UAPNode* x_node, UAPNode* aml_node) {
00265
00266 bool ok;
00267 string x_class = x_node_to_x_class (x_node);
00268
00269
00270
00271 if (x_class == "multipole") {
00272
00273
00274
00275 UAPNode* m_node = aml_node->getChildByName("multipole", true);
00276
00277
00278
00279 StrList knl_list, ksl_list;
00280
00281 AttributeVec a_list = x_node->getAttributes();
00282 for (AttributeVecCIter ia = a_list.begin(); ia != a_list.end(); ia++) {
00283
00284 string attrib_name = ia->getName();
00285 string attrib_value = ia->getValue();
00286
00287 if (attrib_name != "knl" && attrib_name != "ksl") continue;
00288
00289 for (int n = 0;; n++) {
00290 size_t ix_comma = attrib_value.find(",");
00291 string val = trim(attrib_value.substr(0,ix_comma));
00292 if (val.find_first_not_of("0. ") != string::npos) {
00293 if (attrib_name == "knl") {
00294 UAPNode* knl_node = m_node->addChild("kl");
00295 knl_node->addAttribute("n", int_to_string(n));
00296 knl_node->addAttribute("design", val);
00297 } else if (attrib_name == "ksl") {
00298 UAPNode* ksl_node = m_node->addChild("ksl");
00299 ksl_node->addAttribute("n", int_to_string(n));
00300 ksl_node->addAttribute("design", val);
00301 }
00302 }
00303 if (ix_comma == string::npos) break;
00304 attrib_value.erase(0,++ix_comma);
00305 }
00306 }
00307
00308 return;
00309 }
00310
00311
00312
00313 return;
00314
00315 }
00316
00317
00318
00319
00320 bool MADXParser::custom_aml_node_to_x (UAPNode* aml_ele, UAPNode* x_rep) {
00321
00322 bool ok;
00323
00324
00325
00326 if (aml_ele->getName() == "set") {
00327 Twig twig;
00328 if (!twig.fromString(aml_ele->getAttributeString("attribute"))) return false;
00329 string ele_name = twig.name;
00330 string x_class = ele_name_to_x_class(ele_name);
00331
00332 if (twig.nodeid_vec.size() != 2) return false;
00333 string n0 = twig.nodeid_vec[0].name, n1 = twig.nodeid_vec[1].name;
00334
00335
00336
00337 if (n0 == "multipole" && (n1 == "kl" || n1 == "ksl" || n1 == "tilt")) {
00338 string n = twig.nodeid_vec[1].attribute[0].value;
00339 int n_int = string_to_int(n);
00340 if (!ok) {
00341 info_out.error ("Bad multipole integer order: " + n,
00342 "In AML element:", aml_ele->toStringTree());
00343 return true;
00344 }
00345 string ele_name = twig.name;
00346
00347 string kl_set, ksl_set, tilt_set;
00348 string value = aml_ele->getAttributeString("value");
00349 if (n1 == "kl") kl_set = value;
00350 else if (n1 == "ksl") ksl_set = value;
00351 else if (n1 == "tilt") tilt_set = value;
00352
00353 string kl_ele, ksl_ele, tilt_ele;
00354 if (found (aml_multi_tilt_map, ele_name)) {
00355 kl_ele = aml_multi_kl_map[ele_name][n_int];
00356 ksl_ele = aml_multi_ksl_map[ele_name][n_int];
00357 tilt_ele = aml_multi_tilt_map[ele_name][n_int];
00358 required_multipole_transfer ("tilt", kl_ele, ksl_ele, tilt_ele,
00359 kl_set, ksl_set, tilt_set);
00360 } else {
00361 aml_multi_kl_map[ele_name] = StrVec(N_MULTIPOLE);
00362 aml_multi_ksl_map[ele_name] = StrVec(N_MULTIPOLE);
00363 aml_multi_tilt_map[ele_name] = StrVec(N_MULTIPOLE);
00364 }
00365
00366 string knl, ksl;
00367 multipole_to_k_ks (kl_set, ksl_set, tilt_set, n, knl, ksl);
00368
00369 if (knl != "") {
00370 string prefix = "";
00371 for (int i = 0; i < n_int; i++) {
00372 if (aml_multi_kl_map[ele_name][i] == "")
00373 prefix += "0, ";
00374 else
00375 prefix += aml_multi_kl_map[ele_name][i] + ", ";
00376 }
00377 UAPNode* x_set = x_rep->addChild("set");
00378 x_set->addAttribute("element", ele_name);
00379 x_set->addAttribute("attribute", "knl");
00380 x_set->addAttribute("value", prefix + knl);
00381 }
00382
00383 if (ksl != "") {
00384 string prefix = "";
00385 for (int i = 0; i < n_int; i++) {
00386 if (aml_multi_ksl_map[ele_name][i] == "")
00387 prefix += "0, ";
00388 else
00389 prefix += aml_multi_ksl_map[ele_name][i] + ", ";
00390 }
00391 UAPNode* x_set = x_rep->addChild("set");
00392 x_set->addAttribute("element", ele_name);
00393 x_set->addAttribute("attribute", "ksl");
00394 x_set->addAttribute("value", prefix + ksl);
00395 }
00396
00397
00398 if (n1 == "kl") aml_multi_kl_map[ele_name][n_int] = value;
00399 else if (n1 == "ksl") aml_multi_ksl_map[ele_name][n_int] = value;
00400 else if (n1 == "tilt") aml_multi_tilt_map[ele_name][n_int] = value;
00401
00402 return true;
00403 }
00404
00405 }
00406
00407
00408
00409 return false;
00410
00411 }
00412
00413
00414
00415
00416 bool MADXParser::custom_aml_sector_or_element_to_x (UAPNode* aml_sec_or_ele,
00417 UAPNode* x_rep) {
00418
00419
00420
00421 string aml_name = aml_sec_or_ele->getName();
00422
00423 if (aml_name == "sector" && aml_sec_or_ele->getAttribute("length")) {
00424
00425 string length = aml_sec_or_ele->getAttributeString("length");
00426
00427
00428
00429 UAPNode* x_seq = x_rep->addChild("sequence");
00430 x_seq->addAttribute("name", aml_sec_or_ele->getAttributeString("name"));
00431 x_seq->addAttribute("l", length);
00432
00433 if (aml_sec_or_ele->getChildren().size() == 0) return true;
00434
00435
00436
00437 UAPNode* super_node = aml_sec_or_ele->getChildren().front()->getChildByName("superimpose");
00438 if (!super_node) {
00439 info_out.error ("No superimpose found for sector with a length attribute: " +
00440 aml_sec_or_ele->toStringTree());
00441 return true;
00442 }
00443
00444 string ele_origin0 = super_node->getAttributeString("ele_origin");
00445 string refer;
00446 if (ele_origin0 == "ENTRANCE") {
00447 refer = "enter";
00448 } else if (ele_origin0 == "CENTER") {
00449 refer = "centre";
00450 } else if (ele_origin0 == "EXIT") {
00451 refer = "exit";
00452 }
00453 if (refer != "") x_seq->addAttribute("refer", refer);
00454 if (ele_origin0 == "") ele_origin0 = "CENTER";
00455
00456
00457
00458 NodeVec eles = aml_sec_or_ele->getChildren();
00459 for (NodeVecCIter ie = eles.begin(); ie != eles.end(); ie++) {
00460 UAPNode* aml_seq_ele = *ie;
00461 UAPNode* x_seq_ele;
00462
00463
00464
00465
00466 if (aml_seq_ele->getAttribute("ref")) {
00467 x_seq_ele = x_seq->addChild("element");
00468 if (aml_seq_ele->getName() == "sector") x_seq_ele->setName("sequence");
00469 x_seq_ele->addAttribute("ref", aml_seq_ele->getAttributeString("ref"));
00470
00471 } else {
00472 UAPNode* temp = x_rep->addChildCopy(aml_seq_ele);
00473 temp->getChildByName("superimpose")->deleteNode();
00474 aml_node_to_x (temp, x_seq);
00475 temp->deleteNode();
00476 x_seq_ele = x_seq->getChildren().back();
00477 }
00478
00479 super_node = aml_seq_ele->getChildByName("superimpose");
00480 if (!super_node) {
00481 info_out.error ("No superimpose found for sector with a length attribute: " +
00482 aml_sec_or_ele->toStringTree());
00483 continue;
00484 }
00485
00486 string ele_origin = super_node->getAttributeString("ele_origin");
00487 if (ele_origin == "") ele_origin = "CENTER";
00488 if (ele_origin != ele_origin0) {
00489 info_out.error ("Bad \"ele_origin\" attribute for conversion to a sequence.",
00490 "Must be all the same for all sub-elements.",
00491 aml_sec_or_ele->toStringTree());
00492 return true;
00493 }
00494
00495 if (super_node->getAttribute("ref_origin")) {
00496 info_out.error ("Bad \"ref_origin\" attribute for conversion to a sequence.",
00497 "This attribute cannot be present.",
00498 aml_sec_or_ele->toStringTree());
00499 return true;
00500 }
00501
00502 string offset = super_node->getAttributeString("offset");
00503 super_node->deleteNode();
00504 x_seq_ele->addAttribute("at", offset);
00505
00506 }
00507
00508 return true;
00509 }
00510
00511 return false;
00512
00513 }
00514
00515
00516
00517
00518 bool MADXParser::custom_aml_element_attribute_to_x(UAPNode* aml_root, UAPNode* aml_ele,
00519 UAPNode* aml_attrib, UAPNode* x_ele) {
00520
00521 string aml_parent_name = aml_ele->getName();
00522 string ele_name = x_ele->getAttributeString("name");
00523 string aml_attrib_name = aml_attrib->getName();
00524 string aml_attrib_value = aml_attrib->getAttributeString("design");
00525
00526
00527
00528 return false;
00529
00530 }
00531
00532
00533
00534
00535 void MADXParser::custom2_aml_element_attribute_to_x (UAPNode* aml_ele, UAPNode* x_ele) {
00536
00537 string aml_attrib_name = aml_ele->getName();
00538 string ele_name = x_ele->getAttributeString("name");
00539
00540
00541
00542 if (aml_attrib_name == "multipole" && found(aml_multi_kl_map, ele_name)) {
00543
00544 string inherit = x_ele->getAttributeString("inherit");
00545 if (aml_multi_kl_map.find(inherit) == aml_multi_kl_map.end()) inherit = "";
00546
00547 StrVec knl_vec(N_MULTIPOLE), ksl_vec(N_MULTIPOLE);
00548
00549 for (int n = 0; n < N_MULTIPOLE; n++) {
00550 string kl_base, ksl_base, tilt_base, kl_ele, ksl_ele, tilt_ele;
00551 if (inherit != "") {
00552 kl_base = aml_multi_kl_map[inherit][n];
00553 ksl_base = aml_multi_ksl_map[inherit][n];
00554 tilt_base = aml_multi_tilt_map[inherit][n];
00555 }
00556 kl_ele = aml_multi_kl_map[ele_name][n];
00557 ksl_ele = aml_multi_ksl_map[ele_name][n];
00558 tilt_ele = aml_multi_tilt_map[ele_name][n];
00559 string knl, ksl, n_str = int_to_string(n);
00560 if (inherit != "") required_multipole_transfer ("tilt",
00561 kl_base, ksl_base, tilt_base, kl_ele, ksl_ele, tilt_ele);
00562
00563 multipole_to_k_ks (kl_ele, ksl_ele, tilt_ele, n_str, knl_vec[n], ksl_vec[n]);
00564
00565 if (inherit != "") {
00566 if (kl_ele == "") aml_multi_kl_map[ele_name][n] = kl_base;
00567 if (ksl_ele == "") aml_multi_ksl_map[ele_name][n] = ksl_base;
00568 if (tilt_ele == "") aml_multi_tilt_map[ele_name][n] = tilt_base;
00569 }
00570
00571 }
00572
00573
00574
00575 int n_knl_max(-1), n_ksl_max(-1);
00576 for (int i = 0; i < N_MULTIPOLE; i++) {
00577 if (knl_vec[i] != "") n_knl_max = i;
00578 if (ksl_vec[i] != "") n_ksl_max = i;
00579 }
00580
00581
00582
00583 string knl_tot, ksl_tot;
00584
00585 for (int n = 0; n < N_MULTIPOLE; n++) {
00586
00587 if (n <= n_knl_max) {
00588 if (knl_vec[n] == "") knl_tot += "0";
00589 else knl_tot += knl_vec[n];
00590 }
00591
00592 if (n <= n_ksl_max) {
00593 if (ksl_vec[n] == "") ksl_tot += "0";
00594 else ksl_tot += ksl_vec[n];
00595 }
00596
00597 if (n < n_knl_max) knl_tot += ", ";
00598 if (n < n_ksl_max) ksl_tot += ", ";
00599
00600 }
00601
00602 if (knl_tot != "") x_ele->addAttribute("knl", knl_tot);
00603 if (ksl_tot != "") x_ele->addAttribute("ksl", ksl_tot);
00604
00605 }
00606
00607
00608
00609
00610 if (aml_attrib_name == "quadrupole" && found(aml_k_map, ele_name)) {
00611 if (aml_k_map[ele_name] != "") x_ele->addAttribute("k1", aml_k_map[ele_name]);
00612 if (aml_ks_map[ele_name] != "") x_ele->addAttribute("k1s", aml_ks_map[ele_name]);
00613 if (aml_tilt_map[ele_name] != "") x_ele->addAttribute("tilt", aml_tilt_map[ele_name]);
00614 }
00615
00616 if (aml_attrib_name == "sextupole" && found(aml_k_map, ele_name)) {
00617 if (aml_k_map[ele_name] != "") x_ele->addAttribute("k2", aml_k_map[ele_name]);
00618 if (aml_ks_map[ele_name] != "") x_ele->addAttribute("k2s", aml_ks_map[ele_name]);
00619 if (aml_tilt_map[ele_name] != "") x_ele->addAttribute("tilt", aml_tilt_map[ele_name]);
00620 }
00621
00622 if (aml_attrib_name == "octupole" && found(aml_k_map, ele_name)) {
00623 if (aml_k_map[ele_name] != "") x_ele->addAttribute("k3", aml_k_map[ele_name]);
00624 if (aml_ks_map[ele_name] != "") x_ele->addAttribute("k3s", aml_ks_map[ele_name]);
00625 if (aml_tilt_map[ele_name] != "") x_ele->addAttribute("tilt", aml_tilt_map[ele_name]);
00626 }
00627
00628
00629
00630 if (x_ele->getAttribute("x_limit") && !x_ele->getAttribute("y_limit")) {
00631 info_out.error("Do not know how to translate AML x_limit to MADX if there is no y_limit.",
00632 x_ele->toString());
00633 x_ele->removeAttribute("x_limit");
00634 }
00635
00636 if (x_ele->getAttribute("y_limit") && !x_ele->getAttribute("x_limit")) {
00637 info_out.error("Do not know how to translate AML y_limit to MADX if there is no x_limit.",
00638 x_ele->toString());
00639 x_ele->removeAttribute("y_limit");
00640 }
00641
00642 if (x_ele->getAttribute("x_limit") && x_ele->getAttribute("y_limit")) {
00643 x_ele->addAttribute("aperture", x_ele->getAttributeString("x_limit") + ", " +
00644 x_ele->getAttributeString("y_limit"));
00645 x_ele->removeAttribute("x_limit");
00646 x_ele->removeAttribute("y_limit");
00647 }
00648
00649 if (x_ele->getAttribute("xy_limit")) {
00650 x_ele->addAttribute("aperture", x_ele->getAttributeString("xy_limit"));
00651 x_ele->removeAttribute("xy_limit");
00652 }
00653
00654
00655
00656 return;
00657
00658 }
00659
00660
00661
00662
00663 bool MADXParser::custom_x_element_to_x_file (UAPNode* x_node, string& comment,
00664 StreamStruct& x_out) {
00665
00666 string x_name = x_node->getName();
00667
00668
00669
00670 if (x_name == "use") {
00671 x_out << "use, period = " << x_node->getAttributeString("line") << comment << fini;
00672 return true;
00673 }
00674
00675
00676
00677 if (x_name == "set") {
00678 x_out << x_node->getAttributeString("element") << "->" <<
00679 x_node->getAttributeString("attribute") <<
00680 x_node->getAttributeString("design") << comment << fini;
00681 return true;
00682 }
00683
00684
00685
00686
00687 return false;
00688
00689 }
00690
00691
00692
00693
00694 void custom_x_ele_attributes_to_x_file (UAPNode* x_node,
00695 const string& ele_class, StreamStruct& x_out) {
00696
00697 if (ele_class == "multipole") {
00698 string knl_str = x_node->getAttributeString("knl");
00699 if (knl_str != "") x_out << ", knl = {" << knl_str << "}";
00700 string ksl_str = x_node->getAttributeString("ksl");
00701 if (ksl_str != "") x_out << ", ksl = {" << ksl_str << "}";
00702 }
00703
00704 return;
00705
00706 }
00707
00708
00709
00710
00711 void MADXParser::custom_x_attrib_to_x_file_translate (string& attrib_name,
00712 string& attrib_value) {
00713
00714 if (attrib_name == "aperture" || attrib_name == "knl" || attrib_name == "ksl") {
00715 attrib_value = "{" + attrib_value + "}";
00716 }
00717
00718 return;
00719 }
00720
00721
00722
00723
00724 void MADXParser::init_lists_madx () {
00725
00726
00727 StrVec aper, madx_extra;
00728 madx_extra << "lrad" << "calib" << "polarity" << "slot_id"
00729 << "assembly_id" << "mech_sep" << "kmin" << "kmax" << "from";
00730 aper << "aperture" << "apertype";
00731
00732 map_element_to_attribs["marker"] << "l" << aper << madx_extra;
00733 map_element_to_attribs["matrix"] << aper << madx_extra;
00734 map_element_to_attribs["drift"] << aper << madx_extra;
00735 map_element_to_attribs["sbend"] << "k0" << aper << madx_extra;
00736 map_element_to_attribs["rbend"] << "k0" << aper << madx_extra;
00737 map_element_to_attribs["rcollimator"] << aper << madx_extra;
00738 map_element_to_attribs["ecollimator"] << aper << madx_extra;
00739 map_element_to_attribs["quadrupole"] << "k1s" << aper << madx_extra;
00740 map_element_to_attribs["sextupole"] << "k2s" << aper << madx_extra;
00741 map_element_to_attribs["octupole"] << "k3s" << aper << madx_extra;
00742 map_element_to_attribs["multipole"] << aper << madx_extra;
00743 map_element_to_attribs["solenoid"] << aper << madx_extra;
00744 map_element_to_attribs["hkicker"] << "hkick" << aper << madx_extra;
00745 map_element_to_attribs["vkicker"] << "vkick" << aper << madx_extra;
00746 map_element_to_attribs["kicker"] << aper << madx_extra;
00747 map_element_to_attribs["rfcavity"] << aper << madx_extra;
00748 map_element_to_attribs["lcavity"] << aper << madx_extra;
00749 map_element_to_attribs["elseparator"] << aper << madx_extra;
00750 map_element_to_attribs["monitor"] << aper << madx_extra;
00751 map_element_to_attribs["instrument"] << aper << madx_extra;
00752 map_element_to_attribs["beambeam"] << aper << madx_extra;
00753 map_element_to_attribs["beam"] << "sequence" << "dtbyds" << "deltap" << "beta"
00754 << "alfa" << "u0" << "qs" << "arad" << "bv"
00755 << "pdamp" << "n1min" << "freq0" << "circ";
00756
00757 map_element_to_attribs["multipole"] << "l" << "tilt" << "knl" << "ksl" << "type"
00758 << "at" << madx_extra;
00759
00760 register_attribute("beam:dtbyds", "beam['{http://cern.ch/madx}madx:dtbyds']");
00761 register_attribute("beam:u0", "beam['{http://cern.ch/madx}madx:u0']");
00762 register_attribute("beam:qs", "beam['{http://cern.ch/madx}madx:qs']");
00763 register_attribute("beam:arad", "beam['{http://cern.ch/madx}madx:arad']");
00764 register_attribute("beam:bv", "beam['{http://cern.ch/madx}madx:bv']");
00765 register_attribute("beam:pdamp", "beam['{http://cern.ch/madx}madx:pdamp']");
00766 register_attribute("beam:n1min", "beam['{http://cern.ch/madx}madx:n1min']");
00767 register_attribute("beam:freq0", "beam['{http://cern.ch/madx}madx:freq0']");
00768 register_attribute("beam:circ", "beam['{http://cern.ch/madx}madx:circ']");
00769 register_attribute("beam:sequence", "beam['{http://cern.ch/madx}madx:sequence']");
00770 register_attribute("beam:deltap", "beam['{http://cern.ch/madx}madx:deltap']");
00771 register_attribute("beam:beta", "beam['{http://cern.ch/madx}madx:beta']");
00772 register_attribute("beam:alfa", "beam['{http://cern.ch/madx}madx:alfa']");
00773
00774 register_attribute("sbend:k0", "'{http://cern.ch/madx}madx:madx':'madx:k0'");
00775 register_attribute("rbend:k0", "'{http://cern.ch/madx}madx:madx':'madx:k0'");
00776
00777 register_attribute("kmin", "'{http://cern.ch/madx}madx:madx':'madx:kmin'");
00778 register_attribute("kmax", "'{http://cern.ch/madx}madx:madx':'madx:kmax'");
00779 register_attribute("lrad", "'{http://cern.ch/madx}madx:madx':'madx:lrad'");
00780 register_attribute("calib", "'{http://cern.ch/madx}madx:madx':'madx:calib'");
00781 register_attribute("polarity", "'{http://cern.ch/madx}madx:madx':'madx:polarity'");
00782 register_attribute("slot_id", "'{http://cern.ch/madx}madx:madx':'madx:slot_id'");
00783 register_attribute("assembly_id", "'{http://cern.ch/madx}madx:madx':'madx:assembly_id'");
00784 register_attribute("mech_sep", "'{http://cern.ch/madx}madx:madx':'madx:mech_sep'");
00785
00786 register_attribute("quadrupole:k1s", "quadrupole:ks");
00787 register_attribute("sextupole:k2s", "sextupole:ks");
00788 register_attribute("octupole:k3s", "octupole:ks");
00789
00790 register_attribute("apertype", "aperture@shape");
00791 register_attribute("aperture", "aperture:xy_limit");
00792 register_attribute("x_limit", "aperture:x_limit");
00793 register_attribute("y_limit", "aperture:y_limit");
00794
00795 StrVec matrix_attrib;
00796 matrix_attrib << "type" << "at" << "l";
00797 for (int i = 1; i < 7; i++) {
00798 ostringstream iss; iss << i;
00799 matrix_attrib << "kick" + iss.str();
00800 for (int j = 1; j < 7; j++) {
00801 ostringstream jss; jss << j;
00802 matrix_attrib << "rm" + iss.str() + jss.str();
00803 for (int k = 1; k < 7; k++) {
00804 ostringstream kss; kss << k;
00805 matrix_attrib << "tm" + iss.str() + jss.str() + kss.str();
00806 }
00807 }
00808 }
00809 map_element_to_attribs["matrix"] = matrix_attrib;
00810
00811 for (int i = 1; i < 7; i++) {
00812 ostringstream iss; iss << i;
00813 string kick = "matrix:kick" + iss.str();
00814 string taylor = "taylor_map:term(i_out=" + iss.str() + ",exp=\"0 0 0 0 0 0\")@coef";
00815 register_attribute (kick, taylor);
00816 for (int j = 1; j < 7; j++) {
00817 ostringstream jss; jss << j;
00818 string rm = "matrix:rm" + iss.str() + jss.str();
00819 string exp = "\"0 0 0 0 0 0\"";
00820 exp[2*j-1] = '1';
00821 taylor = "taylor_map:term(i_out=" + iss.str() + ",exp=" + exp + ")@coef";
00822 register_attribute (rm, taylor);
00823 for (int k = 1; k < 7; k++) {
00824 ostringstream kss; kss << k;
00825 exp = "\"0 0 0 0 0 0\"";
00826 exp[2*j-1] = '1';
00827 if (j == k)
00828 exp[2*k-1] = '2';
00829 else
00830 exp[2*k-1] = '1';
00831 taylor = "taylor_map:term(i_out=" + iss.str() + ",exp=" + exp + ")@coef";
00832 string tm = "matrix:tm" + iss.str() + jss.str() + kss.str();
00833 register_attribute (tm, taylor);
00834 }
00835 }
00836 }
00837
00838
00839
00840 register_attribute("hkicker:hkick", "kicker:x_kick");
00841 register_attribute("vkicker:vkick", "kicker:y_kick");
00842
00843 register_attribute("lcavity:volt", "rf_cavity:gradient", "# * 1e6 / ![length]",
00844 "# * !->l / 1e6");
00845 register_attribute("lcavity:lag", "rf_cavity:phase0", "# * twopi", "# / twopi");
00846
00847 register_attribute("rfcavity:volt", "rf_cavity:gradient", "# * 1e6 / ![length]",
00848 "# * !->l / 1e6");
00849 register_attribute("rfcavity:lag", "rf_cavity:phase0", "# * twopi", "# / twopi");
00850 register_attribute("rfcavity:freq", "rf_cavity:rf_freq", "# * 1e9", "# / 1e9");
00851
00852 register_attribute("e", "electric_kicker:y_kick_u", "# * 1e6 / ![length]", "# * !->l / 1e6");
00853
00854 register_param_value_conversion ("ELLIPSE", "ELLIPTICAL");
00855 register_param_value_conversion ("RECTANGLE", "RECTANGULAR");
00856
00857 return;
00858
00859 }