LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
testing::BasicEnvironmentConfiguration Struct Reference

Class holding a configuration for a test environment. More...

#include "unit_test_base.h"

Public Member Functions

 BasicEnvironmentConfiguration ()
 Default constructor; this is what is used in Boost unit test. More...
 
 BasicEnvironmentConfiguration (int argc, char **argv)
 Constructor: acquires parameters from the command line. More...
 
 BasicEnvironmentConfiguration (std::string name)
 Constructor; accepts the name as parameter. More...
 
 BasicEnvironmentConfiguration (int argc, char **argv, std::string name)
 
Access to configuration

Name of the application

std::string ApplicationName () const
 Path to the configuration file. More...
 
std::string ConfigurationPath () const
 Path to the configuration file. More...
 
std::string TesterParameterSetPath (std::string name) const
 FHiCL path for the configuration of the test algorithm. More...
 
std::string MainTesterParameterSetName () const
 Name of the test algorithm instance. More...
 
std::string MainTesterParameterSetPath () const
 FHiCL path for the configuration of the test algorithm. More...
 
std::string ServiceParameterSetPath (std::string name) const
 FHiCL path for the configuration of the service. More...
 
std::string DefaultTesterConfiguration (std::string tester_name) const
 A string describing default parameter set to configure specified test. More...
 
std::string DefaultServiceConfiguration (std::string service_name) const
 A string describing the default parameter set to configure the test. More...
 
std::string DefaultConfiguration () const
 A string describing the full default parameter set. More...
 
std::string ExecutablePath () const
 Returns the name of the executable as started. More...
 
std::vector< std::string > const & EexcutableArguments () const
 Returns the list of non-Boost-test arguments on the command line. More...
 
Set configuration
void SetApplicationName (std::string name)
 Sets the name of the application. More...
 
void SetConfigurationPath (std::string path)
 Sets the path to the configuration file. More...
 
void SetMainTesterParameterSetName (std::string name)
 Sets the FHiCL name for the configuration of the test algorithm. More...
 
void SetTesterParameterSetPath (std::string test_name, std::string path)
 Sets the FHiCL path for the configuration of a test algorithm. More...
 
void SetMainTesterParameterSetPath (std::string path)
 Sets the FHiCL path for the configuration of the main test algorithm. More...
 
void SetServiceParameterSetPath (std::string service_name, std::string path)
 Sets the FHiCL path for the configuration of a test algorithm. More...
 
void AddDefaultServiceConfiguration (std::string service_name, std::string service_cfg)
 Adds a default configuration for the specified service. More...
 
void AddDefaultTesterConfiguration (std::string tester_name, std::string tester_cfg)
 Adds a default configuration for the specified tester. More...
 
void AddDefaultTesterConfiguration (std::string tester_cfg)
 Adds a default configuration for the main tester. More...
 

Protected Types

using ConfigurationMap_t = std::map< std::string, std::string >
 
using PathMap_t = std::map< std::string, std::string >
 

Protected Member Functions

void ParseCommandLine (int argc, char **argv)
 Extracts arguments from the command line, uses first one as config path. More...
 
void DefaultInit ()
 Initialize with some default values. More...
 
std::string BuildDefaultServiceConfiguration () const
 A string describing the full default parameter set. More...
 
std::string BuildDefaultTestConfiguration () const
 A string describing the full default parameter set. More...
 
std::string BuildDefaultConfiguration () const
 A string describing the full default parameter set. More...
 

Static Protected Member Functions

static std::string DefaultApplicationName ()
 Returns the default test name. More...
 
static std::string BuildServiceConfiguration (ConfigurationMap_t const &services)
 A string with the service section from service parameter sets. More...
 
static std::string BuildTestConfiguration (ConfigurationMap_t const &analyzers)
 A string with the physics section from analyzer parameter sets. More...
 
static std::string BuildConfiguration (ConfigurationMap_t const &services, ConfigurationMap_t const &modules)
 A string describing the full default parameter set. More...
 

Protected Attributes

std::string appl_name
 name of the application More...
 
std::string config_path
 configuration file path More...
 
std::string main_test_name
 name of main test algorithm More...
 
std::string main_test_path
 path of main test algorithm configuration More...
 
