Changeset 442 in PSPA for Interface_Web/trunk/pspaWT/sources/controler/src/particleBeam.cc
- Timestamp:
- Dec 11, 2013, 9:33:35 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/src/particleBeam.cc
r435 r442 5 5 #include "mathematicalTools.h" 6 6 #include "mixedTools.h" 7 8 #include "UAP/UAPUtilities.hpp" 9 #include "AML/AMLReader.hpp" 7 10 8 11 #include <stdio.h> … … 203 206 sortie << endl; 204 207 return sortie.str(); 208 } 209 210 211 void particleBeam::writeToAMLFile(string fileName) { 212 UAPNode* uap_root = new UAPNode("UAP_root"); 213 UAPNode* rep = uap_root->addChild("AML_representation"); 214 215 // root node in the hierarchy 216 UAPNode* lab = rep->addChild("laboratory"); 217 lab->addAttribute("name","PSPA lab"); 218 219 220 221 // root node in the hierarchy 222 UAPNode* par = lab->addChild("particles"); 223 par->addAttribute("name","PSPA particles"); 224 225 unsigned int k; 226 if ( particleRepresentationOk_ ) { 227 for ( k = 0 ; k < relativePartic_.size(); k++) 228 { 229 TRIDVECTOR& position = relativePartic_.at(k).getReferenceToPosition(); 230 TRIDVECTOR& betgam = relativePartic_.at(k).getReferenceToBetaGamma(); 231 UAPNode* partic = par->addChild("particle"); 232 string txt; 233 txt = mixedTools::doubleToString(position.getComponent(0)); 234 partic->addAttribute("x",txt); 235 txt = mixedTools::doubleToString(position.getComponent(1)); 236 partic->addAttribute("y",txt); 237 txt = mixedTools::doubleToString(position.getComponent(2)); 238 partic->addAttribute("cdeltat",txt); 239 txt = mixedTools::doubleToString(betgam.getComponent(0)); 240 partic->addAttribute("betagamma_x",txt); 241 txt = mixedTools::doubleToString(betgam.getComponent(1)); 242 partic->addAttribute("betagamma_y",txt); 243 txt = mixedTools::doubleToString(betgam.getComponent(2)); 244 partic->addAttribute("betagamma_z",txt); 245 } 246 247 } else { 248 cout << " particleBeam::writeToAMLFile : representation 'particules' indisponible" << endl; 249 } 250 251 cout << "!Create the AML particle file ---------------------------" << endl; 252 AMLReader reader; 253 reader.AMLRepToAMLFile (uap_root, fileName); 254 255 } 256 257 bool particleBeam::readFromAMLFile(string fileName) { 258 259 cout << "!read the AML particle file ---------------------------" << endl; 260 AMLReader reader; 261 UAPNode* uap_root = NULL; 262 uap_root = reader.AMLFileToAMLRep (fileName); 263 if ( !uap_root ) { 264 cout << " particleBeam::readFromAMLFile ERREUR lecture fichier particules " << endl; 265 return false; 266 } 267 268 269 NodeVec lesParticules = uap_root->getSubNodesByName(string("particles")); 270 271 NodeVec& listPart = (*lesParticules.begin())->getChildren(); 272 273 if ( !listPart.size() ) { 274 cout << " particleBeam::readFromAMLFile ERREUR lecture fichier : pas de particules ? " << endl; 275 return false; 276 } 277 278 vector<bareParticle> vecteurParticules; 279 bareParticle reference; 280 for (NodeVecIter iter = listPart.begin(); iter != listPart.end(); iter++) { 281 TRIDVECTOR position, betagamma; 282 UAPAttribute* att = NULL; 283 att = (*iter)->getAttribute("x"); 284 if ( att ) att->getDouble(position.component(0)); 285 att = (*iter)->getAttribute("y"); 286 if ( att ) att->getDouble(position.component(1)); 287 att = (*iter)->getAttribute("cdeltat"); 288 if ( att ) att->getDouble(position.component(2)); 289 290 att = (*iter)->getAttribute("betagamma_x"); 291 if ( att ) att->getDouble(betagamma.component(0)); 292 att = (*iter)->getAttribute("betagamma_y"); 293 if ( att ) att->getDouble(betagamma.component(1)); 294 att = (*iter)->getAttribute("betagamma_z"); 295 if ( att ) att->getDouble(betagamma.component(2)); 296 297 if ( fabs(position.component(0)) < PETIT && fabs(position.component(1)) < PETIT && fabs(position.component(2)) < PETIT ) { 298 reference = bareParticle(position, betagamma); 299 } 300 vecteurParticules.push_back(bareParticle(position, betagamma)); 301 } 302 vector<double> centroid(6,0.0); 303 setWithParticles(centroid, reference, vecteurParticules); 304 return true; 205 305 } 206 306
Note: See TracChangeset
for help on using the changeset viewer.