LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DumpChannelMap_module.cc
Go to the documentation of this file.
1 
9 // LArSoft libraries
10 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
11 
12 // framework libraries
13 #include "fhiclcpp/ParameterSet.h"
16 
17 // C/C++ standard libraries
18 #include <string>
19 
20 // ... more follow
21 
22 namespace geo {
23  class DumpChannelMap;
24 }
25 
50 public:
51  explicit DumpChannelMap(fhicl::ParameterSet const & p);
52 
53  // Plugins should not be copied or assigned.
54  DumpChannelMap(DumpChannelMap const &) = delete;
55  DumpChannelMap(DumpChannelMap &&) = delete;
56  DumpChannelMap & operator = (DumpChannelMap const &) = delete;
58 
59  // Required functions
60  virtual void analyze(art::Event const&) override {}
61 
63  virtual void beginRun(art::Run const&) override;
64 
65  private:
66 
67  std::string OutputCategory;
70 
73 
74 }; // geo::DumpChannelMap
75 
76 
77 //==============================================================================
78 //=== Algorithms declaration
79 //===
80 
81 // LArSoft libraries
82 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
83 
84 // C/C++ standard libraries
85 #include <string>
86 
87 // ... and more below...
88 
89 namespace geo {
90  class GeometryCore;
91 } // namespace geo
92 
93 namespace {
94 
96  class DumpChannelToWires {
97  public:
98 
100  DumpChannelToWires()
103  {}
104 
106  void Setup(geo::GeometryCore const& geometry)
107  { pGeom = &geometry; }
108 
110  void SetLimits
111  (raw::ChannelID_t first_channel, raw::ChannelID_t last_channel)
112  { FirstChannel = first_channel; LastChannel = last_channel; }
113 
115  void Dump(std::string OutputCategory) const;
116 
117 
118  protected:
119  geo::GeometryCore const* pGeom = nullptr;
120 
123 
125  void CheckConfig() const;
126 
127  }; // class DumpChannelToWires
128 
129 
131  class DumpWireToChannel {
132  public:
133 
135  DumpWireToChannel() {}
136 
138  void Setup(geo::GeometryCore const& geometry)
139  { pGeom = &geometry; }
140 
142  void Dump(std::string OutputCategory) const;
143 
144 
145  protected:
146  geo::GeometryCore const* pGeom = nullptr;
147 
149  void CheckConfig() const;
150 
151  }; // class DumpWireToChannel
152 
153 
154 } // local namespace
155 
156 
157 //==============================================================================
158 //=== Module implementation
159 //===
160 
161 // LArSoft libraries
162 #include "larcoreobj/SimpleTypesAndConstants/RawTypes.h" // raw::ChannelID_t
165 
166 // framework libraries
169 
170 // C/C++ standard libraries
171 #include <string>
172 
173 // ... and more below ...
174 
175 //------------------------------------------------------------------------------
177  : EDAnalyzer(p)
178  , OutputCategory(p.get<std::string> ("OutputCategory", "DumpChannelMap"))
179  , DoChannelToWires(p.get<bool> ("ChannelToWires", true))
180  , DoWireToChannel(p.get<bool> ("WireToChannel", false))
181  , FirstChannel(p.get<raw::ChannelID_t>("FirstChannel", raw::InvalidChannelID))
182  , LastChannel(p.get<raw::ChannelID_t> ("LastChannel", raw::InvalidChannelID))
183 {
184 
185 } // geo::DumpChannelMap::DumpChannelMap()
186 
187 //------------------------------------------------------------------------------
189 
191 
192  if (DoChannelToWires) {
193  DumpChannelToWires dumper;
194  dumper.Setup(geom);
195  dumper.SetLimits(FirstChannel, LastChannel);
196  dumper.Dump(OutputCategory);
197  }
198 
199  if (DoWireToChannel) {
200  DumpWireToChannel dumper;
201  dumper.Setup(geom);
202  // dumper.SetLimits(FirstChannel, LastChannel);
203  dumper.Dump(OutputCategory);
204  }
205 
206 } // geo::DumpChannelMap::beginRun()
207 
208 //------------------------------------------------------------------------------
210 
211 //==============================================================================
212 //=== Algorithm implementation
213 //===
214 
215 // LArSoft libraries
216 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::WireID
218 
219 // framework libraries
222 
223 // C/C++ standard libraries
224 #include <vector>
225 
226 //------------------------------------------------------------------------------
227 //--- DumpChannelToWires
228 //------------------------------------------------------------------------------
229 void DumpChannelToWires::CheckConfig() const {
230 
232  if (!pGeom) {
234  << "DumpChannelToWires: no valid geometry available!";
235  }
236 } // DumpChannelToWires::CheckConfig()
237 
238 //------------------------------------------------------------------------------
239 void DumpChannelToWires::Dump(std::string OutputCategory) const {
240 
242  CheckConfig();
243 
245  unsigned int const NChannels = pGeom->Nchannels();
246 
247  if (NChannels == 0) {
248  mf::LogError(OutputCategory)
249  << "Nice detector we have here, with no channels.";
250  return;
251  }
252 
253  raw::ChannelID_t const PrintFirst
255  raw::ChannelID_t const PrintLast
257 
258  // print intro
259  unsigned int const NPrintedChannels = (PrintLast - PrintFirst) + 1;
260  if (NPrintedChannels == NChannels) {
261  mf::LogInfo(OutputCategory) << "Printing all " << NChannels << " channels";
262  }
263  else {
264  mf::LogInfo(OutputCategory) << "Printing channels from " << PrintFirst
265  << " to " << LastChannel << " (" << NPrintedChannels
266  << " channels out of " << NChannels << ")";
267  }
268 
269  // print map
270  mf::LogVerbatim log(OutputCategory);
271  for (raw::ChannelID_t channel = PrintFirst; channel <= PrintLast; ++channel) {
272  std::vector<geo::WireID> const Wires = pGeom->ChannelToWire(channel);
273 
274  log << "\n " << ((int) channel) << " ->";
275  switch (Wires.size()) {
276  case 0: log << " no wires"; break;
277  case 1: break;
278  default: log << " [" << Wires.size() << " wires]"; break;
279  } // switch
280 
281  for (geo::WireID const& wireID: Wires)
282  log << " { " << std::string(wireID) << " };";
283 
284  } // for (channels)
285 
286 } // DumpChannelToWires::Dump()
287 
288 //------------------------------------------------------------------------------
289 //--- DumpWireToChannel
290 //------------------------------------------------------------------------------
291 void DumpWireToChannel::CheckConfig() const {
292 
294  if (!pGeom) {
296  << "DumpWireToChannel: no valid geometry available!";
297  }
298 } // DumpWireToChannel::CheckConfig()
299 
300 //------------------------------------------------------------------------------
301 void DumpWireToChannel::Dump(std::string OutputCategory) const {
302 
304  CheckConfig();
305 
307  unsigned int const NChannels = pGeom->Nchannels();
308 
309  if (NChannels == 0) {
310  mf::LogError(OutputCategory)
311  << "Nice detector we have here, with no channels.";
312  return;
313  }
314 
315  // print intro
316  mf::LogInfo(OutputCategory)
317  << "Printing wire channels for up to " << NChannels << " channels";
318 
319  // print map
320  mf::LogVerbatim log(OutputCategory);
321  for (geo::WireID const& wireID: pGeom->IterateWireIDs()) {
322  raw::ChannelID_t channel = pGeom->PlaneWireToChannel(wireID);
323  log << "\n { " << std::string(wireID) << " } => ";
324  if (raw::isValidChannelID(channel)) log << channel;
325  else log << "invalid!";
326  } // for
327 
328 } // DumpWireToChannel::Dump()
329 
330 
331 //==============================================================================
std::string OutputCategory
name of the category for output
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
STL namespace.
Raw data description.
Definition: RawTypes.h:6
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Definition: Run.h:30
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:42
virtual void beginRun(art::Run const &) override
Drives the dumping.
constexpr bool isValidChannelID(raw::ChannelID_t channel)
Definition: RawTypes.h:36
bool DoWireToChannel
dump wire -> channel mapping
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Description of geometry of one entire detector.
bool DoChannelToWires
dump channel -> wires mapping
raw::ChannelID_t LastChannel
last channel to be printed
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
virtual void analyze(art::Event const &) override
Prints on screen the current channel-wire map.
raw::ChannelID_t FirstChannel
first channel to be printed
unsigned int ChannelID_t
Type representing the ID of a readout channel.
Definition: RawTypes.h:27
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description
DumpChannelMap(fhicl::ParameterSet const &p)