ConfigurationMap_t services_default_cfg
 Configuration of all the services. More...
 
ConfigurationMap_t analyzers_default_cfg
 Configuration of all the analyzer modules. More...
 
PathMap_t test_paths
 Set of paths for tester configuration. More...
 
PathMap_t service_paths
 Set of paths for service configuration. More...
 

Private Attributes

details::CommandLineArguments arguments
 command line arguments More...
 

Detailed Description

Class holding a configuration for a test environment.


This class needs to be fully constructed by the default constructor in order to be useful as Boost unit test fixture. It is supposed to be passed as a template parameter to another class that can store an instance of it and extract configuration information from it.

Definition at line 129 of file unit_test_base.h.

Member Typedef Documentation

using testing::BasicEnvironmentConfiguration::ConfigurationMap_t = std::map<std::string, std::string>
protected

Definition at line 260 of file unit_test_base.h.

using testing::BasicEnvironmentConfiguration::PathMap_t = std::map<std::string, std::string>
protected

Definition at line 261 of file unit_test_base.h.

Constructor & Destructor Documentation

testing::BasicEnvironmentConfiguration::BasicEnvironmentConfiguration ( )
inline

Default constructor; this is what is used in Boost unit test.

Definition at line 132 of file unit_test_base.h.

132 { DefaultInit(); }
void DefaultInit()
Initialize with some default values.
testing::BasicEnvironmentConfiguration::BasicEnvironmentConfiguration ( int  argc,
char **  argv 
)
inline

Constructor: acquires parameters from the command line.

Definition at line 135 of file unit_test_base.h.

135  :
137  { ParseCommandLine(argc, argv); }
void ParseCommandLine(int argc, char **argv)
Extracts arguments from the command line, uses first one as config path.
BasicEnvironmentConfiguration()
Default constructor; this is what is used in Boost unit test.
testing::BasicEnvironmentConfiguration::BasicEnvironmentConfiguration ( std::string  name)
inline

Constructor; accepts the name as parameter.

Definition at line 140 of file unit_test_base.h.

References mf::SetApplicationName().

140  :
142  { SetApplicationName(name); }
void SetApplicationName(std::string name)
Sets the name of the application.
BasicEnvironmentConfiguration()
Default constructor; this is what is used in Boost unit test.
testing::BasicEnvironmentConfiguration::BasicEnvironmentConfiguration ( int  argc,
char **  argv,
std::string  name 
)
inline

Definition at line 144 of file unit_test_base.h.

References mf::SetApplicationName().

144  :
146  { SetApplicationName(name); }
void SetApplicationName(std::string name)
Sets the name of the application.
BasicEnvironmentConfiguration()
Default constructor; this is what is used in Boost unit test.

Member Function Documentation

void testing::BasicEnvironmentConfiguration::AddDefaultServiceConfiguration ( std::string  service_name,
std::string  service_cfg 
)
inline

Adds a default configuration for the specified service.

Definition at line 237 of file unit_test_base.h.

238  { services_default_cfg[service_name] = service_cfg; }
ConfigurationMap_t services_default_cfg
Configuration of all the services.
void testing::BasicEnvironmentConfiguration::AddDefaultTesterConfiguration ( std::string  tester_name,
std::string  tester_cfg 
)
inline

Adds a default configuration for the specified tester.

Definition at line 242 of file unit_test_base.h.

243  { analyzers_default_cfg[tester_name] = tester_cfg; }
ConfigurationMap_t analyzers_default_cfg
Configuration of all the analyzer modules.
void testing::BasicEnvironmentConfiguration::AddDefaultTesterConfiguration ( std::string  tester_cfg)
inline

Adds a default configuration for the main tester.

Definition at line 246 of file unit_test_base.h.

247  {
248  if (MainTesterParameterSetName().empty()) {
249  throw std::logic_error
250  ("Request adding configuration of non-existent main tester");
251  }
253  }
std::string MainTesterParameterSetName() const
Name of the test algorithm instance.
void AddDefaultTesterConfiguration(std::string tester_name, std::string tester_cfg)
Adds a default configuration for the specified tester.
std::string testing::BasicEnvironmentConfiguration::ApplicationName ( ) const
inline

Path to the configuration file.

Definition at line 151 of file unit_test_base.h.

