GeometryTestAlg.h
Go to the documentation of this file.
1 /**
2  * @file GeometryTestAlg.h
3  * @brief Unit test for geometry functionalities
4  * @date 2011/02/17
5  * @author brebel@fnal.gov
6  * @see GeometryTestAlg.cxx
7  *
8  * Refactored by Gianluca Petrillo on May 5th, 2015.
9  */
10 
11 #ifndef GEO_GEOMETRYTESTALG_H
12 #define GEO_GEOMETRYTESTALG_H
13 
14 // GArSoft includes
15 #include "TestUtils/NameSelector.h"
16 
17 // C/C++ standard libraries
18 #include <string>
19 #include <set>
20 #include <vector>
21 #include <array>
22 #include <memory> // std::unique_ptr<>
23 
24 // forward declarations
25 namespace fhicl {
26  class ParameterSet;
27 }
28 
29 namespace gar {
30  namespace geo {
31 
32  // forward declarations
33  class GeometryCore;
34 
35  namespace details {
36  class TestTrackerClassBase;
37  } // namespace details
38 
39 
40  /** **************************************************************************
41  * @brief Performs tests on the geometry as seen by Geometry service
42  *
43  * Configuration parameters
44  * =========================
45  *
46  * - **ForgiveExceptions** (list of strings, default: empty): the categories
47  * of exceptions in this list are "forgiven" (non-fatal)
48  * - **RunTests** (string list): marks which tests to run; each entry can be
49  * specified with a "+" or "-" prepended, to indicate to add or to remove
50  * the test from the set to be run, respectively. The directives act against
51  * a pre-existing default set that executes all tests, except the ones
52  * explicitly marked as excluded by default in the list below:
53  * + `CheckOverlaps` (not in default) perform overlap checks
54  * + `ThoroughCheck` (not in default) makes ROOT perform full geometry check
55  * + `FindVolumes`: checks it can find the volumes corresponding to world
56  * + `NearestChannel`:
57  * + `default`: represents the default set (optionally prepended by '@')
58  * + `!` (special): means to forget the tests configured so far; used as the
59  * first test name, removes the default list but leaves unchanged the
60  * default behaviour (the one specified with "+*" or "-*")
61  * - **CheckForOverlaps** (boolean, default: false): equivalent to enabling
62  * `+CheckOverlaps` in `RunTests`
63  */
65  public:
66  explicit GeometryTestAlg(fhicl::ParameterSet const& pset);
67 
68  /// Virtual destructor
69  virtual ~GeometryTestAlg() = default;
70 
71  /// Runs the test
72  virtual void Setup(geo::GeometryCore const& new_geo) { geom = &new_geo; }
73 
74  /// Runs the test, returns a number of errors (very unlikely!)
75  virtual unsigned int Run();
76 
77 
78  private:
79  gar::geo::GeometryCore const* geom; ///< pointer to geometry service provider
80  std::set<std::string> fNonFatalExceptions;
81 
82  // using as pointer just not to have to write the declaration in the header
83  testing::NameSelector fRunTests; ///< test filter
84 
85  void printChannelSummary();
86  void printVolBounds();
87  void printDetDim();
88  void printAllGeometry() const;
89  void testFindVolumes();
90  void testNearestChannel();
91  void testStepping();
92 
93  bool shouldRunTests(std::string test_name) const;
94 
95  // single tests for testFindVolumes
96  unsigned int testFindWorldVolumes();
97  unsigned int testFindTPCvolumePaths();
98 
99 
100  };
101 
102 
103  namespace details {
104  /// Class telling whether a test needs to be run
106  public:
107  using TestList_t = std::set<std::string>;
108 
109  virtual ~TestTrackerClassBase() = default;
110 
111  /// Returns whether the specified test should run
112  virtual bool ShouldRun(std::string test_name) const = 0;
113 
114  /// Checks the test and records the request
115  bool operator() (std::string test_name);
116 
117  /// Allow the specified test to run
118  virtual void PleaseRunAlso(std::string test_name) = 0;
119 
120  /// Returns the tests that have been run
121  TestList_t const& RunTests() const { return run; }
122 
123  /// Returns the tests that have been skipped
124  TestList_t const& SkippedTests() const { return skipped; }
125 
126  /// Returns the tests that have been queried
127  TestList_t QueriedTests() const;
128 
129  /// Checks that the validity of the configuration (after the fact)
130  virtual bool CheckQueriesRegistry() const;
131 
132  /// Prints information about the configuration of the filter
133  virtual void PrintConfiguration(std::ostream&) const;
134 
135  protected:
136  TestList_t run; ///< requested tests that should be run
137  TestList_t skipped; ///< requested tests that should be skipped
138 
139  virtual void RecordRequest(std::string test_name, bool bRun);
140 
141  /// Checks the test and records the request
142  virtual bool Query(std::string test_name);
143 
144  /// Adds a vector of tests into a test set
145  static void CopyList(TestList_t & dest,
146  std::vector<std::string> const& from);
147 
148  }; // class TestTrackerClassBase
149 
150  } // namespace details
151 
152 
153  } // namespace geo
154 } // namespace gar
155 
156 #endif // GEO_GEOMETRYTESTALG_H
testing::NameSelector fRunTests
test filter
Performs tests on the geometry as seen by Geometry service.
Class telling whether a test needs to be run.
TestList_t const & SkippedTests() const
Returns the tests that have been skipped.
std::string string
Definition: nybbler.cc:12
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
Manages a set of names.
Definition: NameSelector.h:36
TestList_t skipped
requested tests that should be skipped
std::set< std::string > fNonFatalExceptions
gar::geo::GeometryCore const * geom
pointer to geometry service provider
TestList_t run
requested tests that should be run
General GArSoft Utilities.
TestList_t const & RunTests() const
Returns the tests that have been run.
virtual void Setup(geo::GeometryCore const &new_geo)
Runs the test.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void PrintConfiguration(typename lar::example::PointIsolationAlg< T >::Configuration_t const &config, std::ostream &out=std::cout)