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