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

rework the reading of a BETA file

parent 27ba7232
......@@ -29,9 +29,21 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf);
} while ( buf.find("* TITRE") == string::npos && !ifs.eof() );
string nameOfMachine;
if( buf.find("* TITRE") == string::npos ) {
// set position of stream to the beginning
ifs.clear();
ifs.seekg(0,ios::beg);
nameOfMachine= "NOTITLE";
} else {
getline(ifs,buf);
cout << "found TITRE => " << buf << endl;
string nameOfMachine= buf;
nameOfMachine= buf;
}
// find the ELEMENTS
do {
......@@ -39,6 +51,14 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf);
} while ( buf.find("* LIST OF ELEMENTS") == string::npos && !ifs.eof() );
if (buf.find("* LIST OF ELEMENTS") == string::npos) {
cout << "BETAParser::FileToAMLRep:: LIST OF ELEMENTS is mandatory\n";
return NULL;
}
ListOfElements(ifs);
// find the STRUCTURE
......@@ -47,6 +67,14 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf);
} while ( buf.find("* STRUCTURE") == string::npos && !ifs.eof() );
if (buf.find("* STRUCTURE") == string::npos) {
cout << "BETAParser::FileToAMLRep:: STRUCTURE is mandatory\n";
return NULL;
}
getline(ifs,buf);
int num= BasicUtilities::string_to_int( buf );
......@@ -76,6 +104,15 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf);
} while ( buf.find("* PARTICLE") == string::npos && !ifs.eof() );
if( buf.find("* PARTICLE") == string::npos ) {
ifs.clear();
ifs.seekg(0,ios::beg);
n5->addChild("particle")->addAttribute("type","ELECTRON");
} else {
getline(ifs,buf);
string ptype;
if (buf.find("E") != string::npos) {
......@@ -91,6 +128,7 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
ptype= "OTHER";
}
n5->addChild("particle")->addAttribute("type",ptype);
}
// find ENERGIE CINETIQUE (MeV)
do {
......@@ -98,10 +136,19 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf);
} while ( buf.find("* ENERGIE") == string::npos && !ifs.eof() );
if( buf.find("* ENERGIE") == string::npos ) {
ifs.clear();
ifs.seekg(0,ios::beg);
} else {
ifs >> buf;
n5->addChild("total_energy")->addAttribute("design",buf);
ifs >> buf;
n5->addChild("mass")->addAttribute("design",buf);
}
// find EMITTANCE
do {
......@@ -109,6 +156,14 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf);
} while ( buf.find("* EMITTANCE") == string::npos && !ifs.eof() );
if( buf.find("* EMITTANCE") == string::npos ) {
ifs.clear();
ifs.seekg(0,ios::beg);
} else {
ifs >> buf;
n5->addChild("emittance_a")->addAttribute("design",buf);
ifs >> buf;
......@@ -116,6 +171,10 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
ifs >> buf;
n5->addChild("emittance_z")->addAttribute("design",buf);
}
ifs.close();
// Creates a UAPNode named "machine"
UAPNode *nde= NULL;
nde= new UAPNode("laboratory");
......@@ -132,7 +191,7 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
nde->addChild( n3 );
nde->addChild( n4 );
cout << "BETAPARSER:: " << nde->toStringTree() << endl;
//cout << "BETAPARSER:: " << nde->toStringTree() << endl;
return nde;
}
......
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