All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DumpPMTconfiguration_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpPMTconfiguration_module.cc
3  * @brief Dumps on console the content of `sbn::PMTconfiguration` data product.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date March 17, 2021
6  */
7 
8 // SBN libraries
10 
11 // framework libraries
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "art/Framework/Core/EDAnalyzer.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "canvas/Persistency/Provenance/RunID.h"
16 #include "canvas/Utilities/InputTag.h"
17 #include "messagefacility/MessageLogger/MessageLogger.h"
18 #include "fhiclcpp/types/Atom.h"
19 
20 // C/C++ standard libraries
21 #include <set>
22 #include <string>
23 #include <sstream> // std::ostringstream
24 
25 
26 //------------------------------------------------------------------------------
27 namespace sbn { class DumpPMTconfiguration; }
28 
29 /**
30  * @brief Dumps on console the content of `sbn::PMTconfiguration` data product.
31  *
32  *
33  *
34  * Input data products
35  * ====================
36  *
37  * * `sbn::PMTconfiguration`: configuration of PMT in `art::Run` data product.
38  * See e.g. `icarus::PMTconfigurationExtraction` module.
39  *
40  *
41  *
42  * Configuration parameters
43  * =========================
44  *
45  * A terse description of the parameters is printed by running
46  * `lar --print-description DumpPMTconfiguration`.
47  *
48  * * `PMTconfigurationTag` (data product input tag): the tag identifying the
49  * data product to dump; this data product must be in `art::Run`.
50  * * `Verbosity` (integral, default: maximum): verbosity level used in the
51  * dump; see `sbn::PMTconfiguration::dump()` for details.
52  * * `SkipDuplicateRuns` (flag, default: `true`): multiple files can contain
53  * information from the same run; with this flag set, only the first time
54  * a run is encountered its PMT configuration is dumped; otherwise, each
55  * time a run is opened by _art_, its configuration is printed.
56  * * `OutputCategory` (string, default: `DumpPMTconfiguration`): name of the
57  * message facility output stream to dump the information into
58  *
59  */
60 class sbn::DumpPMTconfiguration: public art::EDAnalyzer {
61 
62  public:
63 
64  // --- BEGIN Configuration ---------------------------------------------------
65  struct Config {
66 
67  using Name = fhicl::Name;
68  using Comment = fhicl::Comment;
69 
70  fhicl::Atom<art::InputTag> PMTconfigurationTag {
71  Name("PMTconfigurationTag"),
72  Comment("tag of PMT configuration data product (from art::Run)")
73  };
74 
75  fhicl::Atom<unsigned int> Verbosity {
76  Name("Verbosity"),
77  Comment("verbosity level [default: maximum]"),
79  };
80 
81  fhicl::Atom<bool> SkipDuplicateRuns {
82  Name("SkipDuplicateRuns"),
83  Comment("print only one PMT configuration from each run"),
84  true // default
85  };
86 
87  fhicl::Atom<std::string> OutputCategory {
88  Name("OutputCategory"),
89  Comment("name of the category used for the output"),
90  "DumpPMTconfiguration"
91  };
92 
93  }; // struct Config
94 
95  using Parameters = art::EDAnalyzer::Table<Config>;
96  // --- END Configuration -----------------------------------------------------
97 
98 
99  // --- BEGIN Constructors ----------------------------------------------------
100  explicit DumpPMTconfiguration(Parameters const& config);
101 
102  // --- END Constructors ------------------------------------------------------
103 
104 
105  // --- BEGIN Framework hooks -------------------------------------------------
106 
107  /// Dumps the data product.
108  virtual void beginRun(art::Run const& run) override;
109 
110  /// Does nothing, but it is mandatory.
111  virtual void analyze(art::Event const& event) override {}
112 
113  // --- END Framework hooks ---------------------------------------------------
114 
115 
116  private:
117 
118  // --- BEGIN Configuration variables -----------------------------------------
119 
120  art::InputTag const fPMTconfigurationTag; ///< Input PMT configuration tag.
121 
122  unsigned int const fVerbosity; ///< Verbosity level used for dumping.
123 
124  bool const fSkipDuplicateRuns; ///< Print only once from each run.
125 
126  /// Category used for message facility stream.
127  std::string const fOutputCategory;
128 
129  // --- END Configuration variables -------------------------------------------
130 
131 
132  std::set<art::RunID> fRuns; ///< Set of runs already encountered.
133 
134 }; // sbn::DumpPMTconfiguration
135 
136 
137 //------------------------------------------------------------------------------
138 //--- Implementation
139 //------------------------------------------------------------------------------
140 //--- sbn::DumpPMTconfiguration
141 //------------------------------------------------------------------------------
143  (Parameters const& config)
144  : art::EDAnalyzer(config)
145  // configuration
146  , fPMTconfigurationTag(config().PMTconfigurationTag())
147  , fVerbosity (config().Verbosity())
148  , fSkipDuplicateRuns (config().SkipDuplicateRuns())
149  , fOutputCategory (config().OutputCategory())
150 {
151 
152  consumes<sbn::PMTconfiguration, art::InRun>(fPMTconfigurationTag);
153 
154 } // sbn::DumpPMTconfiguration::DumpPMTconfiguration()
155 
156 
157 //------------------------------------------------------------------------------
158 void sbn::DumpPMTconfiguration::beginRun(art::Run const& run) {
159 
160  if (fSkipDuplicateRuns) {
161  art::RunID const& id = run.id();
162  if (fRuns.count(id)) {
163  mf::LogTrace(fOutputCategory) << id << " has already been encountered.";
164  return;
165  }
166  fRuns.insert(id);
167  } // if skip duplicates
168 
169  auto const& config
170  = run.getProduct<sbn::PMTconfiguration>(fPMTconfigurationTag);
171 
172  std::ostringstream sstr;
173  config.dump(sstr, " ", "", fVerbosity);
174 
175  mf::LogVerbatim(fOutputCategory) << run.id() << ": " << sstr.str();
176 
177 
178 } // sbn::DumpPMTconfiguration::beginRun()
179 
180 
181 //------------------------------------------------------------------------------
182 DEFINE_ART_MODULE(sbn::DumpPMTconfiguration)
183 
184 
185 //------------------------------------------------------------------------------
Dumps on console the content of sbn::PMTconfiguration data product.
std::string const fOutputCategory
Category used for message facility stream.
bool const fSkipDuplicateRuns
Print only once from each run.
art::InputTag const fPMTconfigurationTag
Input PMT configuration tag.
fhicl::Atom< art::InputTag > PMTconfigurationTag
static constexpr unsigned int MaxDumpVerbosity
Maximum supported verbosity level supported by dump().
DumpPMTconfiguration(Parameters const &config)
void dump(std::ostream &out, std::string const &indent, std::string const &firstIndent, unsigned int verbosity=MaxDumpVerbosity) const
Dumps the content of the configuration into out stream.
art::EDAnalyzer::Table< Config > Parameters
BEGIN_PROLOG vertical distance to the surface Name
Information from the configuration of PMT readout.
unsigned int const fVerbosity
Verbosity level used for dumping.
virtual void analyze(art::Event const &event) override
Does nothing, but it is mandatory.
std::set< art::RunID > fRuns
Set of runs already encountered.
Class containing configuration for PMT readout.
virtual void beginRun(art::Run const &run) override
Dumps the data product.