LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
DumpGeometry_module.cc
Go to the documentation of this file.
1 
9 // LArSoft libraries
13 
14 // framework libraries
19 #include "fhiclcpp/types/Atom.h"
20 #include "fhiclcpp/types/Comment.h"
21 #include "fhiclcpp/types/Name.h"
23 
24 // C/C++ standard libraries
25 #include <string>
26 
27 namespace geo {
28  class DumpGeometry;
29 }
30 
45 
46 public:
47  struct Config {
48  using Name = fhicl::Name;
50 
52  Name("outputCategory"),
53  Comment(
54  "name of message facility output category to stream the information into (INFO level)"),
55  "DumpGeometry"};
56 
57  }; // struct Config
58 
60 
61  explicit DumpGeometry(Parameters const& config);
62 
63  // Plugins should not be copied or assigned.
64  DumpGeometry(DumpGeometry const&) = delete;
65  DumpGeometry(DumpGeometry&&) = delete;
66  DumpGeometry& operator=(DumpGeometry const&) = delete;
67  DumpGeometry& operator=(DumpGeometry&&) = delete;
68 
69  // Required functions
70  virtual void analyze(art::Event const&) override {}
71 
73  virtual void beginJob() override;
74 
76  virtual void beginRun(art::Run const& run) override;
77 
78 private:
79  std::string fOutputCategory;
80  std::string fLastDetectorName;
81 
83  template <typename Stream>
84  void dumpGeometryCore(Stream&& out, geo::GeometryCore const& geom) const;
85 
87  template <typename Stream>
88  void dump(Stream&& out, geo::GeometryCore const& geom);
89 
91  bool shouldDumpGeometry(geo::GeometryCore const& geom) const;
92 
93 }; // class geo::DumpGeometry
94 
95 //==============================================================================
96 //=== Module implementation
97 //===
98 
99 //------------------------------------------------------------------------------
101  : EDAnalyzer(config), fOutputCategory(config().outputCategory())
102 {}
103 
104 //------------------------------------------------------------------------------
106 {
107 
108  auto const& geom = *(lar::providerFrom<geo::Geometry>());
110 
111 } // geo::DumpGeometry::beginJob()
112 
113 //------------------------------------------------------------------------------
115 {
116 
117  auto const& geom = *(lar::providerFrom<geo::Geometry>());
118  if (shouldDumpGeometry(geom)) {
120  log << "\nGeometry used in " << run.id() << ":\n";
121  dump(log, geom);
122  }
123 
124 } // geo::DumpGeometry::beginRun()
125 
126 //------------------------------------------------------------------------------
127 template <typename Stream>
128 void geo::DumpGeometry::dumpGeometryCore(Stream&& out, geo::GeometryCore const& geom) const
129 {
130 
131  out << "Detector description: '" << geom.ROOTFile() << "'\n";
132  geom.Print(std::forward<Stream>(out));
133 
134 } // geo::DumpGeometry::dumpGeometryCore()
135 
136 //------------------------------------------------------------------------------
137 template <typename Stream>
138 void geo::DumpGeometry::dump(Stream&& out, geo::GeometryCore const& geom)
139 {
140 
142  dumpGeometryCore(std::forward<Stream>(out), geom);
143 
144 } // geo::DumpGeometry::dump()
145 
146 //------------------------------------------------------------------------------
148 {
149 
150  // only dump if not already dumped
151  return geom.DetectorName() != fLastDetectorName;
152 
153 } // geo::DumpGeometry::shouldDumpGeometry()
154 
155 //------------------------------------------------------------------------------
157 
158 //==============================================================================
Utilities related to art service access.
void dumpGeometryCore(Stream &&out, geo::GeometryCore const &geom) const
Dumps the specified geometry into the specified output stream.
RunID id() const
Definition: Run.cc:21
void Print(Stream &&out, std::string indent=" ") const
Prints geometry information with maximum verbosity.
DumpGeometry(Parameters const &config)
std::string fLastDetectorName
Name of the last geometry dumped.
std::string const & ROOTFile() const
Returns the full directory path to the geometry file source.
Definition: GeometryCore.h:184
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.cc:6
Describes on screen the current geometry.
Definition: Run.h:37
void dump(Stream &&out, geo::GeometryCore const &geom)
Dumps the geometry and records it.
Access the description of detector geometry.
virtual void beginRun(art::Run const &run) override
Dumps the geometry if changed from the previous run.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
DumpGeometry & operator=(DumpGeometry const &)=delete
Description of geometry of one entire detector.
Definition: GeometryCore.h:119
fhicl::Atom< std::string > outputCategory
std::string fOutputCategory
Name of the category for output.
virtual void beginJob() override
Dumps the geometry at once.
virtual void analyze(art::Event const &) override
bool shouldDumpGeometry(geo::GeometryCore const &geom) const
Returns whether the specified geometry should be dumped.
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
Definition: GeometryCore.h:203
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description