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