All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // LArSoft libraries
13 
14 // framework libraries
15 #include "art/Framework/Core/EDAnalyzer.h"
16 #include "art/Framework/Core/ModuleMacros.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
19 #include "canvas/Persistency/Provenance/RunID.h"
20 #include "fhiclcpp/types/Atom.h"
21 #include "fhiclcpp/types/Comment.h"
22 #include "fhiclcpp/types/Name.h"
23 
24 // C/C++ standard libraries
25 #include <string>
26 
27 namespace geo {
28  class DumpGeometry;
29 }
30 
31 /** ****************************************************************************
32  * @brief Describes on screen the current geometry.
33  *
34  * One print is performed at the beginning of each run.
35  *
36  *
37  * Configuration parameters
38  * =========================
39  *
40  * - *OutputCategory* (string, default: DumpGeometry): output category used
41  * by the message facility to output information (INFO level)
42  *
43  */
44 class geo::DumpGeometry: public art::EDAnalyzer {
45 
46  public:
47  struct Config {
48  using Name = fhicl::Name;
49  using Comment = fhicl::Comment;
50 
51  fhicl::Atom<std::string> outputCategory {
52  Name("outputCategory"),
53  Comment
54  ("name of message facility output category to stream the information into (INFO level)"),
55  "DumpGeometry"
56  };
57 
58  }; // struct Config
59 
60  using Parameters = art::EDAnalyzer::Table<Config>;
61 
62  explicit DumpGeometry(Parameters const& config);
63 
64  // Plugins should not be copied or assigned.
65  DumpGeometry(DumpGeometry const&) = delete;
66  DumpGeometry(DumpGeometry &&) = delete;
67  DumpGeometry& operator = (DumpGeometry const&) = delete;
69 
70  // Required functions
71  virtual void analyze(art::Event const&) override {}
72 
73  /// Dumps the geometry at once.
74  virtual void beginJob() override;
75 
76  /// Dumps the geometry if changed from the previous run.
77  virtual void beginRun(art::Run const& run) override;
78 
79  private:
80 
81  std::string fOutputCategory; ///< Name of the category for output.
82  std::string fLastDetectorName; ///< Name of the last geometry dumped.
83 
84  /// Dumps the specified geometry into the specified output stream.
85  template <typename Stream>
86  void dumpGeometryCore(Stream&& out, geo::GeometryCore const& geom) const;
87 
88  /// Dumps the geometry and records it.
89  template <typename Stream>
90  void dump(Stream&& out, geo::GeometryCore const& geom);
91 
92  /// Returns whether the specified geometry should be dumped.
93  bool shouldDumpGeometry(geo::GeometryCore const& geom) const;
94 
95 }; // class geo::DumpGeometry
96 
97 
98 //==============================================================================
99 //=== Module implementation
100 //===
101 
102 //------------------------------------------------------------------------------
104  : EDAnalyzer(config)
105  , fOutputCategory(config().outputCategory())
106  {}
107 
108 
109 //------------------------------------------------------------------------------
111 
112  auto const& geom = *(lar::providerFrom<geo::Geometry>());
113  dump(mf::LogVerbatim(fOutputCategory), geom);
114 
115 } // geo::DumpGeometry::beginJob()
116 
117 
118 //------------------------------------------------------------------------------
119 void geo::DumpGeometry::beginRun(art::Run const& run) {
120 
121  auto const& geom = *(lar::providerFrom<geo::Geometry>());
122  if (shouldDumpGeometry(geom)) {
123  mf::LogVerbatim log(fOutputCategory);
124  log << "\nGeometry used in " << run.id() << ":\n";
125  dump(log, geom);
126  }
127 
128 } // geo::DumpGeometry::beginRun()
129 
130 
131 //------------------------------------------------------------------------------
132 template <typename Stream>
134  (Stream&& out, geo::GeometryCore const& geom) const
135 {
136 
137  out << "Detector description: '" << geom.ROOTFile() << "'\n";
138  geom.Print(std::forward<Stream>(out));
139 
140 } // geo::DumpGeometry::dumpGeometryCore()
141 
142 
143 //------------------------------------------------------------------------------
144 template <typename Stream>
146 
147  fLastDetectorName = geom.DetectorName();
148  dumpGeometryCore(std::forward<Stream>(out), geom);
149 
150 } // geo::DumpGeometry::dump()
151 
152 
153 //------------------------------------------------------------------------------
155 {
156 
157  // only dump if not already dumped
158  return geom.DetectorName() != fLastDetectorName;
159 
160 } // geo::DumpGeometry::shouldDumpGeometry()
161 
162 
163 //------------------------------------------------------------------------------
164 DEFINE_ART_MODULE(geo::DumpGeometry)
165 
166 //==============================================================================
Utilities related to art service access.
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.
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.
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
DumpGeometry & operator=(DumpGeometry const &)=delete
BEGIN_PROLOG vertical distance to the surface Name
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.
art::EDAnalyzer::Table< Config > Parameters
art framework interface to geometry description
bnb BNB Stream