Changeset 431 in PSPA for Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc
- Timestamp:
- Nov 15, 2013, 3:30:50 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc
r424 r431 1 #include <stdio.h> 2 #include <fstream> 3 1 4 #include "dataManager.h" 2 5 #include "mathematicalConstants.h" 3 6 #include "PhysicalConstants.h" 7 8 #include "GWt_pspaApplication.h" 9 #include "GWt_console.h" 10 4 11 #include "softwareParmela.h" 5 12 #include "softwareTransport.h" 6 #include "GWt_pspaApplication.h"7 #include "GWt_console.h"8 13 #include "softwareGenerator.h" 9 14 #include "softwareTest.h" 15 #include "softwareMadx.h" //xx 16 #include "softwareUnknown.h" //xx 10 17 11 18 #include <boost/filesystem.hpp> 12 #include <stdio.h>13 #include <fstream>14 19 15 20 #include "UAP/UAPUtilities.hpp" 16 21 #include "AML/AMLReader.hpp" 22 23 #define BAVARD 0 17 24 18 25 dataManager::dataManager(PspaApplication* pspa) : … … 23 30 dataManager::~dataManager() 24 31 { 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_; 30 } 31 32 void dataManager::consoleMessage(string message) { 33 GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); 34 if (console) console->addConsoleMessage(message + "\n"); 35 pspa_->processEvents(); 32 unsigned k; 33 for (k=0; k < jobList_.size();k++) { 34 if ( jobList_[k] != NULL ) delete jobList_[k]; 35 } 36 if ( currentBeam_ == NULL ) delete currentBeam_; 37 } 38 39 void dataManager::consoleMessage(string message) 40 { 41 GWt_console* console = static_cast<GWt_console*> (wApp->findWidget ("console")); 42 if (console) console->addConsoleMessage(message + "\n"); 43 pspa_->processEvents(); 36 44 } 37 45 38 46 string dataManager::getLabelFromElementNumero(int numero) 39 47 { 40 abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(numero-1); 41 if ( ptr == NULL ) return ""; 42 return ptr->getLabel(); 43 } 44 48 abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(numero-1); 49 if ( ptr == NULL ) return ""; 50 return ptr->getLabel(); 51 } 45 52 46 53 int dataManager::getNumeroFromElementLabel(string label) 47 54 { 48 int index = -1; 49 50 for (int 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 55 int index = -1; 56 for (int k = 0; k < getBeamLineSize() ; k++) { 57 if (pspa_->getBeamLine()->getAbstractElement(k) != NULL) { 58 if ( pspa_->getBeamLine()->getAbstractElement(k)->getLabel() == label ) 59 { 60 index = (int)k + 1; 61 return index; 62 } 63 } 64 } 65 return index; 66 } 63 67 64 68 abstractElement* dataManager::getElementPointerFromNumero(int k) … … 67 71 } 68 72 69 sectionToExecute* dataManager::addSectionToExecute(abstractElement* debut,int debutIndex, abstractElement* fin, int finIndex, nomDeLogiciel logiciel) 70 { 73 sectionToExecute* dataManager::addSectionToExecute(abstractElement* debut,int debutIndex, abstractElement* fin, int finIndex, nomDeLogiciel logiciel) 74 { 75 #if BAVARD > 0 76 cout << "***********************************" << endl; 77 cout << " dataManager::addSectionToExecute " << endl << endl; 78 #endif 79 71 80 abstractSoftware* prog; 72 81 string inputFileName; … … 82 91 } else if (logiciel == nomDeLogiciel::test) { 83 92 prog = new softwareTest(inputFileName, &globParam_, this); 93 } else if (logiciel == nomDeLogiciel::madx) { 94 inputFileName = "madx.input"; 95 prog = new softwareMadx(inputFileName,§orParam_,this); 84 96 } else { 85 prog = NULL; 86 } 87 88 // abstractSoftware* prog = createSoftwareConnexion(logiciel); 89 jobList_.push_back(new sectionToExecute(debut, debutIndex, fin, finIndex, prog)); 90 // return prog; 97 prog = new softwareUnknown(); // xx 98 } 99 100 jobList_.push_back(new sectionToExecute(debut,debutIndex,fin,finIndex,prog)); 91 101 return jobList_.back(); 92 102 } … … 94 104 void dataManager::clearSectionToExecute() 95 105 { 96 97 106 unsigned k; 107 for(k = 0; k < jobList_.size(); k++) 98 108 { 99 100 } 101 102 } 103 104 105 void dataManager::clearSectionToExecute(int a){106 cout << " dataManager::clearSectionToExecute efaacement section d'index :" << a << endl;109 if ( jobList_[k] != NULL ) clearSectionToExecute(k); 110 } 111 jobList_.clear(); 112 } 113 114 void dataManager::clearSectionToExecute(int a) 115 { 116 cout << " dataManager::clearSectionToExecute : effacement de la section d'index = " << a << endl; 107 117 if (a < 0) return; 108 118 if (a >= (int)jobList_.size()) return; 109 119 110 120 // lors de la creation de la section on a fait un 'new' d'un 111 121 // softwareXXXX : on fait ici le 'delete' 112 122 113 123 const abstractSoftware* soft = jobList_.at(a)->getSoftware(); 114 124 if ( soft != NULL ) delete soft; 115 125 jobList_.erase (jobList_.begin()+a); 116 126 } 117 118 127 119 128 void dataManager::initializeExecution() … … 141 150 void dataManager::removeFile(string nameOfFile) 142 151 { 143 144 145 146 147 148 152 ifstream fileExists; 153 fileExists.open(nameOfFile.c_str(), ios::in); 154 if (fileExists) { 155 fileExists.close(); 156 remove(nameOfFile.c_str()); 157 } 149 158 } 150 159 151 160 bool dataManager::executeAll() 152 161 { 162 cout << "***********************************" << endl; 163 cout << " dataManager::executeAll() " << endl << endl; 164 153 165 bool success = true; 154 166 abstractSoftware* softw = NULL; 155 167 string workingDir = pspa_->getWorkingDir(); 156 168 157 169 // on verifie la consecution des sections 158 170 int lastel = 0; … … 165 177 } 166 178 } 167 179 168 180 unsigned debut; 169 181 unsigned fin; 170 182 for(unsigned k = 0; k < jobList_.size(); k++) { 183 171 184 cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->getSoftware()->getName()) << endl; 172 185 173 186 debut = jobList_[k]->getElementNumberInSection(); 174 187 fin = jobList_[k]->getLastElementNumberInSection(); 175 188 softw = jobList_[k]->getSoftware(); 176 189 190 //cout << "k= " << k << ", de " << jobList_[k]->getFirstElement()->getLabel() << " à " << jobList_[k]->getLastElement()->getLabel() << " avec " << softw->getName() << endl; 191 177 192 if (softw == NULL) { 178 success = false; 179 consoleMessage("dataManager::executeAll : unknown software"); 180 break; 193 success = false; 194 consoleMessage("dataManager::executeAll : unknown software"); 195 break; 196 } 197 198 success = softw->createInputFile(currentBeam_,debut,fin,workingDir); 199 if ( success ) { 200 success = softw->execute(workingDir); 201 if ( success ) { 202 success = softw->buildBeamAfterElements(workingDir); 181 203 } 182 183 success = softw->createInputFile(currentBeam_,debut,fin,workingDir); 184 if ( success ) { 185 success = softw->execute(workingDir); 186 if ( success ) { 187 success = softw->buildBeamAfterElements(workingDir); 188 } 189 } 190 191 if ( success ) { 192 currentBeam_ = &diagnosticBeam_.at(indexElementToIndexDiag_.back()); 193 cout << " execute termine avec succes " << endl; 194 } else { 195 currentBeam_ = NULL; 196 cout << " execute termine en ECHEC " << endl; 197 } 198 if ( !success ) break; 199 200 if ( debut < firstComputedElemNumero_ ) firstComputedElemNumero_ = debut; 201 if ( fin > lastComputedElemNumero_ ) lastComputedElemNumero_ = fin; 202 203 //debug 204 cout << "dataManager::executeAll #diagnosticBeam= " << diagnosticBeam_.size() << endl; 205 cout << "dataManager::executeAll #getBeamLineSize()= " << getBeamLineSize() << endl; 206 for (unsigned j = debut; j <= fin; j++) { 207 abstractElement* elPtr= getElementPointerFromNumero(j); 208 cout << "[" << j << "] " << elPtr->getNomdElement().getExpandedName() << endl; 209 } 204 } 205 206 if ( success ) { 207 currentBeam_ = &diagnosticBeam_.at(indexElementToIndexDiag_.back()); 208 cout << " execute termine avec succes " << endl; 209 } else { 210 currentBeam_ = NULL; 211 cout << " execute termine en ECHEC " << endl; 212 } 213 if ( !success ) break; 214 215 if ( debut < firstComputedElemNumero_ ) firstComputedElemNumero_ = debut; 216 if ( fin > lastComputedElemNumero_ ) lastComputedElemNumero_ = fin; 217 218 //debug 219 cout << "dataManager::executeAll #diagnosticBeam= " << diagnosticBeam_.size() << endl; 220 cout << "dataManager::executeAll #getBeamLineSize()= " << getBeamLineSize() << endl; 221 for (unsigned j = debut; j <= fin; j++) { 222 abstractElement* elPtr= getElementPointerFromNumero(j); 223 cout << "[" << j << "] " << elPtr->getNomdElement().getExpandedName() << endl; 224 } 210 225 } //k 211 226 … … 216 231 void dataManager::saveConfiguration(string folder, string nameOfFile) 217 232 { 218 ofstream outfile; 219 // string name = pspa_->getWorkingDir()+ folder + "/" + nameOfFile + ".save"; 220 cout << " dataManager::saveConfiguration : suppression du folder dans le nom de " << endl; 221 cout << " sauvegarde, en attendant que ce soit autre chose que le sessionId" << endl; 222 cout << " et qu'on puisse restaurer normalement" << endl; 223 string name = pspa_->getWorkingDir() + "/" + nameOfFile + ".save"; 224 225 // make dir if not exist 226 boost::filesystem::create_directories(pspa_->getWorkingDir() + folder + "/"); 227 228 outfile.open(name.c_str(), ios::out); 229 if (!outfile) { 230 cerr << " error opening output file for persistency " << name << endl; 231 } 232 233 outfile << globParam_.FileOutputFlow(); 234 abstractElement* elPtr; 235 for(int k = 0; k < getBeamLineSize() ; k++) 233 ofstream outfile; 234 // string name = pspa_->getWorkingDir()+ folder + "/" + nameOfFile + ".save"; 235 cout << " dataManager::saveConfiguration : suppression du folder dans le nom de " << endl; 236 cout << " sauvegarde, en attendant que ce soit autre chose que le sessionId" << endl; 237 cout << " et qu'on puisse restaurer normalement" << endl; 238 239 string name = pspa_->getWorkingDir() + "/" + nameOfFile + ".save"; 240 // make dir if not exist 241 boost::filesystem::create_directories(pspa_->getWorkingDir() + folder + "/"); 242 243 outfile.open(name.c_str(), ios::out); 244 if (!outfile) { 245 cerr<<" ERROR opening output file for persistency "<<name<<endl; 246 } 247 248 outfile << globParam_.FileOutputFlow(); 249 outfile << sectorParam_.FileOutputFlow(); 250 abstractElement* elPtr; 251 for(int k = 0; k < getBeamLineSize() ; k++) 236 252 { 237 253 elPtr = pspa_->getBeamLine()->getAbstractElement(k); 238 254 outfile << elPtr->FileOutputFlow(); 239 255 } 240 256 outfile.close(); 241 257 } 242 258 … … 247 263 uap_root = new UAPNode("UAP_root"); 248 264 UAPNode* rep = uap_root->addChild("AML_representation"); 249 265 250 266 // root node in the hierarchy 251 267 UAPNode* lab = rep->addChild("laboratory"); 252 268 lab->addAttribute("name","PSPA lab"); 253 269 254 270 // general global parameters 255 271 globParam_.InputRep(lab); 256 272 257 273 // accelerator or section of accelerator 258 274 //UAPNode* acc = lab->addChild("machine"); 259 275 //acc->addAttribute("name",fileName); 276 277 sectorParam_.InputRep(lab); 260 278 261 279 // sequence of elements … … 275 293 } 276 294 277 bool dataManager::restoreElements( string inputFileName) 278 { 279 cout << "dataManager::restoreElements() fichier " << inputFileName << endl; 280 ifstream infile; 281 string name = inputFileName; 282 infile.open(name.c_str(), ios::in); 283 if (!infile) { 284 cerr << " error opening input stream " << name << endl; 285 return false; 286 } 287 else cout << " successful opening input stream " << name << endl; 288 289 string globalTitle; 290 if ( infile >> globalTitle ) { 291 if ( globalTitle == string("globals") ) { 292 globParam_.raz(); 293 globParam_.FileInput(infile); 294 } else { 295 cerr << " dataManager::restoreElements ERROR : global parameters seems to be missing" << endl; 296 return false; 297 } 295 bool dataManager::restoreElements(string inputFileName) 296 { 297 cout << "***********************************" << endl; 298 cout << " dataManager::restoreElements() fichier :" << inputFileName << endl << endl; 299 300 ifstream infile; 301 string name = inputFileName; 302 infile.open(name.c_str(), ios::in); 303 if (!infile) { 304 cerr << " error opening input stream " << name << endl; 305 return false; 306 } 307 else cout << " successful opening input stream : " << name << endl; 308 309 string globalTitle; 310 if ( infile >> globalTitle ) { 311 if ( globalTitle == string("globals") ) { 312 globParam_.raz(); 313 globParam_.FileInput(infile); 298 314 } else { 299 cerr << " dataManager::restoreElements ERROR : reading data save file" << endl; 300 return false; 301 } 302 303 pspa_->getBeamLine()->clear(); 304 305 nomdElements::typedElement elementType; 306 string elementLabel; 307 while (infile >> elementLabel) { 308 elementType = nomdElements::getTypeFromLabel(elementLabel); 309 310 GWt_abstractElement* nouveau = pspa_->getBeamLine()->addElement(elementType); 311 312 if ( nouveau == NULL ) { 313 cerr << " dataManager::restoreElements ERROR : restoring element " << elementLabel << " failed " << endl; 314 return false; 315 } 316 nouveau->FileInput(infile); 317 } 318 infile.close(); 319 320 // debug 321 // unsigned k; 322 // for(k = 0; k < getBeamLineSize(); k++) { 323 // abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(k); 324 // cout << "reupere " << ptr->getLabel() << endl; 325 // } 326 return true; 315 //cout << " INFO::dataManager::restoreElements : global parameters seems to be missing" << endl; 316 //return false; 317 } 318 } else { 319 cerr << " ERROR::dataManager::restoreElements : reading globalParameters in save file" << endl; 320 return false; 321 } 322 323 //NOTE:: je ne sais pas si les parametres "secteur" seront conservés, aussi pour ne pas trop changer les fichiers je lis les données aprÚs "globals" dans la boucle 324 325 pspa_->getBeamLine()->clear(); 326 nomdElements::typedElement elementType; 327 string elementLabel; 328 while (infile >> elementLabel) { 329 330 if (elementLabel == string("lattice") ) { 331 sectorParam_.raz(); 332 sectorParam_.FileInput(infile); 333 } else { 334 elementType = nomdElements::getTypeFromLabel(elementLabel); 335 GWt_abstractElement* nouveau = pspa_->getBeamLine()->addElement(elementType); 336 if ( nouveau == NULL ) { 337 cerr << " dataManager::restoreElements() : restore element " << elementLabel << " failed " << endl; 338 return false; 339 } else { 340 nouveau->FileInput(infile); 341 } 342 } 343 }// while 344 345 #if BAVARD > 1 346 unsigned k; 347 for(k = 0; k < getBeamLineSize(); k++) { 348 abstractElement* ptr = pspa_->getBeamLine()->getAbstractElement(k); 349 cout << "recupere " << ptr->getLabel() << endl; 350 } 351 #endif 352 353 infile.close(); 354 return true; 327 355 } 328 356 … … 386 414 abstractSoftware* dataManager::createSoftwareConnexion(nomDeLogiciel logi) 387 415 { 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 416 string inputFileName; 417 if(logi == nomDeLogiciel::parmela) { 418 cout << " dataManager::createSoftwareConnexion : logiciel identifie : parmela " << endl; 419 inputFileName = "parmin"; 420 return new softwareParmela(inputFileName, &globParam_, this); 421 } else if (logi == nomDeLogiciel::transport) { 422 cout << " dataManager::createSoftwareConnexion : logiciel identifie : transport " << endl; 423 inputFileName = "transport.input"; 424 return new softwareTransport(inputFileName, &globParam_, this); 425 } else if (logi == nomDeLogiciel::generator) { 426 cout << " dataManager::createSoftwareConnexion : logiciel identifie : generator " << endl; 427 inputFileName = "generator.in"; 428 return new softwareGenerator(inputFileName, &globParam_, this); 429 } else if (logi == nomDeLogiciel::test) { 430 cout << " dataManager::createSoftwareConnexion : logiciel identifie : test " << endl; 403 431 return new softwareTest(inputFileName, &globParam_, this); 404 405 406 407 408 } 432 } else { 433 cout << " dataManager::createSoftwareConnexion : logiciel identifie : null " << endl; 434 return NULL; 435 } 436 }
Note: See TracChangeset
for help on using the changeset viewer.