Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

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) ...@@ -29,9 +29,21 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf); getline(ifs,buf);
} while ( buf.find("* TITRE") == string::npos && !ifs.eof() ); } while ( buf.find("* TITRE") == string::npos && !ifs.eof() );
getline(ifs,buf);
cout << "found TITRE => " << buf << endl; string nameOfMachine;
string nameOfMachine= buf; 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;
nameOfMachine= buf;
}
// find the ELEMENTS // find the ELEMENTS
do { do {
...@@ -39,6 +51,14 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName) ...@@ -39,6 +51,14 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf); getline(ifs,buf);
} while ( buf.find("* LIST OF ELEMENTS") == string::npos && !ifs.eof() ); } 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); ListOfElements(ifs);
// find the STRUCTURE // find the STRUCTURE
...@@ -47,6 +67,14 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName) ...@@ -47,6 +67,14 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf); getline(ifs,buf);
} while ( buf.find("* STRUCTURE") == string::npos && !ifs.eof() ); } 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); getline(ifs,buf);
int num= BasicUtilities::string_to_int( buf ); int num= BasicUtilities::string_to_int( buf );
...@@ -76,46 +104,77 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName) ...@@ -76,46 +104,77 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
getline(ifs,buf); getline(ifs,buf);
} while ( buf.find("* PARTICLE") == string::npos && !ifs.eof() ); } while ( buf.find("* PARTICLE") == string::npos && !ifs.eof() );
getline(ifs,buf);
string ptype; if( buf.find("* PARTICLE") == string::npos ) {
if (buf.find("E") != string::npos) {
ptype= "ELECTRON"; ifs.clear();
} else if (buf.find("P") != string::npos) { ifs.seekg(0,ios::beg);
ptype= "PROTON"; n5->addChild("particle")->addAttribute("type","ELECTRON");
} else if (buf.find("D") != string::npos) {
ptype= "DEUTRON";
} else if (buf.find("M") != string::npos) {
ptype= "MUON";
} else { } else {
cout << "OTHER => the next line contains the mass number ans the charge number of the particle\n";
ptype= "OTHER"; getline(ifs,buf);
string ptype;
if (buf.find("E") != string::npos) {
ptype= "ELECTRON";
} else if (buf.find("P") != string::npos) {
ptype= "PROTON";
} else if (buf.find("D") != string::npos) {
ptype= "DEUTRON";
} else if (buf.find("M") != string::npos) {
ptype= "MUON";
} else {
cout << "OTHER => the next line contains the mass number ans the charge number of the particle\n";
ptype= "OTHER";
}
n5->addChild("particle")->addAttribute("type",ptype);
} }
n5->addChild("particle")->addAttribute("type",ptype);
// find ENERGIE CINETIQUE (MeV) // find ENERGIE CINETIQUE (MeV)
do { do {
getline(ifs,buf); getline(ifs,buf);
} while ( buf.find("* ENERGIE") == string::npos && !ifs.eof() ); } while ( buf.find("* ENERGIE") == string::npos && !ifs.eof() );
ifs >> buf;
n5->addChild("total_energy")->addAttribute("design",buf);
ifs >> buf;
n5->addChild("mass")->addAttribute("design",buf);
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 // find EMITTANCE
do { do {
getline(ifs,buf); getline(ifs,buf);
} while ( buf.find("* EMITTANCE") == string::npos && !ifs.eof() ); } while ( buf.find("* EMITTANCE") == string::npos && !ifs.eof() );
ifs >> buf;
n5->addChild("emittance_a")->addAttribute("design",buf); if( buf.find("* EMITTANCE") == string::npos ) {
ifs >> buf;
n5->addChild("emittance_b")->addAttribute("design",buf); ifs.clear();
ifs >> buf; ifs.seekg(0,ios::beg);
n5->addChild("emittance_z")->addAttribute("design",buf);
} else {
ifs >> buf;
n5->addChild("emittance_a")->addAttribute("design",buf);
ifs >> buf;
n5->addChild("emittance_b")->addAttribute("design",buf);
ifs >> buf;
n5->addChild("emittance_z")->addAttribute("design",buf);
}
ifs.close();
// Creates a UAPNode named "machine" // Creates a UAPNode named "machine"
UAPNode *nde= NULL; UAPNode *nde= NULL;
nde= new UAPNode("laboratory"); nde= new UAPNode("laboratory");
...@@ -132,7 +191,7 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName) ...@@ -132,7 +191,7 @@ UAPNode* BETAParser::FileToAMLRep (const string& fileName)
nde->addChild( n3 ); nde->addChild( n3 );
nde->addChild( n4 ); nde->addChild( n4 );
cout << "BETAPARSER:: " << nde->toStringTree() << endl; //cout << "BETAPARSER:: " << nde->toStringTree() << endl;
return nde; 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