All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
unit_test_base.h
Go to the documentation of this file.
1 /**
2  * @file unit_test_base.h
3  * @brief Base class for unit tests using FHiCL configuration
4  * @date December 1st, 2015
5  * @author petrillo@fnal.gov
6  *
7  * Provides an environment for easy set up of a message-facility-aware test.
8  *
9  * For an example of how to expand it to host services,
10  * see geometry_unit_test_base.h
11  *
12  * Currently provides:
13  * - BasicEnvironmentConfiguration: a test environment configuration
14  * - TestSharedGlobalResource: mostly internal use
15  * - TesterEnvironment: a prepacked test environment with some provider support
16  *
17  * This is a pure template header. It will require the following libraries:
18  *
19  * * `MF_MessageLogger`
20  * * `fhiclcpp`
21  * * `cetlib`
22  *
23  */
24 
25 
26 #ifndef TEST_UNIT_TEST_BASE_H
27 #define TEST_UNIT_TEST_BASE_H
28 
29 // LArSoft libraries
33 
34 // utility libraries
35 #include "fhiclcpp/ParameterSet.h"
36 #include "fhiclcpp/intermediate_table.h"
37 #include "fhiclcpp/parse.h"
38 #include "fhiclcpp/types/Comment.h"
39 #include "fhiclcpp/types/Name.h"
40 #include "fhiclcpp/types/Atom.h"
41 #include "fhiclcpp/types/Table.h"
42 // #include "fhiclcpp/exception.h"
43 #include "messagefacility/MessageLogger/MessageLogger.h"
44 
45 // CET libraries
46 #include "cetlib/filesystem.h" // cet::is_absolute_filepath()
47 #include "cetlib/filepath_maker.h"
48 #include "cetlib/search_path.h"
49 
50 // C/C++ standard libraries
51 #include <iostream> // for output before message facility is set up
52 #include <string>
53 #include <memory> // std::unique_ptr<>
54 #include <utility> // std::move(), std::forward()
55 #include <map>
56 #include <type_traits> // std::add_rvalue_reference()
57 #include <stdexcept> // std::logic_error
58 
59 
60 namespace testing {
61 
62  namespace details {
63 
64  /// Reads and makes available the command line parameters
66  public:
67  /// Constructor: automatically parses from Boost arguments
69 
70  /// Constructor: parses from specified arguments
71  CommandLineArguments(int argc, char** argv)
72  { ParseArguments(argc, argv); }
73 
74  /// Parses arguments
75  void ParseArguments(int argc, char** argv);
76 
77  /// Returns the name of the executable as started
78  std::string Executable() const { return exec_name; }
79 
80  /// Returns the list of non-Boost-test arguments on the command line
81  std::vector<std::string> const& Arguments() const { return args; }
82 
83  /// Returns whether we have arguments up to the iArg-th (0-based)
84  bool hasArgument(size_t iArg) const { return iArg < args.size(); }
85 
86  /// Returns the value of the iArg-th (0-based; no range check!)
87  std::string const& Argument(size_t iArg) const { return args[iArg]; }
88 
89  private:
90  std::string exec_name; ///< name of the test executable (from argv[0])
91  std::vector<std::string> args; ///< command line arguments (from argv[0])
92 
93  /// Erases the stored arguments
94  void Clear() { exec_name.clear(); args.clear(); }
95 
96  }; // class CommandLineArguments
97 
98 
99  inline void CommandLineArguments::ParseArguments(int argc, char** argv) {
100  Clear();
101  if (argc == 0) return;
102 
103  exec_name = argv[0];
104 
105  args.resize(argc - 1);
106  std::copy(argv + 1, argv + argc, args.begin());
107 
108  } // CommandLineArguments:ParseArguments()
109 
110 
111  // forward declaration
112  template
113  <typename TestEnv, typename Pack, typename... Provs>
115 
116  } // namespace details
117 
118 
119  /** **************************************************************************
120  * @brief Class holding a configuration for a test environment
121  *
122  * This class needs to be fully constructed by the default constructor
123  * in order to be useful as Boost unit test fixture.
124  * It is supposed to be passed as a template parameter to another class
125  * that can store an instance of it and extract configuration information
126  * from it.
127  */
129 
130  /// Default constructor; this is what is used in Boost unit test
132 
133  /// Constructor: acquires parameters from the command line
134  BasicEnvironmentConfiguration(int argc, char** argv):
136  { ParseCommandLine(argc, argv); }
137 
138  /// Constructor; accepts the name as parameter
141  { SetApplicationName(name); }
142 
143  BasicEnvironmentConfiguration(int argc, char** argv, std::string name):
145  { SetApplicationName(name); }
146 
147  /// @{
148  /// @name Access to configuration
149  /// Name of the application
150  std::string ApplicationName() const { return appl_name; }
151 
152  /// Path to the configuration file
153  std::string ConfigurationPath() const { return config_path; }
154 
155  /// FHiCL path for the configuration of the test algorithm
156  std::string TesterParameterSetPath(std::string name) const
157  {
158  auto iPath = test_paths.find(name);
159  return (iPath == test_paths.end())
160  ? ("physics.analyzers." + name): iPath->second;
161  }
162 
163  /// Name of the test algorithm instance
164  std::string MainTesterParameterSetName() const { return main_test_name; }
165 
166  /// FHiCL path for the configuration of the test algorithm
167  std::string MainTesterParameterSetPath() const
168  {
169  return MainTesterParameterSetName().empty()
171  }
172 
173  /// FHiCL path for the configuration of the service
174  std::string ServiceParameterSetPath(std::string name) const
175  {
176  auto iPath = service_paths.find(name);
177  return (iPath == service_paths.end())
178  ? ("services." + name): iPath->second;
179  } // ServiceParameterSetPath()
180 
181  /// A string describing default parameter set to configure specified test
182  std::string DefaultTesterConfiguration(std::string tester_name) const
183  { return analyzers_default_cfg.at(tester_name); }
184 
185  /// A string describing the default parameter set to configure the test
186  std::string DefaultServiceConfiguration(std::string service_name) const
187  { return services_default_cfg.at(service_name); }
188 
189  /// A string describing the full default parameter set
190  std::string DefaultConfiguration() const
191  { return BuildDefaultConfiguration(); }
192 
193  /// Returns the name of the executable as started
194  std::string ExecutablePath() const { return arguments.Executable(); }
195 
196  /// Returns the list of non-Boost-test arguments on the command line
197  std::vector<std::string> const& EexcutableArguments() const
198  { return arguments.Arguments(); }
199 
200  ///@}
201 
202 
203  /// @{
204  /// @name Set configuration
205 
206  /// Sets the name of the application
207  void SetApplicationName(std::string name) { appl_name = name; }
208 
209  /// Sets the path to the configuration file
210  void SetConfigurationPath(std::string path) { config_path = path; }
211 
212  /// Sets the FHiCL name for the configuration of the test algorithm
214  { main_test_name = name; }
215 
216  /// Sets the FHiCL path for the configuration of a test algorithm
217  void SetTesterParameterSetPath(std::string test_name, std::string path)
218  { test_paths[test_name] = path; }
219 
220  /// Sets the FHiCL path for the configuration of the main test algorithm
222  {
224  throw std::logic_error
225  ("Request setting configuration of non-existent main tester");
226  }
228  }
229 
230  /// Sets the FHiCL path for the configuration of a test algorithm
231  void SetServiceParameterSetPath(std::string service_name, std::string path)
232  { service_paths[service_name] = path; }
233 
234  /// Adds a default configuration for the specified service
236  (std::string service_name, std::string service_cfg)
237  { services_default_cfg[service_name] = service_cfg; }
238 
239  /// Adds a default configuration for the specified tester
241  (std::string tester_name, std::string tester_cfg)
242  { analyzers_default_cfg[tester_name] = tester_cfg; }
243 
244  /// Adds a default configuration for the main tester
245  void AddDefaultTesterConfiguration(std::string tester_cfg)
246  {
248  throw std::logic_error
249  ("Request adding configuration of non-existent main tester");
250  }
252  }
253 
254  ///@}
255 
256 
257 
258  protected:
259  using ConfigurationMap_t = std::map<std::string, std::string>;
260  using PathMap_t = std::map<std::string, std::string>;
261 
262  std::string appl_name; ///< name of the application
263  std::string config_path; ///< configuration file path
264  std::string main_test_name; ///< name of main test algorithm
265  std::string main_test_path; ///< path of main test algorithm configuration
266 
267  /// Returns the default test name
268  static std::string DefaultApplicationName() { return "Test"; }
269 
270  /// Configuration of all the services
272  /// Configuration of all the analyzer modules
274 
275  /// Set of paths for tester configuration
277  /// Set of paths for service configuration
279 
280  /// Extracts arguments from the command line, uses first one as config path
281  void ParseCommandLine(int argc, char** argv)
282  {
283  arguments.ParseArguments(argc, argv);
284  if (arguments.hasArgument(0))
285  SetConfigurationPath(arguments.Argument(0)); // first argument
286  }
287 
288  /// Initialize with some default values
289  void DefaultInit()
290  {
293  // a destination which will react to all messages from DEBUG up:
295  R"( debugModules: [ '*' ] destinations : { stdout: { type: cout threshold: DEBUG categories: { default: { limit: -1 } } // categories } // stdout statistics: {type:cout} } // destinations )");
296  } // DefaultInit()
297 
298  /// A string describing the full default parameter set
299  std::string BuildDefaultServiceConfiguration() const
301 
302  /// A string describing the full default parameter set
303  std::string BuildDefaultTestConfiguration() const
305 
306  /// A string describing the full default parameter set
307  std::string BuildDefaultConfiguration() const
308  {
310  }
311 
312 
313  /// A string with the service section from service parameter sets
314  static std::string BuildServiceConfiguration
316  {
317  std::string cfg;
318  cfg += "\nservices: {";
319  for (auto const& service_info: services) {
320  cfg += "\n " + service_info.first + ": {";
321  cfg += "\n" + service_info.second;
322  cfg += "\n } # " + service_info.first;
323  } // for services
324  cfg +=
325  "\n} # services"
326  "\n";
327  return cfg;
328  } // BuildServiceConfiguration()
330  /// A string with the physics section from analyzer parameter sets
331  static std::string BuildTestConfiguration
333  {
334  std::string cfg;
335  cfg +=
336  "\nphysics: {"
337  "\n analyzers: {"
338  ;
339  for (auto const& module_info: analyzers) {
340  cfg += "\n " + module_info.first + ": {";
341  cfg += "\n" + module_info.second;
342  cfg += "\n } # " + module_info.first;
343  } // for analyzers
344  cfg +=
345  "\n } # analyzers"
346  "\n} # physics";
347  return cfg;
348  } // BuildServiceConfiguration()
349 
350  /// A string describing the full default parameter set
351  static std::string BuildConfiguration
352  (ConfigurationMap_t const& services, ConfigurationMap_t const& modules)
353  {
354  std::string cfg;
355  cfg += BuildServiceConfiguration(services);
356  cfg += BuildTestConfiguration(modules);
357  return cfg;
358  } // BuildConfiguration()
359 
360  private:
361  details::CommandLineArguments arguments; ///< command line arguments
362 
363  }; // class BasicEnvironmentConfiguration<>
364 
365 
367  /** **************************************************************************
368  * @brief Utility class providing singleton objects to the derived classes
369  * @tparam RES the type of object (include constantness if needed)
370  *
371  * The object is expected to be shared.
372  */
373  template <typename RES>
375  using Resource_t = RES;
376 
377  public:
378  using ResourcePtr_t = std::shared_ptr<Resource_t>;
379 
380  /// @name Add and share resources
381  /// @{
382 
383  /// Adds a shared resource to the resource registry
384  static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
385  { Resources[res_name] = res_ptr; }
386 
387  /// Adds a shared resource to the resource registry (empty name)
389  { AddSharedResource(std::string(), res_ptr); }
390 
391  /// Registers a shared resource only if none exists yet
392  template <typename... Args>
394  (std::string res_name, ResourcePtr_t res_ptr)
395  {
396  if (hasResource(res_name)) return ResourcePtr_t();
397  AddSharedResource(res_name, res_ptr);
398  return res_ptr;
399  }
400 
401  /// Creates a shared resource as default only if none exists yet
402  template <typename... Args>
404  { return ProvideSharedResource(std::string(), res_ptr); }
405 
406  //@{
407  /// Adds a shared resource only if it is old_res_ptr
409  std::string res_name,
410  Resource_t const* old_res_ptr, ResourcePtr_t res_ptr
411  )
412  {
413  ResourcePtr_t current_res_ptr = ShareResource();
414  if (current_res_ptr.get() != old_res_ptr) return false;
415  AddSharedResource(res_name, res_ptr);
416  return true;
417  }
418  static bool ReplaceSharedResource
419  (std::string res_name, ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
420  { return ReplaceSharedResource(res_name, old_res_ptr.get(), res_ptr); }
421  //@}
423  //@{
424  /// Adds a shared resource as default resource only if it is old_res_ptr
425  static bool ReplaceDefaultSharedResource
426  (Resource_t const* old_res_ptr, ResourcePtr_t res_ptr)
427  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
428  static bool ReplaceDefaultSharedResource
429  (ResourcePtr_t old_res_ptr, ResourcePtr_t res_ptr)
430  { return ReplaceSharedResource(std::string(), old_res_ptr, res_ptr); }
431  //@}
432 
433  /// Constructs and registers a new resource with a specified name
434  template <typename... Args>
435  static ResourcePtr_t CreateResource(std::string res_name, Args&&... args)
436  {
437  ResourcePtr_t res_ptr(new Resource_t(std::forward<Args>(args)...));
438  AddSharedResource(res_name, res_ptr);
439  return res_ptr;
440  }
441 
442  /// Constructs and registers a new resource with no name
443  template <typename... Args>
444  static void CreateDefaultResource(Args&&... args)
445  { CreateResource(std::string(), std::forward<Args>(args)...); }
446 
447 
448  /// Creates a shared resource only if none exists yet
449  template <typename... Args>
451  (std::string res_name, Args&&... args)
452  {
453  return hasResource(res_name)?
454  ResourcePtr_t():
455  CreateResource(res_name, std::forward<Args>(args)...);
456  }
457 
458  /// Creates a shared resource as default only if none exists yet
459  template <typename... Args>
461  {
462  return ProposeSharedResource
463  (std::string(), std::forward<Args>(args)...);
464  }
466  /// @}
467 
468  /// @name Resource access
469  /// @{
470 
471  /// Returns whether a resource exists
472  /// @throws std::out_of_range if not available
473  static bool hasResource(std::string name = "")
474  {
475  auto iRes = Resources.find(name);
476  return (iRes != Resources.end()) && bool(iRes->second);
477  }
478 
479  /// Retrieves the specified resource for sharing (nullptr if none)
480  static ResourcePtr_t ShareResource(std::string name = "")
481  {
482  auto iRes = Resources.find(name);
483  return (iRes == Resources.end())? ResourcePtr_t(): iRes->second;
484  }
485 
486  /// Retrieves the specified resource, or throws if not available
487  static Resource_t& Resource(std::string name = "")
488  { return *(Resources.at(name).get()); }
489 
490  /// @}
491 
492  /// Destroys the specified resource (does nothing if no such resource)
493  static Resource_t& DestroyResource(std::string name = "")
494  { Resources.erase(name); }
495 
496  private:
497  static std::map<std::string, ResourcePtr_t> Resources;
498 
499  }; // class TestSharedGlobalResource<>
500 
502  template <typename RES>
503  std::map<std::string, typename TestSharedGlobalResource<RES>::ResourcePtr_t>
505 
506 
507  /** **************************************************************************
508  * @brief Environment for a test
509  * @tparam ConfigurationClass a class providing compile-time configuration
510  *
511  * The test environment is set up on construction.
512  *
513  * The environment provides:
514  * - Parameters() method returning the complete FHiCL configuration
515  * - TesterParameters() method returning the configuration for the test
516  *
517  * This class or a derived one can be used as global fixture for unit tests.
518  *
519  * Unfortunately Boost does not give any control on the initialization of the
520  * object, so everything must be ready to go as hard coded.
521  * The ConfigurationClass class tries to alleviate that.
522  * That is another, small static class that BasicTesterEnvironment uses to
523  * get its parameters.
524  *
525  * The requirements for the ConfigurationClass are:
526  * - `std::string ApplicationName()`: the application name
527  * - `std::string ConfigurationPath()`: path to the configuration file
528  * - `std::string MainTesterParameterSetName()`: name of the
529  * configuration of the main test (commodity)
530  * - `std::string DefaultTesterConfiguration()` returning a FHiCL string
531  * to be parsed to extract the default test configuration
532  *
533  * Whether the configuration comes from a file or from the two provided
534  * defaults, it is always expected within the parameter set paths:
535  * the default configuration must also contain that path.
536  *
537  * Note that there is no room for polymorphism here since the setup happens
538  * on construction.
539  * Some methods are declared virtual in order to allow to tweak some steps
540  * of the set up, but it's not trivial to create a derived class that works
541  * correctly: the derived class must declare a new default constructor,
542  * and that default constructor must call the protected constructor
543  * (BasicTesterEnvironment<ConfigurationClass>(no_setup))
544  */
545  template <typename ConfigurationClass>
546  class BasicTesterEnvironment {
547 
548  public:
549  using Configuration_t = ConfigurationClass;
550 
551  /**
552  * @brief Constructor: sets everything up and declares the test started
553  * @param bSetup (_default: `true`_) call `Setup()` after construction
554  *
555  * The configuration is from a default-constructed ConfigurationClass.
556  * This is suitable for use as Boost unit test fixture.
557  */
558  BasicTesterEnvironment(bool bSetup = true) { if (bSetup) Setup(); }
559 
560  //@{
561  /**
562  * @brief Setup from a configuration
563  * @param configurer an instance of `ConfigurationClass`
564  * @param bSetup (_default: `true`_) call `Setup()` after construction
565  *
566  * The configuration is from the specified configurer class.
567  *
568  * This constructor allows to use a non-default-constructed configuration.
569  * This can't be used (at best of my knowledge) when using this class as
570  * Boost unit test fixture.
571  *
572  * In the r-value-reference constructor, the configurer is moved.
573  */
575  (Configuration_t const& configurer, bool bSetup = true):
576  config(configurer)
577  { if (bSetup) Setup(); }
578  BasicTesterEnvironment(Configuration_t&& configurer, bool bSetup = true):
579  config(configurer)
580  { if (bSetup) Setup(); }
581  //@}
582 
583  /// Destructor: closing remarks
584  virtual ~BasicTesterEnvironment();
585 
586 
587  /// @{
588  /// @name Configuration retrieval
590  /// Returns the full configuration
591  fhicl::ParameterSet const& Parameters() const { return params; }
593  /// Returns the configuration of the specified service
594  fhicl::ParameterSet ServiceParameters(std::string service_name) const
595  {
596  return params.get<fhicl::ParameterSet>
597  (config.ServiceParameterSetPath(service_name));
598  }
599 
600  /// Returns the configuration of the specified test
601  fhicl::ParameterSet TesterParameters(std::string test_name) const
602  {
603  return params.get<fhicl::ParameterSet>
604  (config.TesterParameterSetPath(test_name));
605  }
606 
607  /// Returns the configuration of the main test (undefined if no main test)
608  fhicl::ParameterSet TesterParameters() const
609  {
610  if (config.MainTesterParameterSetName().empty()) return {};
611  else return TesterParameters(config.MainTesterParameterSetName());
612  }
613 
614  /// @}
616  static fhicl::ParameterSet CompileParameterSet(std::string cfg);
617 
618  protected:
619 
620  /// Returns a read-only version of the configuration
621  Configuration_t const& Config() const { return config; }
623  /// The complete initialization, ran at construction by default
624  virtual void Setup();
625 
626  /// Reads and translates the configuration
627  virtual void Configure();
628 
629  /**
630  * @brief Creates a full configuration for the test
631  * @return a parameters set with the complete configuration
632  */
633  virtual fhicl::ParameterSet DefaultParameters() const
634  { return CompileParameterSet(config.DefaultConfiguration()); }
636  //@{
637  /// Sets up the message facility
638  virtual void SetupMessageFacility
639  (fhicl::ParameterSet const& pset, std::string appl_name = "") const;
640  virtual void SetupMessageFacility() const
641  { SetupMessageFacility(Parameters(), config.ApplicationName()); }
642  //@}
643 
644  /**
645  * @brief Fills the test configuration from file or from default
646  *
647  * If a FHiCL configuration file is specified, the configuration of the test
648  * is read from it according to the parameter set path of the test.
649  * Otherwise, it is parsed from the default one provided by the configurer.
650  */
651  /// Parses from file and returns a FHiCL data structure
652  static fhicl::ParameterSet ParseParameters(std::string config_path);
653 
654  private:
655  /// Test environment options
656  struct Options_t {
657  bool MessageLevels = false; ///< print message levels on screen
658  }; // Options_t
659 
660  Configuration_t config; ///< instance of the configurer
661  Options_t options; ///< options for the test environment
662 
663  /// Parses the configuration, looking for the test environment options
665 
666  fhicl::ParameterSet params; ///< full configuration of the test
667 
668  }; // class BasicTesterEnvironment<>
669 
672  //****************************************************************************
673  /**
674  * @brief A test environment with some support for service providers
675  * @tparam ConfigurationClass a class providing compile-time configuration
676  *
677  * This test environment extends BasicTesterEnvironment with some basic
678  * support for service providers.
679  *
680  *
681  * Service provider support
682  * =========================
683  *
684  * This environment makes it available the method `Provider<Prov>()`, which
685  * returns a pointer to the provider of type Prov.
686  *
687  * All providers must be set up _after_ the test environment is constructed.
688  * The environment provides the following facilities:
689  *
690  * * SetupProvider() to set up a service provider with generic arguments
691  * * SetupProviderFromService() to set up a service provider with a parameter
692  * set extracted from the configuration
693  * * AcquireProvider() to register a service provider already available
694  * * DropProvider() to destroy an existing provider
695  *
696  * The set up methods support a `For` variant (e.g. `SetupProviderFor()`) to
697  * register the provider also under the type of its interface. For example,
698  * if `LArPropertiesStandard` is an implementation of `LArProperties`,
699  * the call:
700  *
701  * env.SetupProviderFor<LArProperties, LArPropertiesStandard>(pset);
702  *
703  * will set up a `LArPropertiesStandard` provider just like
704  *
705  * env.SetupProvider<LArPropertiesStandard>(pset);
706  *
707  * would, and it makes the provider available as `LArProperties` too, so that
708  * both calls:
709  *
710  * env.Provider<LArProperties>();
711  * env.Provider<LArPropertiesStandard>();
712  *
713  * are valid and return the same provider.
714  *
715  *
716  * Use as test fixture
717  * ====================
718  *
719  * The providers must be set up _after_ the test environment is constructed.
720  * This also means an additional complication for fixtures that require to
721  * be constructed in a final state, as it is the case for Boost unit test
722  * suite fixtures.
723  * In these cases, a class should publicly derive from TesterEnvironment, and
724  * the necessary setup should be added into the constructor of this derived
725  * class.
726  *
727  * Note that, as in the case of BasicTesterEnvironment, in this case there is
728  * no room for polymorphism here since the setup need to happen on
729  * construction.
730  */
731  template <typename ConfigurationClass>
732  class TesterEnvironment
733  : public BasicTesterEnvironment<ConfigurationClass>
734  {
737 
738  public:
739  // inherit constructors
740  using TesterEnvBase_t::TesterEnvBase_t;
741 
742  /**
743  * @brief Sets a service provider up by calling its testing::setupProvider()
744  * @tparam Prov type of provider
745  * @tparam Args type of arguments for the setup function
746  * @param args arguments for the setup function
747  * @return a pointer to the provider set up
748  * @throw runtime_error if the provider already exists
749  * @see SetupProviderFor(), AcquireProvider()
750  *
751  * A provider of type Prov is created, set up and recorded.
752  * Provider setup is delegated to `testing::setupProvider` function specific
753  * to the provider itself (that is, `testing::setupProvider<Prov>(args...)`)
754  * to which the setup arguments are forwarded.
755  * If the provider already exists, an exception is thrown.
756  */
757  template <typename Prov, typename... Args>
758  Prov* SetupProvider(Args&&... args)
759  {
760  if (!providers.setup<Prov>(std::forward<Args>(args)...))
761  throw std::runtime_error("Provider already exists!");
762  return providers.getPointer<Prov>();
763  }
764 
765  /**
766  * @brief Sets a service provider up by calling its testing::setupProvider()
767  * @tparam Prov type of provider
768  * @tparam Args type of arguments for the setup function
769  * @param name the service name (for configuration retrieval)
770  * @param args arguments for the setup function
771  * @return a pointer to the provider set up
772  * @see SetupProvider()
773  * @throw runtime_error if the provider already exists
774  *
775  * A provider of type Prov is created, set up and recorded.
776  * Provider setup is attempted by constructing the provider with a parameter
777  * set from the registered configuration of service with specified `name`.
778  */
779  template <typename Prov, typename... Args>
780  Prov* SetupProviderFromService(std::string name, Args&&... args)
781  {
782  return SetupProvider<Prov>
783  (this->ServiceParameters(name, std::forward<Args>(args)...));
784  }
785 
786  /**
787  * @brief Acquires a service provider
788  * @tparam Prov type of provider
789  * @param prov the provider to be acquired
790  * @return a pointer to the provider
791  * @see SetupProvider()
792  * @throw runtime_error if the provider already exists
793  *
794  * This method registers and takes ownership of the specified provider.
795  * It is similar to SetupProvider() except that user is in charge of the
796  * preliminary creation and setup of the provider.
797  */
798  template <typename Prov>
799  Prov* AcquireProvider(std::unique_ptr<Prov>&& prov)
800  {
801  if (!providers.acquire(std::move(prov)))
802  throw std::runtime_error("Provider already exists!");
803  return providers.getPointer<Prov>();
804  }
805 
806  /**
807  * @brief Sets a provider up, recording it as implementation of Interface
808  * @tparam Interface type of provider interface being implemented
809  * @tparam Prov type of provider
810  * @tparam Args type of arguments for the setup function
811  * @param args arguments for the setup function
812  * @return a pointer to the provider set up
813  * @see SetupProvider()
814  *
815  * This method performs the same type of setup as SetupProvider().
816  * In addition, it registers the provider as an implementation of Interface.
817  * This means that the provider can be obtained not only with
818  * `provider<Prov>()`, which returns a pointer to the actual class Prov,
819  * but also as `provider<Interface>()`, which returns a pointer to the base
820  * class Interface.
821  */
822  template <typename Interface, typename Prov, typename... Args>
823  Prov* SetupProviderFor(Args&&... args)
824  {
825  auto prov = SetupProvider<Prov>(std::forward<Args>(args)...);
826  providers.set_alias<Prov, Interface>();
827  return prov;
828  }
829 
830  /**
831  * @brief Sets a provider up, recording it as implementation of Interface
832  * @tparam Interface type of provider interface being implemented
833  * @tparam Prov type of provider
834  * @tparam Args type of arguments for the setup function
835  * @param name the service name (for configuration retrieval)
836  * @param args arguments for the setup function
837  * @return a pointer to the provider set up
838  * @see SetupProviderFromService(), SetupProviderFor()
839  * @throw runtime_error if the provider already exists
840  *
841  * This method performs the same type of setup as
842  * SetupProviderFromService().
843  * In addition, it registers the provider as an implementation of Interface.
844  * This means that the provider can be obtained not only with
845  * `provider<Prov>()`, which returns a pointer to the actual class Prov,
846  * but also as `provider<Interface>()`, which returns a pointer to the base
847  * class Interface.
848  */
849  template <typename Interface, typename Prov, typename... Args>
850  Prov* SetupProviderFromServiceFor(std::string name, Args&&... args)
851  {
852  auto* prov
853  = SetupProviderFromService<Prov>(name, std::forward<Args>(args)...);
854  providers.set_alias<Prov, Interface>();
855  return prov;
856  }
857 
858  /**
859  * @brief Acquires a service provider implementing an interface
860  * @tparam Prov type of provider
861  * @tparam Interface type provider alias
862  * @param prov the provider to be acquired
863  * @return a pointer to the provider
864  * @see SetupProviderFor(), AcquireProvider()
865  *
866  * This method registers and takes ownership of the specified provider,
867  * like AcquireProvider() does. It also registers the provider as an
868  * implementation of Interface class, as SetupProviderFor does.
869  * It is similar to SetupProvider() except that user is in charge of the
870  * preliminar creation and setup of the provider.
871  */
872  template <typename Interface, typename Prov>
873  Prov* AcquireProviderFor(std::unique_ptr<Prov>&& prov)
874  {
875  auto prov_ptr = providers.acquire(prov);
876  providers.set_alias<Prov, Interface>();
877  return prov_ptr;
878  }
879 
880  /**
881  * @brief Oversimplified provider setup
882  * @return a pointer to the provider
883  * @tparam Prov provider type
884  *
885  * This is a one-step setup of the specified provider.
886  *
887  * It is available only if Prov provider comes with an implementation of
888  * testing::SimpleEnvironmentSetupClass that explains how to set up an
889  * environment.
890  *
891  */
892  template <typename Prov>
893  Prov* SimpleProviderSetup() { return simpleEnvironmentSetup<Prov>(*this); }
894 
895  /**
896  * @brief Removes and destroys the specified provider
897  * @tparam Prov type of provider to be destroyed
898  * @throw runtime_error if the provider was not present
899  */
900  template <typename Prov>
901  void DropProvider()
902  {
903  if (!providers.erase<Prov>())
904  throw std::runtime_error("Provider not present!");
905  }
906 
907  /// Return the specified provider (throws if not available)
908  template <typename Prov>
909  Prov const* Provider() const
910  { return providers.getPointer<Prov>(); }
911 
912  /**
913  * @brief Fills the specified provider pack with providers
914  * @throw runtime_error and everything provider() method can throw
915  * @see Provider()
916  */
917  template <typename... Provs>
919  {
921  <TesterEnv_t, lar::ProviderPack<Provs...>, Provs...>
922  ::fill
923  (*this, pack);
924  } // FillProviderPack()
925 
926 
927  /**
928  * @brief Returns a provider pack for the specified provider
929  * @tparam Prov type of the provider
930  * @throw runtime_error and everything provider() method can throw
931  * @see FillProviderPack()
932  *
933  * The provider is required to have a `providers_type` type defined as an
934  * specialisation of lar::ProviderPack.
935  */
936  template <typename Prov>
937  typename Prov::providers_type ProviderPackFor() const
938  {
939  typename Prov::providers_type pack;
940  FillProviderPack(pack);
941  return pack;
942  } // ProviderPackFor()
943 
944 
945  protected:
946  ProviderList providers; ///< list of available providers
947  }; // class TesterEnvironment<>
948 
949 
950 
951  /**
952  * @brief Constructs and returns a TesterEnvironment object
953  * @tparam CONFIG type of configuration object (detected from arguments)
954  * @tparam TESTENV type of the tester environment (default: TesterEnvironment)
955  * @tparam ARGS pack of types of the remining constructor arguments (optional)
956  * @param config the configuration object to be used
957  * @param other_args the remaining arguments of the tester constructor
958  *
959  * This function creates and returns a tester environment.
960  * By default, the tester environment class is TesterEnvironment<CONFIG>
961  * and no additional constructor arguments are needed except for special
962  * needs. The simplest way to use the function with an already available
963  * configuration is:
964  *
965  * auto TestEnv = testing::CreateTesterEnvironment(config);
966  *
967  * where TestEnv is assigned a specialization of TesterEnvironment.
968  *
969  * The template class TESTENV undergoes the following requirement:
970  *
971  * - it must have a constructor using a CONFIG constant reference as first
972  * argument
973  *
974  * The CONFIG object is subject to no special requirements besides the ones
975  * from TESTENV constructor.
976  */
977  // Note: this function is expected to be used with automatic type detection;
978  // the rules on "universal references" dictate that if config is a (l-value)
979  // reference, CONFIG itself is a l-value reference. We don't want to create
980  // a TesterEnvironment<Config&>, so we explicitly remove the reference from
981  // CONFIG (decay does that and aso removes the constantness, that we also
982  // don't want to be embedded in CONFIG).
983  template <
984  typename CONFIG,
985  typename TESTENV = TesterEnvironment<std::decay_t<CONFIG>>,
986  typename... ARGS
987  >
988  TESTENV CreateTesterEnvironment(CONFIG&& config, ARGS... other_args)
989  {
990  return TESTENV
991  (std::forward<CONFIG>(config), std::forward<ARGS>(other_args)...);
992  }
993 
994 
995 
996  //****************************************************************************
997  namespace details {
998  // Class to implement FHiCL file search.
999  // This is badly ripped off from ART, but we need to stay out of it
1000  // so I have to replicate that functionality.
1001  // I used the same class name.
1002  class FirstAbsoluteOrLookupWithDotPolicy: public cet::filepath_maker {
1003  public:
1004  FirstAbsoluteOrLookupWithDotPolicy(std::string const& paths):
1005  first(true), after_paths(paths)
1006  {}
1007 
1008  virtual std::string operator() (std::string const& filename);
1009 
1010  void reset() { first = true; }
1011 
1012  private:
1013  bool first; ///< whether we are waiting for the first query
1014  cet::search_path after_paths; ///< path for the other queries
1015 
1016  }; // class FirstAbsoluteOrLookupWithDotPolicy
1017 
1019  inline std::string FirstAbsoluteOrLookupWithDotPolicy::operator()
1020  (std::string const &filename)
1021  {
1022  if (first) {
1023  first = false;
1024  if (cet::is_absolute_filepath(filename)) return filename;
1025  return cet::search_path("./:" + after_paths.to_string())
1026  .find_file(filename);
1027  } else {
1028  return after_paths.find_file(filename);
1029  }
1030  } // FirstAbsoluteOrLookupWithDotPolicy::operator()
1031 
1032 
1033  /// Helper to fill a provider pack: main specialisation
1034  template
1035  <typename TestEnv, typename Pack, typename Prov, typename... Others>
1036  struct ProviderPackFiller<TestEnv, Pack, Prov, Others...> {
1037  static void fill(TestEnv const& env, Pack& pack)
1038  {
1039  pack.set(env.template Provider<Prov>());
1041  } // fill()
1042 
1043  }; // ProviderPackFiller<TestEnv, Pack, Prov, Others...>
1044 
1045  // end-of-recursion specialisation
1046  template <typename TestEnv, typename Pack>
1047  struct ProviderPackFiller<TestEnv, Pack> {
1048  static void fill(TestEnv const&, Pack&) {}
1049  }; // ProviderPackFiller<>
1052  } // namespace details
1053 
1054 
1055  //****************************************************************************
1056  template <typename ConfigurationClass>
1058 
1059  mf::LogInfo("Test") << config.ApplicationName() << " completed.";
1060 
1061  } // BasicTesterEnvironment<>::~BasicTesterEnvironment()
1063 
1064  /** **************************************************************************
1065  * @brief Compiles a parameter set from a string
1066  * @return a parameters set with the complete configuration
1067  */
1068  template <typename ConfigurationClass>
1069  fhicl::ParameterSet
1071  (std::string cfg)
1072  {
1073  fhicl::ParameterSet global_pset;
1074  global_pset = fhicl::ParameterSet::make(cfg);
1075  return global_pset;
1076  } // BasicTesterEnvironment<>::CompileParameterSet()
1077 
1078 
1079  /** **************************************************************************
1080  * @brief Returns the configuration from a FHiCL file
1081  * @param config_path full path of the FHiCL configuration file
1082  * @return a parameters set with the complete configuration from the file
1083  */
1084  template <typename ConfigurationClass>
1085  fhicl::ParameterSet
1087  (std::string config_path)
1088  {
1089  // configuration file lookup policy
1090  char const* fhicl_env = getenv("FHICL_FILE_PATH");
1091  std::string search_path = fhicl_env? std::string(fhicl_env) + ":": ".:";
1092  details::FirstAbsoluteOrLookupWithDotPolicy policy(search_path);
1093 
1094  // parse a configuration file; obtain intermediate form
1095  fhicl::intermediate_table table;
1096  table = fhicl::parse_document(config_path, policy);
1097 
1098  // translate into a parameter set
1099  fhicl::ParameterSet global_pset;
1100  global_pset = fhicl::ParameterSet::make(table);
1102  return global_pset;
1103  } // BasicTesterEnvironment<>::ParseParameters()
1104 
1105 
1106  /** **************************************************************************
1107  * @brief Fills the configuration
1108  *
1109  * The complete configuration (message facility and services) is read and
1110  * saved, hence accessible by Parameters() method.
1111  *
1112  * The configuration file path is taken by default from the first argument
1113  * of the test.
1114  * If that first argument is not present or empty, the default configuration
1115  * path is received from the configurer.
1116  * If the configuration path is still empty, a hard-coded configuration
1117  * is used; otherwise, the FHiCL file specified in that path is parsed and
1118  * used as full configuration.
1119  */
1120  template <typename ConfigurationClass>
1122  std::string config_path = config.ConfigurationPath();
1123  params = config_path.empty()?
1124  DefaultParameters(): ParseParameters(config_path);
1125  } // BasicTesterEnvironment::Configure()
1126 
1127 
1128  /** **************************************************************************
1129  * @brief Sets the message facility up
1130  *
1131  * Message facility configuration is expected in "services.message" parameter
1132  * set. If not there, the default configuration is used.
1133  */
1134  template <typename ConfigurationClass>
1136  (fhicl::ParameterSet const& pset, std::string appl_name /* = "" */) const
1137  {
1138  fhicl::ParameterSet mf_pset;
1139 
1140  if
1141  (!pset.get_if_present(config.ServiceParameterSetPath("message"), mf_pset))
1142  {
1143  mf_pset
1144  = CompileParameterSet(config.DefaultServiceConfiguration("message"));
1145  std::cout << "Using default message facility configuration:\n"
1146  << mf_pset.to_indented_string(1) << std::endl;
1147  } // if no configuration is available
1148 
1149  mf::StartMessageFacility(mf_pset);
1150  if (!appl_name.empty()) mf::SetApplicationName(appl_name);
1151  mf::SetContextIteration("Initialization");
1152  if (options.MessageLevels) {
1153  std::cout << "Printing message levels in 'MessageFacility' category."
1154  << std::endl;
1155 
1156  mf::LogProblem("MessageFacility") << "Error messages are shown.";
1157  mf::LogPrint("MessageFacility") << "Warning messages are shown.";
1158  mf::LogVerbatim("MessageFacility") << "Info messages are shown.";
1159  mf::LogTrace("MessageFacility") << "Debug messages are shown.";
1160  MF_LOG_TRACE("MessageFacility")
1161  << "MF_LOG_TRACE/MF_LOG_DEBUG messages are not compiled away.";
1162  } // if print message levels
1163  mf::LogInfo("MessageFacility") << "MessageFacility started.";
1164  mf::SetContextSinglet("main");
1165  } // BasicTesterEnvironment::SetupMessageFacility()
1166 
1167 
1168 
1169  template <typename ConfigurationClass>
1171  ) {
1172 
1173  //
1174  // get the configuration
1175  //
1176  Configure();
1177 
1178  //
1179  // parse the options specific to the test environment
1180  //
1181  ParseEnvironmentOptions();
1182 
1183  //
1184  // set up the message facility
1185  //
1187 
1188  //
1189  // Optionally print the configuration
1190  //
1191  {
1192  mf::LogInfo msg("Configuration");
1193  msg << "Complete configuration (";
1194  if (config.ConfigurationPath().empty()) msg << "default";
1195  else msg << "'" << config.ConfigurationPath() << "'";
1196  msg << "):\n" << Parameters().to_indented_string(1);
1197  }
1198 
1199 
1200  mf::LogInfo("Test") << config.ApplicationName() << " base setup complete.";
1201 
1202  } // BasicTesterEnvironment<>::Setup()
1203 
1204 
1205 
1206  template <typename ConfigurationClass>
1208 
1209  struct OptionsFromConfig_t {
1210  fhicl::Atom<bool> messageLevels{
1211  fhicl::Name("messageLevels"),
1212  fhicl::Comment("prints a message per level (to verify the visible ones"),
1213  false // default: no
1214  };
1215  fhicl::Atom<bool> printOptions{
1216  fhicl::Name("printOptions"),
1217  fhicl::Comment("prints a the list of options (this is one of them!)"),
1218  false // default: no
1219  };
1220  }; // OptionsFromConfig_t
1222 
1223  struct ValidationHelper {
1224  static void printDummy(std::ostream& out)
1225  {
1226  fhicl::Table<OptionsFromConfig_t>
1227  (fhicl::Name("test"), fhicl::Comment("Test environment options"))
1228  .print_allowed_configuration(out);
1229  } // printDummy()
1230 
1231  static fhicl::Table<OptionsFromConfig_t> validate
1232  (fhicl::ParameterSet const& pset)
1233  {
1234  try {
1235  return fhicl::Table<OptionsFromConfig_t>(pset, {});
1236  }
1237  catch (...) {
1238  std::cerr << "Error parsing environment test options! Valid options:"
1239  << std::endl;
1240  ValidationHelper::printDummy(std::cerr);
1241  throw;
1242  }
1243  } // validate()
1244  };
1245 
1246 
1247  fhicl::ParameterSet pset = params.get<fhicl::ParameterSet>("test", {});
1248 
1249  // automatically performs validation
1250  fhicl::Table<OptionsFromConfig_t> configTable
1251  (ValidationHelper::validate(pset));
1252 
1253  if (configTable().printOptions()) {
1254  std::cout
1255  << "The following options can be passed to the test environment"
1256  << " by putting them in the \"test: {}\" table of the configuration file:"
1257  << std::endl;
1258  ValidationHelper::printDummy(std::cout);
1259  }
1260 
1261  options.MessageLevels = configTable().messageLevels();
1262 
1263  } // BasicTesterEnvironment<>::ParseEnvironmentOptions()
1264 
1265 
1266 } // namespace testing
1267 
1268 #endif // TEST_UNIT_TEST_BASE_H
1269 
Container of service providers accessed by type and optional label.
Definition: ProviderList.h:160
std::string main_test_name
name of main test algorithm
fhicl::ParameterSet const & Parameters() const
Returns the full configuration.
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics sequence::physics pathW services
virtual std::string operator()(std::string const &filename)
fhicl::ParameterSet params
full configuration of the test
T const * getPointer(std::string label="") const
Retrieve the object of type T stored with the specified label.
Definition: ProviderList.h:358
Prov const * Provider() const
Return the specified provider (throws if not available)
static fhicl::ParameterSet ParseParameters(std::string config_path)
Fills the test configuration from file or from default.
static void CreateDefaultResource(Args &&...args)
Constructs and registers a new resource with no name.
Helper classes to be used together with LArSoft&#39;s unit test.
void ParseArguments(int argc, char **argv)
Parses arguments.
std::string BuildDefaultConfiguration() const
A string describing the full default parameter set.
std::map< std::string, std::string > PathMap_t
Options_t options
options for the test environment
BEGIN_PROLOG could also be cerr
static ResourcePtr_t ProvideSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Registers a shared resource only if none exists yet.
void SetApplicationName(std::string name)
Sets the name of the application.
std::map< std::string, std::string > ConfigurationMap_t
std::string DefaultConfiguration() const
A string describing the full default parameter set.
Prov * SetupProviderFromService(std::string name, Args &&...args)
Sets a service provider up by calling its testing::setupProvider()
virtual fhicl::ParameterSet DefaultParameters() const
Creates a full configuration for the test.
Container for service providers used in a test.
ConfigurationMap_t services_default_cfg
Configuration of all the services.
std::shared_ptr< Resource_t > ResourcePtr_t
BasicEnvironmentConfiguration(std::string name)
Constructor; accepts the name as parameter.
BasicTesterEnvironment(bool bSetup=true)
Constructor: sets everything up and declares the test started.
Configuration_t config
instance of the configurer
static ResourcePtr_t ProposeSharedResource(std::string res_name, Args &&...args)
Creates a shared resource only if none exists yet.
bool first
whether we are waiting for the first query
std::string main_test_path
path of main test algorithm configuration
void SetMainTesterParameterSetName(std::string name)
Sets the FHiCL name for the configuration of the test algorithm.
BEGIN_PROLOG could also be dds filename
std::string DefaultTesterConfiguration(std::string tester_name) const
A string describing default parameter set to configure specified test.
std::string ExecutablePath() const
Returns the name of the executable as started.
virtual void Configure()
Reads and translates the configuration.
details::CommandLineArguments arguments
command line arguments
Class holding a configuration for a test environment.
static std::string BuildConfiguration(ConfigurationMap_t const &services, ConfigurationMap_t const &modules)
A string describing the full default parameter set.
Environment for a test.
static bool hasResource(std::string name="")
BasicEnvironmentConfiguration(int argc, char **argv, std::string name)
std::string Executable() const
Returns the name of the executable as started.
std::string TesterParameterSetPath(std::string name) const
FHiCL path for the configuration of the test algorithm.
static bool ReplaceDefaultSharedResource(Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource as default resource only if it is old_res_ptr.
static std::string DefaultApplicationName()
Returns the default test name.
Prov * SetupProviderFromServiceFor(std::string name, Args &&...args)
Sets a provider up, recording it as implementation of Interface.
Configuration_t const & Config() const
Returns a read-only version of the configuration.
void FillProviderPack(lar::ProviderPack< Provs...> &pack) const
Fills the specified provider pack with providers.
Prov * AcquireProvider(std::unique_ptr< Prov > &&prov)
Acquires a service provider.
static void AddDefaultSharedResource(ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry (empty name)
static std::string BuildServiceConfiguration(ConfigurationMap_t const &services)
A string with the service section from service parameter sets.
void ParseCommandLine(int argc, char **argv)
Extracts arguments from the command line, uses first one as config path.
CommandLineArguments()
Constructor: automatically parses from Boost arguments.
PathMap_t test_paths
Set of paths for tester configuration.
std::string MainTesterParameterSetPath() const
FHiCL path for the configuration of the test algorithm.
void AddDefaultServiceConfiguration(std::string service_name, std::string service_cfg)
Adds a default configuration for the specified service.
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
bool acquire(std::unique_ptr< T > &&obj_ptr, std::string label="")
Registers and gets ownership of the specified object.
Definition: ProviderList.h:268
CommandLineArguments(int argc, char **argv)
Constructor: parses from specified arguments.
static std::string BuildTestConfiguration(ConfigurationMap_t const &analyzers)
A string with the physics section from analyzer parameter sets.
void SetupMessageFacility(fhicl::ParameterSet const &pset, std::string applName="standalone")
Sets up the message facility service.
std::string ServiceParameterSetPath(std::string name) const
FHiCL path for the configuration of the service.
bool erase(std::string label="")
Drops the object with the specified type and label.
Definition: ProviderList.h:290
Prov::providers_type ProviderPackFor() const
Returns a provider pack for the specified provider.
static Resource_t & DestroyResource(std::string name="")
Destroys the specified resource (does nothing if no such resource)
Prov * SimpleProviderSetup()
Oversimplified provider setup.
ProviderList providers
list of available providers
static std::map< std::string, ResourcePtr_t > Resources
bool hasArgument(size_t iArg) const
Returns whether we have arguments up to the iArg-th (0-based)
void DropProvider()
Removes and destroys the specified provider.
std::string config_path
configuration file path
std::string MainTesterParameterSetName() const
Name of the test algorithm instance.
void ParseEnvironmentOptions()
Parses the configuration, looking for the test environment options.
static bool ReplaceSharedResource(std::string res_name, Resource_t const *old_res_ptr, ResourcePtr_t res_ptr)
Adds a shared resource only if it is old_res_ptr.
std::string DefaultServiceConfiguration(std::string service_name) const
A string describing the default parameter set to configure the test.
static Resource_t & Resource(std::string name="")
Retrieves the specified resource, or throws if not available.
static ResourcePtr_t ShareResource(std::string name="")
Retrieves the specified resource for sharing (nullptr if none)
void AddDefaultTesterConfiguration(std::string tester_name, std::string tester_cfg)
Adds a default configuration for the specified tester.
std::vector< std::string > const & Arguments() const
Returns the list of non-Boost-test arguments on the command line.
bool set_alias(std::string alias_label="", std::string prov_label="")
Sets the Alias type as an alias of the Prov provider (with labels)
Definition: ProviderList.h:309
std::string exec_name
name of the test executable (from argv[0])
BasicTesterEnvironment< ConfigurationClass > TesterEnvBase_t
TESTENV CreateTesterEnvironment(CONFIG &&config, ARGS...other_args)
Constructs and returns a TesterEnvironment object.
std::vector< std::string > args
command line arguments (from argv[0])
bool MessageLevels
print message levels on screen
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
BEGIN_PROLOG vertical distance to the surface Name
ConfigurationClass Configuration_t
fhicl::ParameterSet ServiceParameters(std::string service_name) const
Returns the configuration of the specified service.
std::string const & Argument(size_t iArg) const
Returns the value of the iArg-th (0-based; no range check!)
Reads and makes available the command line parameters.
Utility class providing singleton objects to the derived classes.
void SetTesterParameterSetPath(std::string test_name, std::string path)
Sets the FHiCL path for the configuration of a test algorithm.
bool setup(Args &&...args)
Construct and register an object of type T with specified arguments.
Definition: ProviderList.h:252
std::string BuildDefaultTestConfiguration() const
A string describing the full default parameter set.
PathMap_t service_paths
Set of paths for service configuration.
Prov * SetupProvider(Args &&...args)
Sets a service provider up by calling its testing::setupProvider()
cet::search_path after_paths
path for the other queries
virtual void Setup()
The complete initialization, ran at construction by default.
A test environment with some support for service providers.
BasicEnvironmentConfiguration()
Default constructor; this is what is used in Boost unit test.
fhicl::Table< sbnd::crt::CRTDetSimParams > Parameters
Prov * AcquireProviderFor(std::unique_ptr< Prov > &&prov)
Acquires a service provider implementing an interface.
void SetConfigurationPath(std::string path)
Sets the path to the configuration file.
fhicl::ParameterSet TesterParameters() const
Returns the configuration of the main test (undefined if no main test)
void AddDefaultTesterConfiguration(std::string tester_cfg)
Adds a default configuration for the main tester.
static ResourcePtr_t ProvideDefaultSharedResource(ResourcePtr_t res_ptr)
Creates a shared resource as default only if none exists yet.
then shift ARGS
std::string ConfigurationPath() const
Path to the configuration file.
Container for a list of pointers to providers.
Definition: ProviderPack.h:114
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker options
std::string appl_name
name of the application
T copy(T const &v)
std::string BuildDefaultServiceConfiguration() const
A string describing the full default parameter set.
Data structure containing constant pointers to classes.
then echo fcl name
std::vector< std::string > const & EexcutableArguments() const
Returns the list of non-Boost-test arguments on the command line.
TesterEnvironment< ConfigurationClass > TesterEnv_t
process_name analyzers
void Clear()
Erases the stored arguments.
void SetServiceParameterSetPath(std::string service_name, std::string path)
Sets the FHiCL path for the configuration of a test algorithm.
void SetMainTesterParameterSetPath(std::string path)
Sets the FHiCL path for the configuration of the main test algorithm.
void DefaultInit()
Initialize with some default values.
bool empty(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:555
static fhicl::ParameterSet CompileParameterSet(std::string cfg)
Compiles a parameter set from a string.
static ResourcePtr_t ProposeDefaultSharedResource(Args &&...args)
Creates a shared resource as default only if none exists yet.
ConfigurationMap_t analyzers_default_cfg
Configuration of all the analyzer modules.
static ResourcePtr_t CreateResource(std::string res_name, Args &&...args)
Constructs and registers a new resource with a specified name.
static void AddSharedResource(std::string res_name, ResourcePtr_t res_ptr)
Adds a shared resource to the resource registry.
BEGIN_PROLOG could also be cout
virtual ~BasicTesterEnvironment()
Destructor: closing remarks.
virtual void SetupMessageFacility() const
Prov * SetupProviderFor(Args &&...args)
Sets a provider up, recording it as implementation of Interface.
BasicEnvironmentConfiguration(int argc, char **argv)
Constructor: acquires parameters from the command line.