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

Hadrons: better handling of automatic directory creation

This commit is contained in:
Antonin Portelli 2018-05-07 19:43:40 +01:00
parent 2017e4e3b4
commit f362c00739
4 changed files with 19 additions and 22 deletions

View File

@ -170,14 +170,8 @@ protected:
{
ScidacWriter binWriter(evec[0]._grid->IsBoss());
XmlWriter xmlWriter("", "eigenPackPar");
std::string d = dirname(filename);
int status = mkdir(d);
if (status)
{
HADRONS_ERROR(Io, "cannot create directory '" + d
+ "' (status " + std::to_string(status) + ")");
}
makeFileDir(filename, evec[0]._grid);
xmlWriter.pushXmlString(record.operatorXml);
xmlWriter.pushXmlString(record.solverXml);
binWriter.open(filename);
@ -201,14 +195,8 @@ protected:
ScidacWriter binWriter(evec._grid->IsBoss());
XmlWriter xmlWriter("", "eigenPackPar");
VecRecord vecRecord;
std::string d = dirname(filename);
int status = mkdir(d);
if (status)
{
HADRONS_ERROR(Io, "cannot create directory '" + d
+ "' (status " + std::to_string(status) + ")");
}
makeFileDir(filename, evec._grid);
xmlWriter.pushXmlString(record.operatorXml);
xmlWriter.pushXmlString(record.solverXml);
binWriter.open(filename);

View File

@ -158,3 +158,18 @@ std::string Hadrons::dirname(const std::string &s)
return "";
}
}
void Hadrons::makeFileDir(const std::string filename, GridBase *g)
{
if (g->IsBoss())
{
std::string dir = dirname(filename);
int status = mkdir(dir);
if (status)
{
HADRONS_ERROR(Io, "cannot create directory '" + dir
+ "' ( " + std::strerror(errno) + ")");
}
}
}

View File

@ -192,6 +192,7 @@ name + "." + std::to_string(vm().getTrajectory()) + "." + resultFileExt
int mkdir(const std::string dirName);
std::string basename(const std::string &s);
std::string dirname(const std::string &s);
void makeFileDir(const std::string filename, GridBase *g);
// default Schur convention
#ifndef HADRONS_DEFAULT_SCHUR

View File

@ -122,14 +122,7 @@ MACRO_REDIRECT(__VA_ARGS__, envTmpLat5, envTmpLat4)(__VA_ARGS__)
#define saveResult(ioStem, name, result)\
if (env().getGrid()->IsBoss())\
{\
std::string _dirname = dirname(ioStem);\
int _status = mkdir(_dirname);\
\
if (_status)\
{\
HADRONS_ERROR(Io, "cannot create directory '" + _dirname \
+ "' (status " + std::to_string(_status) + ")");\
}\
makeFileDir(ioStem, env().getGrid());\
{\
ResultWriter _writer(RESULT_FILE_NAME(ioStem));\
write(_writer, name, result);\