1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-04 19:25:56 +01:00

Hadrons: function to save an application as an XML file

This commit is contained in:
Antonin Portelli 2016-12-14 18:01:56 +00:00
parent 3af663e17b
commit 34df71e755
5 changed files with 55 additions and 7 deletions

View File

@ -79,12 +79,17 @@ void Application::setPar(const Application::GlobalPar &par)
env_.setSeed(strToVec<int>(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)"

View File

@ -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 <typename M>
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

View File

@ -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)
{

View File

@ -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 <typename M>

View File

@ -107,6 +107,7 @@ public:
virtual std::vector<std::string> 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<P>::parseParameters(XmlReader &reader, const std::string name)
read(reader, name, par_);
}
template <typename P>
void Module<P>::saveParameters(XmlWriter &writer, const std::string name)
{
write(writer, name, par_);
}
template <typename P>
const P & Module<P>::par(void) const
{