151 { return appl_name; }
std::string appl_name
name of the application
static std::string testing::BasicEnvironmentConfiguration::BuildConfiguration ( ConfigurationMap_t const &  services,
ConfigurationMap_t const &  modules 
)
inlinestaticprotected

A string describing the full default parameter set.

Definition at line 367 of file unit_test_base.h.

368  {
369  std::string cfg;
370  cfg += BuildServiceConfiguration(services);
371  cfg += BuildTestConfiguration(modules);
372  return cfg;
373  } // BuildConfiguration()
static std::string BuildServiceConfiguration(ConfigurationMap_t const &services)
A string with the service section from service parameter sets.
static std::string BuildTestConfiguration(ConfigurationMap_t const &analyzers)
A string with the physics section from analyzer parameter sets.
std::string testing::BasicEnvironmentConfiguration::BuildDefaultConfiguration ( ) const
inlineprotected

A string describing the full default parameter set.

Definition at line 322 of file unit_test_base.h.

323  {
325  }
ConfigurationMap_t services_default_cfg
Configuration of all the services.
static std::string BuildConfiguration(ConfigurationMap_t const &services, ConfigurationMap_t const &modules)
A string describing the full default parameter set.
ConfigurationMap_t analyzers_default_cfg
Configuration of all the analyzer modules.
std::string testing::BasicEnvironmentConfiguration::BuildDefaultServiceConfiguration ( ) const
inlineprotected

A string describing the full default parameter set.

Definition at line 314 of file unit_test_base.h.

ConfigurationMap_t services_default_cfg
Configuration of all the services.
static std::string BuildServiceConfiguration(ConfigurationMap_t const &services)
A string with the service section from service parameter sets.
std::string testing::BasicEnvironmentConfiguration::BuildDefaultTestConfiguration ( ) const
inlineprotected

A string describing the full default parameter set.

Definition at line 318 of file unit_test_base.h.

static std::string BuildTestConfiguration(ConfigurationMap_t const &analyzers)
A string with the physics section from analyzer parameter sets.
ConfigurationMap_t analyzers_default_cfg
Configuration of all the analyzer modules.
static std::string testing::BasicEnvironmentConfiguration::BuildServiceConfiguration ( ConfigurationMap_t const &  services)
inlinestaticprotected

A string with the service section from service parameter sets.

Definition at line 330 of file unit_test_base.h.

331  {
332  std::string cfg;
333  cfg += "\nservices: {";
334  for (auto const& service_info: services) {
335  cfg += "\n " + service_info.first + ": {";
336  cfg += "\n" + service_info.second;
337  cfg += "\n } # " + service_info.first;
338  } // for services
339  cfg +=
340  "\n} # services"
341  "\n";
342  return cfg;
343  } // BuildServiceConfiguration()
static std::string testing::BasicEnvironmentConfiguration::BuildTestConfiguration ( ConfigurationMap_t const &  analyzers)
inlinestaticprotected

A string with the physics section from analyzer parameter sets.

Definition at line 347 of file unit_test_base.h.

348  {
349  std::string cfg;
350  cfg +=
351  "\nphysics: {"
352  "\n analyzers: {"
353  ;
354  for (auto const& module_info: analyzers) {
355  cfg += "\n " + module_info.first + ": {";
356  cfg += "\n" + module_info.second;
357  cfg += "\n } # " + module_info.first;
358  } // for analyzers
359  cfg +=
360  "\n } # analyzers"
361  "\n} # physics";
362  return cfg;
363  } // BuildServiceConfiguration()
std::string testing::BasicEnvironmentConfiguration::ConfigurationPath ( ) const
inline

Path to the configuration file.

Definition at line 154 of file unit_test_base.h.

154 { return config_path; }
std::string config_path
configuration file path
static std::string testing::BasicEnvironmentConfiguration::DefaultApplicationName ( )
inlinestaticprotected

Returns the default test name.

Definition at line 269 of file unit_test_base.h.

269 { return "Test"; }
std::string testing::BasicEnvironmentConfiguration::DefaultConfiguration ( ) const
inline

A string describing the full default parameter set.

Definition at line 191 of file unit_test_base.h.

