All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DumpOpDetBacktrackerRecords_module.cc
Go to the documentation of this file.
1 /**
2  * @file DumpOpDetBacktrackerRecords_module.cc
3  * @brief Module dumping OpDetBacktrackerRecords information on screen
4  * @date August 8, 2016
5  * @author Lucas Mendes Santos (lmendes@ifi.unicamp.br)
6  *
7  */
8 
9 
10 // lardataobj libraries
12 
13 // framework libraries
14 #include "art/Framework/Core/EDAnalyzer.h"
15 #include "art/Framework/Core/ModuleMacros.h"
16 #include "art/Framework/Principal/Event.h"
17 #include "art/Framework/Principal/Handle.h"
18 #include "canvas/Utilities/InputTag.h"
19 
20 #include "fhiclcpp/types/Atom.h"
21 #include "messagefacility/MessageLogger/MessageLogger.h"
22 
23 
24 namespace sim {
25  class DumpOpDetBacktrackerRecords;
26 } // namespace sim
27 
28 namespace {
29  using namespace fhicl;
30 
31  /// Collection of configuration parameters for the module
32  struct Config {
33  using Name = fhicl::Name;
34  using Comment = fhicl::Comment;
35 
36  fhicl::Atom<art::InputTag> InputOpDetBacktrackerRecord {
37  Name("InputOpDetBacktrackerRecord"),
38  Comment("data product with the OpDetBacktrackerRecord to be dumped")
39  };
40 
41  fhicl::Atom<std::string> OutputCategory {
42  Name("OutputCategory"),
43  Comment("name of the output stream (managed by the message facility)"),
44  "DumpOpDetBacktrackerRecords" /* default value */
45  };
46 
47  }; // struct Config
48 
49 
50 } // local namespace
51 
52 
53 class sim::DumpOpDetBacktrackerRecords: public art::EDAnalyzer {
54  public:
55  // type to enable module parameters description by art
56  using Parameters = art::EDAnalyzer::Table<Config>;
57 
58  /// Configuration-checking constructor
59  explicit DumpOpDetBacktrackerRecords(Parameters const& config);
60 
61  // Plugins should not be copied or assigned.
64  DumpOpDetBacktrackerRecords& operator = (DumpOpDetBacktrackerRecords const&) = delete;
66 
67 
68  // Operates on the event
69  void analyze(art::Event const& event) override;
70 
71 
72  /**
73  * @brief Dumps the content of the specified OpDetBacktrackerRecord in the output stream
74  * @tparam Stream the type of output stream
75  * @param out the output stream
76  * @param simchannel the OpDetBacktrackerRecord to be dumped
77  * @param indent base indentation string (default: none)
78  * @param bIndentFirst if first output line should be indented (default: yes)
79  *
80  * The indent string is prepended to every line of output, with the possible
81  * exception of the first one, in case bIndentFirst is true.
82  *
83  * The output starts on the current line, and the last line is NOT broken.
84  */
85  template <typename Stream>
86  void DumpOpDetBacktrackerRecord(
87  Stream&& out, sim::OpDetBacktrackerRecord const& simchannel,
88  std::string indent = "", bool bIndentFirst = true
89  ) const;
90 
91 
92  private:
93 
94  art::InputTag fInputChannels; ///< name of OpDetBacktrackerRecord's data product
95  std::string fOutputCategory; ///< name of the stream for output
96 
97 }; // class sim::DumpOpDetBacktrackerRecords
98 
99 
100 //------------------------------------------------------------------------------
101 //--- module implementation
102 //---
103 //------------------------------------------------------------------------------
105  : EDAnalyzer(config)
106  , fInputChannels(config().InputOpDetBacktrackerRecord())
107  , fOutputCategory(config().OutputCategory())
108 {}
109 
110 
111 //------------------------------------------------------------------------------
112 template <typename Stream>
114  Stream&& out, sim::OpDetBacktrackerRecord const& channel,
115  std::string indent /* = "" */, bool bIndentFirst /* = true */
116 ) const {
117  if (bIndentFirst) out << indent;
118  channel.Dump(out, indent);
119 } // sim::DumpOpDetBacktrackerRecords::DumpOpDetBacktrackerRecords()
120 
121 
122 //------------------------------------------------------------------------------
123 void sim::DumpOpDetBacktrackerRecords::analyze(art::Event const& event) {
124 
125  // get the particles from the event
126  auto const& OpDetBacktrackerRecord
127  = *(event.getValidHandle<std::vector<sim::OpDetBacktrackerRecord>>(fInputChannels));
128 
129  mf::LogVerbatim(fOutputCategory) << "Event " << event.id()
130  << " : data product '" << fInputChannels.encode() << "' contains "
131  << OpDetBacktrackerRecord.size() << " OpDetBacktrackerRecord";
132 
133  unsigned int iOpDetBacktrackerRecord = 0;
134  for (sim::OpDetBacktrackerRecord const& simChannel: OpDetBacktrackerRecord) {
135 
136  // a bit of a header
137  mf::LogVerbatim log(fOutputCategory);
138  log << "[#" << (iOpDetBacktrackerRecord++) << "] ";
139  DumpOpDetBacktrackerRecord(log, simChannel, " ", false);
140 
141  } // for
142  mf::LogVerbatim(fOutputCategory) << "\n";
143 
144 } // sim::DumpOpDetBacktrackerRecords::analyze()
145 
146 
147 //------------------------------------------------------------------------------
148 DEFINE_ART_MODULE(sim::DumpOpDetBacktrackerRecords)
149 
150 //------------------------------------------------------------------------------
process_name opflashCryo1 flashfilter analyze
DumpOpDetBacktrackerRecords(Parameters const &config)
Configuration-checking constructor.
art::InputTag fInputChannels
name of OpDetBacktrackerRecord&#39;s data product
Energy deposited on a readout Optical Detector by simulated tracks.
void Dump(Stream &&out, std::string indent, std::string first_indent) const
Dumps the full content of the OpDetBacktrackerRecord into a stream.
BEGIN_PROLOG vertical distance to the surface Name
void analyze(art::Event const &event) override
void DumpOpDetBacktrackerRecord(Stream &&out, sim::OpDetBacktrackerRecord const &simchannel, std::string indent="", bool bIndentFirst=true) const
Dumps the content of the specified OpDetBacktrackerRecord in the output stream.
bnb BNB Stream
std::string fOutputCategory
name of the stream for output