diff --git a/extras/Hadrons/Application.cc b/extras/Hadrons/Application.cc index 62c69230..07971a16 100644 --- a/extras/Hadrons/Application.cc +++ b/extras/Hadrons/Application.cc @@ -79,12 +79,17 @@ void Application::setPar(const Application::GlobalPar &par) env_.setSeed(strToVec(par_.seed)); } +const Application::GlobalPar & Application::getPar(void) +{ + return par_; +} + // execute ///////////////////////////////////////////////////////////////////// void Application::run(void) { if (!parameterFileName_.empty()) { - parseParameterFile(); + parseParameterFile(parameterFileName_); } schedule(); configLoop(); @@ -99,13 +104,13 @@ public: std::string, type); }; -void Application::parseParameterFile(void) +void Application::parseParameterFile(const std::string parameterFileName) { - XmlReader reader(parameterFileName_); + XmlReader reader(parameterFileName); GlobalPar par; ObjectId id; - LOG(Message) << "Reading '" << parameterFileName_ << "'..." << std::endl; + LOG(Message) << "Reading '" << parameterFileName << "'..." << std::endl; read(reader, "parameters", par); setPar(par); push(reader, "modules"); @@ -119,6 +124,28 @@ void Application::parseParameterFile(void) pop(reader); } +void Application::saveParameterFile(const std::string parameterFileName) +{ + XmlWriter writer(parameterFileName); + ObjectId id; + const unsigned int nMod = env_.getNModule(); + + LOG(Message) << "Writing '" << parameterFileName << "'..." << std::endl; + write(writer, "parameters", getPar()); + push(writer, "modules"); + for (unsigned int i = 0; i < nMod; ++i) + { + push(writer, "module"); + id.name = env_.getModuleName(i); + id.type = env_.getModule(i)->getRegisteredName(); + write(writer, "id", id); + env_.getModule(i)->saveParameters(writer, "options"); + pop(writer); + } + pop(writer); + pop(writer); +} + // schedule computation //////////////////////////////////////////////////////// #define MEM_MSG(size)\ sizeString((size)*locVol_) << " (" << sizeString(size) << "/site)" diff --git a/extras/Hadrons/Application.hpp b/extras/Hadrons/Application.hpp index 846b4dfa..65e9ad34 100644 --- a/extras/Hadrons/Application.hpp +++ b/extras/Hadrons/Application.hpp @@ -77,7 +77,8 @@ public: // destructor virtual ~Application(void) = default; // access - void setPar(const GlobalPar &par); + void setPar(const GlobalPar &par); + const GlobalPar & getPar(void); // module creation template void createModule(const std::string name); @@ -85,8 +86,9 @@ public: void createModule(const std::string name, const typename M::Par &par); // execute void run(void); - // parse parameter file - void parseParameterFile(void); + // XML parameter file I/O + void parseParameterFile(const std::string parameterFileName); + void saveParameterFile(const std::string parameterFileName); // schedule computation void schedule(void); // loop on configurations diff --git a/extras/Hadrons/Environment.cc b/extras/Hadrons/Environment.cc index 67880cd3..600ca855 100644 --- a/extras/Hadrons/Environment.cc +++ b/extras/Hadrons/Environment.cc @@ -190,6 +190,11 @@ void Environment::pushModule(Environment::ModPt &pt) } } +unsigned int Environment::getNModule(void) const +{ + return module_.size(); +} + void Environment::createModule(const std::string name, const std::string type, XmlReader &reader) { diff --git a/extras/Hadrons/Environment.hpp b/extras/Hadrons/Environment.hpp index 88661c2e..065c889a 100644 --- a/extras/Hadrons/Environment.hpp +++ b/extras/Hadrons/Environment.hpp @@ -117,6 +117,7 @@ public: void createModule(const std::string name, const std::string type, XmlReader &reader); + unsigned int getNModule(void) const; ModuleBase * getModule(const unsigned int address) const; ModuleBase * getModule(const std::string name) const; template diff --git a/extras/Hadrons/Module.hpp b/extras/Hadrons/Module.hpp index 78ce8a6a..358621f4 100644 --- a/extras/Hadrons/Module.hpp +++ b/extras/Hadrons/Module.hpp @@ -107,6 +107,7 @@ public: virtual std::vector getOutput(void) = 0; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name) = 0; + virtual void saveParameters(XmlWriter &writer, const std::string name) = 0; // setup virtual void setup(void) {}; // execution @@ -130,6 +131,7 @@ public: virtual ~Module(void) = default; // parse parameters virtual void parseParameters(XmlReader &reader, const std::string name); + virtual void saveParameters(XmlWriter &writer, const std::string name); // parameter access const P & par(void) const; void setPar(const P &par); @@ -150,6 +152,11 @@ public: virtual ~Module(void) = default; // parse parameters (do nothing) virtual void parseParameters(XmlReader &reader, const std::string name) {}; + virtual void saveParameters(XmlWriter &writer, const std::string name) + { + push(writer, "options"); + pop(writer); + }; }; /****************************************************************************** @@ -166,6 +173,12 @@ void Module

::parseParameters(XmlReader &reader, const std::string name) read(reader, name, par_); } +template +void Module

::saveParameters(XmlWriter &writer, const std::string name) +{ + write(writer, name, par_); +} + template const P & Module

::par(void) const {