LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
DumpGeometry_module.cc
Go to the documentation of this file.
1 
9 // framework libraries
13 #include "fhiclcpp/types/Atom.h"
14 #include "fhiclcpp/types/Comment.h"
15 #include "fhiclcpp/types/Name.h"
16 
17 // C/C++ standard libraries
18 #include <string>
19 
20 // ... more follow
21 
22 namespace geo {
23  class GeometryCore;
24  class DumpGeometry;
25 }
26 
41 
42  public:
43  struct Config {
44  using Name = fhicl::Name;
46 
48  Name("outputCategory"),
49  Comment
50  ("name of message facility output category to stream the information into (INFO level)"),
51  "DumpGeometry"
52  };
53 
54  }; // struct Config
55 
57 
58  explicit DumpGeometry(Parameters const& config);
59 
60  // Plugins should not be copied or assigned.
61  DumpGeometry(DumpGeometry const&) = delete;
62  DumpGeometry(DumpGeometry &&) = delete;
63  DumpGeometry& operator = (DumpGeometry const&) = delete;
65 
66  // Required functions
67  virtual void analyze(art::Event const&) override {}
68 
70  virtual void beginJob() override;
71 
73  virtual void beginRun(art::Run const& run) override;
74 
75  private:
76 
77  std::string fOutputCategory;
78  std::string fLastDetectorName;
79 
81  template <typename Stream>
82  void dumpGeometryCore(Stream&& out, geo::GeometryCore const& geom) const;
83 
85  template <typename Stream>
86  void dump(Stream&& out, geo::GeometryCore const& geom);
87 
89  bool shouldDumpGeometry(geo::GeometryCore const& geom) const;
90 
91 }; // class geo::DumpGeometry
92 
93 
94 //==============================================================================
95 //=== Module implementation
96 //===
97 
98 // LArSoft libraries
101 
102 // framework libraries
105 
106 
107 //------------------------------------------------------------------------------
109  : EDAnalyzer(config)
110  , fOutputCategory(config().outputCategory())
111  {}
112 
113 
114 //------------------------------------------------------------------------------
116 
117  auto const& geom = *(lar::providerFrom<geo::Geometry>());
119 
120 } // geo::DumpGeometry::beginJob()
121 
122 
123 //------------------------------------------------------------------------------
125 
126  auto const& geom = *(lar::providerFrom<geo::Geometry>());
127  if (shouldDumpGeometry(geom)) {
129  log << "\nGeometry used in " << run.id() << ":\n";
130  dump(log, geom);
131  }
132 
133 } // geo::DumpGeometry::beginRun()
134 
135 
136 //------------------------------------------------------------------------------
137 template <typename Stream>
139  (Stream&& out, geo::GeometryCore const& geom) const
140 {
141 
142  out << "Detector description: '" << geom.ROOTFile() << "'\n";
143  geom.Print(std::forward<Stream>(out));
144 
145 } // geo::DumpGeometry::dumpGeometryCore()
146 
147 
148 //------------------------------------------------------------------------------
149 template <typename Stream>
150 void geo::DumpGeometry::dump(Stream&& out, geo::GeometryCore const& geom) {
151 
153  dumpGeometryCore(std::forward<Stream>(out), geom);
154 
155 } // geo::DumpGeometry::dump()
156 
157 
158 //------------------------------------------------------------------------------
160 {
161 
162  // only dump if not already dumped
163  return geom.DetectorName() != fLastDetectorName;
164 
165 } // geo::DumpGeometry::shouldDumpGeometry()
166 
167 
168 //------------------------------------------------------------------------------
170 
171 //==============================================================================
172 
void dumpGeometryCore(Stream &&out, geo::GeometryCore const &geom) const
Dumps the specified geometry into the specified output stream.
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.
Describes on screen the current geometry.
std::string ROOTFile() const
Returns the full directory path to the geometry file source.
Definition: Run.h:30
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:42
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
DumpGeometry & operator=(DumpGeometry const &)=delete
RunID const & id() const
Definition: Run.h:41
EDAnalyzer(Table< Config > const &config)
Definition: EDAnalyzer.h:100
Description of geometry of one entire detector.
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.
Namespace collecting geometry-related classes utilities.
art framework interface to geometry description