All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LoadStandardICARUSgeometry.h
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Geometry/LoadStandardICARUSgeometry.h
3  * @brief Single-line utility to create `geo::GeometryCore` in non-art contexts.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  *
6  * Provides `icarus::geo::LoadStandardICARUSgeometry()`.
7  *
8  * This library is (intentionally and stubbornly) header-only.
9  * It requires linking with:
10  * * `icarusalg_Geometry`
11  * * `larcorealg_Geometry`
12  * * `MF_MessageLogger`
13  * * `fhiclcpp`
14  *
15  * (and, indirectly, more).
16  *
17  */
18 
19 #ifndef ICARUSALG_GEOMETRY_LOADSTANDARDICARUSGEOMETRY_H
20 #define ICARUSALG_GEOMETRY_LOADSTANDARDICARUSGEOMETRY_H
21 
22 
23 // ICARUS libraries
26 
27 // LArSoft and framework libraries
29 #include "messagefacility/MessageLogger/MessageLogger.h" // mf::StartMessageFacility()
30 #include "fhiclcpp/make_ParameterSet.h"
31 #include "fhiclcpp/ParameterSet.h"
32 #include "cetlib/filepath_maker.h"
33 
34 // C/C++ libraries
35 #include <stdexcept> // std::runtime_error
36 #include <memory> // std::unique_ptr
37 #include <string>
38 
39 
40 // -----------------------------------------------------------------------------
41 namespace icarus::geo {
42  std::unique_ptr<::geo::GeometryCore> LoadStandardICARUSgeometry [[nodiscard]]
43  (std::string const& configPath);
44 } // namespace icarus::geo
45 
46 
47 // -----------------------------------------------------------------------------
48 // --- inline implementation
49 // -----------------------------------------------------------------------------
50 /**
51  * @brief Returns an instance of `geo::GeometryCore` with ICARUS geometry loaded
52  * @param configPath path to a FHiCL configuration file including geometry
53  * @return a unique pointer with `geo::GeometryCore` object
54  *
55  * The geometry is initialized with the configuration found in the FHiCL file
56  * pointed by `configPath`.
57  * Within that file, the geometry service provider configuration table is
58  * expected to be found as `services.Geometry` or, as fallback as `Geometry`.
59  * If neither is present, the whole configuration will be used.
60  *
61  * ICARUS geometry configuration has special conventions, which include:
62  * * a full `ChannelMapping` configuration in the `Geometry` configuration
63  * block, equivalent to the one passed to `ExptGeoHelperInterface` service;
64  * * within it, a `tool_type` name.
65  *
66  * The `ChannelMapping` table *must* be present in the configuration, and the
67  * `tool_type` configuration atom must match
68  * `ICARUSsplitInductionChannelMapSetupTool`. These parameters confirm that the
69  * standard ICARUS geometry is intended.
70  *
71  * If a configuration table `service.message` or `message` is found, message
72  * facility is initialised with it, unless it is already running.
73  *
74  * This utility is as simple to use as:
75  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
76  * std::unique_ptr<geo::GeometryCore> geom
77  * = icarus::geo::LoadStandardICARUSgeometry("standard_g4_icarus.fcl");
78  * geom->Print(std::cout);
79  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80  * It has been tested in Cling interpreter provided with ROOT 6.22/08.
81  *
82  * Note that it is considered an error not to use the return value of this
83  * function.
84  *
85  */
86 inline std::unique_ptr<::geo::GeometryCore>
88  (std::string const& configPath)
89 {
90  /*
91  * 1. load the FHiCL configuration
92  * 2. configuration check
93  * 3. load the standard geometry
94  * 4. return the geometry object
95  */
96 
97  using namespace std::string_literals;
98 
99  // this is the name of the tool expected in the configuration
100  static std::string const MagicToolName
101  { "ICARUSsplitInductionChannelMapSetupTool"s };
102 
103  //
104  // 1. load the FHiCL configuration
105  //
106  fhicl::ParameterSet config;
107  {
108  std::unique_ptr<cet::filepath_maker> const policy
109  { cet::lookup_policy_selector{}.select("permissive", "FHICL_FILE_PATH") };
110  fhicl::make_ParameterSet(configPath, *policy, config);
111  }
112 
113 
114  //
115  // 2. configuration check
116  //
117  std::string mfConfigPath;
118  if (!mf::isMessageProcessingSetUp()) {
119  for (std::string const& path: { "services.message"s, "message"s }) {
120  if (!config.is_key_to_table(path)) continue;
121  mfConfigPath = path;
122  break;
123  }
124  } // if no message facility yet
125 
126  std::string geomConfigPath;
127  for (std::string const& path: { "services.Geometry"s, "Geometry"s }) {
128  if (!config.is_key_to_table(path)) continue;
129  geomConfigPath = path;
130  break;
131  }
132  fhicl::ParameterSet const geomConfig = geomConfigPath.empty()
133  ? config: config.get<fhicl::ParameterSet>(geomConfigPath);
134 
135  if (!geomConfig.is_key_to_table("ChannelMapping")) {
136  throw std::runtime_error("icarus::geo::LoadStandardICARUSgeometry():"
137  " FHiCL configuration does not have a `ChannelMapping` section"
138  " (this is a ICARUS convention).\nConfiguration:\n"
139  + std::string(80, '-') + '\n'
140  + geomConfig.to_indented_string(1U)
141  + std::string(80, '-') + '\n'
142  );
143  }
144 
145  std::string const channelMappingToolType
146  = geomConfig.get("ChannelMapping.tool_type", ""s);
147  if (channelMappingToolType != MagicToolName) {
148  throw std::runtime_error("icarus::geo::LoadStandardICARUSgeometry() "
149  ": unexpected value '" + channelMappingToolType
150  + "' for `ChannelMapping.tool_type` configuration parameter (expected: '"
151  + MagicToolName + "').\nConfiguration:\n"
152  + std::string(80, '-') + '\n'
153  + geomConfig.to_indented_string(1U)
154  + std::string(80, '-') + '\n'
155  );
156  }
157 
158  //
159  // 3. load the standard geometry
160  //
161 
162  // set up message facility (we can live without, output would go to std::cerr)
163  if (!mfConfigPath.empty())
164  mf::StartMessageFacility(config.get<fhicl::ParameterSet>(mfConfigPath));
165 
166 
167  // 4. return the geometry object
168  return SetupICARUSGeometry<icarus::ICARUSChannelMapAlg>(geomConfig);
169 
170 } // icarus::geo::LoadStandardICARUSgeometry()
171 
172 
173 #endif // ICARUSALG_GEOMETRY_LOADSTANDARDICARUSGEOMETRY_H
Channel mapping algorithms for ICARUS detector.
std::unique_ptr<::geo::GeometryCore > LoadStandardICARUSgeometry(std::string const &configPath)
Returns an instance of geo::GeometryCore with ICARUS geometry loaded.
Functions to facilitate ICARUS geometry initialization outside art.
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 caloskimCalorimetryCryoE physics caloskimCalorimetryCryoW physics path
Access the description of detector geometry.
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60