All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LArPropertiesStandard_test.cc
Go to the documentation of this file.
1 /**
2  * @file LArPropertiesStandard_test.cc
3  * @brief Simple instantiation-only test for LArPropertiesStandard
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 1st, 2015
6  */
7 
8 // LArSoft libraries
12 
13 
14 //------------------------------------------------------------------------------
15 //--- The test environment
16 //---
17 
18 /*
19  * TesterEnvironment, configured with a "standard" configuration object, is used
20  * in a non-Boost-unit-test context.
21  * It provides:
22  * - `detinfo::LArProperties const* Provider<detinfo::LArProperties>()`
23  *
24  */
25 using TestEnvironment
27 
28 
29 //------------------------------------------------------------------------------
30 //--- The tests
31 //---
32 
33 
34 /** ****************************************************************************
35  * @brief Runs the test
36  * @param argc number of arguments in argv
37  * @param argv arguments to the function
38  * @return number of detected errors (0 on success)
39  * @throw cet::exception most of error situations throw
40  *
41  * The arguments in argv are:
42  * 0. name of the executable ("LArPropertiesStandard_test")
43  * 1. (mandatory) path to the FHiCL configuration file
44  * 2. FHiCL path to the configuration of the test
45  * (default: physics.analyzers.larptest)
46  * 3. FHiCL path to the configuration of LArProperties service
47  * (default: services.LArPropertiesService)
48  *
49  */
50 //------------------------------------------------------------------------------
51 int main(int argc, char const** argv) {
52 
53  testing::BasicEnvironmentConfiguration config("larp_test");
54 
55  //
56  // parameter parsing
57  //
58  int iParam = 0;
59 
60  // first argument: configuration file (mandatory)
61  if (++iParam < argc) config.SetConfigurationPath(argv[iParam]);
62  else {
63  std::cerr << "FHiCL configuration file path required as first argument!"
64  << std::endl;
65  return 1;
66  }
67 
68  // second argument: path of the parameter set for geometry test configuration
69  // (optional; default does not have any tester)
70  if (++iParam < argc) config.SetMainTesterParameterSetPath(argv[iParam]);
71 
72  // third argument: path of the parameter set for LArProperties configuration
73  // (optional; default: "services.LArProperties" from the inherited object)
74  if (++iParam < argc)
75  config.SetServiceParameterSetPath("LArPropertiesService", argv[iParam]);
76 
77 
78  unsigned int nErrors = 0 /* Tester.Run() */ ;
79 
80  //
81  // testing environment setup
82  //
83  TestEnvironment TestEnv(config);
84 
85  // LArPropertiesStandard supports the simple set up; so we invoke it
87 
88  //
89  // run the test algorithm
90  // (I leave it here for reference -- there is no test algorithm here)
91  //
92 
93  // 1. we initialize it from the configuration in the environment,
94 // MyTestAlgo Tester(TestEnv.TesterParameters());
95 
96  // 2. we set it up with the geometry from the environment
97 // Tester.Setup(*(TestEnv.LArProperties()));
98 
99  // 3. then we run it!
100  mf::LogInfo("larp_test")
101  << "The atomic number of liquid argon is "
102  << TestEnv.Provider<detinfo::LArProperties>()->AtomicNumber()
103  ;
104 
105  // 4. And finally we cross fingers.
106  if (nErrors > 0) {
107  mf::LogError("larp_test") << nErrors << " errors detected!";
108  }
109 
110  return nErrors;
111 } // main()
Prov const * Provider() const
Return the specified provider (throws if not available)
Service provider with utility LAr functions.
BEGIN_PROLOG could also be cerr
Helper functions for support of LArPropertiesService in LArSoft tests.
Class holding a configuration for a test environment.
Prov * SimpleProviderSetup()
Oversimplified provider setup.
A test environment with some support for service providers.
void SetConfigurationPath(std::string path)
Sets the path to the configuration file.
Properties related to liquid argon environment in the detector.
int main(int argc, char **argv)
Base class for unit tests using FHiCL configuration.
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.