Commit 06f72501 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

focus on definition of beamlines, sublines, reflexion & repetition

parent 7b462918
......@@ -215,9 +215,9 @@ bool dataManager::parseXFile( string fileName )
{
if(debug > 0) cout << "dataManager::parseXFile()\n";
UAPNode *UAPRoot= NULL;
TranslateCore *reader= new MADXParser();
fileName= userDir_ + fileName;
UAPNode *UAPRoot= NULL;
UAPRoot= reader->XFileToAMLRep( fileName );
UAPNode *nd1= UAPRoot->getChildByName("AML_representation");
......@@ -229,7 +229,7 @@ bool dataManager::parseXFile( string fileName )
// recovers the working beam line ( lower case )
string nameOfMachine= a1->getValue();
if(debug > 0) cout << "machine = " << nameOfMachine << endl;
if(debug > 0) cout << "machine => " << nameOfMachine << endl;
clearSectors(); // clear the BeamLine
......@@ -268,11 +268,11 @@ bool dataManager::parseXFile( string fileName )
// among <sector> nodes recovers the one which describes the beam line
NodeVec lst1= nd2->getChildrenByName( "sector" );
NodeVecIter where= AMLtools::find(lst1.begin(),lst1.end(),nameOfMachine);
if(debug > 0) cout << (*where)->toStringTree() << endl;
// creates the sector::nameOfMachine with its elements
NodeVec lst2= nd2->getChildrenByName( "element" );
NodeVec lst2= nd2->getChildrenByName( "element" );
machineElements(*where,lst1,lst2);
if(debug > 0) cout << (*where)->toStringTree() << endl;
// creates the machine made up sector::BUNCH and sector::nameOfMachine
if ( !machineCourante_ ) machineCourante_ = new machine(this);
......@@ -290,47 +290,90 @@ bool dataManager::parseXFile( string fileName )
machineCourante_->addSector( sectors_.at(k) );
}
}
if (debug > 0) {
vector<sector*>& sors= machineCourante_->getSectors();
for (unsigned k = 0; k < sors.size(); k++)
{
cout << "SOR[" << k << "] => " << sors.at(k)->getLabel() << endl;
vector<abstractElement*>& e= sors.at(k)->getElements();
for (unsigned j = 0; j < e.size(); j++)
{
cout << "**** " << e.at(j)->getComponentName() << " => " << e.at(j)->getGenericName() << endl;
}
}
}
return true;
}
void dataManager::machineElements(UAPNode *nde,NodeVec& sList,NodeVec& eList,bool reflx)
void dataManager::machineElements(UAPNode *w,NodeVec& sList,NodeVec& eList,bool reflx)
{
if(debug > 0) cout << "dataManager::machineElements()\n";
if (debug > 0) cout << w->toStringTree() << endl;
NodeVec v;
NodeVec& children= nde->getChildren();
NodeVecIter it;
for (it = children.begin(); it != children.end(); ++it)
// sequence of elements which define the beamline
NodeVec sequence;
// <machine> node
NodeVec& machine= w->getChildren();
for (NodeVecIter it = machine.begin(); it != machine.end(); ++it)
{
v.push_back(*it);
if ((*it)->getName() == "element") {
sequence.push_back(*it);
}
if ((*it)->getName() == "sector") {
UAPAttribute *a2= (*it)->getAttribute("ref");
UAPAttribute *a3= (*it)->getAttribute("reflection");
NodeVecIter kt;
kt= AMLtools::find(sList.begin(),sList.end(),a2->getValue());
if ( a3 ) machineElements(*kt,sList,eList,true);
else machineElements(*kt,sList,eList,false);
UAPAttribute *a1= (*it)->getAttribute("ref");
if( a1 ) {
sequence.push_back(*it);
if (debug > 0) cout << "sector => " << a1->getValue() << endl;
NodeVecIter kt;
kt= AMLtools::find(sList.begin(),sList.end(),a1->getValue());
bool reflection= false;
UAPAttribute *a3= (*it)->getAttribute("reflection");
if ( a3 ) reflection= true;
machineElements(*kt,sList,eList,reflection);
} else {
int repetition= 1;
UAPAttribute *a4= (*it)->getAttribute("repeat");
if ( a4 ) {
repetition= BasicUtilities::string_to_int( a4->getValue() );
}
for (int j = 0; j < repetition; j++)
{
NodeVec lst= (*it)->getChildrenByName( "element" );
for (NodeVecIter jt = lst.begin(); jt != lst.end(); ++jt)
{
sequence.push_back(*jt);
}
}
}
}
}
string s= nde->getAttributeString("name");
string s= w->getAttributeString("name");
string upper= BasicUtilities::str_to_upper( s );
if( reflx ) {
upper.insert(0,"-");
std::reverse(v.begin(),v.end()); // reverse of the sequence
if (reflx) {
//upper.insert(0,"-");
// reverse of the sequence
std::reverse(sequence.begin(),sequence.end());
}
if(debug > 0) {
cout<<"dataManager::machineElements(): new sector "<< upper << endl;
cout << "machineElements:: new sector => "<< upper << endl;
}
sector *sor= new sector(this,upper);
sectors_.push_back( sor );
sor->sectorTree(v,eList);
sor->sectorTree(sequence,eList);
return;
}
......
......@@ -456,7 +456,7 @@ void sector::sectorTree(NodeVec& vnodes,NodeVec& eList)
StrMap map_key_to_pspa;
map_key_to_pspa["bend"]= "bend";
// cathode
// drift
map_key_to_pspa["length"]= "drift";
map_key_to_pspa["kicker"]= "kicker";
map_key_to_pspa["linear_cavity"]= "linear_cavity";
map_key_to_pspa["marker"]= "marker";
......@@ -466,45 +466,39 @@ void sector::sectorTree(NodeVec& vnodes,NodeVec& eList)
map_key_to_pspa["solenoid"]= "solenoid";
map_key_to_pspa["sextupole"]= "spole";
if(debug > 0) cout << "open sector [" << getLabel() << "]\n";
NodeVecIter jt;
for (jt = vnodes.begin(); jt != vnodes.end(); jt++)
if (debug > 0) cout << "open sector [" << getLabel() << "]\n";
for (NodeVecIter jt = vnodes.begin(); jt != vnodes.end(); jt++)
{
if ((*jt)->getName() == "sector") {
if (debug > 0) {
string s= (*jt)->getParent()->getAttributeString("name");
cout << "*** sector.name => " << s << endl;
}
nc= createElementAfterComponent("composanteSecteur",nc);
if (nc != NULL) nc->AMLRepToPSPA("composanteSecteur",*jt);
if( nc != NULL ) nc->AMLRepToPSPA("composanteSecteur",*jt);
} else if ((*jt)->getName() == "element") {
}
if( (*jt)->getName() == "element" ) {
UAPAttribute *a2= (*jt)->getAttribute("ref");
UAPAttribute *a= (*jt)->getAttribute("ref");
if (debug > 0) {
if (a) cout << "*** a->getValue() => " << a->getValue() << endl;
}
NodeVecIter w;
w= AMLtools::find(eList.begin(),eList.end(),a2->getValue());
w= AMLtools::find(eList.begin(),eList.end(),a->getValue());
NodeVec& v3= (*w)->getChildren();
switch( v3.size() )
{
case 0:
// <marker> does not have any children
nc= createElementAfterComponent("marker",nc);
if(nc != NULL) nc->AMLRepToPSPA("marker",*w);
break;
case 1:
// <drift> does not have any key from map_key_to_pspa
nc= createElementAfterComponent("drift",nc);
if(nc != NULL) nc->AMLRepToPSPA("drift",v3[0]);
break;
default:
for (NodeVecIter it = v3.begin(); it!= v3.end(); it++)
{
StrMapIter kt= map_key_to_pspa.find( (*it)->getName() );
if (kt != map_key_to_pspa.end()) {
nc= createElementAfterComponent(kt->second,nc);
if (nc != NULL) nc->AMLRepToPSPA(kt->second,*it);
}
}
}
NodeVecIter it= v3.begin();
StrMapIter found= map_key_to_pspa.find( (*it)->getName() );
if (found != map_key_to_pspa.end()) {
nc= createElementAfterComponent(found->second,nc);
if (nc != NULL) nc->AMLRepToPSPA(found->second,*it);
} else {
cout << "key <" << (*it)->getName() << "> not found\n";
}
}
}
}
......
#include <iostream>
#include "elementDrift.h"
#include "mathematicalTools.h"
#include "mixedTools.h"
......@@ -159,8 +158,6 @@ void elementDrift::toJSON(json& j)
void elementDrift::fromJSON(json j)
{
//cout << "elementDrift::fromJSON()\n";
string type= j.find( "type" ).value();
if ( type != genericName_ ) return;
string key= j.find( "displayName" ).value();
......
......@@ -9,7 +9,7 @@ elementMarker::elementMarker() : abstractElement()
setElement();
}
elementMarker::elementMarker(const elementMarker& elem) : abstractElement(elem)
elementMarker::elementMarker(const elementMarker& e) : abstractElement(e)
{
setDefaultValues();
}
......@@ -84,14 +84,14 @@ void elementMarker::FileAMLInput(UAPNode* entree)
if ( !checkAMLelementGenericName(entree) ) return;
}
void elementMarker::AMLRepToPSPA(string key,UAPNode *up)
void elementMarker::AMLRepToPSPA(string key,UAPNode *knode)
{
if ( key != genericName_ ) {
cout << "elementMarker::AMLRepToPSPA: ERROR kind of element (" << key << ")\n";
return;
}
//UAPNode *up= knode->getParent();
UAPNode *up= knode->getParent();
string upName= up->getAttributeString("name");
string FullName= getSectorPrefix();
FullName += "." + upName;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment