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