192  { return BuildDefaultConfiguration(); }
std::string BuildDefaultConfiguration() const
A string describing the full default parameter set.
void testing::BasicEnvironmentConfiguration::DefaultInit ( )
inlineprotected

Initialize with some default values.

Definition at line 290 of file unit_test_base.h.

References mf::SetApplicationName().

291  {
294  // a destination which will react to all messages from DEBUG up:
296  R"(
297  debugModules: [ '*' ]
298  destinations : {
299  stdout: {
300  type: cout
301  threshold: DEBUG
302  categories: {
303  default: {
304  limit: -1
305  }
306  } // categories
307  } // stdout
308  statistics: {type:cout}
309  } // destinations
310  )");
311  } // DefaultInit()
void SetApplicationName(std::string name)
Sets the name of the application.
void SetMainTesterParameterSetName(std::string name)
Sets the FHiCL name for the configuration of the test algorithm.
static std::string DefaultApplicationName()
Returns the default test name.
void AddDefaultServiceConfiguration(std::string service_name, std::string service_cfg)
Adds a default configuration for the specified service.
std::string testing::BasicEnvironmentConfiguration::DefaultServiceConfiguration ( std::string  service_name) const
inline

A string describing the default parameter set to configure the test.

Definition at line 187 of file unit_test_base.h.

188  { return services_default_cfg.at(service_name); }
ConfigurationMap_t services_default_cfg
Configuration of all the services.
std::string testing::BasicEnvironmentConfiguration::DefaultTesterConfiguration ( std::string  tester_name) const
inline

A string describing default parameter set to configure specified test.

Definition at line 183 of file unit_test_base.h.

184  { return analyzers_default_cfg.at(tester_name); }
ConfigurationMap_t analyzers_default_cfg
Configuration of all the analyzer modules.
std::vector<std::string> const& testing::BasicEnvironmentConfiguration::EexcutableArguments ( ) const
inline

Returns the list of non-Boost-test arguments on the command line.

Definition at line 198 of file unit_test_base.h.

199  { return arguments.Arguments(); }
details::CommandLineArguments arguments
command line arguments
std::vector< std::string > const & Arguments() const
Returns the list of non-Boost-test arguments on the command line.
std::string testing::BasicEnvironmentConfiguration::ExecutablePath ( ) const
inline

Returns the name of the executable as started.

Definition at line 195 of file unit_test_base.h.

195 { return arguments.Executable(); }
details::CommandLineArguments arguments
command line arguments
std::string Executable() const
Returns the name of the executable as started.
std::string testing::BasicEnvironmentConfiguration::MainTesterParameterSetName ( ) const
inline

Name of the test algorithm instance.

Definition at line 165 of file unit_test_base.h.

165 { return main_test_name; }
std::string main_test_name
name of main test algorithm
std::string testing::BasicEnvironmentConfiguration::MainTesterParameterSetPath ( ) const
inline

FHiCL path for the configuration of the test algorithm.

Definition at line 168 of file unit_test_base.h.

169  {
170  return MainTesterParameterSetName().empty()
172  }
std::string TesterParameterSetPath(std::string name) const
FHiCL path for the configuration of the test algorithm.
std::string MainTesterParameterSetName() const
Name of the test algorithm instance.
void testing::BasicEnvironmentConfiguration::ParseCommandLine ( int  argc,
char **  argv 
)
inlineprotected

Extracts arguments from the command line, uses first one as config path.

Definition at line 282 of file unit_test_base.h.

283  {
284  arguments.ParseArguments(argc, argv);
285  if (arguments.hasArgument(0))
286  SetConfigurationPath(arguments.Argument(0)); // first argument
287  }
void ParseArguments(int argc, char **argv)
Parses arguments.
details::CommandLineArguments arguments
command line arguments
bool hasArgument(size_t iArg) const
Returns whether we have arguments up to the iArg-th (0-based)
std::string const & Argument(size_t iArg) const
Returns the value of the iArg-th (0-based; no range check!)
void SetConfigurationPath(std::string path)
Sets the path to the configuration file.
std::string testing::BasicEnvironmentConfiguration::ServiceParameterSetPath ( std::string  name) const
inline

FHiCL path for the configuration of the service.

Definition at line 175 of file unit_test_base.h.

