Commit d054d610 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

fix the import for JSON type file

parent 1f80c8de
......@@ -398,6 +398,15 @@ std::vector<smap> computingBlock::matchAMLInput( UAPNode *nde )
v.push_back( amap ); // v[ 0 ]
if( !amap.empty() ) amap.clear();
NodeVec inode= nde->getChildrenByName("twiss");
for(unsigned k = 0; k < inode.size(); ++k)
{
UAPNode* child= inode[k];
string key= child->getAttributeString("item");
amap[ key ].push_back( child->getAttributeString("design") );
}
/**
NodeVec inode= nde->getChildrenByName("twiss");
int ikey= 0;
for(unsigned k = 0; k < inode.size(); ++k)
......@@ -408,6 +417,7 @@ std::vector<smap> computingBlock::matchAMLInput( UAPNode *nde )
amap[ key ].push_back( child->getAttributeString("design") );
ikey++;
}
*/
v.push_back( amap ); // v[ 1 ]
if( !amap.empty() ) amap.clear();
......@@ -706,6 +716,17 @@ void computingBlock::matchAMLOutput(UAPNode *node,const vector<smap>& v)
return;
}
if ( !v[ 1 ].empty() ) {
smap::const_iterator it;
for (it = v[ 4 ].begin(); it != v[ 4 ].end(); ++it)
{
UAPNode* n1= node->addChild("twiss");
n1->addAttribute( "item", it->first );
n1->addAttribute( "design", it->second.at(0) );
}
}
/**
if ( !v[ 1 ].empty() ) {
for(int k = 0; k < v[ 1 ].size(); ++k)
{
......@@ -716,6 +737,7 @@ void computingBlock::matchAMLOutput(UAPNode *node,const vector<smap>& v)
n1->addAttribute( "design", it->second.at(1) );
}
}
*/
if( !v[ 2 ].empty() ) {
for(int k = 0; k < v[ 2 ].size(); ++k)
......@@ -844,6 +866,7 @@ void computingBlock::toJSON(json& j)
else j["action"]= action;
const vector<smap>& v= actions_.at( 0 ).second;
if( action == "emitt" ) j["parameters"]= json({});
if( action == "twiss" ) jtwissOutput( j["parameters"],v );
if( action == "track" ) jtrackOutput( j["parameters"],v );
......@@ -1060,7 +1083,25 @@ void computingBlock::jtunesOutput(json& j,const vector<smap>& v)
void computingBlock::jmatchOutput(json& j,const vector<smap>& v)
{
string str= v[0].find("action")->second.at(0);
if( !v[ 1 ].empty() ) {
j["matchingCommands"].push_back("initialValues");
smap::const_iterator it;
for (it = v[ 1 ].begin(); it != v[ 1 ].end(); ++it)
{
string key;
string tx= it->first;
if( tx.find("beta_x") != string::npos ) key= "betaX";
if( tx.find("beta_y") != string::npos ) key= "betaY";
if( tx.find("alfa_x") != string::npos ) key= "alphaX";
if( tx.find("alfa_y") != string::npos ) key= "alphaY";
if( tx.find("dx") != string::npos ) key= "dx";
if( tx.find("dpx") != string::npos ) key= "dpx";
j["initialValues"][key]= it->second.at(0);
}
}
/**
if( !v[ 1 ].empty() ) {
j["matchingCommands"].push_back("initialValues");
for(int k = 0; k < v[ 1 ].size(); ++k)
......@@ -1080,6 +1121,7 @@ void computingBlock::jmatchOutput(json& j,const vector<smap>& v)
j["initialValues"][key]= it->second.at(1);
}
}
*/
if (!v[ 2 ].empty() || !v[ 3 ].empty()) {
j["matchingCommands"].push_back("constraints");
......@@ -1244,9 +1286,9 @@ bool computingBlock::fromJSON(json j)
if( action == "tunes" ) v= jtunesInput( j );
if( action == "match" ) v= jmatchInput( j );
if( action == "track" ) v= jtrackInput( j );
//if( action == "emitt" )
actions_.push_back( pair< string,vector<smap> >( action,v ) );
//if( action == "emitt" )
actions_.push_back( pair< string,vector<smap> >( action,v ) );
return status;
}
......@@ -1559,12 +1601,14 @@ std::vector<smap> computingBlock::jmatchInput(json j)
auto z= up->find( "matchingCommands" ).value();
json::iterator it= find(z.begin(),z.end(),"initialValues");
//std::cout << std::boolalpha;
//std::cout << "initialValues was found: " << (it != z.end()) << '\n';
std::cout << std::boolalpha;
if (debug > 0) std::cout << "initialValues was found: " << (it != z.end()) << '\n';
if (it != z.end()) {
auto z1= up->find( "initialValues" ).value();
for (auto& ref : z1.items())
{
//std::cout << ref.key() << " : " << ref.value() << "\n";
string key;
if (ref.key() == "betaX") key= "beta_x";
if (ref.key() == "betaY") key= "beta_y";
......@@ -1572,6 +1616,8 @@ std::vector<smap> computingBlock::jmatchInput(json j)
if (ref.key() == "alphaY") key= "alfa_y";
if (ref.key() == "dx") key= "dx";
if (ref.key() == "dpx") key= "dpx";
if (ref.value() == nullptr) continue;
amap[ key ].push_back( ref.value() );
}
}
......@@ -1580,6 +1626,7 @@ std::vector<smap> computingBlock::jmatchInput(json j)
if( !amap.empty() ) amap.clear();
it= find(z.begin(),z.end(),"constraints");
if (debug > 0) std::cout << "constraints was found: " << (it != z.end()) << '\n';
if (it != z.end() && up->find( "simpleConstraints" ) != up->end()) {
auto z2 = up->find( "simpleConstraints" ).value();
......@@ -1587,15 +1634,24 @@ std::vector<smap> computingBlock::jmatchInput(json j)
{
string key= mixedTools::intToString( k );
auto ref= z2.at(k);
amap[ key ].push_back( ref.find( "range" ).value() );
amap[ key ].push_back( ref.find( "constraintVariable" ).value() );
amap[ key ].push_back( ref.find( "constraintValue" ).value() );
json::iterator jt= ref.find( "weight" );
if (jt != ref.end()) {
amap[ key ].push_back( jt.value() );
} else {
amap[ key ].push_back( "none" );
string range= ref.find( "range" ).value();
if (range.empty()) break;
string constraintVariable= ref.find( "constraintVariable" ).value();
if (constraintVariable.empty()) break;
string constraintValue= ref.find( "constraintValue" ).value();
if (constraintValue.empty()) break;
string weight= "none";
if (ref.find( "weight" ) != ref.end()) {
string str= ref.find( "weight" ).value();
if (!str.empty()) weight= str;
}
amap[ key ].push_back( range );
amap[ key ].push_back( constraintVariable);
amap[ key ].push_back( constraintValue);
amap[ key ].push_back( weight );
}
}
......@@ -1608,21 +1664,29 @@ std::vector<smap> computingBlock::jmatchInput(json j)
{
string key= mixedTools::intToString( k );
auto ref= z3.at(k);
amap[ key ].push_back( ref.find( "tuneVariable" ).value() );
amap[ key ].push_back( ref.find( "tuneValue" ).value() );
json::iterator jt= ref.find( "weight" );
if (jt != ref.end()) {
amap[ key ].push_back( jt.value() );
} else {
amap[ key ].push_back( "none" );
string tuneVariable= ref.find( "tuneVariable" ).value();
if (tuneVariable.empty()) break;
string tuneValue= ref.find( "tuneValue" ).value();
if (tuneValue.empty()) break;
string weight= "none";
if (ref.find( "weight" ) != ref.end()) {
string str= ref.find( "weight" ).value();
if (!str.empty()) weight= str;
}
amap[ key ].push_back( tuneVariable );
amap[ key ].push_back( tuneValue );
amap[ key ].push_back( weight );
}
}
v.push_back( amap ); // v[ 3 ]
if( !amap.empty() ) amap.clear();
it= find(z.begin(),z.end(),"variableParameters");
if (debug > 0) std::cout << "variableParameters was found: " << (it != z.end()) << '\n';
if (it != z.end()) {
for (auto& ref : up->find( "paramsToBeVaried" ).value())
......@@ -1631,34 +1695,37 @@ std::vector<smap> computingBlock::jmatchInput(json j)
if (jt.value() == "None") continue;
string txt= ref.find( "label" ).value();
amap[ txt ].push_back( jt.value() );
jt= ref.find( "step" );
if (jt != ref.end()) {
amap[ txt ].push_back( jt.value() );
} else {
amap[ txt ].push_back( "none" );
amap[ txt ].push_back( jt.value() ); // m[label]= variable
string step= "none";
if (ref.find( "step" ) != ref.end()) {
string str= ref.find( "step" ).value();
if (!str.empty()) step= str;
}
jt = ref.find( "lower" );
if( jt != ref.end() ) {
amap[ txt ].push_back( jt.value() );
} else {
amap[ txt ].push_back( "none" );
amap[ txt ].push_back( step );
string lower= "none";
if (ref.find( "lower" ) != ref.end()) {
string str= ref.find( "lower" ).value();
if (!str.empty()) lower= str;
}
jt = ref.find( "upper" );
if( jt != ref.end() ) {
amap[ txt ].push_back( jt.value() );
} else {
amap[ txt ].push_back( "none" );
amap[ txt ].push_back( lower );
string upper= "none";
if (ref.find( "upper" ) != ref.end()) {
string str= ref.find( "upper" ).value();
if (!str.empty()) upper= str;
}
amap[ txt ].push_back( upper );
}
}
v.push_back( amap ); // v[ 4 ]
if( !amap.empty() ) amap.clear();
it= find(z.begin(),z.end(),"constraintsOnTranferMap");
if (debug > 0) std::cout << "constraintsOnTranferMap was found: " << (it != z.end()) << '\n';
if (it != z.end()) {
auto z5 = up->find( "constraintsOnTranferMap" ).value();
for (unsigned k = 0; k < z5.size(); ++k)
......@@ -1671,36 +1738,59 @@ std::vector<smap> computingBlock::jmatchInput(json j)
amap[ key ].push_back( ref.find( "weight" ).value() );
}
}
v.push_back( amap ); // v[ 5 ]
if( !amap.empty() ) amap.clear();
auto z6= up->find( "optimizationSetup" ).value();
json::iterator jt;
jt= z6.find( "mode" );
if (jt != z6.end()) amap[ "mode" ].push_back( jt.value() );
else amap[ "mode" ].push_back( "none" );
json::iterator jt= z6.find( "mode" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "mode" ].push_back( jt.value() );
} else {
amap[ "mode" ].push_back( "none" );
}
jt= z6.find( "method" );
if (jt != z6.end()) amap[ "method" ].push_back( jt.value() );
else amap[ "method" ].push_back( "none" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "method" ].push_back( jt.value() );
} else {
amap[ "method" ].push_back( "none" );
}
jt= z6.find( "tolerance" );
if (jt != z6.end()) amap[ "tolerance" ].push_back( jt.value() );
else amap[ "tolerance" ].push_back( "none" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "tolerance" ].push_back( jt.value() );
} else {
amap[ "tolerance" ].push_back( "none" );
}
jt= z6.find( "evaluations" );
if (jt != z6.end()) amap[ "evaluations" ].push_back( jt.value() );
else amap[ "evaluations" ].push_back( "none" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "evaluations" ].push_back( jt.value() );
} else {
amap[ "evaluations" ].push_back( "none" );
}
jt= z6.find( "target" );
if (jt != z6.end()) amap[ "target" ].push_back( jt.value() );
else amap[ "target" ].push_back( "none" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "target" ].push_back( jt.value() );
} else {
amap[ "target" ].push_back( "none" );
}
jt= z6.find( "passes" );
if (jt != z6.end()) amap[ "passes" ].push_back( jt.value() );
else amap[ "passes" ].push_back( "none" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "passes" ].push_back( jt.value() );
} else {
amap[ "passes" ].push_back( "none" );
}
jt= z6.find( "restarts" );
if (jt != z6.end()) amap[ "restarts" ].push_back( jt.value() );
else amap[ "restarts" ].push_back( "none" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "restarts" ].push_back( jt.value() );
} else {
amap[ "restarts" ].push_back( "none" );
}
jt= z6.find( "equation" );
if (jt != z6.end()) amap[ "equation" ].push_back( jt.value() );
else amap[ "equation" ].push_back( "none" );
if (jt != z6.end() && !jt->is_null()) {
amap[ "equation" ].push_back( jt.value() );
} else {
amap[ "equation" ].push_back( "none" );
}
v.push_back( amap ); // v[ 6 ]
return v;
......
......@@ -622,7 +622,7 @@ bool dataManager::parseJSONFile( string fileName )
bool dataManager::fromSimulate(json j)
{
if(debug > 0) std::cout << "dataManager::fromSimulate()\n";
auto mac= j.find( "machine" );
if( mac == j.end() ) {
cout << "dataManager::fromSimumate: can't find the <machine> key\n";
......
......@@ -729,6 +729,8 @@ void expandedMachine::toJSON(json& j)
bool expandedMachine::fromJSON(json j)
{
if (debug > 0) cout << "expandedMachine::fromJSON()\n";
bool status= true;
computingBlocks_.clear();
for (auto kt = j.begin(); kt != j.end(); ++kt)
......
......@@ -147,8 +147,8 @@ void machine::toJSON(json& j)
bool machine::fromJSON(json j)
{
if(debug > 0) std::cout << "machine::fromJSON()\n";
bool status= true;
if(debug > 0) std::cout << "machine::fromJSON( 1 )\n";
bool status= true;
containedSectors_.clear();
auto mac= j.find( "machine" );
......@@ -160,7 +160,7 @@ bool machine::fromJSON(json j)
}
if(debug > 0)
cout << "machine has " << containedSectors_.size() << " sector(s)\n";
cout << "=> machine has " << containedSectors_.size() << " sector(s)\n";
computingBlocks_.clear();
auto exp= j.find( "simulations" );
......@@ -187,6 +187,7 @@ bool machine::fromJSON(json j)
bool machine::fromJSON(map< string,vector<json> > cmap,json exp)
{
if(debug > 0) std::cout << "machine::fromJSON( 2 )\n";
bool status= true;
containedSectors_.clear();
......@@ -204,7 +205,8 @@ bool machine::fromJSON(map< string,vector<json> > cmap,json exp)
if ( sor ) containedSectors_.push_back( sor );
}
cout << "machine has " << containedSectors_.size() << " sector(s)\n";
if (debug > 0)
cout << "machine has " << containedSectors_.size() << " sector(s)\n";
computingBlocks_.clear();
if( exp.is_null() ) {
......
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