1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-10 07:55:35 +00:00

Added the ability to write a version of the validated XML file excluding any of the module IDs supplied in a separate exclude file

This commit is contained in:
Michael Marshall 2019-07-26 19:46:55 +01:00
parent e7050a7aed
commit f5ad4f3de8
3 changed files with 60 additions and 11 deletions

View File

@ -180,7 +180,7 @@ void Application::parseParameterFile(const std::string parameterFileName)
pop(reader);
}
void Application::saveParameterFile(const std::string parameterFileName, unsigned int prec)
void Application::saveParameterFile(const std::string &parameterFileName, const std::vector<std::string> &Except, unsigned int prec)
{
LOG(Message) << "Saving application to '" << parameterFileName << "'..." << std::endl;
if (env().getGrid()->IsBoss())
@ -194,18 +194,27 @@ void Application::saveParameterFile(const std::string parameterFileName, unsigne
push(writer, "modules");
for (unsigned int i = 0; i < nMod; ++i)
{
push(writer, "module");
id.name = vm().getModuleName(i);
if( std::find( Except.begin(), Except.end(), id.name ) == Except.end() )
{
push(writer, "module");
id.type = vm().getModule(i)->getRegisteredName();
write(writer, "id", id);
vm().getModule(i)->saveParameters(writer, "options");
pop(writer);
}
}
pop(writer);
pop(writer);
}
}
void Application::saveParameterFile(const std::string &parameterFileName, unsigned int prec)
{
const std::vector<std::string> Except;
saveParameterFile(parameterFileName, Except, prec);
}
// schedule computation ////////////////////////////////////////////////////////
void Application::schedule(void)
{

View File

@ -81,7 +81,8 @@ public:
void run(void);
// XML parameter file I/O
void parseParameterFile(const std::string parameterFileName);
void saveParameterFile(const std::string parameterFileName, unsigned int prec=15);
void saveParameterFile(const std::string &parameterFileName, unsigned int prec=15);
void saveParameterFile(const std::string &parameterFileName, const std::vector<std::string> &Except, unsigned int prec=15);
// schedule computation
void schedule(void);
void saveSchedule(const std::string filename);

View File

@ -27,24 +27,52 @@ See the full license in the file "LICENSE" in the top level distribution directo
/* END LEGAL */
#include <Hadrons/Application.hpp>
#include <sys/stat.h>
#include <fstream>
#include <string>
using namespace Grid;
using namespace QCD;
using namespace Hadrons;
// Does the specified file exist?
bool FileExists(const std::string& Filename)
{
struct stat buf;
return stat(Filename.c_str(), &buf) != -1;
}
void Shorten( Application &app, const std::string &FileList, const std::string OutFileName )
{
std::vector<std::string> Except;
std::ifstream list{ FileList };
for( std::string s; std::getline(list, s); ) {
//const std::string::size_type l{ s.find_first_of( '.' ) };
//if( l != std::string::npos )
//s.resize( l );
if( s.length() )
Except.push_back( s );
}
std::sort( Except.begin(), Except.end() );
for( const std::string &s : Except )
std::cout << s << std::endl;
app.saveParameterFile( OutFileName, Except );
}
int main(int argc, char *argv[])
{
// parse command line
std::string parameterFileName;
if (argc != 2)
if (argc != 2 && argc != 4)
{
std::cerr << "usage: " << argv[0] << " <parameter file>";
std::cerr << "usage: " << argv[0] << " <parameter file> [filelist.txt output.xml]";
std::cerr << std::endl;
std::exit(EXIT_FAILURE);
}
parameterFileName = argv[1];
if( argc == 4 )
Grid_init(&argc, &argv);
try
{
Application application(parameterFileName);
@ -54,11 +82,22 @@ int main(int argc, char *argv[])
vm.getModuleGraph();
LOG(Message) << "Application valid (check XML warnings though)"
<< std::endl;
if( argc == 4 ) {
const std::string FileList{ argv[3] };
const std::string OutFileName{ argv[2] };
if( !FileExists( FileList ) )
std::cout << "File list \"" << FileList << "\" does not exist" << std::endl;
else {
Shorten( application, FileList, OutFileName );
}
}
}
catch (const std::exception& e)
{
Exceptions::abort(e);
}
if( argc == 4 )
Grid_finalize();
return EXIT_SUCCESS;
}