summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Vazquez <christian.vazquez@epfl.ch>2011-05-28 15:13:39 +0000
committerChristian Vazquez <christian.vazquez@epfl.ch>2011-05-28 15:13:39 +0000
commita01261efa97302414bd59ce0c6c5359e542b4ac2 (patch)
treed73a7dbd1f2ce61de13262f49f29c3a77b1135f5
parentc0eed2e038948fa9cdba36f81a8cef211542aa7f (diff)
downloadvhc-a01261efa97302414bd59ce0c6c5359e542b4ac2.tar.gz
vhc-a01261efa97302414bd59ce0c6c5359e542b4ac2.tar.bz2
vhc-a01261efa97302414bd59ce0c6c5359e542b4ac2.zip
Mis à jour le parseur, et la fichier simulation.cc (renommé en simulation.cc et déplacé dans le dossier test).
Modifié le fichier simulation.xml. La classe parseur ne compile pas ('undefined reference to'). Après consultation du forum, c'est peut-être un problème en rapport avec le makefile.
-rw-r--r--src/main/Parser.cc651
-rw-r--r--src/main/Parser.h278
-rw-r--r--src/main/simulation.cc0
-rw-r--r--src/main/simulation.xml194
-rw-r--r--src/test/simulationTest.cc32
5 files changed, 730 insertions, 425 deletions
diff --git a/src/main/Parser.cc b/src/main/Parser.cc
index 0aed354..0331c4c 100644
--- a/src/main/Parser.cc
+++ b/src/main/Parser.cc
@@ -4,115 +4,94 @@
* Created on: 11 mai 2011
* Author: christian
*/
+#include <isotream>
+#include <string>
#include "Parser.h"
-//TODO balises fermantes et header et constantes et commentaires????????
+using namespace std;
namespace vhc {
-/** Cf. header.**/
-Parser::Parser(): nameOfFile("") {};
-
-Parser::Parser(std::string file): nameOfFile(file) {};
-
-Parser::~Parser() {};
-
//===========================================balises ouvrantes==========================================================================
//balises ouvrantes d'un système
-tagStat Parser::system = "<System>";
-tagStat Parser::accelerator ="<Accelerator>";
-tagStat Parser::comment = "<--";
-
-//balises ouvrantes des constantes
-tagStat Parser::constants = "<constants>";
-tagStat Parser::dt = "<dt>";
-tagStat Parser::C = "<C>";
-tagStat Parser::E = "<E>";
-tagStat Parser::PROTON_MASS = "<PROTON_MASS>";
-tagStat Parser::ELECTRON_MASS = "<ELECTRON_MASS>";
+static tag Parser::system = "<System>";
+static tag Parser::accelerator ="<Accelerator>";
+static tag Parser::comment = "<!--";
//balises ouvrantes d'une particule
-tagStat Parser::particle ="<Particle>";
-tagStat Parser::position = "<Position>";
-tagStat Parser::mass = "<Mass>";
-tagStat Parser::charge = "<Charge>";
-tagStat Parser::energy = "<Energy>";
-tagStat Parser::direction = "<Direction>";
+static tag Parser::particle ="<Particle>";
+static tag Parser::position = "<Position>";
+static tag Parser::mass = "<Mass>";
+static tag Parser::charge = "<Charge>";
+static tag Parser::energy = "<Energy>";
+static tag Parser::direction = "<Direction>";
//balises ouvrantes d'un Element
-tagStat Parser::entryPos = "<EntryPosition>";
-tagStat Parser::exitPos = "<ExitPosition>";
-tagStat Parser::sectionRadius = "<SectionRadius>";
+static tag Parser::entryPos = "<EntryPosition>";
+static tag Parser::exitPos = "<ExitPosition>";
+static tag Parser::sectionRadius = "<SectionRadius>";
//balises ouvrantes d'un Dipole
-tagStat Parser::dipole ="<Dipole>";
-tagStat Parser::curvature = "<Curvature>";
-tagStat Parser::magneticField = "<MagneticField>";
+static tag Parser::dipole ="<Dipole>";
+static tag Parser::curvature = "<Curvature>";
+static tag Parser::magneticField = "<MagneticField>";
//balise ouvrante commune aux quadrupoles et aux fodo
-tagStat Parser::focCoeff = "<FocalizingCoefficient>";
+static tag Parser::focCoeff = "<FocalizingCoefficient>";
//balises ouvrantes d'une FODO
-tagStat Parser::fodo ="<FODO>";
-tagStat Parser::straightLength = "<StraightLenght>";
+static tag Parser::fodo ="<FODO>";
+static tag Parser::straightLength = "<StraightLenght>";
//balises ouvrantes d'un Quadrupole
-tagStat Parser::quadrupole ="<Quadrupole>";
+static tag Parser::quadrupole ="<Quadrupole>";
//balises ouvrantes d'un StraightElement
-tagStat Parser::straightElement ="<StraightElement>";
+static tag Parser::straightElement ="<StraightElement>";
//===================================================balises fermantes==================================================================
//balises fermantes d'un système
-tagStat Parser::systemCl = "<\System>";
-tagStat Parser::acceleratorCl ="<\Accelerator>";
-tagStat Parser::commentCl = "-->";
-
-//balises fermantes des constantes
-tagStat Parser::constantsCl = "<\constants>";
-tagStat Parser::dtCl = "<\dt>";
-tagStat Parser::CCl = "<\C>";
-tagStat Parser::ECl = "<\E>";
-tagStat Parser::PROTON_MASSCl = "<\PROTON_MASS>";
-tagStat Parser::ELECTRON_MASSCl = "<\ELECTRON_MASS>";
+static tag Parser::systemCl = "<\System>";
+static tag Parser::acceleratorCl ="<\Accelerator>";
+static tag Parser::commentCl = "-->";
//balises fermantes d'une particule
-tagStat Parser::particleCl ="<\Particle>";
-tagStat Parser::positionCl = "<\Position>";
-tagStat Parser::massCl = "<\Mass>";
-tagStat Parser::chargeCl = "<\Charge>";
-tagStat Parser::energyCl = "<\Energy>";
-tagStat Parser::directionCl = "<\Direction>";
+static tag Parser::particleCl ="<\Particle>";
+static tag Parser::positionCl = "<\Position>";
+static tag Parser::massCl = "<\Mass>";
+static tag Parser::chargeCl = "<\Charge>";
+static tag Parser::energyCl = "<\Energy>";
+static tag Parser::directionCl = "<\Direction>";
//balises fermantes d'un Element
-tagStat Parser::entryPosCl = "<\EntryPosition>";
-tagStat Parser::exitPosCl = "<\ExitPosition>";
-tagStat Parser::sectionRadiusCl = "<\SectionRadius>";
+static tag Parser::entryPosCl = "<\EntryPosition>";
+static tag Parser::exitPosCl = "<\ExitPosition>";
+static tag Parser::sectionRadiusCl = "<\SectionRadius>";
//balises fermantes d'un Dipole
-tagStat Parser::dipoleCl ="<\Dipole>";
-tagStat Parser::curvatureCl = "<\Curvature>";
-tagStat Parser::magneticFieldCl = "<\MagneticField";
+static tag Parser::dipoleCl ="<\Dipole>";
+static tag Parser::curvatureCl = "<\Curvature>";
+static tag Parser::magneticFieldCl = "<\MagneticField";
//balise fermantes commune aux quadrupoles et aux fodo
-tagStat Parser::focCoeffCl = "<\FocalizingCoefficient>";
+static tag Parser::focCoeffCl = "<\FocalizingCoefficient>";
//balises fermantes d'une FODO
-tagStat Parser::fodoCl ="<\FODO>";
-tagStat Parser::straightLengthCl = "<\StraightLenght>";
+static tag Parser::fodoCl ="<\FODO>";
+static tag Parser::straightLengthCl = "<\StraightLenght>";
//balises fermantes d'un Quadrupole
-tagStat Parser::quadrupoleCl ="<\Quadrupole>";
+static tag Parser::quadrupoleCl ="<\Quadrupole>";
//balises fermantes d'un StraightElement
-tagStat Parser::straightElementCl ="<\StraightElement>";
+static tag Parser::straightElementCl ="<\StraightElement>";
//===========================================================création et renvoi d'un accélérateur=======================================
Parser::extract() {
- Accelerator* acc;
+ Accelerator* acc = new Accelerator;
//on déclare une flot d'entrée
ifstream entry;
@@ -137,6 +116,7 @@ Parser::extract() {
throw IOException("Cannot open file. "+nameOfFile+" not found.");
}
+ acc->close();
return acc;
}
@@ -157,6 +137,7 @@ Parser::readFile(ifstream& file, Accelerator& acc){
case system :
readSystem(file, acc);
+ closingTag(file, systemCl);
break;
case comment :
@@ -177,7 +158,7 @@ Parser::readFile(ifstream& file, Accelerator& acc){
}
catch(Exception const& ex){
- std::cout<<ex.getMessage()<<std::endl;
+ cout<<ex.getMessage()<<endl;
}
}
@@ -190,18 +171,12 @@ Parser::readSystem(ifstream& file, Accelerator& acc){
tag tmp2 = readOneTag(file);
/*on teste si tmp2 correspond à une des balises suivantes :
- * - soit constants
* - soit accelerator
* - soit un commentaire
* - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là
*/
switch(tmp2){
- case constants :
-
- readConstants(file);
- break;
-
case accelerator :
buildAccelerator(file, acc);
@@ -218,105 +193,26 @@ Parser::readSystem(ifstream& file, Accelerator& acc){
*/
default:
- throw ReadException("Values found outside of following tags : "+constants+accelerator+
+ throw ReadException("Values found outside of following tags : "+accelerator+
"\n Value is : "+tmp2);
break;
}
}
catch(Exception const& ex){
- std::cout<<ex.getMessage()<<std::endl;
- }
-}
-
-//====================================================================lecture de constantes=============================================
-Parser::readConstants(ifstream& file){
- try {
-
- // on lit la balise qu'on doit traiter
- tag tmp31 = readOneTag(file);
-
- /*on teste si tmp31 correspond à une des balises suivantes :
- * - soit C
- * - soit E
- * - soit PROTON_MASS
- * - soit ELECTRON_MASS
- * - soit un commentaire
- * - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là
- */
- switch(tmp31){
-
- case C :
-
- readC(file);
- break;
-
- case E :
-
- readE(file);
- break;
-
- case PROTON_MASS :
-
- readPROTON_MASS(file);
- break;
-
- case ELECTRON_MASS :
-
- readELECTRON_MASS(file);
- break;
-
- case comment :
-
- jumpComment(file);
- break;
-
- /* si la variable tmp31 ne contient pas les balises voulues, c'est qu'une valeur
- * (celle contenue par la variable tmp31 donc)
- * n'a pas été récupérée comme il faut.
- */
- default:
-
- throw ReadException("Values found outside of following tags : "+dt+C+E+PROTON_MASS+ELECTRON_MASS+
- "\n Value is : "+tmp31);
- break;
- }
- }
-
- catch(Exception const& ex){
- std::cout<<ex.getMessage()<<std::endl;
+ cout<<ex.getMessage()<<endl;
}
}
-Parser::readC(ifstream& file){
- Parser::CP = readOneDouble(file);
- closingTag(file);
-}
-
-Parser::readE(ifstream& file){
- Parser::EP = readOneDouble(file);
- closingTag(file);
-}
-
-Parser::readPROTON_MASS(ifstream& file){
- Parser::PROTON_MASSP = readOneDouble(file);
- closingTag(file);
-}
-
-Parser::readELECTRON_MASS(ifstream& file){
- Parser::ELECTRON_MASSP = readOneDouble(file);
- closingTag(file);
-}
-
//==========================================================fabrication de l'accélérateur===============================================
-Parser::buildAccelerator(ifstream& file, Accelerator const& acc){
+Parser::buildAccelerator(ifstream& file, Accelerator& acc){
try {
// on lit la balise qu'on doit traiter
- tag tmp32 = readOneTag(file);
+ tag tmp3 = readOneTag(file);
- /*on teste si tmp32 correspond à une des balises suivantes :
+ /*on teste si tmp3 correspond à une des balises suivantes :
* - soit dipole
* - soit fodo
* - soit particle
@@ -325,60 +221,87 @@ Parser::buildAccelerator(ifstream& file, Accelerator const& acc){
* - soit un commentaire
* - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là
*/
- switch(tmp32){
+ switch(tmp3){
case dipole :
- acc.add(buildDipole(file));
- break;
+ acc.add(*buildDipole(file));
+ readClosingTag(file, dipoleCl);
+ tmp3 = readOneTag(file);
+ if(tmp3 == acceleratorCl)
+ break;
+ else
+ continue;
case fodo :
- acc.add(buildFODO(file));
- break;
+ acc.add(*buildFODO(file));
+ readClosingTag(file, fodoCl);
+ tmp3 = readOneTag(file);
+ if(tmp3 == acceleratorCl)
+ break;
+ else
+ continue;
case particle :
- Particle* p = new Particle;
- acc.add(buildParticle(file,*pa));
- break;
+ acc.add(*buildParticle(file));
+ readClosingTag(file, particleCl);
+ tmp3 = readOneTag(file);
+ if(tmp3 == acceleratorCl)
+ break;
+ else
+ continue;;
case quadrupole :
- acc.add(buildQuadrupole(file));
- break;
+ acc.add(*buildQuadrupole(file));
+ readClosingTag(file, quadrupoleCl);
+ tmp3 = readOneTag(file);
+ if(tmp3 == acceleratorCl)
+ break;
+ else
+ continue;
case straightElement :
- acc.add(buildStraightElement(file));
- break;
+ acc.add(*buildStraightElement(file));
+ readClosingTag(file, straightElementCl);
+ tmp3 = readOneTag(file);
+ if(tmp3 == acceleratorCl)
+ break;
+ else
+ continue;
case comment :
jumpComment(file);
break;
- /* si la variable tmp32 ne contient pas les balises voulues, c'est qu'une valeur
- * (celle contenue par la variable tmp32 donc)
+ /* si la variable tmp3 ne contient pas les balises voulues, c'est qu'une valeur
+ * (celle contenue par la variable tmp3 donc)
* n'a pas été récupérée comme il faut.
*/
default:
throw ReadException("Values found outside of following tags : "+dipole+fodo+particle+quadrupole+straightElement+
- "\n Value is : "+tmp32);
+ "\n Value is : "+tmp3);
break;
}//switch
}//try
catch(Exception const& ex){
- std::cout<<ex.getMessage()<<std::endl;
+ cout<<ex.getMessage()<<endl;
}
}
-//===========================================================construction d'une nouvelle particule======================================
-Parser::buildParticle(ifstream& file, Particle const& p){
+//===========================================================création d'une particule===================================================
+Particle* Parser::buildParticle(ifstream& file){
try {
+ //Initialisation des variables nécessaires à la construction d'une particule.
+ Vector3D po(0,0,0); double ma(0); double ch(0); double en(0); Vector3D dir(0,0,0);
+
// on lit la balise qu'on doit traiter
tag tmp41 = readOneTag(file);
@@ -395,27 +318,32 @@ Parser::buildParticle(ifstream& file, Particle const& p){
case position :
- p.setPosition(readPosition(file));
+ po = readVector3D(file);
+ closingTag(file, positionCl);
break;
case mass :
- p.setMass(readMass(file));
+ ma = readOneDouble(file);
+ closingTag(file, massCl);
break;
case charge :
- p.setCharge(readCharge(file));
+ ch = readOneDouble(file);
+ closingTag(file, chargeCl);
break;
case energy :
- p.setEnergy(readEnergy(file));//TODO faire un set Energy!!!!!
+ en = readOneDouble(file);
+ closingTag(file, energyCl);
break;
case direction :
- acc.add(buildStraightElement(file));
+ dir = readVector3D(file);
+ closingTag(file, directionCl);
break;
case comment :
@@ -429,83 +357,346 @@ Parser::buildParticle(ifstream& file, Particle const& p){
*/
default:
- throw ReadException("Values found outside of following tags : "+dipole+fodo+particle+quadrupole+straightElement+
+ throw ReadException("Values found outside of following tags : "+position+mass+charge+energy+direction+
"\n Value is : "+tmp41);
break;
}//switch
+
+ //Construction d'une particule avec les varables récoltées.
+ Particle* p = new Particle(po,
+ ma * constants::PROTON_MASS,
+ ch * constants::E,
+ en * constants::GeV,
+ dir);
+
+ return p;
+
}//try
catch(Exception const& ex){
- std::cout<<ex.getMessage()<<std::endl;
+ cout<<ex.getMessage()<<endl;
}
}
-Parser::readPosition(ifstream& file){
+//===========================================================création d'un Dipole=======================================================
+/** Cf. header. */
+Diple* Parser::buildDipole(ifstream& file){
+ try {
-}
+ //Initialsation des variables nécessaires à la construction d'un Dipole.
+ Vector3D enp(0,0,0); Vector3D exp(0,0,0); double sr(0); double cu(0); Vector3D mf(0,0,0);
-Parser::readMass(ifstream& file){
+ // on lit la balise qu'on doit traiter
+ tag tmp42 = readOneTag(file);
+
+ /*on teste si tmp42 correspond à une des balises suivantes :
+ * - soit entryPos
+ * - soit exitPos
+ * - soit sectionRadius
+ * - soit curvature
+ * - soit magneticField
+ * - soit un commentaire
+ * - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là
+ */
+ switch(tmp42){
-}
+ case entryPos :
-Parser::readCharge(ifstream& file){
+ enp = readVector3D(file);
+ closingTag(file, entryPosCl);
+ break;
-}
+ case exitPos :
-Parser::readEnergy(ifstream& file){
+ exp = readVector3D(file);
+ closingTag(file, exitPosCl);
+ break;
-}
+ case sectionRadius :
-Parser::readDirection(ifstream& file){
+ sr = readOneDouble(file);
+ closingTag(file, sectionRadiusCl);
+ break;
-}
+ case curvature :
-//===========================================================construction d'une nouvelle FODO===========================================
-Parser::buildFODO(ifstream& file){
+ cu = readOneDouble(file);
+ closingTag(file, curvatureCl);
+ break;
-}
+ case magneticField :
+
+ mf = readVector3D(file);
+ closingTag(file, magneticFieldCl);
+ break;
+
+ case comment :
+
+ jumpComment(file);
+ break;
-//===========================================================construction d'un nouveau Dipole===========================================
-Parser::buildDipole(ifstream& file){
+ /* si la variable tmp42 ne contient pas les balises voulues, c'est qu'une valeur
+ * (celle contenue par la variable tmp42 donc)
+ * n'a pas été récupérée comme il faut.
+ */
+ default:
+
+ throw ReadException("Values found outside of following tags : "+entryPos+exitPos+sectionRadius+curvature+magneticField+
+ "\n Value is : "+tmp42);
+ break;
+ }//switch
+ //Construction d'un dipole avec les variables récoltées.
+ Dipole* di = new Dipole(enp, exp, sr, cu, mf);
+
+ return di;
+
+ }//try
+
+ catch(Exception const& ex){
+ cout<<ex.getMessage()<<endl;
+ }
}
-//============================================================construction d'un nouveau quadrupole======================================
-Parser::buildQuadrupole(ifstream& file){
+//===========================================================modification d'une FODO====================================================
+/** Cf. header. */
+FODO* Parser::buildFODO(ifstream& file){
+ try {
+
+ //Initialsation des variables nécessaires à la construction d'une FODO.
+ Vector3D enp(0,0,0); Vector3D exp(0,0,0); double sr(0); double sl(0); double fc(0);
+
+ // on lit la balise qu'on doit traiter
+ tag tmp43 = readOneTag(file);
+
+ /*on teste si tmp43 correspond à une des balises suivantes :
+ * - soit entryPos
+ * - soit exitPos
+ * - soit sectionRadius
+ * - soit straightLength
+ * - soit focCoeff
+ * - soit un commentaire
+ * - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là
+ */
+ switch(tmp43){
+
+ case entryPos :
+
+ enp = readVector3D(file);
+ closingTag(file, entryPosCl);
+ break;
+
+ case exitPos :
+
+ exp = readVector3D(file);
+ closingTag(file, exitPosCl);
+ break;
+
+ case sectionRadius :
+
+ sr = readOneDouble(file);
+ closingTag(file, sectionRadiusCl);
+ break;
+
+ case straightLength :
+
+ sl = readOneDouble(file);
+ closingTag(file, straightLengthCl);
+ break;
+
+ case focCoeff :
+
+ fc = readOneDouble(file);
+ closingTag(file, focCoeffCl);
+ break;
+ case comment :
+
+ jumpComment(file);
+ break;
+
+ /* si la variable tmp43 ne contient pas les balises voulues, c'est qu'une valeur
+ * (celle contenue par la variable tmp43 donc)
+ * n'a pas été récupérée comme il faut.
+ */
+ default:
+
+ throw ReadException("Values found outside of following tags : "+entryPos+exitPos+sectionRadius+straightLength+focCoeff+
+ "\n Value is : "+tmp43);
+ break;
+ }//switch
+
+ //Construction d'une FODO avec les variables récoltées.
+ FODO* fo = new FODO(enp, exp, sr, sl, fc);
+
+ return fo;
+
+ }//try
+
+ catch(Exception const& ex){
+ cout<<ex.getMessage()<<endl;
+ }
}
-//============================================================construction d'un nouveau straight Element================================
-Parser::buildStraightElement(ifstream& file){
+//============================================================création d'un quadrupole==================================================
+/** Cf. header. */
+Quadrupole* Parser::buildQuadrupole(ifstream& file){
+ try {
+
+ //Initialsation des variables nécessaires à la construction d'un Quadrupole.
+ Vector3D enp(0,0,0); Vector3D exp(0,0,0); double sr(0); double fc(0);
+
+ // on lit la balise qu'on doit traiter
+ tag tmp44 = readOneTag(file);
+
+ /*on teste si tmp44 correspond à une des balises suivantes :
+ * - soit entryPos
+ * - soit exitPos
+ * - soit sectionRadius
+ * - soit focCoeff
+ * - soit un commentaire
+ * - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là
+ */
+ switch(tmp44){
+
+ case entryPos :
+
+ enp = readVector3D(file);
+ closingTag(file, entryPosCl);
+ break;
+
+ case exitPos :
+
+ exp = readVector3D(file);
+ closingTag(file, exitPosCl);
+ break;
+
+ case sectionRadius :
+
+ sr = readOneDouble(file);
+ closingTag(file, sectionRadiusCl);
+ break;
+
+ case focCoeff :
+
+ fc = readOneDouble(file);
+ closingTag(file, focCoeffCl);
+ break;
+
+ case comment :
+
+ jumpComment(file);
+ break;
+
+ /* si la variable tmp44 ne contient pas les balises voulues, c'est qu'une valeur
+ * (celle contenue par la variable tmp44 donc)
+ * n'a pas été récupérée comme il faut.
+ */
+ default:
+
+ throw ReadException("Values found outside of following tags : "+entryPos+exitPos+sectionRadius+focCoeff+
+ "\n Value is : "+tmp44);
+ break;
+ }//switch
+
+ //Construction d'un Quadrupole avec les variables récoltées.
+ Quadrupole* qu = new Quadrupole(enp, exp, sr, fc);
+
+ return qu;
+
+ }//try
+
+ catch(Exception const& ex){
+ cout<<ex.getMessage()<<endl;
+ }
}
+//============================================================création d'un StraightElement=============================================
+/** Cf. header. */
+StraightElement* Parser::buildStraightElement(ifstream& file){
+ try {
+
+ //Initialsation des variables nécessaires à la construction d'un StraightElement.
+ Vector3D enp(0,0,0); Vector3D exp(0,0,0); double sr(0);
+
+ // on lit la balise qu'on doit traiter
+ tag tmp45 = readOneTag(file);
+
+ /*on teste si tmp45 correspond à une des balises suivantes :
+ * - soit entryPos
+ * - soit exitPos
+ * - soit sectionRadius
+ * - soit un commentaire
+ * - sinon il y a un problème car on ne s'attend pas à autre chose à ce niveau-là
+ */
+ switch(tmp45){
+
+ case entryPos :
+
+ enp = readVector3D(file);
+ closingTag(file, entryPosCl);
+ break;
+
+ case exitPos :
+
+ exp = readVector3D(file);
+ closingTag(file, exitPosCl);
+ break;
+
+ case sectionRadius :
+
+ sr = readOneDouble(file);
+ closingTag(file, sectionRadiusCl);
+ break;
+
+ case comment :
+
+ jumpComment(file);
+ break;
+
+ /* si la variable tmp45 ne contient pas les balises voulues, c'est qu'une valeur
+ * (celle contenue par la variable tmp45 donc)
+ * n'a pas été récupérée comme il faut.
+ */
+ default:
+
+ throw ReadException("Values found outside of following tags : "+entryPos+exitPos+sectionRadius+
+ "\n Value is : "+tmp45);
+ break;
+ }//switch
+
+ //Construction d'un StraightElement avec les variables récoltées.
+ StraightElement* se = new StraightElement(enp, exp, sr);
+
+ return se;
+
+ }//try
+
+ catch(Exception const& ex){
+ cout<<ex.getMessage()<<endl;
+ }
+
//=======================================================lecture atomique===============================================================
-Parser::readOneChar(ifstream& file){
- file>>ws;
- char tmp;
- file>>tmp;
- return tmp;
-}
-Parser::readOneInt(ifstream& file){
- file>>ws;
- int tmp;
- file>>tmp;
- return tmp;
-}
-Parser::readOneDouble(ifstream& file){
+
+/** Cf. header. */
+double Parser::readOneDouble(ifstream& file){
file>>ws;
double tmp;
file>>tmp;
return tmp;
}
-Parser::readComma(ifstream& file){
+
+/** Cf. header. */
+void Parser::readComma(ifstream& file){
char trash;
file>>ws;
file>>trash;
}
+
//===========================================================lecture moléculaire========================================================
-Parser::readVector3D(ifstream& file){
+/** Cf. header. */
+Vector3D Parser::readVector3D(ifstream& file){
double x = readOneDouble(file);
readComma(file);
@@ -516,28 +707,38 @@ Parser::readVector3D(ifstream& file){
return Vector3D(x,y,z);
}
-Parser::readOneTag(ifstream& file){
+
+/** Cf. header. */
+tag Parser::readOneTag(ifstream& file){
tag tmp;
+ file>>ws;
file>>tag;
return tmp;
}
-Parser::closingTag(ifstream& file){
+
+/** Cf. header. */
+void Parser::closingTag(ifstream& file, std::string ta){
tag tmp;
file>>ws;
file>>tmp;
//si on a pas de balise fermante (ici il devrait il y en avoir normalement une) alors on lance une exception
- found=tmp.find("<");
+ found=tmp.find(ta);
if(found() == string::npos)
- throw ReadExceptionMessage("No closing tag found.");
+ throw ReadExceptionMessage("No closing tag "+ta+" found.");
}
//===========================================================lecture commentaire========================================================
-Parser::jumpComment(ifstream& file){
+/**Cf. header. */
+void Parser::jumpComment(ifstream& file){
tag tmp;
- file>>ws;
- //TODO getLine(file,tmp);
- //si on a pas de balise fermante (ici il devrait il y en avoir normalement une) alors on lance une exception
- found=tmp.find("-->");
- if(found() == string::npos)
+
+ do{
+ file>>ws;
+ file>>tmp;
+ found=tmp.find("-->");
+ }
+ while(found() == string::npos);
+
+ if(file.eof())
throw ReadExceptionMessage("No closing tag for comment found.");
}
diff --git a/src/main/Parser.h b/src/main/Parser.h
index a0d5103..12ff5a5 100644
--- a/src/main/Parser.h
+++ b/src/main/Parser.h
@@ -4,9 +4,13 @@
* Created on: 11 mai 2011
* Author: christian
*/
+#ifndef PARSER_H_
+#define PARSER_H_
+
#include <iostream>
#include <string>
#include <fstream>
+#include <math.h>
#include "Vector3D.h"
#include "Accelerator.h"
#include "Dipole.h"
@@ -16,203 +20,185 @@
#include "Particle.h"
#include "exceptions.h"
-#ifndef PARSER_H_
-#define PARSER_H_
+using namespace std;
-typedef tag string;
-typedef tagStat static tag;
+typedef string tag;
namespace vhc {
-/** Cette classe contient une méthode <code>extract<\code> chargée de créer et renvoyer un pointeur
- * sur l'accélérateur contenu dans le .xml. <b>ATTENTION : cette méthode est une "factory method",
- * donc il faut soi-même ajouter le <code>delete<\code> après appel à <code>extract<\code> !<\b>
- * Sont à supprimer : les pointeurs sur chaque particule, element ou accelerateur contenu dans le .xml
- **/
+/** Classe permettant l'extraction d'un Accelerator depuis un fichier .xml.
+ * Cette classe contient une méthode <code>extract()<\code> chargée de créer et renvoyer un pointeur
+ * sur l'accélérateur contenu dans le .xml. <b>ATTENTION<\b>: cette méthode est une "factory method",
+ * donc il faut soi-même ajouter les <code>delete<\code> après appel à <code>extract()<\code> !
+ * Sont à supprimer : les pointeurs sur chaque Particle, Element ou Accelerateur contenu dans le .xml
+ */
class Parser {
public:
- Parser();
- /** Constructeur d'un Parseur. Prend en argument le chemin d'accès du fichier à lire. **/
- Parser(std::string file);
+ /** Constructeur d'un Parseur.
+ * @param file chemin d'accès du fichier à lire */
+ inline Parser(std::string file)
+ : nameOfFile(file)
+ {}
- /**Destructeur virtuel. **/
- virtual ~Parser();
+ /**Destructeur virtuel. */
+ inline virtual ~Parser() {}
- /** Méthode chargée de lire le fichier .xml et de renvoyer un pointeur sur l'accélérateur ainsi construit. **/
+ /** Méthode chargée de lire le fichier .xml (lance une exception si le fichier n'est pas valide),
+ * de créer et renvoyer un accélérateur par appel de fonction privées.
+ * @return Accelerator construit avec les données récoltées dans le fichier .xml */
Accelerator* extract();
-private:
- /** Attribut contenant le chemin d'accès du fichier. **/
- string nameOfFile;
+protected:
-//===========================================constantes=================================================================================
+ /** Contient le chemin d'accès du fichier à lire. */
+ string nameOfFile;
- const double CP;
- const double EP;
- const double PROTON_MASSP;
- const double ELECTRON_MASSP;
- const double GeVP = 1E9 * EP;
+private:
//===========================================balises ouvrantes==========================================================================
- /** Balises ouvrantes d'un système. **/
- tagStat system;
- tagStat accelerator;
- tagStat comment;
-
- /** Balises ouvrantes des constantes. **/
- tagStat constants;
- tagStat dt;
- tagStat C;
- tagStat E;
- tagStat PROTON_MASS;
- tagStat ELECTRON_MASS;
-
- /** Balises ouvrantes d'une particule. **/
- tagStat particle;
- tagStat position;
- tagStat mass;
- tagStat charge;
- tagStat energy;
- tagStat direction;
-
- /** Balises ouvrantes d'un Element. **/
- tagStat entryPos;
- tagStat exitPos;
- tagStat sectionRadius;
-
- /** Balises ouvrantes d'un dipole. **/
- tagStat dipole;
- tagStat curvature;
- tagStat magneticField;
-
- /** Balise ouvrantes commune aux quadrupoles et aux fodo. **/
- tagStat focCoeff;
-
- /** Balises ouvrantes d'une FODO. **/
- tagStat fodo;
- tagStat straightLength;
-
- /** Balises ouvrante d'un quadrupole. **/
- tagStat quadrupole;
-
- /** Balises ouvrantes d'une straightElement. **/
- tagStat straightElement;
+ /** Balises ouvrantes d'un système.
+ * On ne peut pas y spécifier des constantes, car elle font partie d'un namespace. */
+ static tag system;
+ static tag accelerator;
+ static tag comment;
+
+ /** Balises ouvrantes d'une particule. */
+ static tag particle;
+ static tag position;
+ static tag mass;
+ static tag charge;
+ static tag energy;
+ static tag direction;
+
+ /** Balises ouvrantes d'un Element. */
+ static tag entryPos;
+ static tag exitPos;
+ static tag sectionRadius;
+
+ /** Balises ouvrantes d'un dipole. */
+ static tag dipole;
+ static tag curvature;
+ static tag magneticField;
+
+ /** Balise ouvrantes commune aux quadrupoles et aux fodo. */
+ static tag focCoeff;
+
+ /** Balises ouvrantes d'une FODO. */
+ static tag fodo;
+ static tag straightLength;
+
+ /** Balises ouvrante d'un quadrupole. */
+ static tag quadrupole;
+
+ /** Balises ouvrantes d'une straightElement. */
+ static tag straightElement;
//===================================================balises fermantes==================================================================
- /** Balises fermantes d'un système. **/
- tagStat systemCl;
- tagStat acceleratorCl;
- tagStat commentCl;
-
- /** Balises fermantes des constantes. **/
- tagStat constantsCl;
- tagStat dtCl;
- tagStat CCl;
- tagStat ECl;
- tagStat PROTON_MASSCl;
- tagStat ELECTRON_MASSCl;
-
- /** Balises fermantes d'une particule. **/
- tagStat particleCl;
- tagStat positionCl;
- tagStat massCl;
- tagStat chargeCl;
- tagStat energyCl;
- tagStat directionCl;
-
- /** Balises fermantes d'un Element. **/
- tagStat entryPosCl;
- tagStat exitPosCl;
- tagStat sectionRadiusCl;
-
- /** Balises fermantes d'un dipole. **/
- tagStat dipoleCl;
- tagStat curvatureCl;
- tagStat magneticFieldCl;
-
- /** Balise fermantes commune aux quadrupoles et aux fodo. **/
- tagStat focCoeffCl;
-
- /** Balises fermantes d'une FODO. **/
- tagStat fodoCl;
- tagStat straightLengthCl;
-
- /** Balises fermantes d'un quadrupole. **/
- tagStat quadrupoleCl;
-
- /** Balises fermantes d'une straightElement. **/
- tagStat straightElementCl;
+ /** Balises fermantes d'un système. */
+ static tag systemCl;
+ static tag acceleratorCl;
+ static tag commentCl;
-//=============================================================méthodes=================================================================
+ /** Balises fermantes d'une Particle. */
+ static tag particleCl;
+ static tag positionCl;
+ static tag massCl;
+ static tag chargeCl;
+ static tag energyCl;
+ static tag directionCl;
- /** Crée et renvoie un accélérateur par appel de la fonction readFile. **/
- Accelerator* extract();
+ /** Balises fermantes d'un Element. */
+ static tag entryPosCl;
+ static tag exitPosCl;
+ static tag sectionRadiusCl;
- /** Lit le fichier .xml. **/
- void readFile(ifstream& file, Accelerator& acc);
+ /** Balises fermantes d'un dipole. */
+ static tag dipoleCl;
+ static tag curvatureCl;
+ static tag magneticFieldCl;
- /** Lit la balise system. Cette méthode appelle readConstants et buildAccelerator. **/
- void readSystem(ifstream& file, Accelerator& acc);
+ /** Balise fermantes commune aux quadrupoles et aux fodo. */
+ static tag focCoeffCl;
- /** Affecte les attributs statiques contenant les constantes physiques. **/
- void readConstants(ifstream& file);
+ /** Balises fermantes d'une FODO. */
+ static tag fodoCl;
+ static tag straightLengthCl;
- /** Affecte l'attribut dt. **/
- void readdt(ifstream& file);
+ /** Balises fermantes d'un quadrupole. */
+ static tag quadrupoleCl;
- /** Affecte l'attribut C. **/
- void readC(ifstream& file);
+ /** Balises fermantes d'une straightElement. */
+ static tag straightElementCl;
- /** Affecte l'attribut E. **/
- void readE(ifstream& file);
+//=============================================================méthodes=================================================================
- /** Affecte l'attribut PROTON_MASS. **/
- void readPROTON_MASS(ifstream& file);
+ /** Lit le fichier .xml.
+ * @param file fichier à lire
+ * @param acc référence sur un Accelerator déjà construit */
+ void readFile(ifstream& file, Accelerator& acc);
- /** Affecte l'attribut ELECTRON_MASS. **/
- void readELECTRON_MASS(ifstream& file);
+ /** Lit la balise system. Cette méthode appelle readConstants et buildAccelerator.
+ * @param file fichier à lire
+ * @param acc référence sur un Accelerator déjà construit */
+ void readSystem(ifstream& file, Accelerator& acc);
- /** Ajoute les différents éléments et particules du fichier dans l'Accelerator passé en argument. **/
+ /** Ajoute les différents éléments et particules du fichier dans l'Accelerator passé en argument.
+ * @param file fichier à lire
+ * @param acc référence sur un Accelerator déjà construit */
void buildAccelerator(ifstream& file, Accelerator const& acc);
- /** Construction d'une nouvelle Particle. **/
+ /** Construction d'une nouvelle Particle.
+ * @param file fichier à lire
+ * @return Particle créée avec les valeurs récoltées dans le fichier .xml */
Particle* buildParticle(ifstream& file);
- /** Construction d'une nouvelle FODO. **/
+ /** Construction d'une nouvelle FODO.
+ * @param file fichier à lire
+ * @return FODO créée avec les valeurs récoltées dans le fichier .xml */
FODO* buildFODO(ifstream& file);
- /** Construction d'un nouveau Dipole. **/
+ /** Construction d'un nouveau Dipole.
+ * @param file fichier à lire
+ * @return Dipole créé avec les valeurs récoltées dans le fichier .xml */
Dipole* buildDipole(ifstream& file);
- /** Construction d'un nouveau quadrupole. **/
+ /** Construction d'un nouveau quadrupole.
+ * @param file fichier à lire
+ * @return Quadrupole créé avec les valeurs récoltées dans le fichier .xml */
Quadrupole* buildQuadrupole(ifstream& file);
- /** Construction d'un nouveau StraightElement. **/
+ /** Construction d'un nouveau StraightElement.
+ * @param file fichier à lire
+ * @return StraightElement créé avec les valeurs récoltées dans le fichier .xml */
StraightElement* buildStraightElement(ifstream& file);
- /** Lit un char. **/
- char readOneChar(ifstream& file);
- /** Lit un int. **/
- int readOneInt(ifstream& file);
- /** Lit un double. **/
+ /** Lit un double.
+ * @param file fichier à lire */
double readOneDouble(ifstream& file);
- /** Saute une virgule. **/
+ /** Saute une virgule.
+ * @param file fichier à lire*/
void readComma(ifstream& file);
- /** Lit un Vector3D. **/
+ /** Lit un Vector3D.
+ * @param file fichier à lire*/
Vector3D readVector3D(ifstream& file);
- /** Lit ue balise. **/
+ /** Lit ue balise.
+ * @param file fichier à lire*/
tag readOneTag(ifstream& file);
- /** Cherche et lit une balise fermante. **/
- void closingTag(ifstream& file);
- /** Saute un commentaire. **/
+ /** Cherche et lit une balise fermante contenant à la chaîne de caractère passée en argument.
+ * @param file fichier à lire
+ * @param ta contenu de la balise à trouver */
+ void closingTag(ifstream& file, std::string ta);
+ /** Cherche et lit une balise fermante d'un commentaire.
+ * @param file fichier à lire*/
void jumpComment(ifstream& file);
};
}
+
#endif /* PARSER_H_ */
diff --git a/src/main/simulation.cc b/src/main/simulation.cc
deleted file mode 100644
index e69de29..0000000
--- a/src/main/simulation.cc
+++ /dev/null
diff --git a/src/main/simulation.xml b/src/main/simulation.xml
index 24d1b79..61e4173 100644
--- a/src/main/simulation.xml
+++ b/src/main/simulation.xml
@@ -1,11 +1,4 @@
<System>
- <constants>
- <dt>10E-11<\dt>
- <C>299792458.0<\C>
- <E>1.60217653E-19<\E>
- <PROTON_MASS>1.672623E-27<\PROTON_MASS>
- <ELECTRON_MASS>9.109383E-31<\ELECTRON_MASS>
- <\constants>
<Accelerator>
<Particle>
<Position>
@@ -19,76 +12,169 @@
1
<\Charge>
<!-- ICI PAR RAPPORT A LA CHARGE DE L'ELECTRON -->
+ <Direction>
+ 0,-1,0
+ <\Direction>
<Energy>
2
<\Energy>
<!-- ICI PAR RAPPORT A UN GeV -->
+ <\Particle>
+ <Particle>
+ <Position>
+ 2.99,0,0
+ <\Position>
+ <Mass>
+ 1
+ <\Mass>
+ <!-- ICI PAR RAPPORT A LA MASSE DU PROTON -->
+ <Charge>
+ 1
+ <\Charge>
+ <!-- ICI PAR RAPPORT A LA CHARGE DE L'ELECTRON -->
<Direction>
0,-1,0
<\Direction>
- <\Particle>
- <Particle>
- <Position>2.99,0,0<\Position>
- <Mass>1<\Mass><!-- ICI PAR RAPPORT A LA MASSE DU PROTON -->
- <Charge>1<\Charge><!-- ICI PAR RAPPORT A LA CHARGE DE L'ELECTRON -->
- <Energy>2<\Energy><!-- ICI PAR RAPPORT A UN GeV -->
- <Direction>0,-1,0<\Direction>
+ <Energy>
+ 2
+ <\Energy>
+ <!-- ICI PAR RAPPORT A UN GeV -->
<\Particle>
<FODO>
- <EntryPosition>3,2,0<\EntryPosition>
- <ExitPosition>3,-2,0<\ExitPosition>
- <SectionRadius>0.2<\SectionRadius>
- <StraightLenght>1.<\StraightLenght>
- <FocalizingCoefficient>1.2<\FocalizingCoefficient>
+ <EntryPosition>
+ 3,2,0
+ <\EntryPosition>
+ <ExitPosition>
+ 3,-2,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.2
+ <\SectionRadius>
+ <StraightLenght>
+ 1.
+ <\StraightLenght>
+ <FocalizingCoefficient>
+ 1.2
+ <\FocalizingCoefficient>
<\FODO>
<Dipole>
- <EntryPosition>3,-2,0<\EntryPosition>
- <ExitPosition>2,-3,0<\ExitPosition>
- <SectionRadius>0.1<\SectionRadius>
- <Curvature>1.<\Curvature>
- <MagneticField>0,0,5.89158<\MagneticField>
+ <EntryPosition>
+ 3,-2,0
+ <\EntryPosition>
+ <ExitPosition>
+ 2,-3,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.1
+ <\SectionRadius>
+ <Curvature>
+ 1.
+ <\Curvature>
+ <MagneticField>
+ 0,0,5.89158
+ <\MagneticField>
<\Dipole>
<FODO>
- <EntryPosition>2,-3,0<\EntryPosition>
- <ExitPosition>-2,-3,0<\ExitPosition>
- <SectionRadius>0.2<\SectionRadius>
- <StraightLenght>1.<\StraightLenght>
- <FocalizingCoefficient>1.2<\FocalizingCoefficient>
+ <EntryPosition>
+ 2,-3,0
+ <\EntryPosition>
+ <ExitPosition>
+ -2,-3,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.2
+ <\SectionRadius>
+ <StraightLenght>
+ 1.
+ <\StraightLenght>
+ <FocalizingCoefficient>
+ 1.2
+ <\FocalizingCoefficient>
<\FODO>
<Dipole>
- <EntryPosition>-2,-3,0<\EntryPosition>
- <ExitPosition>-3,-2,0<\ExitPosition>
- <SectionRadius>0.1<\SectionRadius>
- <Curvature>1.<\Curvature>
- <MagneticField>0,0,5.89158<\MagneticField>
+ <EntryPosition>
+ -2,-3,0
+ <\EntryPosition>
+ <ExitPosition>
+ -3,-2,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.1
+ <\SectionRadius>
+ <Curvature>
+ 1.
+ <\Curvature>
+ <MagneticField>
+ 0,0,5.89158
+ <\MagneticField>
<\Dipole>
<FODO>
- <EntryPosition>-3,-2,0<\EntryPosition>
- <ExitPosition>-3,2,0<\ExitPosition>
- <SectionRadius>0.2<\SectionRadius>
- <StraightLenght>1.<\StraightLenght>
- <FocalizingCoefficient>1.2<\FocalizingCoefficient>
+ <EntryPosition>
+ -3,-2,0
+ <\EntryPosition>
+ <ExitPosition>
+ -3,2,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.2
+ <\SectionRadius>
+ <StraightLenght>
+ 1.
+ <\StraightLenght>
+ <FocalizingCoefficient>
+ 1.2
+ <\FocalizingCoefficient>
<\FODO>
<Dipole>
- <EntryPosition>-3,2,0<\EntryPosition>
- <ExitPosition>-2,3,0<\ExitPosition>
- <SectionRadius>0.1<\SectionRadius>
- <Curvature>1.<\Curvature>
- <MagneticField>0,0,5.89158<\MagneticField>
+ <EntryPosition>
+ -3,2,0
+ <\EntryPosition>
+ <ExitPosition>
+ -2,3,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.1
+ <\SectionRadius>
+ <Curvature>
+ 1.
+ <\Curvature>
+ <MagneticField>
+ 0,0,5.89158
+ <\MagneticField>
<\Dipole>
<FODO>
- <EntryPosition>-2,3,0<\EntryPosition>
- <ExitPosition>2,3,0<\ExitPosition>
- <SectionRadius>0.2<\SectionRadius>
- <StraightLenght>1.<\StraightLenght>
- <FocalizingCoefficient>1.2<\FocalizingCoefficient>
+ <EntryPosition>
+ -2,3,0
+ <\EntryPosition>
+ <ExitPosition>
+ 2,3,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.2
+ <\SectionRadius>
+ <StraightLenght>
+ 1.
+ <\StraightLenght>
+ <FocalizingCoefficient>
+ 1.2
+ <\FocalizingCoefficient>
<\FODO>
<Dipole>
- <EntryPosition>2,3,0<\EntryPosition>
- <ExitPosition>3,2,0<\ExitPosition>
- <SectionRadius>0.1<\SectionRadius>
- <Curvature>1.<\Curvature>
- <MagneticField>0,0,5.89158<\MagneticField>
+ <EntryPosition>
+ 2,3,0
+ <\EntryPosition>
+ <ExitPosition>
+ 3,2,0
+ <\ExitPosition>
+ <SectionRadius>
+ 0.1
+ <\SectionRadius>
+ <Curvature>
+ 1.
+ <\Curvature>
+ <MagneticField>
+ 0,0,5.89158
+ <\MagneticField>
<\Dipole>
<\Accelerator>
<\System> \ No newline at end of file
diff --git a/src/test/simulationTest.cc b/src/test/simulationTest.cc
new file mode 100644
index 0000000..b9ac1a4
--- /dev/null
+++ b/src/test/simulationTest.cc
@@ -0,0 +1,32 @@
+/*
+ * simulationTest.cc
+ *
+ * Created on: 28 mai 2011
+ * Author: christian
+ */
+#include <iostream>
+#include "Parser.h"
+#include "Accelerator.h"
+#include "exceptions.h"
+
+using namespace std;
+using namespace vhc;
+
+int main(){
+ try{
+ Parser pars("simulation.xml");
+
+ Accelerator* a = pars.extract();
+
+ cout<< *a <<endl;
+
+ a->clear();
+
+ delete a;
+ }
+ catch(Exception const& ex){
+ cout<<ex.getExceptionType()<<endl
+ <<ex.getMessage()<<endl;
+ }
+ return 0;
+}