Changeset 342 in PSPA for Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc
- Timestamp:
- Feb 26, 2013, 2:35:45 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc
r341 r342 11 11 #include <stdio.h> 12 12 #include <fstream> 13 //#include <algorithm>14 15 13 16 14 dataManager::dataManager(PspaApplication* pspa) : 17 currentBeam_(NULL) 18 ,pspa_ ( pspa) 19 { 20 // workingDir_ = pspa_->getWorkingDir(); 21 } 22 23 24 dataManager::~dataManager() { 25 unsigned k; 26 for (k=0; k < jobList_.size();k++) { 27 if ( jobList_[k] != NULL ) delete jobList_[k]; 28 } 29 if ( currentBeam_ == NULL ) delete currentBeam_; 15 currentBeam_(NULL), 16 pspa_ (pspa) 17 {} 18 19 dataManager::~dataManager() 20 { 21 unsigned k; 22 for (k=0; k < jobList_.size();k++) { 23 if ( jobList_[k] != NULL ) delete jobList_[k]; 24 } 25 if ( currentBeam_ == NULL ) delete currentBeam_; 30 26 } 31 27 32 28 void dataManager::consoleMessage(string message) { 33 34 35 29 GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); 30 if (console) console->addConsoleMessage(message); 31 pspa_->processEvents(); 36 32 } 37 33 … … 44 40 45 41 46 int dataManager::getNumeroFromElementLabel(string label){ 47 int index = -1; 48 unsigned int k; 49 50 for (k = 0; k < getBeamLineSize() ; k++) 51 { 52 if (pspa_->getBeamLine()->getAbstractElement(k) != NULL){ 53 if ( pspa_->getBeamLine()->getAbstractElement(k)->getLabel() == label ) 54 { 55 index = (int)k + 1; 56 return index; 57 } 58 } 59 } 60 return index; 61 } 62 63 64 abstractElement* dataManager::getElementPointerFromNumero(int k){ 65 return pspa_->getBeamLine()->getAbstractElement(k-1); 42 int dataManager::getNumeroFromElementLabel(string label) 43 { 44 int index = -1; 45 46 for (int k = 0; k < getBeamLineSize() ; k++) 47 { 48 if (pspa_->getBeamLine()->getAbstractElement(k) != NULL){ 49 if ( pspa_->getBeamLine()->getAbstractElement(k)->getLabel() == label ) 50 { 51 index = (int)k + 1; 52 return index; 53 } 54 } 55 } 56 return index; 57 } 58 59 60 abstractElement* dataManager::getElementPointerFromNumero(int k) 61 { 62 return pspa_->getBeamLine()->getAbstractElement(k-1); 66 63 } 67 64 … … 69 66 void dataManager::addSectionToExecute(int debut, int fin, nomDeLogiciel prog) 70 67 { 71 72 73 74 68 jobList_.push_back(new sectionToExecute); 69 jobList_.back()->firstElement = debut; 70 jobList_.back()->lastElement = fin; 71 jobList_.back()->software = prog; 75 72 } 76 73 77 74 void dataManager::clearSectionToExecute() 78 75 { 79 80 81 { 82 83 } 84 76 unsigned k; 77 for(k = 0; k < jobList_.size(); k++) 78 { 79 if ( jobList_[k] != NULL ) delete jobList_[k]; 80 } 81 jobList_.clear(); 85 82 } 86 83 87 84 trivaluedBool dataManager::checkExecute(string& diagnostic) 88 85 { 89 cout << "dataManager::checkExecute()" << endl; 90 consoleMessage(" VERIFICATION AVANT EXECUTION "); 91 // console_ = static_cast<GWt_console*> (wApp->findWidget ("console")); 92 // if (console_) console_->addConsoleMessage(" VERIFICATION AVANT EXECUTION "); 93 86 cout << "dataManager::checkExecute()" << endl; 87 consoleMessage(" VERIFICATION AVANT EXECUTION "); 88 94 89 trivaluedBool resul = ok; 95 unsigned k,j;96 90 diagnostic.clear(); 97 unsigned numeroDeb, numeroFin; 98 cout << "controle execution : " << endl; 99 for(k = 0; k < jobList_.size(); k++) { 100 numeroDeb = jobList_[k]->firstElement; 101 numeroFin = jobList_[k]->lastElement; 102 if ( numeroFin < numeroDeb ) 103 { 104 diagnostic += " last element before first for job " + (jobList_[k]->software).getString() + " \n"; 105 resul = error; 106 break; 107 } 108 cout << " numeroDeb= " << numeroDeb << " numeroFin= " << numeroFin << endl; 109 // indexDeb--; 110 // indexFin--; 111 112 abstractElement* elPtr; 91 92 for(unsigned k = 0; k < jobList_.size(); k++) { 93 94 unsigned numeroDeb = jobList_[k]->firstElement; 95 unsigned numeroFin = jobList_[k]->lastElement; 96 97 if ( numeroFin < numeroDeb ) { 98 diagnostic += " last element before first for job " + (jobList_[k]->software).getString() + " \n"; 99 resul = error; 100 break; 101 } 102 113 103 string checkCompatibility; 114 resul = checkElementsForExec(jobList_[k]->software, numeroDeb, numeroFin,checkCompatibility);104 resul = checkElementsForExec(jobList_[k]->software,numeroDeb,numeroFin,checkCompatibility); 115 105 diagnostic += checkCompatibility; 106 } //k 107 108 return resul; 109 } 110 111 trivaluedBool dataManager::checkElementsForExec(nomDeLogiciel logiciel,unsigned numeroDeb,unsigned numeroFin,string& diagnostic) 112 { 113 trivaluedBool resul = ok; 114 trivaluedBool accepted; 115 116 diagnostic.clear(); 117 abstractElement* elPtr; 118 119 for(unsigned j = numeroDeb; j <= numeroFin; j++) { 120 elPtr = pspa_->getBeamLine()->getAbstractElement(j-1); 121 accepted = elPtr->is_accepted_by_software(logiciel); 122 123 if(accepted == error) { 124 diagnostic += " the element " + elPtr->getNomdElement().getElementName() + " is not allowed with " + logiciel.getString() + " \n"; 125 resul = error; 126 } else if (accepted == warning) { 127 diagnostic += " the element " + elPtr->getNomdElement().getElementName() + " will be ignored by " + logiciel.getString() + " \n"; 128 if ( resul != error ) resul = warning; 129 } 116 130 } 117 cout << " data manager renvoie resul = " << resul << endl; 131 118 132 return resul; 119 133 } 120 121 122 trivaluedBool dataManager::checkElementsForExec(nomDeLogiciel logiciel, unsigned numeroDeb, unsigned numeroFin, string& diagnostic)123 {124 trivaluedBool resul = ok;125 diagnostic.clear();126 trivaluedBool accepted;127 abstractElement* elPtr;128 for(unsigned j = numeroDeb; j <= numeroFin; j++) {129 elPtr = pspa_->getBeamLine()->getAbstractElement(j-1);130 accepted = elPtr->is_accepted_by_software(logiciel);131 if(accepted == error ) {132 diagnostic += " the element " + elPtr->getNomdElement().getElementName() + " is not allowed with " + logiciel.getString() + " \n";133 resul = error;134 } else if ( accepted == warning ) {135 diagnostic += " the element " + elPtr->getNomdElement().getElementName() + " will be ignored by " + logiciel.getString() + " \n";136 if ( resul != error ) resul = warning;137 }138 }139 return resul;140 }141 142 143 144 134 145 135 void dataManager::initializeExecution() … … 174 164 bool dataManager::executeAll() 175 165 { 176 177 // resul.clear();178 // string resultatPartiel;179 unsigned k; 180 abstractSoftware* softw =NULL;181 string workingDir = pspa_->getWorkingDir();182 for(k = 0; k < jobList_.size(); k++)183 {166 bool success = true; 167 abstractSoftware* softw = NULL; 168 string workingDir = pspa_->getWorkingDir(); 169 170 for(unsigned k = 0; k < jobList_.size(); k++) 171 { 172 cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->software).getString() << endl; 173 184 174 int debut = jobList_[k]->firstElement; 185 175 int fin = jobList_[k]->lastElement; 186 cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->software).getString() << endl; 187 188 softw = createSoftwareConnexion(jobList_[k]->software ); 189 190 if ( softw == NULL ) { 176 softw = createSoftwareConnexion(jobList_[k]->software); 177 178 if (softw == NULL) { 191 179 success = false; 192 180 consoleMessage("dataManager::executeAll : unknown software"); 193 // resultatPartiel = " unknown software -- STOP \n ";194 181 break; 195 182 } 196 183 197 success = softw->createInputFile(currentBeam_, debut, fin,workingDir);184 success = softw->createInputFile(currentBeam_,debut,fin,workingDir); 198 185 if ( success ) { 199 186 success = softw->execute(debut,fin,workingDir); 200 187 if ( success ) { 201 success = softw->buildBeamAfterElements(debut, fin, diagnosticBeam_,workingDir);188 success = softw->buildBeamAfterElements(debut,fin,diagnosticBeam_,workingDir); 202 189 } 203 190 } 191 204 192 delete softw; 205 193 if ( success ) { … … 211 199 } 212 200 if ( !success ) break; 213 } 214 return success; 215 } 216 201 202 //debug 203 cout << "dataManager::executeAll #diagnosticBeam= " << diagnosticBeam_.size() << endl; 204 cout << "dataManager::executeAll #getBeamLineSize()= " << getBeamLineSize() << endl; 205 for (int j = debut; j <= fin; j++) { 206 abstractElement* elPtr= getElementPointerFromNumero(j); 207 cout << "[" << j << "] " << elPtr->getNomdElement().getElementName() << endl; 208 } 209 210 } //k 211 212 return success; 213 } 217 214 218 215 void dataManager::saveConfiguration( string nameOfCase) 219 216 { 220 ofstream outfile; 221 string name = pspa_->getWorkingDir() + nameOfCase + ".save"; 222 outfile.open(name.c_str(), ios::out); 223 if (!outfile) { 224 cerr << " error opening output file for persistency " << name << endl; 225 } 226 227 outfile << globParam_.FileOutputFlow(); 228 unsigned k; 229 abstractElement* elPtr; 230 for ( k=0 ; k < getBeamLineSize() ; k++) 231 { 232 elPtr = pspa_->getBeamLine()->getAbstractElement(k); 233 outfile << elPtr->FileOutputFlow(); 234 } 235 outfile.close(); 236 } 237 217 ofstream outfile; 218 string name = pspa_->getWorkingDir() + nameOfCase + ".save"; 219 outfile.open(name.c_str(), ios::out); 220 if (!outfile) { 221 cerr << " error opening output file for persistency " << name << endl; 222 } 223 224 outfile << globParam_.FileOutputFlow(); 225 abstractElement* elPtr; 226 for(unsigned k = 0; k < getBeamLineSize() ; k++) 227 { 228 elPtr = pspa_->getBeamLine()->getAbstractElement(k); 229 outfile << elPtr->FileOutputFlow(); 230 } 231 outfile.close(); 232 } 238 233 239 234 bool dataManager::restoreElements( string inputFileName) … … 281 276 282 277 // debug 283 unsigned k; 284 for(k = 0; k < getBeamLineSize(); k++) { 285 abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(k); 278 // unsigned k; 279 // for(k = 0; k < getBeamLineSize(); k++) { 280 // abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(k); 281 // cout << "reupere " << ptr->getLabel() << endl; 282 // } 283 return true; 284 } 285 286 particleBeam* dataManager::getDiagnosticBeam(unsigned index) 287 { 288 if (index >= diagnosticBeam_.size()) { 289 return NULL; 290 } else { 291 return &diagnosticBeam_.at(index); 292 } 293 } 294 295 void dataManager::donneesRmsEnveloppe(string type,unsigned int numeroDeb,unsigned int numeroFin, vector<double>& xcor,vector<double>& ycor) 296 { 297 unsigned k; 298 if ( numeroDeb < 1 ) numeroDeb = 1; 299 if ( numeroFin > diagnosticBeam_.size() ) numeroFin = diagnosticBeam_.size(); 286 300 287 cout << "reupere " << ptr->getLabel() << endl; 288 } 289 return true; 290 } 291 292 293 particleBeam* dataManager::getDiagnosticBeam(unsigned index) 294 { 295 296 297 if ( index >= diagnosticBeam_.size() ) { 298 return NULL; 299 } 300 else { 301 return &diagnosticBeam_.at(index); 302 } 303 } 304 305 306 void dataManager::donneesRmsEnveloppe( string type, unsigned int numeroDeb, unsigned int numeroFin, vector<double>& xcor, vector<double>& ycor) 307 { 308 unsigned k; 309 if ( numeroDeb < 1 ) numeroDeb = 1; 310 if ( numeroFin > diagnosticBeam_.size() ) numeroFin = diagnosticBeam_.size(); 311 312 double longueur = 0.0; 313 double valeur = 0.0; 314 xcor.clear(); 315 ycor.clear(); 316 if ( type == "x" ) 317 { 318 for (k= numeroDeb; k <= numeroFin; k++) 301 double longueur = 0.0; 302 double valeur = 0.0; 303 xcor.clear(); 304 ycor.clear(); 305 if ( type == "x" ) 306 { 307 for (k= numeroDeb; k <= numeroFin; k++) 319 308 { 320 321 322 323 324 309 if ( !diagnosticBeam_.at(k-1).momentRepresentationOk() ) diagnosticBeam_.at(k-1).buildMomentRepresentation(); 310 longueur += pspa_->getBeamLine()->getAbstractElement(k-1)->getLenghtOfElement(); 311 valeur = diagnosticBeam_.at(k-1).getXmaxRms(); 312 xcor.push_back(longueur); 313 ycor.push_back(valeur); 325 314 } 326 315 } 327 else 328 { 329 cerr << " dataManager::donneesRmsEnveloppe type " << type << " not programmed " << endl; 330 return; 331 } 316 else 317 { 318 cerr << " dataManager::donneesRmsEnveloppe type " << type << " not programmed " << endl; 319 return; 320 } 321 } 322 323 // on ne tient pas compte des elements "snapshot" presents dans la beamLine 324 void dataManager::donneesRmsEnveloppe(string type,unsigned int lineSize,vector<double>& xcor,vector<double>& ycor) 325 { 326 double longueur = 0.0; 327 double valeur = 0.0; 328 xcor.clear(); 329 ycor.clear(); 330 331 if ( type == "x" ) { 332 unsigned i = 0; 333 for (unsigned k = 0; k < lineSize; k++) { 334 abstractElement* elPtr = pspa_->getBeamLine()->getAbstractElement(k); 335 if(elPtr->getNomdElement().getElementType() == snapshot) { 336 cout << "TOP 1" << endl; 337 continue; 338 } 339 340 if ( !diagnosticBeam_.at(i).momentRepresentationOk() ) { 341 diagnosticBeam_.at(i).buildMomentRepresentation(); 342 } 343 344 longueur += elPtr->getLenghtOfElement(); 345 valeur = diagnosticBeam_.at(i).getXmaxRms(); 346 xcor.push_back(longueur); 347 ycor.push_back(valeur); 348 i++; 349 } 350 } else { 351 cerr << " dataManager::donneesRmsEnveloppe type " << type << " not programmed " << endl; 352 return; 353 } 332 354 } 333 355 334 356 int dataManager::getBeamLineSize() { 335 return pspa_->getBeamLine()->getBeamLineSize(); 336 } 337 338 abstractSoftware* dataManager::createSoftwareConnexion(nomDeLogiciel logi) { 339 340 string inputFileName; 341 if(logi == nomDeLogiciel::parmela) { 342 inputFileName = "parmin"; 343 return new softwareParmela(inputFileName, &globParam_, this); 344 } else if (logi == nomDeLogiciel::transport) { 345 inputFileName = "transport.input"; 346 return new softwareTransport(inputFileName, &globParam_, this); 347 } else if (logi == nomDeLogiciel::generator) { 348 inputFileName = "generator.in"; 349 return new softwareGenerator(inputFileName, &globParam_, this); 350 } else if (logi == nomDeLogiciel::test) { 351 return new softwareTest(inputFileName, &globParam_, this); 352 } else { 353 return NULL; 354 } 355 356 } 357 return pspa_->getBeamLine()->getBeamLineSize(); 358 } 359 360 abstractSoftware* dataManager::createSoftwareConnexion(nomDeLogiciel logi) 361 { 362 string inputFileName; 363 if(logi == nomDeLogiciel::parmela) { 364 inputFileName = "parmin"; 365 return new softwareParmela(inputFileName, &globParam_, this); 366 } else if (logi == nomDeLogiciel::transport) { 367 inputFileName = "transport.input"; 368 return new softwareTransport(inputFileName, &globParam_, this); 369 } else if (logi == nomDeLogiciel::generator) { 370 inputFileName = "generator.in"; 371 return new softwareGenerator(inputFileName, &globParam_, this); 372 } else if (logi == nomDeLogiciel::test) { 373 return new softwareTest(inputFileName, &globParam_, this); 374 } else { 375 return NULL; 376 } 377 }
Note: See TracChangeset
for help on using the changeset viewer.