artdaq_demo  v3_11_02
EventReporterOutput_module.cc
1 #define TRACE_NAME "EventReporterOutput"
2 
3 #include "art/Framework/Core/ModuleMacros.h"
4 #include "art/Framework/Core/OutputModule.h"
5 #include "art/Framework/Principal/EventPrincipal.h"
6 #include "art/Framework/Principal/OutputHandle.h"
7 #include "art/Framework/Principal/RunPrincipal.h"
8 #include "art/Framework/Principal/SubRunPrincipal.h"
9 #include "art/Framework/Services/Registry/ServiceHandle.h"
10 #include "art/Persistency/Provenance/ModuleContext.h"
11 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
12 #include "canvas/Persistency/Common/Wrapper.h"
13 #include "canvas/Persistency/Provenance/BranchDescription.h"
14 #include "canvas/Persistency/Provenance/BranchKey.h"
15 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
16 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
17 #include "canvas/Persistency/Provenance/ProcessConfigurationID.h"
18 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
19 #include "canvas/Persistency/Provenance/ProductList.h"
20 #include "canvas/Persistency/Provenance/ProductProvenance.h"
21 #include "canvas/Persistency/Provenance/RunAuxiliary.h"
22 #include "canvas/Persistency/Provenance/SubRunAuxiliary.h"
23 #include "canvas/Utilities/DebugMacros.h"
24 #include "canvas/Utilities/Exception.h"
25 #if ART_HEX_VERSION < 0x30901
26 #include "canvas/Utilities/WrappedTypeID.h"
27 #else
28 #include "canvas/Persistency/Common/WrappedTypeID.h"
29 #endif
30 #include "cetlib/column_width.h"
31 #include "cetlib/lpad.h"
32 #include "cetlib/rpad.h"
33 #include "fhiclcpp/ParameterSet.h"
34 #include "fhiclcpp/ParameterSetID.h"
35 #include "fhiclcpp/ParameterSetRegistry.h"
36 
37 #include "artdaq-core/Data/detail/ParentageMap.hh"
38 #include "artdaq/DAQdata/Globals.hh"
39 #include "artdaq/DAQdata/NetMonHeader.hh"
40 #include "artdaq/TransferPlugins/MakeTransferPlugin.hh"
41 #include "artdaq/TransferPlugins/TransferInterface.hh"
42 
43 #include <TClass.h>
44 #include <TMessage.h>
45 
46 #include <unistd.h>
47 #include <algorithm>
48 #include <iomanip>
49 #include <iostream>
50 #include <iterator>
51 #include <sstream>
52 #include <string>
53 #include <vector>
54 
55 namespace art {
56 class EventReporterOutput;
57 } // namespace art
58 
64 class art::EventReporterOutput : public OutputModule
65 {
66 public:
74  explicit EventReporterOutput(fhicl::ParameterSet const& ps);
75 
79  ~EventReporterOutput() override;
80 
81 private:
84  EventReporterOutput& operator=(EventReporterOutput const&) = delete;
85  EventReporterOutput& operator=(EventReporterOutput&&) = delete;
86 
87  void openFile(FileBlock const& /*unused*/) override;
88 
89  virtual void closeFile();
90 
91  void respondToCloseInputFile(FileBlock const& /*unused*/) override;
92 
93  void respondToCloseOutputFiles(FileBlock const& /*unused*/) override;
94 
95  void endJob() override;
96 
97  void write(EventPrincipal& /*ep*/) override;
98 
99  void writeRun(RunPrincipal& /*r*/) override;
100 
101  void writeSubRun(SubRunPrincipal& /*sr*/) override;
102 };
103 
104 art::EventReporterOutput::EventReporterOutput(fhicl::ParameterSet const& ps)
105  : OutputModule(ps)
106 {
107  TLOG(TLVL_DEBUG) << "Begin: EventReporterOutput::EventReporterOutput(ParameterSet const& ps)";
108 }
109 
111 {
112  TLOG(TLVL_DEBUG) << "Begin: EventReporterOutput::~EventReporterOutput()";
113 }
114 
115 void art::EventReporterOutput::openFile(FileBlock const& /*unused*/)
116 {
117  TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::openFile(const FileBlock&)";
118 }
119 
120 void art::EventReporterOutput::closeFile() { TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::closeFile()"; }
121 
122 void art::EventReporterOutput::respondToCloseInputFile(FileBlock const& /*unused*/)
123 {
124  TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::respondToCloseOutputFiles(FileBlock const&)";
125 }
126 
127 void art::EventReporterOutput::respondToCloseOutputFiles(FileBlock const& /*unused*/)
128 {
129  TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::respondToCloseOutputFiles(FileBlock const&)";
130 }
131 
132 void art::EventReporterOutput::endJob() { TLOG(TLVL_DEBUG) << "Begin: EventReporterOutput::endJob()"; }
133 
134 void art::EventReporterOutput::write(EventPrincipal& ep)
135 {
136  TLOG(TLVL_DEBUG) << " Begin: EventReporterOutput::write(const EventPrincipal& ep)";
137 
138  using RawEvent = artdaq::Fragments;
139  ;
140  using RawEvents = std::vector<RawEvent>;
141  using RawEventHandle = art::Handle<RawEvent>;
142  using RawEventHandles = std::vector<RawEventHandle>;
143 
144  auto result_handles = std::vector<art::GroupQueryResult>();
145 
146  auto const& wrapped = art::WrappedTypeID::make<RawEvent>();
147  ModuleContext const mc{moduleDescription()};
148  ProcessTag const processTag{"", mc.moduleDescription().processName()};
149 
150  result_handles = ep.getMany(mc, wrapped, art::MatchAllSelector{}, processTag);
151 
152  for (auto const& result_handle : result_handles)
153  {
154  auto const raw_event_handle = RawEventHandle(result_handle);
155 
156  if (!raw_event_handle.isValid())
157  {
158  continue;
159  }
160 
161  for (auto const& fragment : *raw_event_handle)
162  {
163  TLOG(TLVL_DEBUG) << "EventReporterOutput::write: Event sequenceID=" << fragment.sequenceID()
164  << ", fragmentID=" << fragment.fragmentID();
165  }
166  }
167 }
168 
169 void art::EventReporterOutput::writeRun(RunPrincipal& /*r*/)
170 {
171  TLOG(TLVL_DEBUG) << " EventReporterOutput::writeRun(const RunPrincipal& rp)";
172 }
173 
174 void art::EventReporterOutput::writeSubRun(SubRunPrincipal& /*sr*/)
175 {
176  TLOG(TLVL_DEBUG) << " EventReporterOutput:: writeSubRun(const SubRunPrincipal& srp)";
177 }
178 
179 DEFINE_ART_MODULE(art::EventReporterOutput) // NOLINT(performance-unnecessary-value-param)
An art::OutputModule which does nothing, but reports seen events and their fragments. This module is designed for debugging purposes, where writing events into ROOT files or sending events down stream is not necessary.
EventReporterOutput(fhicl::ParameterSet const &ps)
EventReporterOutput Constructor.
~EventReporterOutput() override
EventReporterOutput Destructor.