Ignore:
Timestamp:
Feb 7, 2014, 2:00:55 PM (10 years ago)
Author:
lemeur
Message:

lecture fichier sauvegarde AML

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Interface_Web/trunk/pspaWT/sources/controler/src/dataManager.cc

    r485 r488  
    1414#include "UAP/UAPUtilities.hpp"
    1515#include "AML/AMLReader.hpp"
     16#include "AMLtools.h"
    1617
    1718#define BAVARD 0
     
    139140}
    140141
    141 void dataManager::saveConfiguration(string folder, string nameOfFile)
    142 {
    143   ofstream outfile;
    144   //string name = pspa_->getWorkingDir()+ folder + "/" + nameOfFile + ".save";
    145   cout << " dataManager::saveConfiguration : suppression du folder dans le nom de " << endl;
    146   cout << " sauvegarde, en attendant que ce soit autre chose que le sessionId" << endl;
    147   cout << " et qu'on puisse restaurer normalement" << endl;
    148 
    149   string name = pspa_->getWorkingDir() + "/" + nameOfFile + ".save"; 
    150   // make dir if not exist
    151   boost::filesystem::create_directories(pspa_->getWorkingDir() + folder + "/");
    152  
    153   outfile.open(name.c_str(), ios::out);
    154   if (!outfile) {
    155     cerr<<" ERROR opening output file for persistency "<<name<<endl;
    156   }
    157  
    158   outfile << globParam_.FileOutputFlow();
    159 
    160   // FIXME Francois: Comment sauver la configuration des section ?
    161   for (unsigned int a=0; a< jobList_.size(); a++) {
    162     outfile << jobList_[a]->getSectorParameters().FileOutputFlow();
    163   }
    164   // END
    165  
    166   abstractElement* elPtr;
    167   for (unsigned k = 0; k < jobList_.size(); k++) {
    168     sector* sector = jobList_[k];
    169     for (unsigned l = 0; l < sector->getSectionsToExecute().size(); l++) {
    170       sectionToExecute* section = sector->getSectionsToExecute()[l];
    171       for (unsigned m = 0; m < section->getElements().size(); m++) {
    172         elPtr = section->getElements()[m];
    173         outfile << elPtr->FileOutputFlow();
    174       }
    175     }
    176   }
    177   outfile.close();
    178 }
     142// void dataManager::saveConfiguration(string folder, string nameOfFile)
     143// {
     144//   ofstream outfile;
     145//   //string name = pspa_->getWorkingDir()+ folder + "/" + nameOfFile + ".save";
     146//   cout << " dataManager::saveConfiguration : suppression du folder dans le nom de " << endl;
     147//   cout << " sauvegarde, en attendant que ce soit autre chose que le sessionId" << endl;
     148//   cout << " et qu'on puisse restaurer normalement" << endl;
     149
     150//   string name = pspa_->getWorkingDir() + "/" + nameOfFile + ".save"; 
     151//   // make dir if not exist
     152//   boost::filesystem::create_directories(pspa_->getWorkingDir() + folder + "/");
     153 
     154//   outfile.open(name.c_str(), ios::out);
     155//   if (!outfile) {
     156//     cerr<<" ERROR opening output file for persistency "<<name<<endl;
     157//   }
     158 
     159//   outfile << globParam_.FileOutputFlow();
     160
     161//   // FIXME Francois: Comment sauver la configuration des section ?
     162//   for (unsigned int a=0; a< jobList_.size(); a++) {
     163//     outfile << jobList_[a]->getSectorParameters().FileOutputFlow();
     164//   }
     165//   // END
     166 
     167//   abstractElement* elPtr;
     168//   for (unsigned k = 0; k < jobList_.size(); k++) {
     169//     sector* sector = jobList_[k];
     170//     for (unsigned l = 0; l < sector->getSectionsToExecute().size(); l++) {
     171//       sectionToExecute* section = sector->getSectionsToExecute()[l];
     172//       for (unsigned m = 0; m < section->getElements().size(); m++) {
     173//         elPtr = section->getElements()[m];
     174//         outfile << elPtr->FileOutputFlow();
     175//       }
     176//     }
     177//   }
     178//   outfile.close();
     179// }
    179180
    180181// ecriture sur fichier AML
     
    219220}
    220221
    221 bool dataManager::restoreElements(string inputFileName)
     222// bool dataManager::restoreElements(string inputFileName)
     223// {
     224//   cout << "***********************************" << endl;
     225//   cout << " dataManager::restoreElements() fichier :" << inputFileName << endl << endl;
     226
     227//   ifstream infile;
     228//   string name = inputFileName;
     229//   infile.open(name.c_str(), ios::in);
     230//   if (!infile) {
     231//     cerr << " error opening input stream " << name << endl;
     232//     return false;
     233//   }
     234//   else cout << " successful opening input stream : " << name << endl;
     235 
     236//   //NOTE:: je ne sais pas si les "secteurs" seront conservés, aussi pour ne pas trop changer les fichiers je lis les données aprÚs "globals" dans la boucle
     237 
     238//   // Clear the BeamLine
     239//   jobList_.clear();
     240
     241//   // FIXME : For test purpose !!!
     242//   sector* mySect = addNewSector();
     243 
     244//   nomdElements::typedElement elementType;
     245//   string elementLabel;
     246//   abstractElement* nouveau = NULL;
     247//   while (infile >> elementLabel) {
     248//     if (elementLabel == string("globals") ) {
     249//       globParam_.raz();
     250//       globParam_.FileInput(infile);
     251//     } else if (elementLabel == string("sectors") ) {
     252//       // FIXME Francois !!!!!!!
     253// //      sectorParam_.raz();
     254// //      sectorParam_.FileInput(infile);
     255//       // END
     256//     } else {
     257//       elementType = nomdElements::getTypeFromLabel(elementLabel);
     258//       nouveau = mySect->addElementAfter(elementType,nouveau);
     259//       if ( nouveau == NULL ) {
     260//      cerr << " dataManager::restoreElements() : restore element " << elementLabel << " failed " << endl;
     261//      return false;
     262//       } else {
     263//      nouveau->FileInput(infile);
     264//       }
     265//     }
     266//   }// while
     267 
     268// #if BAVARD > 1
     269// /*  unsigned k;
     270//   for(k = 0; k < getBeamLineSize(); k++) {
     271//     abstractElement* ptr = pspa_->getBeamLine_deprecated()->getAbstractElement(k);
     272//     cout << "recupere " << ptr->getLabel() << endl;
     273//   }
     274// */
     275// #endif
     276
     277//   infile.close();
     278//   return true;
     279// }
     280
     281bool dataManager::restoreAMLElements(string inputFileName)
    222282{
    223283  cout << "***********************************" << endl;
    224   cout << " dataManager::restoreElements() fichier :" << inputFileName << endl << endl;
    225 
    226   ifstream infile;
    227   string name = inputFileName;
    228   infile.open(name.c_str(), ios::in);
    229   if (!infile) {
    230     cerr << " error opening input stream " << name << endl;
     284  cout << " dataManager::restoreAMLElements() fichier :" << inputFileName << endl << endl;
     285
     286  AMLReader reader;
     287  UAPNode* uap_root = NULL;
     288  uap_root = reader.AMLFileToAMLRep (inputFileName);
     289  if ( !uap_root ) {
     290    cout << " dataManager::restoreAMLElements ERREUR AML lecture fichier  " << inputFileName << endl;
    231291    return false;
    232292  }
    233   else cout << " successful opening input stream : " << name << endl;
    234  
     293
     294  else cout << " successful opening  : " << inputFileName << " UAP_ROOT= " << uap_root->getName() << endl;
     295  UAPNode* uap_labname = NULL;
     296
     297NodeVec laboratories = uap_root->getSubNodesByName(string("laboratory"));
     298 cout << " dataManager::restoreAMLElements nombre de <laboratory> : " << laboratories.size() << endl;
     299
     300 uap_labname = *laboratories.begin();
     301
     302 if ( !uap_labname ) {
     303   cout << " dataManager::restoreAMLElements : fichier non conforme, on ne trouve pas <laboratory...> " << endl;
     304 } else {
     305   cout << " dataManager::restoreAMLElements : GO !" << endl;
     306 }
     307
     308
    235309  //NOTE:: je ne sais pas si les "secteurs" seront conservés, aussi pour ne pas trop changer les fichiers je lis les données aprÚs "globals" dans la boucle
    236310 
     
    241315  sector* mySect = addNewSector();
    242316 
     317
     318   UAPNode* parametresGlobaux = uap_labname->getChildByName(string("global"));
     319  if ( !parametresGlobaux ) {
     320    cout << " dataManager::restoreAMLElements GLOBAUX NON TROUVES " << endl;
     321  } else {
     322    cout << " dataManager::restoreAMLElements GENIAL ! " << endl;
     323  }
     324  globParam_.raz();
     325  globParam_.FileAMLInput(parametresGlobaux);
     326
     327
    243328  nomdElements::typedElement elementType;
    244329  string elementLabel;
    245330  abstractElement* nouveau = NULL;
    246   while (infile >> elementLabel) {
    247     if (elementLabel == string("globals") ) {
    248       globParam_.raz();
    249       globParam_.FileInput(infile);
    250     } else if (elementLabel == string("sectors") ) {
    251       // FIXME Francois !!!!!!!
    252 //      sectorParam_.raz();
    253 //      sectorParam_.FileInput(infile);
    254       // END
    255     } else {
    256       elementType = nomdElements::getTypeFromLabel(elementLabel);
    257       nouveau = mySect->addElementAfter(elementType,nouveau);
     331
     332
     333  NodeVec sectorNode = uap_root->getSubNodesByName(string("sector"));
     334
     335  if ( !sectorNode.size() ) {
     336    cout << " dataManager::restoreAMLElements ERREUR lecture fichier : pas de sectors ? " << endl;
     337    return false;
     338  }
     339
     340
     341  NodeVec& listElem = ( *sectorNode.begin() )->getChildren();
     342  if (  !listElem.size() ) {
     343    cout << " dataManager::restoreAMLElements ERREUR lecture fichier : pas d'elements ? " << endl;
     344    return false;
     345  } else {
     346    cout << " dataManager::restoreAMLElements : liste elements non vide : SUCCES " << endl;
     347  }
     348
     349  for (NodeVecIter iter = listElem.begin(); iter != listElem.end(); iter++) {
     350
     351    string nomNoeud = (*iter)->getName();
     352    if ( nomNoeud != string("element") ) {
     353      cout << " le secteur contient un non-element : " << nomNoeud << endl;
     354      continue;
     355    }
     356
     357    UAPAttribute* att = NULL;
     358    att = (*iter)->getAttribute("name");
     359
     360    cout << " dataManager::restoreAMLElements trouve element " << att->getValue();
     361
     362    string nomGenerique;
     363    AMLtools::readAMLParameterAttribut(*iter, "description", "type", nomGenerique);
     364
     365    // UAPNode*  genericName = (*iter)->getChildByName("description");
     366    // att = genericName->getAttribute("type");
     367
     368    cout <<  " de type " << nomGenerique << endl;
     369
     370
     371    elementType = nomdElements::getTypeFromLabel(nomGenerique);
     372    nouveau = mySect->addElementAfter(elementType,nouveau);
     373
    258374      if ( nouveau == NULL ) {
    259         cerr << " dataManager::restoreElements() : restore element " << elementLabel << " failed " << endl;
     375        cerr << " dataManager::restoreAMLElements() : restore element " << att->getValue() << " failed " << endl;
    260376        return false;
    261377      } else {
    262         nouveau->FileInput(infile);
     378        nouveau->FileAMLInput(*iter);
    263379      }
    264     }
    265   }// while
    266  
    267 #if BAVARD > 1
    268 /*  unsigned k;
    269   for(k = 0; k < getBeamLineSize(); k++) {
    270     abstractElement* ptr = pspa_->getBeamLine_deprecated()->getAbstractElement(k);
    271     cout << "recupere " << ptr->getLabel() << endl;
    272   }
    273 */
    274 #endif
    275 
    276   infile.close();
     380  }
     381
     382 
    277383  return true;
    278384}
     385
    279386
    280387particleBeam* dataManager::getDiagnosticBeam(unsigned index)
Note: See TracChangeset for help on using the changeset viewer.