Changeset 295 in PSPA for Interface_Web
- Timestamp:
- Jan 29, 2013, 6:53:32 PM (12 years ago)
- Location:
- Interface_Web/trunk/pspaWT/sources/controler
- Files:
-
- 7 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/include/dataManager.h
r257 r295 11 11 #include "trivaluedBool.h" 12 12 #include "beam2Moments.h" 13 14 typedef struct 15 { 16 float xx, xxp, begamx,yy,yyp,begamy,z, begamz,phi,wz; 17 float phi0, ksi1,ksi2,ksi3; 18 int ne,np,ngood,npart; 19 20 int readFromParmelaFile(FILE* fp) 21 { 22 return fscanf(fp, " %e %e %e %e %e %e %e %e %e %e %d %d %d %d %e %e %e %e \n", &xx, &xxp, &begamx,&yy,&yyp,&begamy,&z, &begamz,&phi,&wz,&ne,&np,&ngood,&npart,&phi0, &ksi1,&ksi2,&ksi3); 23 } 24 void imprim() 25 { 26 printf( " %e %e %e %e %e %e %e %e %e %e %d %d %d, %d %e %e %e %e \n", xx, xxp, begamx,yy,yyp,begamy,z, begamz,phi,wz,ne,np,ngood,npart,phi0, ksi1,ksi2,ksi3); 27 } 28 } parmelaParticle; 13 #include "parmelaParticle.h" 29 14 30 15 … … 41 26 vector<sectionToExecute*> jobList_; 42 27 43 bool createInputFileParmela( unsigned int numeroDeb, unsigned int numerpFin, string workingDir);44 bool createInputFileTransport( unsigned int numeroDeb, unsigned int numeroFin, string workingDir);45 28 void removeFile(string nameOfFile); 46 29 void clearSectionToExecute(); 47 bool moments2FromTransport(string workingDir, string elLab, const nomdElements elem, beam2Moments& moments) const;48 bool beamFromParmela(string workingDir,unsigned numeroElement, double referencefrequency, vector<double>& centroid, bareParticle& refPart,vector<bareParticle>& particles );49 30 public: 50 31 … … 72 53 trivaluedBool checkExecute(string& diagnostic); 73 54 trivaluedBool checkElementsForExec(nomDeLogiciel logiciel, unsigned indexDeb, unsigned indexFin, string& diagnostic); 74 bool executeTransport( unsigned int numeroDeb, unsigned int numeroFin, string workingDir, string& resul);75 bool executeParmela( unsigned int numeroDeb, unsigned int numeroFin, string workingDir, string& resul);76 bool launchJob(string commandLine, string& resul);77 55 bool executeAll(string workingDir, string& resul); 78 56 void saveConfiguration(string workingDir, string nameOfFile); -
Interface_Web/trunk/pspaWT/sources/controler/include/elementsCollection.h
r257 r295 21 21 22 22 void raz(); 23 unsigned size() ;23 unsigned size() const; 24 24 abstractElement* addElement(typedElement elemType); 25 25 abstractElement* getElementPointer(string label) const; -
Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc
r257 r295 2 2 #include "mathematicalConstants.h" 3 3 #include "PhysicalConstants.h" 4 #include "softwareParmela.h" 5 #include "softwareTransport.h" 4 6 5 7 #include <stdio.h> … … 89 91 90 92 91 bool dataManager::launchJob(string commandLine, string& resul) 92 { 93 ostringstream sortie; 94 bool ExecuteStatus = true; 95 FILE* pp = popen(commandLine.c_str(), "r"); 96 if (pp == NULL) { 97 sortie << " launching failed : " << commandLine << endl; 98 ExecuteStatus = false; 99 } 100 else { 101 cout << " executind command : " << commandLine << endl; 102 // on copie la sortie dans le fichier assigne 103 char buf[132]; 104 while (fgets(buf, sizeof buf, pp)) 105 { 106 sortie << buf; 107 } 108 pclose(pp); 109 } 110 resul = sortie.str(); 111 return ExecuteStatus; 112 } 113 114 bool dataManager::executeTransport( unsigned int numeroDeb, unsigned int numeroFin, string workingDir, string& resul) 115 { 116 ostringstream sortie; 117 resul.clear(); 118 sortie << " EXECUTION DE TRANSPORT DE " << numeroDeb << " a " << numeroFin << endl; 119 if ( !createInputFileTransport( numeroDeb, numeroFin, workingDir) ) 120 { 121 sortie << " error creating transport input file " << endl; 122 resul = sortie.str(); 123 return false; 124 } 125 126 bool ExecuteStatus = true; 127 string bufString; 128 char buf[132]; 129 string transportJob = workingDir + "transport"; 130 transportJob += string(" < "); 131 transportJob += workingDir + "transport.input"; 132 // transportJob += string(" > "); 133 // transportJob += WORKINGAREA + "transport.output"; 134 cout << " job transport= " << transportJob << endl; 135 136 ofstream outfile; 137 string nameOut = workingDir + "transport.output"; 138 139 140 // FILE* pp = popen(transportJob.c_str(), "r"); 141 142 string resultOfRun; 143 // if (pp == NULL) { 144 bool success = launchJob(transportJob, resultOfRun); 145 sortie << resultOfRun << endl; 146 if ( !success) { 147 sortie << " launching of transport failed " << endl; 148 ExecuteStatus = false; 149 } 150 else { 151 cout << " execution transport MARCHE " << endl; 152 outfile.open(nameOut.c_str(), ios::out); 153 if (!outfile) 154 { 155 sortie << " error first opening transport output stream " << nameOut << endl; 156 ExecuteStatus = false; 157 } 158 else { 159 // on copie la sortie dans un fichier 'transport.out' 160 outfile << resultOfRun << endl; 161 // while (fgets(buf, sizeof buf, pp)) 162 // { 163 // // cout << " buf= " << buf << endl; 164 // sortie << buf; 165 // outfile << buf; 166 // // nbl++; 167 // } 168 outfile.close(); 169 unsigned k; 170 for ( k= numeroDeb; k <= numeroFin; k++) 171 { 172 diagnosticBeam_.push_back(particleBeam()); 173 string elemLabel = getLabelFromElementNumero (k); 174 abstractElement* ptr = elementsGallery_.getElementPointerFromNumero(k); 175 176 177 beam2Moments transpMoments; 178 179 if (!moments2FromTransport(workingDir, elemLabel, ptr->getNomdElement(),transpMoments ) ) 180 { 181 sortie << " reading transport output failed " << endl; 182 ExecuteStatus = false; 183 break; 184 } 185 diagnosticBeam_.back().set2Moments(transpMoments); 186 } 187 if ( ExecuteStatus ) currentBeam_ = &diagnosticBeam_.back(); 188 else currentBeam_ = NULL; 189 } 190 // pclose(pp); 191 } 192 resul = sortie.str(); 193 return ExecuteStatus; 194 } 195 196 bool dataManager::executeParmela(unsigned int numeroDeb,unsigned int numeroFin,string workingDir,string& resul) 197 { 198 ostringstream sortie; 199 bool ExecuteStatus = true; 200 resul.clear(); 201 if ( !createInputFileParmela(numeroDeb,numeroFin, workingDir) ) 202 { 203 sortie << " error creating parmela input file " << endl; 204 resul = sortie.str(); 205 return false; 206 } 207 208 sortie << " EXECUTION DE PARMELA DE l'ELEMENT " << numeroDeb << " A L'ELEMENT " << numeroFin << endl; 209 210 char buf[132]; 211 string parmelaJob = workingDir + "parmela"; 212 parmelaJob += string(" "); 213 parmelaJob += workingDir; 214 // cout << " job parmela= " << parmelaJob << endl; 215 216 string resultOfRun; 217 bool success = launchJob(parmelaJob, resultOfRun); 218 sortie << resultOfRun << endl; 219 if ( !success) { 220 sortie << " launching of parmela failed " << endl; 221 ExecuteStatus = false; 222 } 223 else { 224 cout << " execution parmela MARCHE " << endl; 225 sortie << resultOfRun; 226 string::size_type nn = (resultOfRun).find("normal"); 227 if ( nn == string::npos ) 228 { 229 sortie << " abnormal exit of parmela " << endl; 230 ExecuteStatus = false; 231 } 232 else 233 { 234 unsigned k; 235 for ( k= numeroDeb; k <= numeroFin; k++) 236 { 237 diagnosticBeam_.push_back(particleBeam()); 238 vector<double> centroid; 239 bareParticle refPart; 240 vector<bareParticle> particles; 241 if (!beamFromParmela(workingDir,k, globParam_.getFrequency(), centroid, refPart,particles )) 242 { 243 abstractElement* elem = elementsGallery_.getElementPointerFromNumero(k); 244 if ( elem->is_accepted_by_software(nomDeLogiciel::parmela) == warning) { 245 int avantDernier = diagnosticBeam_.size() -2; 246 diagnosticBeam_.back() = diagnosticBeam_.at(avantDernier); 247 } else { 248 sortie << " reading parmdesz failed " << endl; 249 ExecuteStatus = false; 250 break; 251 } 252 } 253 diagnosticBeam_.back().setWithParticles(centroid, refPart,particles); 254 } 255 256 if ( ExecuteStatus ) currentBeam_ = &diagnosticBeam_.back(); 257 else currentBeam_ = NULL; 258 } 259 // pclose(pp); 260 } 261 262 resul = sortie.str(); 263 return ExecuteStatus; 264 } 265 266 bool dataManager::createInputFileTransport( unsigned int numeroDeb, unsigned int numeroFin, string workingDir) 267 { 268 unsigned int k; 269 if ( numeroDeb < 1 || numeroFin > elementsGallery_.size() ) { 270 cerr << " numero of element out of limits " << endl; 271 return false; 272 } 273 274 unsigned indexDeb = numeroDeb - 1; 275 unsigned indexFin = numeroFin - 1; 276 277 abstractElement* premierEl = NULL; 278 premierEl = elementsGallery_.getElementPointerFromIndex(indexDeb); 279 280 // ceinture et bretelles 281 if ( premierEl == NULL ) { 282 cerr << " premier element inexistant ?? " << endl; 283 return false; 284 } 285 286 287 ofstream outfile; 288 string name = workingDir + "transport.input"; 289 outfile.open(name.c_str(), ios::out); 290 if (!outfile) 291 { 292 cerr << " error opening output stream " << name << endl; 293 return false; 294 } 295 296 outfile << string("'titre provisoire'") << endl; 297 outfile << " 0 " << endl; 298 outfile << " UTRANS " << endl; 299 300 301 // si le premier element a traiter est un 'beam', on ne fait rien pour l'instant 302 // il sera traite plus bas de maniere standard 303 304 // Dans le cas où le premier element n'est pas beam 305 if ( premierEl->getNomdElement().getElementType() != beam ) { 306 // s'il n'y a pas faisceau courant, erreur 307 if ( currentBeam_ == NULL ) { 308 cout << " pas de faisceau " << endl; 309 return false; 310 } 311 else { 312 // s'il y a un faisceau courant 313 if ( !currentBeam_->momentRepresentationOk() ) { 314 // s'il n'est pas au format transport (issu de parmela ?) 315 // on le met au format transport, s'il est deja au format 'particules' (par ex/ parmela) 316 if ( !currentBeam_->particleRepresentationOk() ) { 317 cout << " ca cafouille dans les representations de faisceau : ni particules, ni moments ? " << endl; 318 return false; 319 } 320 else { 321 currentBeam_->buildMomentRepresentation(); 322 } 323 } 324 // ici, en principe, on a un faisceau correct 325 // on ecrit sur le fichier input 326 const beam2Moments& moments = currentBeam_->getTransportMoments(); 327 double P0 = currentBeam_->getP0Transport(); 328 outfile << moments.writeToTransportInput(P0); 329 } 330 } 331 332 333 334 outfile << " PRINT, BEAM, ON; " << endl; 335 336 337 abstractElement* elPtr; 338 for ( k=indexDeb; k <= indexFin; k++) 339 { 340 elPtr = elementsGallery_.getElementPointerFromIndex(k); 341 outfile << elPtr->transportOutputFlow() << endl; 342 } 343 344 outfile << " SENTINEL " << endl; 345 outfile << " SENTINEL " << endl; 346 347 outfile.close(); 348 return true; 349 } 350 351 bool dataManager::createInputFileParmela( unsigned int numeroDeb, unsigned int numeroFin, string workingDir) 352 { 353 unsigned int k; 354 355 if ( numeroDeb < 1 || numeroFin > elementsGallery_.size() ) { 356 cerr << " index of element out of limits " << endl; 357 return false; 358 } 359 360 361 unsigned indexDeb = numeroDeb - 1; 362 unsigned indexFin = numeroFin - 1; 363 364 ofstream outfile; 365 string name = workingDir + "parmin"; 366 outfile.open(name.c_str(), ios::out); 367 if (!outfile) { 368 cerr << " error opening output stream " << name << endl; 369 return false; 370 } 371 372 abstractElement* elPtr; 373 double initalKineticEnergy = 0.0; 374 elPtr = elementsGallery_.getElementPointerFromIndex(indexDeb); 375 if ( elPtr->getNomdElement().getElementType() != RFgun ) { 376 cerr << " dataManager::createInputFileParmela : the first element should be rfgun" << endl; 377 return false; 378 } 379 else { 380 elPtr->setPhaseStep( globParam_.getIntegrationStep() ); 381 initalKineticEnergy = elPtr->getInitialKineticEnergy(); 382 } 383 384 385 outfile << "TITLE" << endl; 386 outfile << " titre provisoire " << endl; 387 outfile << "RUN /n0=1 /ip=999 /freq=" << globParam_.getFrequency() << " /z0=0.0 /W0=" << initalKineticEnergy << " /itype=1" << endl; 388 outfile << "OUTPUT 0" << endl; 389 390 for ( k = indexDeb; k <= indexFin; k++) 391 { 392 elPtr = elementsGallery_.getElementPointerFromIndex(k); 393 outfile << elPtr->parmelaOutputFlow() << endl; 394 } 395 396 outfile << "ZOUT" << endl; 397 outfile << "START /wt=0.0 /dwt=" << globParam_.getIntegrationStep() << " /nsteps=" << globParam_.getNbSteps() << " nsc=" << globParam_.getScPeriod() << " /nout=10" << endl; 398 outfile << "END" << endl; 399 outfile.close(); 400 return true; 401 } 93 402 94 403 95 void dataManager::initializeExecution(string workingDir) … … 428 120 string resultatPartiel; 429 121 unsigned k; 122 abstractSoftware* softw =NULL; 123 430 124 for(k = 0; k < jobList_.size(); k++) 431 125 { … … 436 130 437 131 if(jobList_[k]->software == nomDeLogiciel::parmela) { 438 s uccess = executeParmela( debut, fin, workingDir, resultatPartiel);132 softw = new softwareParmela(&globParam_, &elementsGallery_); 439 133 } else if (jobList_[k]->software == nomDeLogiciel::transport) { 440 s uccess = executeTransport( debut, fin, workingDir, resultatPartiel);134 softw = new softwareTransport(&globParam_, &elementsGallery_); 441 135 } else { 442 136 success = false; … … 444 138 break; 445 139 } 140 141 success = softw->createInputFile(currentBeam_, debut, fin, workingDir); 142 if ( !success ) { 143 resultatPartiel += " error creating input file "; 144 } else { 145 success = softw->execute(diagnosticBeam_, debut,fin,workingDir,resultatPartiel); 146 } 147 delete softw; 148 if ( success ) currentBeam_ = &diagnosticBeam_.back(); 149 else currentBeam_ = NULL; 446 150 resul += resultatPartiel; 447 151 if ( !success ) break; … … 569 273 } 570 274 571 bool dataManager::moments2FromTransport(string workingDir, string elLab, const nomdElements elem, beam2Moments& moments) const {572 573 string elementLabel = elLab;574 // transformer le label en majuscules ; je ne suis pas sur que ca575 // marchera a tous les coups (glm)576 std::transform(elementLabel.begin(), elementLabel.end(), elementLabel.begin(), (int (*)(int))std::toupper);577 578 cout << " dataManager::moments2FromTransport on cherche element " << elementLabel << endl;579 ifstream infile;580 string nameIn = workingDir + "transport.output";581 infile.open(nameIn.c_str(), ios::in);582 if (!infile) {583 cerr << " dataManager::moments2FromTransport : error re-opening transport output stream " << nameIn << endl;584 return false;585 }586 // else cout << " particleBeam::setFromTransport() : ouverture du fichier " << nameIn << endl;587 588 string::size_type nn = string::npos;589 string fichier;590 string buf;591 unsigned compteur = 0;592 while ( getline(infile, buf) ) {593 fichier += buf+"\n";594 nn = buf.find(elementLabel);595 if ( nn != string::npos ) {596 compteur++;597 // break;598 }599 }600 infile.close();601 cout << " compteur= " << compteur << endl;602 if ( compteur == 0 ) {603 cerr << " dataManager::moments2FromTransport : element " << elementLabel << " non trouve dans le fichier " << nameIn << endl;604 return false;605 }606 607 608 stringstream fichierStream(fichier);609 buf.clear();610 unsigned relu = 0;611 while ( std::getline(fichierStream, buf) ) {612 // cout << " relecture buffer : " << buf << endl;613 nn = buf.find(elementLabel);614 if ( nn != string::npos ) {615 relu++;616 if ( relu == compteur ) {617 cout << " TROUVE !" << endl;618 break;619 }620 }621 }622 moments.readFromTransportOutput(fichierStream);623 // impressionDesMoments();624 return true;625 626 }627 628 629 bool dataManager::beamFromParmela(string workingDir,unsigned numeroElement, double referencefrequency, vector<double>& centroid, bareParticle& refPart,vector<bareParticle>& particles ) {630 unsigned k;631 FILE* filefais;632 string nomfilefais = workingDir + "parmdesz";633 cout << " nom fichier desz : " << nomfilefais << endl;634 filefais = fopen(nomfilefais.c_str(), "r");635 636 if ( filefais == (FILE*)0 ) {637 cerr << " particleBeam::setFromParmela() erreur a l'ouverture du fichier" << nomfilefais << endl;;638 return false;639 }640 else cout << " particleBeam::setFromParmela() : ouverture du fichier " << nomfilefais << endl;641 642 parmelaParticle partic;643 std::vector<parmelaParticle> faisceau;644 645 cout << " particleBeam::setFromParmela : numeroElement = " << numeroElement << endl;646 unsigned indexElement = numeroElement-1;647 648 649 650 651 int testNombrePartRef =0;652 double phaseRef;653 654 while( partic.readFromParmelaFile(filefais) > 0 ) {655 if ( partic.ne == (int)indexElement )656 {657 faisceau.push_back(partic);658 659 if ( partic.np == 1 ) {660 // en principe on est sur la particule de reference661 if ( fabs(partic.xx) > EPSILON || fabs(partic.yy) > EPSILON || fabs(partic.xxp) > EPSILON || fabs(partic.yyp) > EPSILON) {662 printf(" ATTENTION part. reference douteuse \n");663 partic.imprim();664 }665 phaseRef = partic.phi;666 TRIDVECTOR posRef(partic.xx,partic.yy,0.0);667 TRIDVECTOR betagammaRef(partic.xxp*partic.begamz, partic.yyp*partic.begamz, partic.begamz);668 refPart = bareParticle(posRef, betagammaRef);669 testNombrePartRef++;670 if ( testNombrePartRef != 1 ) {671 cerr << " TROP DE PART. DE REF : " << testNombrePartRef << " !! " << endl;672 return false;673 }674 }675 }676 }677 678 if ( faisceau.size() == 0)679 {680 cerr << " particleBeam::setFromParmela echec lecture element " << numeroElement << endl;681 return false;682 }683 684 // facteur c/ 360. pour calculer (c dphi) / (360.freq)685 // avec freq en Mhz et dphi en degres et résultat en cm:686 double FACTEUR = 83.3333; // ameliorer la precision687 688 689 690 // pour l'instant on choisit un centroid nul;691 centroid.clear();692 centroid = vector<double>(6,0.0);693 694 particles.clear();695 particles.resize(faisceau.size(), bareParticle());696 double x,xp,y,yp;697 double betagammaz;698 double betaz;699 double deltaz;700 double dephas;701 double g;702 TRIDVECTOR pos;703 TRIDVECTOR betagamma;704 // contrairement a ce qu'indique la notice PARMELA, dans parmdesz, les xp et yp705 // sont donnes en radians706 for ( k=0; k < faisceau.size(); k++) {707 x=faisceau.at(k).xx;708 xp=faisceau.at(k).xxp;709 y=faisceau.at(k).yy;710 yp=faisceau.at(k).yyp;711 712 // dephasage par rapport a la reference713 dephas = faisceau.at(k).phi - phaseRef; // degrés714 g = faisceau.at(k).wz/ERESTMeV;715 betagammaz = faisceau.at(k).begamz;716 betaz = betagammaz/(g+1.0);717 deltaz = FACTEUR * betaz * dephas / referencefrequency;718 x += xp * deltaz;719 y += yp * deltaz;720 pos.setComponents(x,y,deltaz);721 betagamma.setComponents(xp*betagammaz, yp*betagammaz, betagammaz);722 particles.at(k) = bareParticle(pos,betagamma);723 }724 return true;725 } -
Interface_Web/trunk/pspaWT/sources/controler/src/elementsCollection.cc
r257 r295 28 28 } 29 29 30 unsigned elementsCollection::size() 30 unsigned elementsCollection::size() const 31 31 { 32 32 return elements_.size();
Note: See TracChangeset
for help on using the changeset viewer.