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