DumpGeometry_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpGeometry_module.cc
3  * @brief Prints on screen the current geometry.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date May 30, 2018
6  *
7  */
8 
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 namespace geo {
21  class DumpGeometry;
22  class GeometryCore;
23 }
24 
25 /** ****************************************************************************
26  * @brief Describes on screen the current geometry.
27  *
28  * One print is performed at the beginning of each run.
29  *
30  *
31  * Configuration parameters
32  * =========================
33  *
34  * - *OutputCategory* (string, default: DumpGeometry): output category used
35  * by the message facility to output information (INFO level)
36  *
37  */
39 
40  public:
41  struct Config {
42  using Name = fhicl::Name;
44 
46  Name("outputCategory"),
47  Comment
48  ("name of message facility output category to stream the information into (INFO level)"),
49  "DumpGeometry"
50  };
51 
52  }; // struct Config
53 
55 
56  explicit DumpGeometry(Parameters const& config);
57 
58  // Plugins should not be copied or assigned.
59  DumpGeometry(DumpGeometry const&) = delete;
60  DumpGeometry(DumpGeometry &&) = delete;
61  DumpGeometry& operator = (DumpGeometry const&) = delete;
63 
64  // Required functions
65  virtual void analyze(art::Event const&) override {}
66 
67  /// Dumps the geometry at once.
68  virtual void beginJob() override;
69 
70  /// Dumps the geometry if changed from the previous run.
71  virtual void beginRun(art::Run const& run) override;
72 
73  private:
74 
75  std::string fOutputCategory; ///< Name of the category for output.
76  std::string fLastDetectorName; ///< Name of the last geometry dumped.
77 
78  /// Dumps the specified geometry into the specified output stream.
79  template <typename Stream>
80  void dumpGeometryCore(Stream&& out, geo::GeometryCore const& geom) const;
81 
82  /// Dumps the geometry and records it.
83  template <typename Stream>
84  void dump(Stream&& out, geo::GeometryCore const& geom);
85 
86  /// Returns whether the specified geometry should be dumped.
87  bool shouldDumpGeometry(geo::GeometryCore const& geom) const;
88 
89 }; // class geo::DumpGeometry
90 
91 
92 //==============================================================================
93 //=== Module implementation
94 //===
95 
96 // LArSoft libraries
99 
100 // framework libraries
102 
103 //------------------------------------------------------------------------------
105  : EDAnalyzer(config)
106  , fOutputCategory(config().outputCategory())
107  {}
108 
109 
110 //------------------------------------------------------------------------------
112 
113  auto const& geom = *(lar::providerFrom<geo::Geometry>());
115 
116 } // geo::DumpGeometry::beginJob()
117 
118 
119 //------------------------------------------------------------------------------
121 
122  auto const& geom = *(lar::providerFrom<geo::Geometry>());
123  if (shouldDumpGeometry(geom)) {
125  log << "\nGeometry used in " << run.id() << ":\n";
126  dump(log, geom);
127  }
128 
129 } // geo::DumpGeometry::beginRun()
130 
131 
132 //------------------------------------------------------------------------------
133 template <typename Stream>
135  (Stream&& out, geo::GeometryCore const& geom) const
136 {
137 
138  out << "Detector description: '" << geom.ROOTFile() << "'\n";
139  geom.Print(std::forward<Stream>(out));
140 
141 } // geo::DumpGeometry::dumpGeometryCore()
142 
143 
144 //------------------------------------------------------------------------------
145 template <typename Stream>
146 void geo::DumpGeometry::dump(Stream&& out, geo::GeometryCore const& geom) {
147 
149  dumpGeometryCore(std::forward<Stream>(out), geom);
150 
151 } // geo::DumpGeometry::dump()
152 
153 
154 //------------------------------------------------------------------------------
156 {
157 
158  // only dump if not already dumped
159  return geom.DetectorName() != fLastDetectorName;
160 
161 } // geo::DumpGeometry::shouldDumpGeometry()
162 
163 
164 //------------------------------------------------------------------------------
166 
167 //==============================================================================
void dumpGeometryCore(Stream &&out, geo::GeometryCore const &geom) const
Dumps the specified geometry into the specified output stream.
RunID id() const
Definition: Run.cc:17
void Print(Stream &&out, std::string indent=" ") const
Prints geometry information with maximum verbosity.
std::string string
Definition: nybbler.cc:12
DumpGeometry(Parameters const &config)
ChannelGroupService::Name Name
std::string fLastDetectorName
Name of the last geometry dumped.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
Describes on screen the current geometry.
art framework interface to geometry description
std::string ROOTFile() const
Returns the full directory path to the geometry file source.
Definition: Run.h:17
void dump(Stream &&out, geo::GeometryCore const &geom)
Dumps the geometry and records it.
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:67
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
static Config * config
Definition: config.cpp:1054
DumpGeometry & operator=(DumpGeometry const &)=delete
Description of geometry of one entire detector.
fhicl::Atom< std::string > outputCategory
#define Comment
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.
Access the description of detector geometry.
LArSoft geometry interface.
Definition: ChannelGeo.h:16