LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
GeometryConfigurationWriter_service.cc
Go to the documentation of this file.
1 
10 // LArSoft libraries
14 
15 // framework libraries
22 
23 // C/C++ standard libraries
24 #include <memory> // std::make_unique()
25 #include <utility> // std::move()
26 
27 // -----------------------------------------------------------------------------
28 namespace geo {
29  class GeometryConfigurationWriter;
30 }
81 
82 public:
84  struct Config {
85  // no configuration parameters at this time
86  };
87 
89 
92 
93 private:
95  virtual void postReadRun(art::Run& run) override;
96 
97 private:
99  using InfoPtr_t = std::unique_ptr<sumdata::GeometryConfigurationInfo>;
100 
102  InfoPtr_t loadInfo(art::Run& run) const;
103 
106 
109 
113 
115  sumdata::RunData const* readRunData(art::Run& run) const;
116 
119 
122  {
123  return std::make_unique<sumdata::GeometryConfigurationInfo>(info);
124  }
125 
126 }; // geo::GeometryConfigurationWriter
127 
128 // -----------------------------------------------------------------------------
129 // --- implementation
130 // -----------------------------------------------------------------------------
132 {
133  produces<sumdata::GeometryConfigurationInfo, art::InRun>();
134 }
135 
136 // -----------------------------------------------------------------------------
138 {
139 
141 
142  if (!confInfo) confInfo = extractInfoFromGeometry();
143 
144  run.put(std::move(confInfo), art::fullRun());
145 
146 } // geo::GeometryConfigurationWriter::postReadRun()
147 
148 // -----------------------------------------------------------------------------
150 {
151 
152  /*
153  * Read geometry configuration information from the run:
154  *
155  * 1. first attempt to directly read information from past runs of this
156  * service
157  * 2. if none is found, attempt reading legacy information and upgrade it
158  * 3. if no legacy information is found either, return a null pointer
159  *
160  */
162 
163  return info ? std::move(info) : makeInfoFromRunData(run);
164 
165 } // geo::GeometryConfigurationWriter::loadInfo()
166 
167 // -----------------------------------------------------------------------------
169 {
170 
172  art::ServiceHandle<geo::Geometry>()->configurationInfo();
173 
174  MF_LOG_DEBUG("GeometryConfigurationWriter")
175  << "Geometry configuration information from service:\n"
176  << confInfo;
177 
178  return makeInfoPtr(std::move(confInfo));
179 
180 } // geo::GeometryConfigurationWriter::extractInfoFromGeometry()
181 
182 // -----------------------------------------------------------------------------
184 {
185 
187  return run.getByLabel(art::InputTag{"GeometryConfigurationWriter"}, infoHandle) ?
188  makeInfoPtr(*infoHandle) :
189  InfoPtr_t{};
190 
191 } // geo::GeometryConfigurationWriter::hasGeometryInformation()
192 
193 // -----------------------------------------------------------------------------
195 {
196 
197  sumdata::RunData const* runData = readRunData(run);
198 
199  return runData ? convertRunDataToGeometryInformation(*runData) : InfoPtr_t{};
200 
201 } // geo::GeometryConfigurationWriter::makeInfoFromRunData()
202 
203 // -----------------------------------------------------------------------------
205 {
206  //std::vector<art::Handle<sumdata::RunData>> allRunData;
207  //run.getManyByType(allRunData);
208  auto allRunData = run.getMany<sumdata::RunData>();
209  return allRunData.empty() ? nullptr : allRunData.front().product();
210 } // geo::GeometryConfigurationWriter::readRunData()
211 
212 // -----------------------------------------------------------------------------
214  sumdata::RunData const& data) -> InfoPtr_t
215 {
216 
218 
219  // we use the simplest version 1 data format (legacy format)
221  confInfo.detectorName = data.DetName();
222 
223  MF_LOG_DEBUG("GeometryConfigurationInfo")
224  << "Built geometry configuration information from run data:\n"
225  << confInfo;
226 
227  return makeInfoPtr(std::move(confInfo));
228 
229 } // geo::GeometryConfigurationWriter::convertRunDataToGeometryInformation()
230 
231 // -----------------------------------------------------------------------------
233 
234 // -----------------------------------------------------------------------------
constexpr auto fullRun()
Writes geometry configuration information into art runs.
DataVersion_t dataVersion
Version of the data in this object (0 is invalid version).
GeometryConfigurationWriter(Parameters const &)
Constructor: gets its configuration and does nothing with it.
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Run.h:121
Definition: Run.h:37
static InfoPtr_t makeInfoPtr(sumdata::GeometryConfigurationInfo const &info)
Alias to std::make_unique<sumdata::GeometryConfigurationInfo>.
static InfoPtr_t convertRunDataToGeometryInformation(sumdata::RunData const &data)
Converts the legacy data into geometry configuration information.
#define DEFINE_ART_PRODUCING_SERVICE(klass)
std::unique_ptr< sumdata::GeometryConfigurationInfo > InfoPtr_t
Alias for the pointer to the data product object to be put into the run.
InfoPtr_t readGeometryInformation(art::Run &run) const
Reads geometry information from the run (returns null pointer if none).
static InfoPtr_t extractInfoFromGeometry()
Creates configuration information based on the current Geometry service.
Description of the current configuration of detector geometry.
unsigned int DataVersion_t
Type used for the version of data.
#define MF_LOG_DEBUG(id)
sumdata::RunData const * readRunData(art::Run &run) const
Returns a pointer to the sumdata::RunData in run (nullptr if none).
Namespace collecting geometry-related classes utilities.
virtual void postReadRun(art::Run &run) override
Writes the information from the service configuration into the run.
art framework interface to geometry description
Description of the current configuration of detector geometry.
std::vector< Handle< PROD > > getMany(SelectorBase const &selector=MatchAllSelector{}) const
InfoPtr_t loadInfo(art::Run &run) const
Loads the geometry information from the run (either directly or legacy).