Geometry.h
Go to the documentation of this file.
1 /**
2  * @file larcore/Geometry/Geometry.h
3  * @brief art framework interface to geometry description
4  * @author brebel@fnal.gov
5  * @see larcore/Geometry/Geometry_service.cc
6  *
7  * Revised <seligman@nevis.columbia.edu> 29-Jan-2009
8  * Revise the class to make it into more of a general detector interface
9  * Revised <petrillo@fnal.gov> 27-Apr-2015
10  * Factorization into a framework-independent GeometryCore.h and a
11  * art framework interface
12  * Revised <petrillo@fnal.gov> 10-Nov-2015
13  * Complying with the provider requirements described in ServiceUtil.h
14  */
15 
16 #ifndef LARCORE_GEOMETRY_GEOMETRY_H
17 #define LARCORE_GEOMETRY_GEOMETRY_H
18 
19 // LArSoft libraries
20 #include "larcore/CoreUtils/ServiceUtil.h" // not used; for user's convenience
23 
24 // the following are included for convenience only
32 
33 // framework libraries
34 #include "fhiclcpp/ParameterSet.h"
38 #include "art/Framework/Services/Registry/ServiceHandle.h" // for the convenience of includers
39 
40 // C/C++ standard libraries
41 #include <vector>
42 #include <map>
43 #include <set>
44 #include <cstring>
45 #include <memory>
46 #include <iterator> // std::forward_iterator_tag
47 
48 
49 namespace geo {
50 
51  /**
52  * @brief The geometry of one entire detector, as served by art
53  *
54  * This class extends the interface of the geometry service provider,
55  * GeometryCore, to the one of an art service.
56  * It handles the correct initialization of the provider using information
57  *
58  * It relies on geo::ExptGeoHelperInterface service to obtain the
59  * channel mapping algorithm proper for the selected geometry.
60  *
61  * The geometry initialization happens immediately on construction.
62  * Optionally, the geometry is automatically reinitialized on each run based
63  * on the information contained in the art::Run object.
64  *
65  * Configuration
66  * ==============
67  *
68  * In addition to the parameters documented in geo::GeometryCore, the
69  * following parameters are supported:
70  *
71  * - *RelativePath* (string, default: no path): this path is prepended to the
72  * geometry file names before searching from them; the path string does not
73  * affect the file name
74  * - *GDML* (string, mandatory): path of the GDML file to be served to Geant4
75  * for detector simulation. The full file is composed out of the optional
76  * relative path specified by `RelativePath` path and the base name
77  * specified in `GDML` parameter; this path is searched for in the
78  * directories configured in the `FW_SEARCH_PATH` environment variable;
79  * - *ROOT* (string, mandatory): currently overridden by `GDML` parameter,
80  * whose value is used instead;
81  * this path is assembled in the same way as the one for `GDML` parameter,
82  * except that no alternative (wireless) geometry is used even if
83  * `DisableWiresInG4` is specified (see below); this file is used to load
84  * the geometry used in the internal simulation and reconstruction,
85  * basically everywhere except for the Geant4 simulation
86  * - *DisableWiresInG4* (boolean, default: false): if true, Geant4 is loaded
87  * with an alternative geometry from a file with the standard name as
88  * configured with the /GDML/ parameter, but with an additional "_nowires"
89  * appended before the ".gdml" suffix
90  * - *SkipConfigurationCheck* (boolean, default: `false`): if set to `true`,
91  * failure of configuration consistency check described below is not fatal
92  * and it will just produce a warning on each failure;
93  * - *SortingParameters* (a parameter set; default: empty): this configuration
94  * is directly passed to the channel mapping algorithm (see
95  * geo::ChannelMapAlg); its content is dependent on the chosen
96  * implementation of `geo::ChannelMapAlg`
97  * - *Builder* (a parameter set: default: empty): configuration for the
98  * geometry builder; if omitted, the standard builder
99  * (`geo::GeometryBuilderStandard`) with standard configuration will be
100  * used; if specified, currently the standard builder is nevertheless used;
101  * this interface can be "toolized", in which case this parameter set will
102  * select and configure the chosen tool.
103  *
104  * @note Currently, the file defined by `GDML` parameter is also served to
105  * ROOT for the internal geometry representation.
106  *
107  *
108  *
109  * Configuration consistency check
110  * ================================
111  *
112  * The `Geometry` service checks that the input files were processed with a
113  * configuration of `Geometry` service compatible with the current one.
114  *
115  * Two checks may be performed: the standard check, and a legacy check.
116  *
117  *
118  * Consistency check
119  * ------------------
120  *
121  * The `Geometry` service checks at the beginning of each run that the
122  * current configuration is compatible with the geometry configuration
123  * declared in the input file.
124  * The `Geometry` service requires that an additional service,
125  * `GeometryConfigurationWriter`, is run: this service is charged with writing
126  * the configuration information into the output files, for the checks in
127  * the future job.
128  *
129  * The compatibility check is currently very silly, but it can improved in
130  * future versions. This check is the same as the legacy check, that verifies
131  * that the configured detector name (`geo::GeometryCore::DetectorName()`)
132  * has not changed.
133  *
134  * To allow this check to operate correctly, the only requirement is that
135  * the service `GeometryConfigurationWriter` be included in the job:
136  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
137  * services.GeometryConfigurationWriter: {}
138  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139  * This must happen on the first job in the processing chain that configures
140  * `Geometry` service. It is irrelevant, but not harmful, in the jobs that
141  * follow.
142  *
143  *
144  * ### Design details
145  *
146  * This section describes the full design of the check from a technical point
147  * of view. Users do not need to understand the mechanisms of this check in
148  * order to configure their jobs to successfully pass it.
149  *
150  * The check happens based on the data contained in the
151  * `sumdata::GeometryConfigurationInfo` data product.
152  * Starting from after the construction is complete, `geo::Geometry` is able
153  * to provide at any time an instance of `sumdata::GeometryConfigurationInfo`
154  * describing the geometry configuration for this job, whether the geometry
155  * is already configured or not.
156  *
157  * The `Geometry` service loads the geometry at the beginning of the job.
158  * At the start of each run from the input file, the `Geometry` service
159  * reads a configuration information `sumdata::GeometryConfigurationInfo` from
160  * the `art::Run` record and verifies that it is compatible with the current
161  * configuration. It is a fatal error for this information not to be available
162  * in `art::Run`, and it is a fatal check failure if the available
163  * information is not compatible with the current configuration.
164  *
165  * The `sumdata::GeometryConfigurationInfo` information is put into `art::Run`
166  * record by the `geo::GeometryConfigurationWriter` producing service.
167  * This service verifies whether there is already such information in the run.
168  * If no information is available yet in `art::Run`, the service obtains the
169  * current configuration information from the `Geometry` service, and then
170  * puts it into the `art::Run` record. The _art_ framework guarantees that
171  * this happens _before_ the `Geometry` service itself is notified by _art_
172  * of the start of the new run.
173  * If some `geo::GeometryConfigurationWriter` information is already in the
174  * run record, `geo::GeometryConfigurationWriter` replicates it again.
175  * As legacy check, if there is no information in the
176  * `sumdata::GeometryConfigurationInfo` form but there is a `sumdata::RunData`
177  * data product, the latter is used as a base for the check.
178  *
179  *
180  * Design notes:
181  *
182  * * the choice of delegating the writing of data product to a producing
183  * service rather than to modules is driven by the fact that there is a way
184  * to enforce this service to be actually run, and that no further
185  * instrumentation is needed;
186  * * the choice of putting the configuration information in the `art::Run` is
187  * driven by the fact that the run is the highest available container;
188  * job-level data products (`art::Results`) behave very differently from
189  * the others and are not currently interfaced with a producing service;
190  * * the information in `sumdata::GeometryConfigurationInfo` should be compact
191  * enough not to bloat the data files with very few events per run, as it
192  * may be for the selection of rare processes or signatures.
193  *
194  *
195  */
196  class Geometry: public GeometryCore
197  {
198  public:
199 
200  using provider_type = GeometryCore; ///< type of service provider
201 
203 
204  /// Returns a pointer to the geometry service provider
205  provider_type const* provider() const
206  { return static_cast<provider_type const*>(this); }
207 
208  /// Returns the current geometry configuration information.
210  { return fConfInfo; }
211 
212  private:
213 
214  /// Updates the geometry if needed at the beginning of each new run
215  void preBeginRun(art::Run const& run);
216 
217  /// Expands the provided paths and loads the geometry description(s)
218  void LoadNewGeometry(
219  std::string gdmlfile, std::string rootfile,
220  bool bForceReload = false
221  );
222 
223  // --- BEGIN -- Configuration information checks ---------------------------
224  /// @name Configuration information checks
225  /// @{
226 
227  /// Fills the service configuration information into `fConfInfo`.
229 
230  /// Returns if the `other` configuration is compatible with our current.
233 
234  /// Reads and returns the geometry configuration information from the run.
236  (art::Run const& run);
237 
238  /// Returns if `A` and `B` are compatible geometry service configurations.
239  static bool CompareConfigurationInfo(
242  );
243 
244  /// @}
245  // --- END -- Configuration information checks -----------------------------
246 
247  void InitializeChannelMap();
248 
249  std::string fRelPath; ///< Relative path added to FW_SEARCH_PATH to search for
250  ///< geometry file
251  bool fDisableWiresInG4; ///< If set true, supply G4 with GDMLfileNoWires
252  ///< rather than GDMLfile
253  bool fNonFatalConfCheck;///< Don't stop if configuration check fails.
254  ///< files specified in the fcl file
255  fhicl::ParameterSet fSortingParameters;///< Parameter set to define the channel map sorting
256  fhicl::ParameterSet fBuilderParameters;///< Parameter set for geometry builder.
257 
258  sumdata::GeometryConfigurationInfo fConfInfo;///< Summary of service configuration.
259 
260  };
261 
262 } // namespace geo
263 
265 
266 #endif // LARCORE_GEOMETRY_GEOMETRY_H
Encapsulate the construction of a single cyostat.
fhicl::ParameterSet fSortingParameters
Parameter set to define the channel map sorting.
Definition: Geometry.h:255
std::string string
Definition: nybbler.cc:12
void FillGeometryConfigurationInfo(fhicl::ParameterSet const &config)
Fills the service configuration information into fConfInfo.
Description of the current configuration of detector geometry.
bool fNonFatalConfCheck
Definition: Geometry.h:253
bool fDisableWiresInG4
Definition: Geometry.h:251
static bool CompareConfigurationInfo(sumdata::GeometryConfigurationInfo const &A, sumdata::GeometryConfigurationInfo const &B)
Returns if A and B are compatible geometry service configurations.
bool CheckConfigurationInfo(sumdata::GeometryConfigurationInfo const &other) const
Returns if the other configuration is compatible with our current.
Geometry(fhicl::ParameterSet const &pset, art::ActivityRegistry &reg)
void preBeginRun(art::Run const &run)
Updates the geometry if needed at the beginning of each new run.
Definition: Run.h:17
static sumdata::GeometryConfigurationInfo const & ReadConfigurationInfo(art::Run const &run)
Reads and returns the geometry configuration information from the run.
fhicl::ParameterSet fBuilderParameters
Parameter set for geometry builder.
Definition: Geometry.h:256
#define DECLARE_ART_SERVICE(svc, scope)
static Config * config
Definition: config.cpp:1054
GeometryCore(fhicl::ParameterSet const &pset)
Initialize geometry from a given configuration.
std::string fRelPath
Definition: Geometry.h:249
void LoadNewGeometry(std::string gdmlfile, std::string rootfile, bool bForceReload=false)
Expands the provided paths and loads the geometry description(s)
Encapsulate the geometry of an auxiliary detector.
The geometry of one entire detector, as served by art.
Definition: Geometry.h:196
Description of geometry of one entire detector.
sumdata::GeometryConfigurationInfo const & configurationInfo() const
Returns the current geometry configuration information.
Definition: Geometry.h:209
sumdata::GeometryConfigurationInfo fConfInfo
Summary of service configuration.
Definition: Geometry.h:258
Encapsulate the geometry of a wire.
Encapsulate the geometry of an optical detector.
provider_type const * provider() const
Returns a pointer to the geometry service provider.
Definition: Geometry.h:205
Encapsulate the construction of a single detector plane.
Access the description of detector geometry.
Interface to algorithm class for a specific detector channel mapping.
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void InitializeChannelMap()
Description of the current configuration of detector geometry.
Encapsulate the construction of a single detector plane.