176  {
177  auto iPath = service_paths.find(name);
178  return (iPath == service_paths.end())
179  ? ("services." + name): iPath->second;
180  } // ServiceParameterSetPath()
PathMap_t service_paths
Set of paths for service configuration.
void testing::BasicEnvironmentConfiguration::SetApplicationName ( std::string  name)
inline

Sets the name of the application.

Definition at line 208 of file unit_test_base.h.

208 { appl_name = name; }
std::string appl_name
name of the application
void testing::BasicEnvironmentConfiguration::SetConfigurationPath ( std::string  path)
inline

Sets the path to the configuration file.

Definition at line 211 of file unit_test_base.h.

211 { config_path = path; }
std::string config_path
configuration file path
void testing::BasicEnvironmentConfiguration::SetMainTesterParameterSetName ( std::string  name)
inline

Sets the FHiCL name for the configuration of the test algorithm.

Definition at line 214 of file unit_test_base.h.

215  { main_test_name = name; }
std::string main_test_name
name of main test algorithm
void testing::BasicEnvironmentConfiguration::SetMainTesterParameterSetPath ( std::string  path)
inline

Sets the FHiCL path for the configuration of the main test algorithm.

Definition at line 222 of file unit_test_base.h.

223  {
224  if (MainTesterParameterSetName().empty()) {
225  throw std::logic_error
226  ("Request setting configuration of non-existent main tester");
227  }
229  }
std::string MainTesterParameterSetName() const
Name of the test algorithm instance.
void SetTesterParameterSetPath(std::string test_name, std::string path)
Sets the FHiCL path for the configuration of a test algorithm.
void testing::BasicEnvironmentConfiguration::SetServiceParameterSetPath ( std::string  service_name,
std::string  path 
)
inline

Sets the FHiCL path for the configuration of a test algorithm.

Definition at line 232 of file unit_test_base.h.

233  { service_paths[service_name] = path; }
PathMap_t service_paths
Set of paths for service configuration.
void testing::BasicEnvironmentConfiguration::SetTesterParameterSetPath ( std::string  test_name,
std::string  path 
)
inline

Sets the FHiCL path for the configuration of a test algorithm.

Definition at line 218 of file unit_test_base.h.

219  { test_paths[test_name] = path; }
PathMap_t test_paths
Set of paths for tester configuration.
std::string testing::BasicEnvironmentConfiguration::TesterParameterSetPath ( std::string  name) const
inline

FHiCL path for the configuration of the test algorithm.

Definition at line 157 of file unit_test_base.h.

158  {
159  auto iPath = test_paths.find(name);
160  return (iPath == test_paths.end())
161  ? ("physics.analyzers." + name): iPath->second;
162  }
PathMap_t test_paths
Set of paths for tester configuration.

Member Data Documentation

ConfigurationMap_t testing::BasicEnvironmentConfiguration::analyzers_default_cfg
protected

Configuration of all the analyzer modules.

Definition at line 274 of file unit_test_base.h.

std::string testing::BasicEnvironmentConfiguration::appl_name
protected

name of the application

Definition at line 263 of file unit_test_base.h.

details::CommandLineArguments testing::BasicEnvironmentConfiguration::arguments
private

command line arguments

Definition at line 376 of file unit_test_base.h.

std::string testing::BasicEnvironmentConfiguration::config_path
protected

configuration file path

Definition at line 264 of file unit_test_base.h.

std::string testing::BasicEnvironmentConfiguration::main_test_name
protected

name of main test algorithm

Definition at line 265 of file unit_test_base.h.

std::string testing::BasicEnvironmentConfiguration::main_test_path
protected

path of main test algorithm configuration

Definition at line 266 of file unit_test_base.h.

PathMap_t testing::BasicEnvironmentConfiguration::service_paths
protected

Set of paths for service configuration.

Definition at line 279 of file unit_test_base.h.

ConfigurationMap_t testing::BasicEnvironmentConfiguration::services_default_cfg
protected

Configuration of all the services.

Definition at line 272 of file unit_test_base.h.

PathMap_t testing::BasicEnvironmentConfiguration::test_paths
protected

Set of paths for tester configuration.

Definition at line 277 of file unit_test_base.h.


The documentation for this struct was generated from the following file: