artdaq_demo  3.12.07
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/WrappedTypeID.h"
13 #include "canvas/Persistency/Common/Wrapper.h"
14 #include "canvas/Persistency/Provenance/BranchDescription.h"
15 #include "canvas/Persistency/Provenance/BranchKey.h"
16 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
17 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
18 #include "canvas/Persistency/Provenance/ProcessConfigurationID.h"
19 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
20 #include "canvas/Persistency/Provenance/ProductList.h"
21 #include "canvas/Persistency/Provenance/ProductProvenance.h"
22 #include "canvas/Persistency/Provenance/RunAuxiliary.h"
23 #include "canvas/Persistency/Provenance/SubRunAuxiliary.h"
24 #include "canvas/Utilities/DebugMacros.h"
25 #include "canvas/Utilities/Exception.h"
26 #include "cetlib/column_width.h"
27 #include "cetlib/lpad.h"
28 #include "cetlib/rpad.h"
29 #include "fhiclcpp/ParameterSet.h"
30 #include "fhiclcpp/ParameterSetID.h"
31 #include "fhiclcpp/ParameterSetRegistry.h"
32 
33 #include "artdaq-core/Data/detail/ParentageMap.hh"
34 #include "artdaq/DAQdata/Globals.hh"
35 #include "artdaq/DAQdata/NetMonHeader.hh"
36 #include "artdaq/TransferPlugins/MakeTransferPlugin.hh"
37 #include "artdaq/TransferPlugins/TransferInterface.hh"
38 
39 #include <TClass.h>
40 #include <TMessage.h>
41 
42 #include <unistd.h>
43 #include <algorithm>
44 #include <iomanip>
45 #include <iostream>
46 #include <iterator>
47 #include <sstream>
48 #include <string>
49 #include <vector>
50 
51 namespace art {
52 class EventReporterOutput;
53 } // namespace art
54 
60 class art::EventReporterOutput : public OutputModule
61 {
62 public:
70  explicit EventReporterOutput(fhicl::ParameterSet const& ps);
71 
75  ~EventReporterOutput() override;
76 
77 private:
80  EventReporterOutput& operator=(EventReporterOutput const&) = delete;
81  EventReporterOutput& operator=(EventReporterOutput&&) = delete;
82 
83  void openFile(FileBlock const& /*unused*/) override;
84 
85  virtual void closeFile();
86 
87  void respondToCloseInputFile(FileBlock const& /*unused*/) override;
88 
89  void respondToCloseOutputFiles(FileBlock const& /*unused*/) override;
90 
91  void endJob() override;
92 
93  void write(EventPrincipal& /*ep*/) override;
94 
95  void writeRun(RunPrincipal& /*r*/) override;
96 
97  void writeSubRun(SubRunPrincipal& /*sr*/) override;
98 };
99 
100 art::EventReporterOutput::EventReporterOutput(fhicl::ParameterSet const& ps)
101  : OutputModule(ps)
102 {
103  TLOG(TLVL_DEBUG) << "Begin: EventReporterOutput::EventReporterOutput(ParameterSet const& ps)";
104 }
105 
107 {
108  TLOG(TLVL_DEBUG) << "Begin: EventReporterOutput::~EventReporterOutput()";
109 }
110 
111 void art::EventReporterOutput::openFile(FileBlock const& /*unused*/)
112 {
113  TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::openFile(const FileBlock&)";
114 }
115 
116 void art::EventReporterOutput::closeFile() { TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::closeFile()"; }
117 
118 void art::EventReporterOutput::respondToCloseInputFile(FileBlock const& /*unused*/)
119 {
120  TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::respondToCloseOutputFiles(FileBlock const&)";
121 }
122 
123 void art::EventReporterOutput::respondToCloseOutputFiles(FileBlock const& /*unused*/)
124 {
125  TLOG(TLVL_DEBUG) << "Begin/End: EventReporterOutput::respondToCloseOutputFiles(FileBlock const&)";
126 }
127 
128 void art::EventReporterOutput::endJob() { TLOG(TLVL_DEBUG) << "Begin: EventReporterOutput::endJob()"; }
129 
130 void art::EventReporterOutput::write(EventPrincipal& ep)
131 {
132  TLOG(TLVL_DEBUG) << " Begin: EventReporterOutput::write(const EventPrincipal& ep)";
133 
134  using RawEvent = artdaq::Fragments;
135  ;
136  using RawEvents = std::vector<RawEvent>;
137  using RawEventHandle = art::Handle<RawEvent>;
138  using RawEventHandles = std::vector<RawEventHandle>;
139 
140  auto result_handles = std::vector<art::GroupQueryResult>();
141 
142  auto const& wrapped = art::WrappedTypeID::make<RawEvent>();
143  ModuleContext const mc{moduleDescription()};
144  ProcessTag const processTag{"", mc.moduleDescription().processName()};
145 
146  result_handles = ep.getMany(mc, wrapped, art::MatchAllSelector{}, processTag);
147 
148  for (auto const& result_handle : result_handles)
149  {
150  auto const raw_event_handle = RawEventHandle(result_handle);
151 
152  if (!raw_event_handle.isValid())
153  {
154  continue;
155  }
156 
157  for (auto const& fragment : *raw_event_handle)
158  {
159  TLOG(TLVL_DEBUG) << "EventReporterOutput::write: Event sequenceID=" << fragment.sequenceID()
160  << ", fragmentID=" << fragment.fragmentID();
161  }
162  }
163 }
164 
165 void art::EventReporterOutput::writeRun(RunPrincipal& /*r*/)
166 {
167  TLOG(TLVL_DEBUG) << " EventReporterOutput::writeRun(const RunPrincipal& rp)";
168 }
169 
170 void art::EventReporterOutput::writeSubRun(SubRunPrincipal& /*sr*/)
171 {
172  TLOG(TLVL_DEBUG) << " EventReporterOutput:: writeSubRun(const SubRunPrincipal& srp)";
173 }
174 
175 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.