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
19 #include "fhiclcpp/types/Atom.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 
53  public:
54  // type to enable module parameters description by art
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;
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 //------------------------------------------------------------------------------
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
137  log << "[#" << (iSimChannel++) << "] ";
138  DumpSimChannel(log, simChannel, " ", false);
139 
140  } // for
142 
143 } // sim::DumpSimChannels::analyze()
144 
145 
146 //------------------------------------------------------------------------------
148 
149 //------------------------------------------------------------------------------
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
Energy deposited on a readout channel by simulated tracks.
Definition: SimChannel.h:140
std::string string
Definition: nybbler.cc:12
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:337
ChannelGroupService::Name Name
DumpSimChannels & operator=(DumpSimChannels const &)=delete
uint8_t channel
Definition: CRTFragment.hh:201
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
std::string encode() const
Definition: InputTag.cc:97
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
Code to link reconstructed objects back to the MC truth information.
#define Comment
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.
DumpSimChannels(Parameters const &config)
Configuration-checking constructor.
void analyze(art::Event const &event) override
Event finding and building.