geometry_loader_test.cxx
Go to the documentation of this file.
1 /**
2  * @file geometry_loader_test.cxx
3  * @brief Unit test for geometry functionalities on a standard detector.
4  * @date June 22, 2017
5  * @author Gianluca Petrillo (petrillo@fnal.gov)
6  *
7  * Usage:
8  *
9  * geometry_loader_test ConfigurationFile [test configuration FHiCL path]
10  *
11  * The configuration file path must be complete, i.e. it must point directly to
12  * the configuration file.
13  * By default, the test configuration is expected in
14  * `"physics.analysis.geotest"`.
15  *
16  * This unit test uses `StaticLoadGeometry()` to set up the geometry.
17  *
18  */
19 
20 
21 // LArSoft libraries
22 #include "test/Geometry/GeometryTestAlg.h"
24 #include "larcorealg/Geometry/StandaloneGeometrySetup.h" // SetupGeometry()
25 #include "larcorealg/Geometry/StandaloneBasicSetup.h" // SetupMessageFacility()...
27 
28 // utility libraries
29 #include "fhiclcpp/ParameterSet.h"
31 
32 // C/C++ standard libraries
33 #include <string>
34 #include <stdexcept> // std::runtime_error
35 
36 
37 //------------------------------------------------------------------------------
38 //--- The tests
39 //---
40 
41 /** ****************************************************************************
42  * @brief Runs the test
43  * @param argc number of arguments in argv
44  * @param argv arguments to the function
45  * @return number of detected errors (0 on success)
46  * @throw cet::exception most of error situations throw
47  *
48  * The arguments in argv are:
49  * 0. name of the executable ("Geometry_test")
50  * 1. path to the FHiCL configuration file
51  * 2. FHiCL path to the configuration of the geometry test
52  * (default: physics.analysers.geotest)
53  * 3. FHiCL path to the configuration of the geometry
54  * (default: services.Geometry)
55  *
56  */
57 //------------------------------------------------------------------------------
58 int main(int argc, char const** argv) {
59 
60  //
61  // parameter parsing
62  //
63  std::string configPath;
64  std::string geoTestConfigPath = "physics.analyzers.geotest";
65 
66  int iParam = 0;
67 
68  // first argument: configuration file (mandatory)
69  if (++iParam < argc) configPath = argv[iParam];
70  else
71  throw std::runtime_error("No configuration file specified.");
72 
73  // second argument: test configuration path
74  if (++iParam < argc) geoTestConfigPath = argv[iParam];
75 
76 
77  //
78  // 1. testing environment setup
79  //
80 
81  using namespace lar::standalone;
82 
83  // parse a configuration file
84  fhicl::ParameterSet pset = ParseConfiguration(configPath);
85 
86  // set up message facility
87  SetupMessageFacility(pset, "geometry_loader_test");
88  mf::SetContextIteration("setup");
89 
90  // set up geometry
91  auto geom = SetupGeometry<geo::ChannelMapStandardAlg>
92  (pset.get<fhicl::ParameterSet>("services.Geometry"));
93 
94  // update the context string for the messages
96 
97  //
98  // 2. prepare the test algorithm
99  //
100 
101  geo::GeometryTestAlg Tester(pset.get<fhicl::ParameterSet>(geoTestConfigPath));
102  Tester.Setup(*geom);
103 
104  //
105  // 3. then we run it!
106  //
107  unsigned int nErrors = Tester.Run();
108 
109  //
110  // 4. And finally we cross fingers.
111  //
113  if (nErrors > 0) {
114  mf::LogError("geometry_test") << nErrors << " errors detected!";
115  }
116 
117  return nErrors;
118 } // main()
Utilities for one-line geometry initialization.
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
virtual unsigned int Run()
Runs the test, returns a number of errors (very unlikely!)
void SetContextIteration(string const &val)
void SetupMessageFacility(fhicl::ParameterSet const &pset, std::string applName="standalone")
Sets up the message facility service.
Collection of functions for quick setup of basic facilities.
Performs tests on the geometry as seen by Geometry service.
T get(std::string const &key) const
Definition: ParameterSet.h:271
virtual void Setup(geo::GeometryCore const &new_geo)
Runs the test.
Utilities for use in an environment without art.
Access the description of detector geometry.
fhicl::ParameterSet ParseConfiguration(std::string configPath, cet::filepath_maker &lookupPolicy)
Parses a FHiCL configuration file.
int main(int argc, char const **argv)
Runs the test.