DumpChannelMap_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpChannelMap_module.cc
3  * @brief Prints on screen the current channel-wire map
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date October 27th, 2015
6  *
7  */
8 
9 // LArSoft libraries
10 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
11 
12 // framework libraries
15 #include "fhiclcpp/types/Atom.h"
16 
17 // C/C++ standard libraries
18 #include <string>
19 
20 // ... more follow
21 
22 namespace geo {
23  class DumpChannelMap;
24  class GeometryCore;
25 }
26 
27 /** ****************************************************************************
28  * @brief Prints on screen the current channel-wire and optical detector maps.
29  *
30  * One print is performed at the beginning of each run.
31  *
32  *
33  * Configuration parameters
34  * =========================
35  *
36  * - *ChannelToWires* (boolean, default: true): prints all the wires
37  * corresponding to each channel
38  * - *WireToChannel* (boolean, default: false): prints which channel covers
39  * each wire
40  * - *OpDetChannels* (boolean, default: false): prints for each optical detector
41  * channel ID the optical detector ID and its center
42  * - *FirstChannel* (integer, default: no limit): ID of the lowest channel to be
43  * printed
44  * - *LastChannel* (integer, default: no limit): ID of the highest channel to be
45  * printed
46  * - *OutputCategory* (string, default: DumpChannelMap): output category used
47  * by the message facility to output information (INFO level)
48  *
49  */
50 
51 
53 public:
54 
55  /// Module configuration.
56  struct Config {
57  using Name = fhicl::Name;
59 
61  Name("OutputCategory"),
62  Comment(
63  "output category used by the message facility to output information (INFO level)"
64  ),
65  "DumpChannelMap"
66  };
67 
69  Name("ChannelToWires"),
70  Comment("print all the wires corresponding to each channel"),
71  true
72  };
73 
75  Name("WireToChannel"),
76  Comment("print which channel covers each wire"),
77  false
78  };
79 
81  Name("OpDetChannels"),
82  Comment(
83  "print for each optical detector channel ID the optical detector ID and its center"
84  ),
85  false
86  };
87 
89  Name("FirstChannel"),
90  Comment("ID of the lowest channel to be printed (default: no limit)"),
92  };
93 
95  Name("LastChannel"),
96  Comment("ID of the highest channel to be printed (default: no limit)"),
98  };
99 
100  }; // Config
101 
103 
104 
105  explicit DumpChannelMap(Parameters const& config);
106 
107  // Plugins should not be copied or assigned.
108  DumpChannelMap(DumpChannelMap const &) = delete;
109  DumpChannelMap(DumpChannelMap &&) = delete;
110  DumpChannelMap & operator = (DumpChannelMap const &) = delete;
112 
113  // Required functions
114  virtual void analyze(art::Event const&) override {}
115 
116  /// Drives the dumping
117  virtual void beginRun(art::Run const&) override;
118 
119  private:
120 
121  std::string OutputCategory; ///< Name of the category for output.
122  bool DoChannelToWires; ///< Dump channel -> wires mapping.
123  bool DoWireToChannel; ///< Dump wire -> channel mapping.
124  bool DoOpDetChannels; ///< Dump optical detector channel -> optical detector.
125 
126  raw::ChannelID_t FirstChannel; ///< First channel to be printed.
127  raw::ChannelID_t LastChannel; ///< Last channel to be printed.
128 
129 }; // geo::DumpChannelMap
130 
131 
132 //==============================================================================
133 //=== Algorithms declaration
134 //===
135 
136 namespace geo {
137  class GeometryCore;
138  class OpDetGeo;
139 } // namespace geo
140 
141 namespace {
142 
143  /// Dumps channel-to-wires mapping
144  class DumpChannelToWires {
145  public:
146 
147  /// Constructor; includes a working default configuration
148  DumpChannelToWires()
151  {}
152 
153  /// Sets up the required environment
154  void Setup(geo::GeometryCore const& geometry)
155  { pGeom = &geometry; }
156 
157  /// Sets the lowest and highest channel ID to be printed (inclusive)
158  void SetLimits
159  (raw::ChannelID_t first_channel, raw::ChannelID_t last_channel)
160  { FirstChannel = first_channel; LastChannel = last_channel; }
161 
162  /// Dumps to the specified output category
163  void Dump(std::string OutputCategory) const;
164 
165 
166  protected:
167  geo::GeometryCore const* pGeom = nullptr; ///< pointer to geometry
168 
169  raw::ChannelID_t FirstChannel; ///< lowest channel to be printed
170  raw::ChannelID_t LastChannel; ///< highest channel to be printed
171 
172  /// Throws an exception if the object is not ready to dump
173  void CheckConfig() const;
174 
175  }; // class DumpChannelToWires
176 
177 
178  /// Dumps wire-to-channel mapping
179  class DumpWireToChannel {
180  public:
181 
182  /// Constructor; includes a working default configuration
183  DumpWireToChannel() {}
184 
185  /// Sets up the required environment
186  void Setup(geo::GeometryCore const& geometry)
187  { pGeom = &geometry; }
188 
189  /// Dumps to the specified output category
190  void Dump(std::string OutputCategory) const;
191 
192 
193  protected:
194  geo::GeometryCore const* pGeom = nullptr; ///< pointer to geometry
195 
196  /// Throws an exception if the object is not ready to dump
197  void CheckConfig() const;
198 
199  }; // class DumpWireToChannel
200 
201 
202  /// Dumps optical detector channel-to-optical detector mapping.
203  class DumpOpticalDetectorChannels {
204  public:
205 
206  /// Constructor; includes a working default configuration
207  DumpOpticalDetectorChannels() {}
208 
209  /// Sets up the required environment
210  void Setup(geo::GeometryCore const& geometry)
211  { pGeom = &geometry; }
212 
213  /// Dumps to the specified output category
214  void Dump(std::string OutputCategory) const;
215 
216 
217  protected:
218  geo::GeometryCore const* pGeom = nullptr; ///< pointer to geometry
219 
220  /// Throws an exception if the object is not ready to dump
221  void CheckConfig() const;
222 
223  /// Returns the optical detector serving `channelID`,
224  /// `nullptr` if not found.
225  geo::OpDetGeo const* getOpticalDetector(unsigned int channelID) const;
226 
227  }; // class DumpOpticalDetectorChannels
228 
229 
230 } // local namespace
231 
232 
233 //==============================================================================
234 //=== Module implementation
235 //===
236 
237 // LArSoft libraries
241 
242 // framework libraries
244 
245 //------------------------------------------------------------------------------
247  : art::EDAnalyzer(config)
248  , OutputCategory (config().OutputCategory())
249  , DoChannelToWires(config().ChannelToWires())
250  , DoWireToChannel (config().WireToChannel())
251  , DoOpDetChannels (config().OpDetChannels())
252  , FirstChannel (config().FirstChannel())
253  , LastChannel (config().LastChannel())
254 {
255 
256 } // geo::DumpChannelMap::DumpChannelMap()
257 
258 //------------------------------------------------------------------------------
260 
262 
263  if (DoChannelToWires) {
264  DumpChannelToWires dumper;
265  dumper.Setup(geom);
266  dumper.SetLimits(FirstChannel, LastChannel);
267  dumper.Dump(OutputCategory);
268  }
269 
270  if (DoWireToChannel) {
271  DumpWireToChannel dumper;
272  dumper.Setup(geom);
273  // dumper.SetLimits(FirstChannel, LastChannel);
274  dumper.Dump(OutputCategory);
275  }
276 
277  if (DoOpDetChannels) {
278  DumpOpticalDetectorChannels dumper;
279  dumper.Setup(geom);
280  dumper.Dump(OutputCategory);
281  }
282 
283 } // geo::DumpChannelMap::beginRun()
284 
285 //------------------------------------------------------------------------------
287 
288 //==============================================================================
289 //=== Algorithm implementation
290 //===
291 
292 // LArSoft libraries
293 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::WireID
295 
296 // framework libraries
299 
300 // C/C++ standard libraries
301 
302 //------------------------------------------------------------------------------
303 //--- DumpChannelToWires
304 //------------------------------------------------------------------------------
305 void DumpChannelToWires::CheckConfig() const {
306 
307  /// check that the configuration is complete
308  if (!pGeom) {
310  << "DumpChannelToWires: no valid geometry available!";
311  }
312 } // DumpChannelToWires::CheckConfig()
313 
314 //------------------------------------------------------------------------------
315 void DumpChannelToWires::Dump(std::string OutputCategory) const {
316 
317  /// check that the configuration is complete
318  CheckConfig();
319 
320  /// extract general channel range information
321  unsigned int const NChannels = pGeom->Nchannels();
322 
323  if (NChannels == 0) {
324  mf::LogError(OutputCategory)
325  << "Nice detector we have here, with no channels.";
326  return;
327  }
328 
329  raw::ChannelID_t const PrintFirst
331  raw::ChannelID_t const PrintLast
333 
334  // print intro
335  unsigned int const NPrintedChannels = (PrintLast - PrintFirst) + 1;
336  if (NPrintedChannels == NChannels) {
337  mf::LogInfo(OutputCategory) << "Printing all " << NChannels << " channels";
338  }
339  else {
340  mf::LogInfo(OutputCategory) << "Printing channels from " << PrintFirst
341  << " to " << LastChannel << " (" << NPrintedChannels
342  << " channels out of " << NChannels << ")";
343  }
344 
345  // print map
346  mf::LogVerbatim log(OutputCategory);
347  for (raw::ChannelID_t channel = PrintFirst; channel <= PrintLast; ++channel) {
348  std::vector<geo::WireID> const Wires = pGeom->ChannelToWire(channel);
349 
350  log << "\n " << ((int) channel) << " ->";
351  switch (Wires.size()) {
352  case 0: log << " no wires"; break;
353  case 1: break;
354  default: log << " [" << Wires.size() << " wires]"; break;
355  } // switch
356 
357  for (geo::WireID const& wireID: Wires)
358  log << " { " << std::string(wireID) << " };";
359 
360  } // for (channels)
361 
362 } // DumpChannelToWires::Dump()
363 
364 //------------------------------------------------------------------------------
365 //--- DumpWireToChannel
366 //------------------------------------------------------------------------------
367 void DumpWireToChannel::CheckConfig() const {
368 
369  /// check that the configuration is complete
370  if (!pGeom) {
372  << "DumpWireToChannel: no valid geometry available!";
373  }
374 } // DumpWireToChannel::CheckConfig()
375 
376 //------------------------------------------------------------------------------
377 void DumpWireToChannel::Dump(std::string OutputCategory) const {
378 
379  /// check that the configuration is complete
380  CheckConfig();
381 
382  /// extract general channel range information
383  unsigned int const NChannels = pGeom->Nchannels();
384 
385  if (NChannels == 0) {
386  mf::LogError(OutputCategory)
387  << "Nice detector we have here, with no channels.";
388  return;
389  }
390 
391  // print intro
392  mf::LogInfo(OutputCategory)
393  << "Printing wire channels for up to " << NChannels << " channels";
394 
395  // print map
396  mf::LogVerbatim log(OutputCategory);
397  for (geo::WireID const& wireID: pGeom->IterateWireIDs()) {
398  raw::ChannelID_t channel = pGeom->PlaneWireToChannel(wireID);
399  log << "\n { " << std::string(wireID) << " } => ";
400  if (raw::isValidChannelID(channel)) log << channel;
401  else log << "invalid!";
402  } // for
403 
404 } // DumpWireToChannel::Dump()
405 
406 
407 //------------------------------------------------------------------------------
408 //--- DumpOpticalDetectorChannels
409 //------------------------------------------------------------------------------
410 void DumpOpticalDetectorChannels::CheckConfig() const {
411 
412  /// check that the configuration is complete
413  if (!pGeom) {
415  << "DumpOpticalDetectorChannels: no valid geometry available!";
416  }
417 } // DumpOpticalDetectorChannels::CheckConfig()
418 
419 
420 //------------------------------------------------------------------------------
421 geo::OpDetGeo const* DumpOpticalDetectorChannels::getOpticalDetector
422  (unsigned int channelID) const
423 {
424  try {
425  return &(pGeom->OpDetGeoFromOpChannel(channelID));
426  }
427  catch (cet::exception const&) {
428  return nullptr;
429  }
430 } // DumpOpticalDetectorChannels::getOpticalDetector()
431 
432 
433 //------------------------------------------------------------------------------
434 void DumpOpticalDetectorChannels::Dump(std::string OutputCategory) const {
435 
436  /// check that the configuration is complete
437  CheckConfig();
438 
439 
440  /// extract general channel range information
441  unsigned int const NChannels = pGeom->NOpChannels();
442 
443  if (NChannels == 0) {
444  mf::LogError(OutputCategory)
445  << "Nice detector we have here, with no optical channels.";
446  return;
447  }
448 
449  // print intro
450  mf::LogInfo(OutputCategory)
451  << "Printing optical detectors for up to " << NChannels << " channels";
452 
453  // print map
454  mf::LogVerbatim log(OutputCategory);
455  for (unsigned int channelID = 0; channelID < NChannels; ++channelID) {
456  log << "\nChannel " << channelID << " => ";
457  geo::OpDetGeo const* opDet = getOpticalDetector(channelID);
458  if (!opDet) {
459  log << "invalid";
460  continue;
461  }
462  log << opDet->ID() << " at " << opDet->GetCenter() << " cm";
463  } // for
464 
465 } // DumpOpticalDetectorChannels::Dump()
466 
467 
468 //==============================================================================
bool DoOpDetChannels
Dump optical detector channel -> optical detector.
std::string OutputCategory
Name of the category for output.
std::string string
Definition: nybbler.cc:12
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
ChannelGroupService::Name Name
fhicl::Atom< std::string > OutputCategory
void GetCenter(double *xyz, double localz=0.0) const
Definition: OpDetGeo.cxx:40
uint8_t channel
Definition: CRTFragment.hh:201
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
art framework interface to geometry description
Definition: Run.h:17
DumpChannelMap & operator=(DumpChannelMap const &)=delete
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
Definition: RawTypes.h:32
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
virtual void beginRun(art::Run const &) override
Drives the dumping.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:37
bool DoWireToChannel
Dump wire -> channel mapping.
Description of geometry of one entire detector.
bool DoChannelToWires
Dump channel -> wires mapping.
raw::ChannelID_t LastChannel
Last channel to be printed.
Encapsulate the geometry of an optical detector.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
virtual void analyze(art::Event const &) override
fhicl::Atom< raw::ChannelID_t > FirstChannel
#define Comment
fhicl::Atom< raw::ChannelID_t > LastChannel
Prints on screen the current channel-wire and optical detector maps.
Access the description of detector geometry.
geo::OpDetID const & ID() const
Returns the geometry ID of this optical detector.
Definition: OpDetGeo.h:72
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)
LArSoft geometry interface.
Definition: ChannelGeo.h:16
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33