Ignore:
Timestamp:
Nov 15, 2013, 3:30:50 PM (11 years ago)
Author:
touze
Message:

systeme periodique (mailles) + multipoles + madx

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
    14#include "dataManager.h"
    25#include "mathematicalConstants.h"
    36#include "PhysicalConstants.h"
     7
     8#include "GWt_pspaApplication.h"
     9#include "GWt_console.h"
     10
    411#include "softwareParmela.h"
    512#include "softwareTransport.h"
    6 #include "GWt_pspaApplication.h"
    7 #include "GWt_console.h"
    813#include "softwareGenerator.h"
    914#include "softwareTest.h"
     15#include "softwareMadx.h" //xx
     16#include "softwareUnknown.h" //xx
    1017
    1118#include <boost/filesystem.hpp>
    12 #include <stdio.h>
    13 #include <fstream>
    1419
    1520#include "UAP/UAPUtilities.hpp"
    1621#include "AML/AMLReader.hpp"
     22
     23#define BAVARD 0
    1724
    1825dataManager::dataManager(PspaApplication* pspa) :
     
    2330dataManager::~dataManager()
    2431{
    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
     39void 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();
    3644}
    3745
    3846string dataManager::getLabelFromElementNumero(int numero)
    3947{
    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}
    4552
    4653int dataManager::getNumeroFromElementLabel(string label)
    4754{
    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}
    6367
    6468abstractElement* dataManager::getElementPointerFromNumero(int k)
     
    6771}
    6872
    69 sectionToExecute*  dataManager::addSectionToExecute(abstractElement* debut,int debutIndex, abstractElement* fin, int finIndex, nomDeLogiciel logiciel)
    70 {
     73sectionToExecute* 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
    7180  abstractSoftware* prog;
    7281  string inputFileName;
     
    8291  } else if (logiciel  == nomDeLogiciel::test) {
    8392    prog = new softwareTest(inputFileName, &globParam_, this);
     93  } else if (logiciel  == nomDeLogiciel::madx) {
     94    inputFileName = "madx.input";
     95    prog = new softwareMadx(inputFileName,&sectorParam_,this); 
    8496  } 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));
    91101  return jobList_.back();
    92102}
     
    94104void dataManager::clearSectionToExecute()
    95105{
    96     unsigned k;
    97     for(k = 0; k < jobList_.size(); k++)
     106  unsigned k;
     107  for(k = 0; k < jobList_.size(); k++)
    98108    {
    99         if ( jobList_[k] != NULL ) clearSectionToExecute(k);
    100     }
    101     jobList_.clear();
    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
     114void dataManager::clearSectionToExecute(int a)
     115{
     116  cout << " dataManager::clearSectionToExecute : effacement de la section d'index = " << a << endl;
    107117  if (a < 0) return;
    108118  if (a >= (int)jobList_.size()) return;
    109 
     119 
    110120  // lors de la creation de la section on a fait un 'new' d'un
    111121  // softwareXXXX : on fait ici le 'delete'
    112 
     122 
    113123  const abstractSoftware* soft = jobList_.at(a)->getSoftware();
    114124  if ( soft != NULL ) delete soft;
    115125  jobList_.erase (jobList_.begin()+a);
    116126}
    117 
    118127
    119128void dataManager::initializeExecution()
     
    141150void dataManager::removeFile(string nameOfFile)
    142151{
    143     ifstream fileExists;
    144     fileExists.open(nameOfFile.c_str(), ios::in);
    145     if (fileExists) {
    146         fileExists.close();
    147         remove(nameOfFile.c_str());
    148     }
     152  ifstream fileExists;
     153  fileExists.open(nameOfFile.c_str(), ios::in);
     154  if (fileExists) {
     155    fileExists.close();
     156    remove(nameOfFile.c_str());
     157  }
    149158}
    150159
    151160bool dataManager::executeAll()
    152161{
     162  cout << "***********************************" << endl;
     163  cout << " dataManager::executeAll() " << endl << endl;
     164
    153165  bool success = true;
    154166  abstractSoftware* softw = NULL;
    155167  string workingDir = pspa_->getWorkingDir();
    156  
     168  
    157169  // on verifie la consecution des sections
    158170  int lastel = 0;
     
    165177    }
    166178  }
    167 
     179 
    168180  unsigned debut;
    169181  unsigned fin;
    170182  for(unsigned k = 0; k < jobList_.size(); k++) {
     183 
    171184    cout << " dataManager::executeAll je m'apprete a executer : " << (jobList_[k]->getSoftware()->getName()) << endl;
    172      
     185   
    173186    debut = jobList_[k]->getElementNumberInSection();
    174187    fin = jobList_[k]->getLastElementNumberInSection();
    175188    softw = jobList_[k]->getSoftware();
    176189   
     190    //cout << "k= " << k << ", de " << jobList_[k]->getFirstElement()->getLabel() << " à " << jobList_[k]->getLastElement()->getLabel() << " avec " << softw->getName() << endl;
     191
    177192    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);
    181203      }
    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    }
    210225  } //k
    211226 
     
    216231void dataManager::saveConfiguration(string folder, string nameOfFile)
    217232{
    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++)
    236252    {
    237253      elPtr = pspa_->getBeamLine()->getAbstractElement(k);
    238254      outfile << elPtr->FileOutputFlow();
    239255    }
    240     outfile.close();
     256  outfile.close();
    241257}
    242258
     
    247263  uap_root = new UAPNode("UAP_root");
    248264  UAPNode* rep = uap_root->addChild("AML_representation");
    249 
     265 
    250266  // root node in the hierarchy
    251267  UAPNode* lab = rep->addChild("laboratory");
    252268  lab->addAttribute("name","PSPA lab");
    253 
     269 
    254270  // general global parameters
    255271  globParam_.InputRep(lab);
    256 
     272 
    257273  // accelerator or section of accelerator
    258274  //UAPNode* acc = lab->addChild("machine");
    259275  //acc->addAttribute("name",fileName);
     276
     277  sectorParam_.InputRep(lab);
    260278
    261279  // sequence of elements
     
    275293}
    276294
    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         }
     295bool 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);
    298314    } 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;
    327355}
    328356
     
    386414abstractSoftware* dataManager::createSoftwareConnexion(nomDeLogiciel logi)
    387415{
    388     string inputFileName;
    389     if(logi == nomDeLogiciel::parmela) {
    390       cout << " dataManager::createSoftwareConnexion : logiciel identifie : parmela " << endl;
    391         inputFileName = "parmin";
    392         return new softwareParmela(inputFileName, &globParam_, this);
    393     } else if (logi == nomDeLogiciel::transport) {
    394       cout << " dataManager::createSoftwareConnexion : logiciel identifie : transport " << endl;
    395         inputFileName = "transport.input";
    396         return new softwareTransport(inputFileName, &globParam_, this);
    397     } else if (logi == nomDeLogiciel::generator) {
    398       cout << " dataManager::createSoftwareConnexion : logiciel identifie : generator " << endl;
    399         inputFileName = "generator.in";
    400         return new softwareGenerator(inputFileName, &globParam_, this);
    401     } else if (logi == nomDeLogiciel::test) {
    402       cout << " dataManager::createSoftwareConnexion : logiciel identifie : test " << endl;
     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;
    403431        return new softwareTest(inputFileName, &globParam_, this);
    404     } else {
    405       cout << " dataManager::createSoftwareConnexion : logiciel identifie : null " << endl;
    406         return NULL;
    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.