artdaq  v3_10_02
EventDump_module.cc
1 // Class: EventDump
3 // Module Type: analyzer
4 // File: EventDump_module.cc
5 // Description: Prints out information about each event.
7 
8 #include "art/Framework/Core/EDAnalyzer.h"
9 #include "art/Framework/Core/ModuleMacros.h"
10 #include "art/Framework/Principal/Event.h"
11 #include "art/Framework/Principal/Handle.h"
12 #include "canvas/Utilities/Exception.h"
13 
14 #include "artdaq-core/Data/ContainerFragment.hh"
15 #include "artdaq-core/Data/Fragment.hh"
16 #include "artdaq-core/Data/RawEvent.hh"
17 
18 #include <algorithm>
19 #include <cassert>
20 #include <cmath>
21 #include <fstream>
22 #include <iomanip>
23 #include <iostream>
24 #include <vector>
25 
26 namespace artdaq {
27 class EventDump;
28 }
29 
33 class artdaq::EventDump : public art::EDAnalyzer
34 {
35 public:
46  explicit EventDump(fhicl::ParameterSet const& pset);
47 
51  ~EventDump() override = default;
52 
60  void analyze(art::Event const& e) override;
61 
62 private:
63  EventDump(EventDump const&) = delete;
64  EventDump(EventDump&&) = delete;
65  EventDump& operator=(EventDump const&) = delete;
66  EventDump& operator=(EventDump&&) = delete;
67 
68  std::string raw_data_label_;
69  int verbosity_;
70 };
71 
72 artdaq::EventDump::EventDump(fhicl::ParameterSet const& pset)
73  : EDAnalyzer(pset)
74  , raw_data_label_(pset.get<std::string>("raw_data_label", "daq"))
75  , verbosity_(pset.get<int>("verbosity", 0)) {}
76 
77 void artdaq::EventDump::analyze(art::Event const& e)
78 {
79  if (verbosity_ > 0)
80  {
81  std::cout << "***** Start of EventDump for event " << e.event() << " *****" << std::endl;
82 
83  std::vector<art::Handle<detail::RawEventHeader>> header_handles;
84 #if ART_HEX_VERSION < 0x30900
85  e.getManyByType(header_handles);
86 #else
87  header_handles = e.getMany<detail::RawEventHeader>();
88 #endif
89 
90  for (auto const& header_handle : header_handles)
91  {
92  std::ostringstream ostr;
93  header_handle->print(ostr);
94  std::cout << "Event Header from " << header_handle.provenance()->processName() << ": " << ostr.str() << std::endl;
95  }
96  if (header_handles.empty())
97  {
98  std::cout << "Unable to read RawEventHeader for event " << e.event() << std::endl;
99  }
100 
101  std::vector<art::Handle<std::vector<artdaq::Fragment>>> fragmentHandles;
102 #if ART_HEX_VERSION < 0x30900
103  e.getManyByType(fragmentHandles);
104 #else
105  fragmentHandles = e.getMany<std::vector<artdaq::Fragment>>();
106 #endif
107 
108  for (auto const& handle : fragmentHandles)
109  {
110  if (!handle->empty())
111  {
112  std::string instance_name = handle.provenance()->productInstanceName();
113  std::cout << instance_name << " fragments: " << std::endl;
114 
115  int jdx = 1;
116  for (auto const& frag : *handle)
117  {
118  std::cout << " " << jdx << ") fragment ID " << frag.fragmentID() << " has type "
119  << static_cast<int>(frag.type()) << ", timestamp " << frag.timestamp()
120  << ", has metadata " << std::boolalpha << frag.hasMetadata()
121  << ", and sizeBytes " << frag.sizeBytes()
122  << " (hdr=" << frag.headerSizeBytes()
123  << ", data=" << frag.dataSizeBytes()
124  << ", meta (calculated)=" << (frag.sizeBytes() - frag.headerSizeBytes() - frag.dataSizeBytes())
125  << ")";
126 
127  if (instance_name.compare(0, 9, "Container") == 0)
128  {
129  artdaq::ContainerFragment cf(frag);
130  std::cout << " (contents: type = " << static_cast<int>(cf.fragment_type()) << ", count = "
131  << cf.block_count() << ", missing data = " << cf.missing_data()
132  << ")" << std::endl;
133  ;
134  if (verbosity_ > 1)
135  {
136  for (size_t idx = 0; idx < cf.block_count(); ++idx)
137  {
138  auto thisFrag = cf.at(idx);
139  std::cout << " " << (idx + 1) << ") fragment type " << static_cast<int>(thisFrag->type())
140  << ", timestamp " << thisFrag->timestamp()
141  << ", has metadata " << std::boolalpha << thisFrag->hasMetadata()
142  << ", and sizeBytes " << thisFrag->sizeBytes()
143  << " (hdr=" << thisFrag->headerSizeBytes()
144  << ", data=" << thisFrag->dataSizeBytes()
145  << ", meta (calculated)=" << (thisFrag->sizeBytes() - thisFrag->headerSizeBytes() - thisFrag->dataSizeBytes())
146  << ")" << std::endl;
147  }
148  }
149  }
150  else
151  {
152  std::cout << std::endl;
153  }
154  ++jdx;
155  }
156  }
157  }
158 
159  std::cout << "***** End of EventDump for event " << e.event() << " *****" << std::endl;
160  }
161 }
162 
163 DEFINE_ART_MODULE(artdaq::EventDump) // NOLINT(performance-unnecessary-value-param)
void analyze(art::Event const &e) override
This method is called for each art::Event in a file or run.
~EventDump() override=default
Default virtual Destructor.
EventDump(fhicl::ParameterSet const &pset)
EventDump Constructor.
Write Event information to the console.