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