Commit 27ba7232 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

development of a parser for BETA

parent 8d30412b
...@@ -1774,8 +1774,8 @@ std::vector<smap> computingBlock::jmatchInput(json j) ...@@ -1774,8 +1774,8 @@ std::vector<smap> computingBlock::jmatchInput(json j)
{ {
//std::cout << ref.key() << " : " << ref.value() << "\n"; //std::cout << ref.key() << " : " << ref.value() << "\n";
string key; string key;
if (ref.key() == "betaX") key= "beta_x"; if (ref.key() == "betaX") key= "beta_x";
if (ref.key() == "betaY") key= "beta_y"; if (ref.key() == "betaY") key= "beta_y";
if (ref.key() == "alphaX") key= "alfa_x"; if (ref.key() == "alphaX") key= "alfa_x";
if (ref.key() == "alphaY") key= "alfa_y"; if (ref.key() == "alphaY") key= "alfa_y";
if (ref.key() == "dx") key= "dx"; if (ref.key() == "dx") key= "dx";
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "AML/AMLReader.hpp" #include "AML/AMLReader.hpp"
#include "Translate/AMLParser.hpp" #include "Translate/AMLParser.hpp"
#include "Translate/MADXParser.hpp" #include "Translate/MADXParser.hpp"
#include "BETAParser.h"
#include "INIReader.h" #include "INIReader.h"
namespace BU = BasicUtilities; namespace BU = BasicUtilities;
...@@ -225,77 +226,98 @@ bool dataManager::parseXFile( string fileName ) ...@@ -225,77 +226,98 @@ bool dataManager::parseXFile( string fileName )
UAPNode *nd3= nd2->getChildByName( "machine" ); UAPNode *nd3= nd2->getChildByName( "machine" );
UAPAttribute *a1= nd3->getChildByName( "sector" )->getAttribute( "ref" ); UAPAttribute *a1= nd3->getChildByName( "sector" )->getAttribute( "ref" );
// recovers the working beam line ( lower case )
string nameOfMachine= a1->getValue(); string nameOfMachine= a1->getValue();
if(debug > 0) cout << "machine = " << nameOfMachine << endl; if(debug > 0) cout << "machine = " << nameOfMachine << endl;
clearSectors(); // clear the BeamLine clearSectors(); // clear the BeamLine
// from the <beam> node creates the sector::BUNCH
UAPNode *nd4= nd2->getChildByName( "beam" ); UAPNode *nd4= nd2->getChildByName( "beam" );
if( nd4 ) { if( nd4 ) {
sectors_.push_back( new sector(this,"beam") );
UAPNode *nd5;
// GeV => in MeV
nd5= nd4->getChildByName( "total_energy" );
if (nd5) {
UAPAttribute *a= nd5->getAttribute( "design" );
double EGev= BasicUtilities::string_to_double( a->getValue() );
string sMev= BasicUtilities::double_to_string( 1000.*EGev );
nd5->addAttribute("design",sMev);
}
// GeV => in MeV
nd5= nd4->getChildByName( "pc" );
if (nd5) {
UAPAttribute *a= nd5->getAttribute( "design" );
double EGev= BasicUtilities::string_to_double( a->getValue() );
string sMev= BasicUtilities::double_to_string( 1000.*EGev );
nd5->addAttribute("design",sMev);
}
sectors_.push_back( new sector(this,"BUNCH") );
sectors_.back()->readAMLTree( nd4 ); sectors_.back()->readAMLTree( nd4 );
} else { } else {
cout << "dataManager::parseXFile:: no beam in the machine?...\n"; cout << "dataManager::parseXFile:: no beam in the machine?...\n";
return false; return false;
} }
// parmi les <sector> recupere celui qui decrit la <machine>
// among <sector> nodes recovers the one which describes the beam line
NodeVec lst1= nd2->getChildrenByName( "sector" ); NodeVec lst1= nd2->getChildrenByName( "sector" );
NodeVecIter where= AMLtools::find(lst1.begin(),lst1.end(),nameOfMachine); NodeVecIter where= AMLtools::find(lst1.begin(),lst1.end(),nameOfMachine);
// creates the sector::nameOfMachine with its elements
NodeVec lst2= nd2->getChildrenByName( "element" ); NodeVec lst2= nd2->getChildrenByName( "element" );
machineElements(*where,lst1,lst2); machineElements(*where,lst1,lst2);
if(debug > 0) cout << (*where)->toStringTree() << endl; if(debug > 0) cout << (*where)->toStringTree() << endl;
// la balise <machine> // creates the machine made up sector::BUNCH and sector::nameOfMachine
if ( !machineCourante_ ) machineCourante_ = new machine(this); if ( !machineCourante_ ) machineCourante_ = new machine(this);
// sector::BUNCH is the first of the list
machineCourante_->addSector( sectors_.at(0) );
// convert to upper case
mixedTools::toupper( nameOfMachine );
// among the others sectors find the one whose name is nameOfMachine
for (unsigned k = 0; k < sectors_.size(); k++) for (unsigned k = 0; k < sectors_.size(); k++)
{ {
// convert to lower case string s= sectors_.at( k )->getLabel();
string s= mixedTools::str_to_lower( sectors_.at(k)->getLabel() ); if (s.find( nameOfMachine ) != std::string::npos) {
if( s.find( "beam" ) != std::string::npos)
machineCourante_->addSector( sectors_.at(k) );
if( s.find( nameOfMachine ) != std::string::npos)
machineCourante_->addSector( sectors_.at(k) ); machineCourante_->addSector( sectors_.at(k) );
}
} }
return true;
/** return true;
UAPNode* ma= new UAPNode("");
ma->addChild("machine")->addAttribute("name","dummy");
ma->addChild("machineSectors");
UAPNode* exma= ma->addChild( "expandedMachine" );
exma->addAttribute("name","dummy");
UAPNode* blk= exma->addChild( "mcomputingBlocks" );
UAPNode* nc= blk->addChild( "computingBlock" );
nc->addChild( "software" )->addAttribute("name","unknown");
UAPNode* nex= nc->addChild( "blocExtension" );
nex->addAttribute("rankOfFirstElement","0");
nex->addAttribute("numberOfelements","0");
nc->addChild( "action" )->addAttribute("name","");
machineCourante_->FileAMLInput(ma);
*/
} }
void dataManager::machineElements(UAPNode* node,NodeVec& sList,NodeVec& eList,bool reflx) void dataManager::machineElements(UAPNode *nde,NodeVec& sList,NodeVec& eList,bool reflx)
{ {
if(debug > 0) cout << "dataManager::machineElements()\n"; if(debug > 0) cout << "dataManager::machineElements()\n";
NodeVec v; NodeVec v;
NodeVec& children= nde->getChildren();
NodeVecIter it; NodeVecIter it;
for (it = node->getChildren().begin(); it != node->getChildren().end(); ++it) for (it = children.begin(); it != children.end(); ++it)
{ {
v.push_back(*it); v.push_back(*it);
if( (*it)->getName() == "sector" ) { if ((*it)->getName() == "sector") {
UAPAttribute* a2= (*it)->getAttribute("ref");
UAPAttribute* a3= (*it)->getAttribute("reflection"); UAPAttribute *a2= (*it)->getAttribute("ref");
UAPAttribute *a3= (*it)->getAttribute("reflection");
NodeVecIter kt; NodeVecIter kt;
kt= AMLtools::find(sList.begin(),sList.end(),a2->getValue()); kt= AMLtools::find(sList.begin(),sList.end(),a2->getValue());
if( a3 ) machineElements(*kt,sList,eList,true); if ( a3 ) machineElements(*kt,sList,eList,true);
else machineElements(*kt,sList,eList,false); else machineElements(*kt,sList,eList,false);
} }
} }
string s= node->getAttributeString("name"); string s= nde->getAttributeString("name");
string upper= BasicUtilities::str_to_upper( s ); string upper= BasicUtilities::str_to_upper( s );
if( reflx ) { if( reflx ) {
upper.insert(0,"-"); upper.insert(0,"-");
...@@ -305,6 +327,7 @@ void dataManager::machineElements(UAPNode* node,NodeVec& sList,NodeVec& eList,bo ...@@ -305,6 +327,7 @@ void dataManager::machineElements(UAPNode* node,NodeVec& sList,NodeVec& eList,bo
if(debug > 0) { if(debug > 0) {
cout<<"dataManager::machineElements(): new sector "<< upper << endl; cout<<"dataManager::machineElements(): new sector "<< upper << endl;
} }
sector *sor= new sector(this,upper); sector *sor= new sector(this,upper);
sectors_.push_back( sor ); sectors_.push_back( sor );
sor->sectorTree(v,eList); sor->sectorTree(v,eList);
...@@ -505,6 +528,8 @@ json dataManager::toJSONFormat() ...@@ -505,6 +528,8 @@ json dataManager::toJSONFormat()
void dataManager::toJSON(json& j) void dataManager::toJSON(json& j)
{ {
if(debug > 0) cout << "\n\ndataManager::toJSON()\n";
if ( !machineCourante_ ) { if ( !machineCourante_ ) {
cout << "dataManager::toJSON:: no machine ?...\n"; cout << "dataManager::toJSON:: no machine ?...\n";
return; return;
...@@ -515,6 +540,7 @@ void dataManager::toJSON(json& j) ...@@ -515,6 +540,7 @@ void dataManager::toJSON(json& j)
{ {
string s1= "sector-" + mixedTools::alea(); string s1= "sector-" + mixedTools::alea();
string s2= sors.at(k)->getLabel(); string s2= sors.at(k)->getLabel();
mixedTools::toupper( s2 );
json x; json x;
x["id"] = s1; x["id"] = s1;
...@@ -524,6 +550,8 @@ void dataManager::toJSON(json& j) ...@@ -524,6 +550,8 @@ void dataManager::toJSON(json& j)
j["machine"].push_back( x ); j["machine"].push_back( x );
} }
// cout << j.dump(4) << endl;
cout << "dataManager::toJSON nameOfCase => " << nameOfCase_ << endl; cout << "dataManager::toJSON nameOfCase => " << nameOfCase_ << endl;
j["name"]= nameOfCase_; j["name"]= nameOfCase_;
...@@ -665,3 +693,57 @@ void dataManager::settingPlot() ...@@ -665,3 +693,57 @@ void dataManager::settingPlot()
json obj= softw->readOpticalParameters(); json obj= softw->readOpticalParameters();
} }
} }
bool dataManager::parseBETAFile( string fileName )
{
if(debug > 0) cout << "dataManager::parseBETAFile()\n";
BETAParser reader;
UAPNode *upRoot= NULL;
fileName= userDir_ + fileName;
upRoot= reader.FileToAMLRep( fileName );
if ( !upRoot ) {
cout << "dataManager::parseBETAFile:: failure to parse " << fileName << "\n";
return false;
}
if(debug > 0) cout << upRoot->toStringTree() << endl;
// From ΒΕΤA sections there are two PSPA::sectors defined
clearSectors();
// The first one contains the element BEAM
UAPNode *nd1= upRoot->getChildByName( "beam" );
if( nd1 ) {
sectors_.push_back( new sector(this,"BUNCH") );
sectors_.back()->readAMLTree( nd1 );
} else {
cout << "dataManager::parseBETAFile:: no beam in the machine\n";
return false;
}
// The second one contains the elements in the STRUCTURE
NodeVec lst1= upRoot->getChildrenByName( "sector" );
NodeVec lst2= upRoot->getChildrenByName( "element" );
machineElements(lst1[0],lst1,lst2);
if (!machineCourante_) machineCourante_= new machine( this );
machineCourante_->addSector( sectors_.at(0) );
machineCourante_->addSector( sectors_.at(1) );
if(debug > 0) {
for (unsigned k = 0; k < sectors_.size(); k++)
{
cout << sectors_.at(k)->getLabel() << " =>\n";
vector<abstractElement*>& elts= sectors_.at(k)->getElements();
for (unsigned i = 0; i < elts.size(); i++)
{
cout << elts.at(i)->getLabel() << endl;
}
}
}
return true;
}
...@@ -34,6 +34,7 @@ class dataManager ...@@ -34,6 +34,7 @@ class dataManager
void writeToAMLFile( string ); void writeToAMLFile( string );
bool parseAMLFile( string ); bool parseAMLFile( string );
bool parseXFile( string ); bool parseXFile( string );
bool parseBETAFile( string );
void setSecteurCourant(string); void setSecteurCourant(string);
sector* getSecteurCourant() const; sector* getSecteurCourant() const;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "softwareUsersprogram.h" #include "softwareUsersprogram.h"
#include "softwareTest.h" #include "softwareTest.h"
#include "softwareMadx.h" //ok #include "softwareMadx.h" //ok
#include "softwareBeta.h" #include "softwareBeta.h" //ok
#include "softwareElegant.h" //ok #include "softwareElegant.h" //ok
#include "softwareGenerator.h" //ok #include "softwareGenerator.h" //ok
#include "softwareAstra.h" //ok #include "softwareAstra.h" //ok
...@@ -89,7 +89,7 @@ abstractSoftware* expandedMachine::getSoftwarePointer(std::string logiciel,compu ...@@ -89,7 +89,7 @@ abstractSoftware* expandedMachine::getSoftwarePointer(std::string logiciel,compu
if (logiciel == "astra") { if (logiciel == "astra") {
prog= new softwareAstra(cpblk,dataManager_ ); prog= new softwareAstra(cpblk,dataManager_ );
} else if (logiciel == "beta") { } else if (logiciel == "beta") {
//prog= new softwareBeta(cpblk,dataManager_); prog= new softwareBeta(cpblk,dataManager_);
} else if (logiciel == "elegant") { } else if (logiciel == "elegant") {
prog= new softwareElegant(cpblk,dataManager_); prog= new softwareElegant(cpblk,dataManager_);
} else if (logiciel == "generator") { } else if (logiciel == "generator") {
...@@ -691,6 +691,9 @@ void expandedMachine::setActionCommands(computingBlock* cpblk,std::string action ...@@ -691,6 +691,9 @@ void expandedMachine::setActionCommands(computingBlock* cpblk,std::string action
void expandedMachine::toJSON(json& j) void expandedMachine::toJSON(json& j)
{ {
if(debug > 0) std::cout << "expandedMachine::toJSON()\n"; if(debug > 0) std::cout << "expandedMachine::toJSON()\n";
std::cout << "expandedMachine::toJSON()\n";
vector<string> color {"blue-table","green-table","purple-table","fuschia-table","red-table","salmon-table","yellow-table","deepblue-table","ocean-table","menthol-table","pink-table"}; vector<string> color {"blue-table","green-table","purple-table","fuschia-table","red-table","salmon-table","yellow-table","deepblue-table","ocean-table","menthol-table","pink-table"};
......
...@@ -115,7 +115,7 @@ bool machine::FileAMLInput(UAPNode *nde) ...@@ -115,7 +115,7 @@ bool machine::FileAMLInput(UAPNode *nde)
if (!expMachine_->FileAMLInput( nd1 )) return false; if (!expMachine_->FileAMLInput( nd1 )) return false;
} else { } else {
expMachine_= NULL; expMachine_= NULL;
return false; return true;
} }
vector<computingBlock*>& blks= expMachine_->getComputingBlocks(); vector<computingBlock*>& blks= expMachine_->getComputingBlocks();
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <algorithm>
#include <vector> #include <vector>
#include <map> #include <map>
...@@ -177,6 +179,20 @@ class mixedTools ...@@ -177,6 +179,20 @@ class mixedTools
return status; return status;
} }
static void toupper(std::string& str)
{
std::for_each(str.begin(), str.end(), [](char & c) {
c = ::toupper(c);
});
}
static void tolower(std::string& str)
{
std::for_each(str.begin(), str.end(), [](char & c) {
c = ::tolower(c);
});
}
static std::string str_to_upper(const std::string& str) static std::string str_to_upper(const std::string& str)
{ {
return BasicUtilities::str_to_upper( str ); return BasicUtilities::str_to_upper( str );
......
...@@ -434,7 +434,7 @@ void particleBeam::buildMomentRepresentation() ...@@ -434,7 +434,7 @@ void particleBeam::buildMomentRepresentation()
rij_.impression(); rij_.impression();
} }
P0Transport_ = 1.0e-3*EREST_MeV*PREFMeV_sur_c; // Gev P0Transport_= 1.0e-3*EREST_MeV*PREFMeV_sur_c; // Gev
momentRepresentationOk_ = true; momentRepresentationOk_ = true;
} }
......
...@@ -414,8 +414,8 @@ void sector::readAMLTree(UAPNode *bm) ...@@ -414,8 +414,8 @@ void sector::readAMLTree(UAPNode *bm)
if(debug > 0) cout << "sector::readAMLTree()\n"; if(debug > 0) cout << "sector::readAMLTree()\n";
expandedElements_.clear(); expandedElements_.clear();
sectorComponent* nc = NULL; sectorComponent *nc = NULL;
nc = createElementAfterComponent("beam",nc); nc= createElementAfterComponent("beam",nc);
if(nc != NULL) nc->AMLRepToPSPA("beam",bm); if(nc != NULL) nc->AMLRepToPSPA("beam",bm);
} }
...@@ -446,12 +446,12 @@ void sector::AMLRepToPSPA(string key,UAPNode *jnode) ...@@ -446,12 +446,12 @@ void sector::AMLRepToPSPA(string key,UAPNode *jnode)
return; return;
} }
void sector::sectorTree(NodeVec& myvector,NodeVec& eList) void sector::sectorTree(NodeVec& vnodes,NodeVec& eList)
{ {
if(debug > 0) cout << "sector::sectorTree()\n"; if(debug > 0) cout << "sector::sectorTree()\n";
expandedElements_.clear(); expandedElements_.clear();
sectorComponent* nc = NULL; sectorComponent *nc = NULL;
StrMap map_key_to_pspa; StrMap map_key_to_pspa;
map_key_to_pspa["bend"]= "bend"; map_key_to_pspa["bend"]= "bend";
...@@ -467,64 +467,61 @@ void sector::sectorTree(NodeVec& myvector,NodeVec& eList) ...@@ -467,64 +467,61 @@ void sector::sectorTree(NodeVec& myvector,NodeVec& eList)
map_key_to_pspa["sextupole"]= "spole"; map_key_to_pspa["sextupole"]= "spole";
if(debug > 0) cout << "open sector [" << getLabel() << "]\n"; if(debug > 0) cout << "open sector [" << getLabel() << "]\n";
for(NodeVecIter jt = myvector.begin(); jt != myvector.end(); jt++) NodeVecIter jt;
for (jt = vnodes.begin(); jt != vnodes.end(); jt++)
{ {
if( (*jt)->getName() == "sector" ) { if ((*jt)->getName() == "sector") {
nc = createElementAfterComponent("composanteSecteur",nc); nc= createElementAfterComponent("composanteSecteur",nc);
if(nc != NULL) nc->AMLRepToPSPA("composanteSecteur",*jt); if (nc != NULL) nc->AMLRepToPSPA("composanteSecteur",*jt);
}
if( (*jt)->getName() == "element" ) {
UAPAttribute* a2= (*jt)->getAttribute("ref"); } else if ((*jt)->getName() == "element") {
UAPAttribute *a2= (*jt)->getAttribute("ref");
NodeVecIter w; NodeVecIter w;
w= AMLtools::find(eList.begin(),eList.end(),a2->getValue()); w= AMLtools::find(eList.begin(),eList.end(),a2->getValue());
int nfois = 1; NodeVec& v3= (*w)->getChildren();
UAPAttribute* a3= (*jt)->getAttribute("repeat");
if(a3) a3->getInt(nfois); switch( v3.size() )
{
if( (*w)->getName() == "lattice" ) { case 0:
nc = createElementAfterComponent("beam",nc); // <marker> does not have any children
if(nc != NULL) nc->AMLRepToPSPA("beam",*w); nc= createElementAfterComponent("marker",nc);
} else { // (*w)->getName() == "element" if(nc != NULL) nc->AMLRepToPSPA("marker",*w);
NodeVec& v3 = (*w)->getChildren(); break;
// kind of element case 1:
NodeVecIter kt = v3.begin(); // <drift> does not have any key from map_key_to_pspa
string key = (*kt)->getName(); nc= createElementAfterComponent("drift",nc);
if( key == "length" ) { if(nc != NULL) nc->AMLRepToPSPA("drift",v3[0]);
for(int k = 0; k < nfois; k++) break;
default:
for (NodeVecIter it = v3.begin(); it!= v3.end(); it++)
{ {
// drift= element with no key from map_key_to_pspa StrMapIter kt= map_key_to_pspa.find( (*it)->getName() );
nc = createElementAfterComponent("drift",nc); if (kt != map_key_to_pspa.end()) {
if(nc != NULL) nc->AMLRepToPSPA("drift",*kt); nc= createElementAfterComponent(kt->second,nc);
if (nc != NULL) nc->AMLRepToPSPA(kt->second,*it);
}
} }
} else { }
for (NodeVecIter it = kt; it!= v3.end(); it++) }
{ }
key = (*it)->getName();
if(map_key_to_pspa.find( key ) != map_key_to_pspa.end()) {
nc=createElementAfterComponent(map_key_to_pspa[key],nc);
if(nc != NULL)
nc->AMLRepToPSPA(map_key_to_pspa[key],*it);
}
} //it
}
}
} //end element
} //jt
} }
void sector::toJSON(json& j) void sector::toJSON(json& j)
{ {
if(debug > 0) cout << "sector::toJSON()\n";
vector<abstractElement*>& elts= this->getElements(); vector<abstractElement*>& elts= this->getElements();
for (unsigned k = 0; k < elts.size(); k++) for (unsigned k = 0; k < elts.size(); k++)
{ {
if(debug > 0) cout << " elt:: " << elts.at(k)->getComponentName() << " => " << elts.at(k)->getGenericName() << endl;
json x; json x;
elts.at(k)->toJSON( x ); elts.at(k)->toJSON( x );
j["elements"].push_back( x ); j["elements"].push_back( x );
} }
} }
......
...@@ -3,45 +3,46 @@ ...@@ -3,45 +3,46 @@
#include <map>