Changeset 359 in PSPA for Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc
- Timestamp:
- Mar 4, 2013, 6:08:02 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc
r357 r359 14 14 15 15 dataManager::dataManager(PspaApplication* pspa) : 16 17 16 currentBeam_(NULL), 17 pspa_ (pspa) 18 18 {} 19 19 20 dataManager::~dataManager() 21 { 22 unsigned k;23 for (k=0; k < jobList_.size();k++) {24 if ( jobList_[k] != NULL ) delete jobList_[k];25 }26 if ( currentBeam_ == NULL ) delete currentBeam_;20 dataManager::~dataManager() 21 { 22 unsigned k; 23 for (k=0; k < jobList_.size();k++) { 24 if ( jobList_[k] != NULL ) delete jobList_[k]; 25 } 26 if ( currentBeam_ == NULL ) delete currentBeam_; 27 27 } 28 28 29 29 void dataManager::consoleMessage(string message) { 30 GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console"));31 if (console) console->addConsoleMessage(message);32 pspa_->processEvents();30 GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); 31 if (console) console->addConsoleMessage(message); 32 pspa_->processEvents(); 33 33 } 34 34 … … 43 43 int dataManager::getNumeroFromElementLabel(string label) 44 44 { 45 int index = -1;46 47 for (int k = 0; k < getBeamLineSize() ; k++)45 int index = -1; 46 47 for (int k = 0; k < getBeamLineSize() ; k++) 48 48 { 49 if (pspa_->getBeamLine()->getAbstractElement(k) != NULL){50 51 52 53 54 55 }56 } 57 return index;49 if (pspa_->getBeamLine()->getAbstractElement(k) != NULL){ 50 if ( pspa_->getBeamLine()->getAbstractElement(k)->getLabel() == label ) 51 { 52 index = (int)k + 1; 53 return index; 54 } 55 } 56 } 57 return index; 58 58 } 59 59 … … 61 61 abstractElement* dataManager::getElementPointerFromNumero(int k) 62 62 { 63 return pspa_->getBeamLine()->getAbstractElement(k-1);63 return pspa_->getBeamLine()->getAbstractElement(k-1); 64 64 } 65 65 … … 67 67 void dataManager::addSectionToExecute(int debut, int fin, nomDeLogiciel prog) 68 68 { 69 jobList_.push_back(new sectionToExecute);70 jobList_.back()->firstElement = debut;71 jobList_.back()->lastElement = fin;72 jobList_.back()->software = prog;69 jobList_.push_back(new sectionToExecute); 70 jobList_.back()->firstElement = debut; 71 jobList_.back()->lastElement = fin; 72 jobList_.back()->software = prog; 73 73 } 74 74 75 75 void dataManager::clearSectionToExecute() 76 76 { 77 unsigned k;78 for(k = 0; k < jobList_.size(); k++)77 unsigned k; 78 for(k = 0; k < jobList_.size(); k++) 79 79 { 80 if ( jobList_[k] != NULL ) delete jobList_[k]; 81 } 82 jobList_.clear(); 83 } 84 85 trivaluedBool dataManager::checkExecute(string& diagnostic) 86 { 87 cout << "dataManager::checkExecute()" << endl; 88 consoleMessage(" VERIFICATION AVANT EXECUTION "); 89 90 trivaluedBool resul = ok; 91 diagnostic.clear(); 92 93 for(unsigned k = 0; k < jobList_.size(); k++) { 94 95 unsigned numeroDeb = jobList_[k]->firstElement; 96 unsigned numeroFin = jobList_[k]->lastElement; 97 98 if ( numeroFin < numeroDeb ) { 99 diagnostic += " last element before first for job " + (jobList_[k]->software).getString() + " \n"; 100 resul = error; 101 break; 102 } 103 104 string checkCompatibility; 105 resul = checkElementsForExec(jobList_[k]->software,numeroDeb,numeroFin,checkCompatibility); 106 diagnostic += checkCompatibility; 107 } //k 108 109 return resul; 110 } 111 112 trivaluedBool dataManager::checkElementsForExec(nomDeLogiciel logiciel,unsigned numeroDeb,unsigned numeroFin,string& diagnostic) 113 { 114 trivaluedBool resul = ok; 115 trivaluedBool accepted; 116 117 diagnostic.clear(); 118 abstractElement* elPtr; 119 120 for(unsigned j = numeroDeb; j <= numeroFin; j++) { 121 elPtr = pspa_->getBeamLine()->getAbstractElement(j-1); 122 accepted = elPtr->is_accepted_by_software(logiciel); 123 124 if(accepted == error) { 125 diagnostic += " the element " + elPtr->getNomdElement().getElementName() + " is not allowed with " + logiciel.getString() + " \n"; 126 resul = error; 127 } else if (accepted == warning) { 128 diagnostic += " the element " + elPtr->getNomdElement().getElementName() + " will be ignored by " + logiciel.getString() + " \n"; 129 if ( resul != error ) resul = warning; 130 } 131 } 132 133 return resul; 134 } 80 if ( jobList_[k] != NULL ) delete jobList_[k]; 81 } 82 jobList_.clear(); 83 } 84 85 86 135 87 136 88 void dataManager::initializeExecution() 137 89 { 138 string workingDir = pspa_->getWorkingDir();90 string workingDir = pspa_->getWorkingDir(); 139 91 if (workingDir == "") { 140 92 return; … … 165 117 bool dataManager::executeAll() 166 118 { 167 bool success = true;168 abstractSoftware* softw = NULL;169 string workingDir = pspa_->getWorkingDir();170 171 for(unsigned k = 0; k < jobList_.size(); k++)172 { 173 cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->software).getString() << endl;174 175 int debut = jobList_[k]->firstElement;176 int fin = jobList_[k]->lastElement;177 softw = createSoftwareConnexion(jobList_[k]->software);178 179 if (softw == NULL) {180 181 182 183 }184 185 success = softw->createInputFile(currentBeam_,debut,fin,workingDir);186 if ( success ) {187 188 189 190 191 }192 193 delete softw;194 if ( success ) {195 196 197 } else {198 199 200 }201 if ( !success ) break;202 203 //debug204 cout << "dataManager::executeAll #diagnosticBeam= " << diagnosticBeam_.size() << endl;205 cout << "dataManager::executeAll #getBeamLineSize()= " << getBeamLineSize() << endl;206 for (int j = debut; j <= fin; j++) {207 208 209 }210 119 bool success = true; 120 abstractSoftware* softw = NULL; 121 string workingDir = pspa_->getWorkingDir(); 122 123 for(unsigned k = 0; k < jobList_.size(); k++) 124 { 125 cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->software).getString() << endl; 126 127 int debut = jobList_[k]->firstElement; 128 int fin = jobList_[k]->lastElement; 129 softw = createSoftwareConnexion(jobList_[k]->software); 130 131 if (softw == NULL) { 132 success = false; 133 consoleMessage("dataManager::executeAll : unknown software"); 134 break; 135 } 136 137 success = softw->createInputFile(currentBeam_,debut,fin,workingDir); 138 if ( success ) { 139 success = softw->execute(debut,fin,workingDir); 140 if ( success ) { 141 success = softw->buildBeamAfterElements(debut,fin,diagnosticBeam_,workingDir); 142 } 143 } 144 145 delete softw; 146 if ( success ) { 147 currentBeam_ = &diagnosticBeam_.back(); 148 cout << " execute termine avec succes " << endl; 149 } else { 150 currentBeam_ = NULL; 151 cout << " execute termine en ECHEC " << endl; 152 } 153 if ( !success ) break; 154 155 //debug 156 cout << "dataManager::executeAll #diagnosticBeam= " << diagnosticBeam_.size() << endl; 157 cout << "dataManager::executeAll #getBeamLineSize()= " << getBeamLineSize() << endl; 158 for (int j = debut; j <= fin; j++) { 159 abstractElement* elPtr= getElementPointerFromNumero(j); 160 cout << "[" << j << "] " << elPtr->getNomdElement().getElementName() << endl; 161 } 162 211 163 } //k 212 213 return success;164 165 return success; 214 166 } 215 167 … … 222 174 cout << " et qu'on puisse restaurer normalement" << endl; 223 175 string name = pspa_->getWorkingDir() + "/" + nameOfFile + ".save"; 224 176 225 177 // make dir if not exist 226 178 boost::filesystem::create_directories(pspa_->getWorkingDir() + folder + "/"); … … 230 182 cerr << " error opening output file for persistency " << name << endl; 231 183 } 232 233 outfile << globParam_.FileOutputFlow();234 abstractElement* elPtr;235 for(unsigned k = 0; k < getBeamLineSize() ; k++)184 185 outfile << globParam_.FileOutputFlow(); 186 abstractElement* elPtr; 187 for(unsigned k = 0; k < getBeamLineSize() ; k++) 236 188 { 237 elPtr = pspa_->getBeamLine()->getAbstractElement(k);238 outfile << elPtr->FileOutputFlow();239 } 240 outfile.close();189 elPtr = pspa_->getBeamLine()->getAbstractElement(k); 190 outfile << elPtr->FileOutputFlow(); 191 } 192 outfile.close(); 241 193 } 242 194 … … 283 235 } 284 236 infile.close(); 285 237 286 238 // debug 287 239 // unsigned k; 288 240 // for(k = 0; k < getBeamLineSize(); k++) { 289 // abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(k); 241 // abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(k); 290 242 // cout << "reupere " << ptr->getLabel() << endl; 291 243 // } … … 295 247 particleBeam* dataManager::getDiagnosticBeam(unsigned index) 296 248 { 297 if (index >= diagnosticBeam_.size()) {298 return NULL;299 } else {300 return &diagnosticBeam_.at(index);301 }249 if (index >= diagnosticBeam_.size()) { 250 return NULL; 251 } else { 252 return &diagnosticBeam_.at(index); 253 } 302 254 } 303 255 … … 331 283 // } 332 284 285 333 286 // on ne tient pas compte des elements "snapshot" presents dans la beamLine 334 287 void dataManager::donneesRmsEnveloppe(string type,vector<double>& xcor,vector<double>& ycor) … … 358 311 i++; 359 312 } 360 } else {361 cerr << " dataManager::donneesRmsEnveloppe type " << type << " not programmed " << endl;362 return;363 313 } 364 314 } 365 315 366 316 int dataManager::getBeamLineSize() { 367 return pspa_->getBeamLine()->getBeamLineSize();368 } 369 370 abstractSoftware* dataManager::createSoftwareConnexion(nomDeLogiciel logi) 371 { 372 string inputFileName;373 if(logi == nomDeLogiciel::parmela) {374 inputFileName = "parmin";375 return new softwareParmela(inputFileName, &globParam_, this);376 } else if (logi == nomDeLogiciel::transport) {377 inputFileName = "transport.input";378 return new softwareTransport(inputFileName, &globParam_, this);379 } else if (logi == nomDeLogiciel::generator) {380 inputFileName = "generator.in";381 return new softwareGenerator(inputFileName, &globParam_, this);382 } else if (logi == nomDeLogiciel::test) {383 return new softwareTest(inputFileName, &globParam_, this);384 } else {385 return NULL;386 }387 } 317 return pspa_->getBeamLine()->getBeamLineSize(); 318 } 319 320 abstractSoftware* dataManager::createSoftwareConnexion(nomDeLogiciel logi) 321 { 322 string inputFileName; 323 if(logi == nomDeLogiciel::parmela) { 324 inputFileName = "parmin"; 325 return new softwareParmela(inputFileName, &globParam_, this); 326 } else if (logi == nomDeLogiciel::transport) { 327 inputFileName = "transport.input"; 328 return new softwareTransport(inputFileName, &globParam_, this); 329 } else if (logi == nomDeLogiciel::generator) { 330 inputFileName = "generator.in"; 331 return new softwareGenerator(inputFileName, &globParam_, this); 332 } else if (logi == nomDeLogiciel::test) { 333 return new softwareTest(inputFileName, &globParam_, this); 334 } else { 335 return NULL; 336 } 337 }
Note: See TracChangeset
for help on using the changeset viewer.