LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpChannelMap_module.cc
Go to the documentation of this file.
1 
9 // LArSoft libraries
13 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
14 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::WireID
15 
16 // framework libraries
21 #include "fhiclcpp/types/Atom.h"
22 #include "fhiclcpp/types/Comment.h"
23 #include "fhiclcpp/types/Name.h"
25 
26 // C/C++ standard libraries
27 #include <string>
28 
29 namespace geo {
30  class DumpChannelMap;
31 }
32 
58 public:
60  struct Config {
61  using Name = fhicl::Name;
63 
65  Name("OutputCategory"),
66  Comment("output category used by the message facility to output information (INFO level)"),
67  "DumpChannelMap"};
68 
70  Comment("print all the wires corresponding to each channel"),
71  true};
72 
74  Comment("print which channel covers each wire"),
75  false};
76 
78  Name("OpDetChannels"),
79  Comment("print for each optical detector channel ID the optical detector ID and its center"),
80  false};
81 
83  Name("FirstChannel"),
84  Comment("ID of the lowest channel to be printed (default: no limit)"),
86 
88  Name("LastChannel"),
89  Comment("ID of the highest channel to be printed (default: no limit)"),
91 
92  }; // Config
93 
95 
96  explicit DumpChannelMap(Parameters const& config);
97 
98  // Plugins should not be copied or assigned.
99  DumpChannelMap(DumpChannelMap const&) = delete;
100  DumpChannelMap(DumpChannelMap&&) = delete;
101  DumpChannelMap& operator=(DumpChannelMap const&) = delete;
103 
104  // Required functions
105  void analyze(art::Event const&) override {}
106 
108  void beginRun(art::Run const&) override;
109 
110 private:
111  std::string OutputCategory;
115 
118 
119 }; // geo::DumpChannelMap
120 
121 //==============================================================================
122 //=== Algorithms declaration
123 //===
124 
125 namespace {
126 
128  class DumpChannelToWires {
129  public:
132  {}
133 
135  void Setup(geo::GeometryCore const& geometry) { pGeom = &geometry; }
136 
138  void SetLimits(raw::ChannelID_t first_channel, raw::ChannelID_t last_channel)
139  {
140  FirstChannel = first_channel;
141  LastChannel = last_channel;
142  }
143 
145  void Dump(std::string OutputCategory) const;
146 
147  protected:
148  geo::GeometryCore const* pGeom = nullptr;
149 
152 
154  void CheckConfig() const;
155 
156  }; // class DumpChannelToWires
157 
159  class DumpWireToChannel {
160  public:
162  DumpWireToChannel() {}
163 
165  void Setup(geo::GeometryCore const& geometry) { pGeom = &geometry; }
166 
168  void Dump(std::string OutputCategory) const;
169 
170  protected:
171  geo::GeometryCore const* pGeom = nullptr;
172 
174  void CheckConfig() const;
175 
176  }; // class DumpWireToChannel
177 
179  class DumpOpticalDetectorChannels {
180  public:
182  DumpOpticalDetectorChannels() {}
183 
185  void Setup(geo::GeometryCore const& geometry) { pGeom = &geometry; }
186 
188  void Dump(std::string OutputCategory) const;
189 
190  protected:
191  geo::GeometryCore const* pGeom = nullptr;
192 
194  void CheckConfig() const;
195 
198  geo::OpDetGeo const* getOpticalDetector(unsigned int channelID) const;
199 
200  }; // class DumpOpticalDetectorChannels
201 
202 } // local namespace
203 
204 //==============================================================================
205 //=== Module implementation
206 //===
207 
208 //------------------------------------------------------------------------------
210  : art::EDAnalyzer(config)
211  , OutputCategory(config().OutputCategory())
212  , DoChannelToWires(config().ChannelToWires())
213  , DoWireToChannel(config().WireToChannel())
214  , DoOpDetChannels(config().OpDetChannels())
215  , FirstChannel(config().FirstChannel())
216  , LastChannel(config().LastChannel())
217 {} // geo::DumpChannelMap::DumpChannelMap()
218 
219 //------------------------------------------------------------------------------
221 {
222 
224 
225  if (DoChannelToWires) {
226  DumpChannelToWires dumper;
227  dumper.Setup(geom);
228  dumper.SetLimits(FirstChannel, LastChannel);
229  dumper.Dump(OutputCategory);
230  }
231 
232  if (DoWireToChannel) {
233  DumpWireToChannel dumper;
234  dumper.Setup(geom);
235  // dumper.SetLimits(FirstChannel, LastChannel);
236  dumper.Dump(OutputCategory);
237  }
238 
239  if (DoOpDetChannels) {
240  DumpOpticalDetectorChannels dumper;
241  dumper.Setup(geom);
242  dumper.Dump(OutputCategory);
243  }
244 
245 } // geo::DumpChannelMap::beginRun()
246 
247 //==============================================================================
248 //=== Algorithm implementation
249 //===
250 
251 //------------------------------------------------------------------------------
252 //--- DumpChannelToWires
253 //------------------------------------------------------------------------------
254 void DumpChannelToWires::CheckConfig() const
255 {
256 
258  if (!pGeom) {
260  << "DumpChannelToWires: no valid geometry available!";
261  }
262 } // DumpChannelToWires::CheckConfig()
263 
264 //------------------------------------------------------------------------------
265 void DumpChannelToWires::Dump(std::string OutputCategory) const
266 {
267 
269  CheckConfig();
270 
272  unsigned int const NChannels = pGeom->Nchannels();
273 
274  if (NChannels == 0) {
275  mf::LogError(OutputCategory) << "Nice detector we have here, with no channels.";
276  return;
277  }
278 
279  raw::ChannelID_t const PrintFirst =
281  raw::ChannelID_t const PrintLast =
283 
284  // print intro
285  unsigned int const NPrintedChannels = (PrintLast - PrintFirst) + 1;
286  if (NPrintedChannels == NChannels) {
287  mf::LogInfo(OutputCategory) << "Printing all " << NChannels << " channels";
288  }
289  else {
290  mf::LogInfo(OutputCategory) << "Printing channels from " << PrintFirst << " to " << LastChannel
291  << " (" << NPrintedChannels << " channels out of " << NChannels
292  << ")";
293  }
294 
295  // print map
296  mf::LogVerbatim log(OutputCategory);
297  for (raw::ChannelID_t channel = PrintFirst; channel <= PrintLast; ++channel) {
298  std::vector<geo::WireID> const Wires = pGeom->ChannelToWire(channel);
299 
300  log << "\n " << ((int)channel) << " ->";
301  switch (Wires.size()) {
302  case 0: log << " no wires"; break;
303  case 1: break;
304  default: log << " [" << Wires.size() << " wires]"; break;
305  } // switch
306 
307  for (geo::WireID const& wireID : Wires)
308  log << " { " << std::string(wireID) << " };";
309 
310  } // for (channels)
311 
312 } // DumpChannelToWires::Dump()
313 
314 //------------------------------------------------------------------------------
315 //--- DumpWireToChannel
316 //------------------------------------------------------------------------------
317 void DumpWireToChannel::CheckConfig() const
318 {
319 
321  if (!pGeom) {
323  << "DumpWireToChannel: no valid geometry available!";
324  }
325 } // DumpWireToChannel::CheckConfig()
326 
327 //------------------------------------------------------------------------------
328 void DumpWireToChannel::Dump(std::string OutputCategory) const
329 {
330 
332  CheckConfig();
333 
335  unsigned int const NChannels = pGeom->Nchannels();
336 
337  if (NChannels == 0) {
338  mf::LogError(OutputCategory) << "Nice detector we have here, with no channels.";
339  return;
340  }
341 
342  // print intro
343  mf::LogInfo(OutputCategory) << "Printing wire channels for up to " << NChannels << " channels";
344 
345  // print map
346  mf::LogVerbatim log(OutputCategory);
347  for (geo::WireID const& wireID : pGeom->Iterate<geo::WireID>()) {
348  raw::ChannelID_t channel = pGeom->PlaneWireToChannel(wireID);
349  log << "\n { " << std::string(wireID) << " } => ";
350  if (raw::isValidChannelID(channel))
351  log << channel;
352  else
353  log << "invalid!";
354  } // for
355 
356 } // DumpWireToChannel::Dump()
357 
358 //------------------------------------------------------------------------------
359 //--- DumpOpticalDetectorChannels
360 //------------------------------------------------------------------------------
361 void DumpOpticalDetectorChannels::CheckConfig() const
362 {
363 
365  if (!pGeom) {
367  << "DumpOpticalDetectorChannels: no valid geometry available!";
368  }
369 } // DumpOpticalDetectorChannels::CheckConfig()
370 
371 //------------------------------------------------------------------------------
372 geo::OpDetGeo const* DumpOpticalDetectorChannels::getOpticalDetector(unsigned int channelID) const
373 {
374  try {
375  return &(pGeom->OpDetGeoFromOpChannel(channelID));
376  }
377  catch (cet::exception const&) {
378  return nullptr;
379  }
380 } // DumpOpticalDetectorChannels::getOpticalDetector()
381 
382 //------------------------------------------------------------------------------
383 void DumpOpticalDetectorChannels::Dump(std::string OutputCategory) const
384 {
385 
387  CheckConfig();
388 
390  unsigned int const NChannels = pGeom->NOpChannels();
391 
392  if (NChannels == 0) {
393  mf::LogError(OutputCategory) << "Nice detector we have here, with no optical channels.";
394  return;
395  }
396 
397  // print intro
398  mf::LogInfo(OutputCategory) << "Printing optical detectors for up to " << NChannels
399  << " channels";
400 
401  // print map
402  mf::LogVerbatim log(OutputCategory);
403  for (unsigned int channelID = 0; channelID < NChannels; ++channelID) {
404  log << "\nChannel " << channelID << " => ";
405  geo::OpDetGeo const* opDet = getOpticalDetector(channelID);
406  if (!opDet) {
407  log << "invalid";
408  continue;
409  }
410  log << opDet->ID() << " at " << opDet->GetCenter() << " cm";
411  } // for
412 
413 } // DumpOpticalDetectorChannels::Dump()
414 
bool DoOpDetChannels
Dump optical detector channel -> optical detector.
std::string OutputCategory
Name of the category for output.
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
fhicl::Atom< std::string > OutputCategory
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
Definition: Run.h:37
DumpChannelMap & operator=(DumpChannelMap const &)=delete
Access the description of detector geometry.
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:31
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void beginRun(art::Run const &) override
Drives the dumping.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:35
bool DoWireToChannel
Dump wire -> channel mapping.
Description of geometry of one entire detector.
Definition: GeometryCore.h:119
Definition of data types for geometry description.
bool DoChannelToWires
Dump channel -> wires mapping.
raw::ChannelID_t LastChannel
Last channel to be printed.
Encapsulate the geometry of an optical detector.
geo::Point_t const & GetCenter() const
Definition: OpDetGeo.h:72
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
fhicl::Atom< raw::ChannelID_t > FirstChannel
fhicl::Atom< raw::ChannelID_t > LastChannel
Prints on screen the current channel-wire and optical detector maps.
Definition: MVAAlg.h:12
geo::OpDetID const & ID() const
Returns the geometry ID of this optical detector.
Definition: OpDetGeo.h:70
raw::ChannelID_t FirstChannel
First channel to be printed.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:28
DumpChannelMap(Parameters const &config)
Namespace collecting geometry-related classes utilities.
void analyze(art::Event const &) override
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33