[asl] 37/177: Writing default config file
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Aug 27 09:22:36 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch master
in repository asl.
commit e521798c2eb0beaad54cf99c803b4308313c3c66
Author: AvtechScientific <AvtechScientific at users.noreply.github.com>
Date: Fri Jun 19 12:51:32 2015 +0300
Writing default config file
---
src/acl/aclHardware.cxx | 1 +
src/aslUtilities.h | 4 +-
src/utilities/aslParametersManager.cxx | 76 +++++++++++++++++++++++++++++++---
src/utilities/aslParametersManager.h | 13 ++++--
4 files changed, 84 insertions(+), 10 deletions(-)
diff --git a/src/acl/aclHardware.cxx b/src/acl/aclHardware.cxx
index 46b3b5a..afb7d9f 100644
--- a/src/acl/aclHardware.cxx
+++ b/src/acl/aclHardware.cxx
@@ -125,6 +125,7 @@ namespace acl
return defaultDeviceInfo;
}
+
void Hardware::loadConfiguration(const string & fileName)
{
/* ParametersManager parametersManager;
diff --git a/src/aslUtilities.h b/src/aslUtilities.h
index e193115..0d650e7 100644
--- a/src/aslUtilities.h
+++ b/src/aslUtilities.h
@@ -41,7 +41,7 @@
namespace asl
{
- /// Converts numbers or an other type to string \ingroup Utilities
+ /// Converts numbers or another type to string \ingroup Utilities
template <typename T> inline std::string numToStr(T i)
{
std::stringstream s;
@@ -50,7 +50,7 @@ namespace asl
}
- /// Converts numbers or an other type to string with given value of positions with 0 before \ingroup Utilities
+ /// Converts numbers or another type to string with given value of positions with 0 before \ingroup Utilities
template <typename T> std::string numToStr(T i, int numberOf0)
{
std::stringstream s;
diff --git a/src/utilities/aslParametersManager.cxx b/src/utilities/aslParametersManager.cxx
index 321cdc7..a2ab3eb 100644
--- a/src/utilities/aslParametersManager.cxx
+++ b/src/utilities/aslParametersManager.cxx
@@ -208,9 +208,20 @@ namespace asl
ParametersManager * ParametersManager::current(NULL);
ParametersManager::ParametersManager():
- configurationOptions("Configuration options")
+ configurationOptions("Configuration options"),
+ parametersFileStr(""),
+ folder(""),
+ folderWithSlash(""),
+ programName(""),
+ programVersion("")
{
enable();
+ // Add platform and device parameters with default values
+ Parameter<string> platform(acl::getPlatformVendor(acl::hardware.defaultQueue),
+ "platform", "Default computation platform", "");
+ Parameter<string> device(acl::getDeviceName(acl::hardware.defaultQueue),
+ "device", "Default computation device", "");
+ // ToDo: if the above doesn't work use add();
}
@@ -264,6 +275,9 @@ namespace asl
{
configurationOptions.add_options()
(key.c_str(), value<T>(¶meter.v())->required(), description.c_str());
+
+ // Add the option to the default parameters file
+ parametersFileStr += "\n# " + description + "\n" + key + " = \n";
}
@@ -273,6 +287,8 @@ namespace asl
{
configurationOptions.add_options()
(key.c_str(), value<T>()->required(), description.c_str());
+ // ToDo: maps - Add the option to the default parameters file
+// parametersFileStr += "\n# " + description + "\n" + key + " = " + numToStr(defaultValue) + "\n";
}
@@ -283,6 +299,9 @@ namespace asl
{
configurationOptions.add_options()
(key.c_str(), value<T>(¶meter.v())->default_value(defaultValue), description.c_str());
+
+ // Add the option to the default parameters file
+ parametersFileStr += "\n# " + description + "\n" + key + " = " + numToStr(defaultValue) + "\n";
}
@@ -304,9 +323,12 @@ namespace asl
void ParametersManager::load(int argc, char * argv[],
- string programName,
- string programVersion)
+ string programName_,
+ string programVersion_)
{
+ programName = programName_;
+ programVersion = programVersion_;
+
variables_map vm;
options_description genericOptions("Generic options");
@@ -315,9 +337,10 @@ namespace asl
("help,h", "display this help and exit")
("version,v", "display version and exit")
("devices,d", "display available devices and exit")
- ("folder,f",
- value<string>()->default_value("Default"),
+ ("folder,f", value<string>()->default_value("Default"),
"path to the working folder that contains configuration file - parameters.ini")
+ ("parameters,p", value<string>()->default_value("."),
+ "generate default configuration file parameters.ini, write it to the provided path and exit")
("check,c", "check configuration for consistency and exit");
positional_options_description positional;
@@ -349,12 +372,31 @@ namespace asl
if (vm.count("devices"))
{
cout << programName + " " + programVersion + "\n\n"
+ << "Default computation device:"
<< acl::hardware.getDefaultDeviceInfo() << "\n\n"
+ << "List of all available platforms and their devices:\n"
<< acl::hardware.getDevicesInfo()
<< endl;
exit(0);
}
+ if (vm.count("parameters"))
+ {
+ path p(vm["parameters"].as<string>());
+ // add at least one slash at the end
+ p /= "/";
+ // and then cut all possible slashes at the end
+ p = p.parent_path();
+ p /= "/";
+ p /= "parameters.ini";
+
+ cout << "Writing default configuration file to: "
+ << p.string() << endl;
+
+ writeParametersFile(p.string());
+ exit(0);
+ }
+
path p(vm["folder"].as<string>());
// add at least one slash at the end
p /= "/";
@@ -366,7 +408,11 @@ namespace asl
p /= "parameters.ini";
ifstream ifs(p.string());
if (!ifs)
+ {
+ // Only warn, since all options might have default values, or required values
+ // provided through the command line - so no configuration file is required
warningMessage("ParametersManager::load() - can not open configuration file: " + p.string());
+ }
parsed_options parsed = parse_config_file(ifs, allOptions, true);
store(parsed, vm);
@@ -376,6 +422,9 @@ namespace asl
populateMaps(vm);
+ // Set Hardware default queue as required through provided options
+ acl::hardware.setDefaultQueue(vm["platform"].as<string>(), vm["device"].as<string>());
+
// Place it after(!) notify(vm);
if (vm.count("check"))
{
@@ -424,5 +473,22 @@ namespace asl
{
return folderWithSlash;
}
+
+
+ void ParametersManager::writeParametersFile(const std::string fileName)
+ {
+ ofstream fo(fileName);
+ if (!fo)
+ errorMessage("ParametersManager::writeParametersFile() - can not open file: " + fileName);
+
+ // Prepend informative header
+ parametersFileStr = "# Parameters file with default values (where available).\n# Generated by "
+ + programName + " version " + programVersion + "\n\n"
+ + "# Get the list of all available computation devices by running:\n"
+ + "# `" + programName + " -d`\n" + parametersFileStr;
+
+ fo << parametersFileStr;
+ fo.close();
+ }
} //namespace asl
diff --git a/src/utilities/aslParametersManager.h b/src/utilities/aslParametersManager.h
index 1c16ecf..32ebf18 100644
--- a/src/utilities/aslParametersManager.h
+++ b/src/utilities/aslParametersManager.h
@@ -97,8 +97,8 @@ namespace asl
/// from command line and/or configuration file (provided
/// through command line)
void load(int argc, char* argv[],
- std::string programName = "program_name",
- std::string programVersion = "1.0");
+ std::string programName_ = "program_name",
+ std::string programVersion_ = "1.0");
/// Loads all previously declared parameters
/// from configuration file \p configFile
void load(std::string configFile);
@@ -111,11 +111,18 @@ namespace asl
boost::program_options::options_description configurationOptions;
std::string folder;
std::string folderWithSlash;
+ std::string programName;
+ std::string programVersion;
/// Accomodates prefixes (defined by attached "*" wildcard)
/// using PrefixStore class
std::vector<std::shared_ptr<PrefixStore>> prefixes;
- void populateMaps(boost::program_options::variables_map & vm);
+ void populateMaps(boost::program_options::variables_map & vm);
+ /// Wrties all parameters and their
+ /// default values (if available) to the file \p fileName
+ void writeParametersFile(const std::string fileName);
+ /// Content of the parameters file
+ std::string parametersFileStr;
};
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/asl.git
More information about the debian-science-commits
mailing list