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