artdaq  v3_08_00
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 
17 #include <algorithm>
18 #include <cassert>
19 #include <cmath>
20 #include <fstream>
21 #include <iomanip>
22 #include <iostream>
23 #include <vector>
24 
25 namespace artdaq {
26 class EventDump;
27 }
28 
32 class artdaq::EventDump : public art::EDAnalyzer
33 {
34 public:
45  explicit EventDump(fhicl::ParameterSet const& pset);
46 
50  virtual ~EventDump() = default;
51 
59  void analyze(art::Event const& e) override;
60 
61 private:
62  std::string raw_data_label_;
63  int verbosity_;
64 };
65 
66 artdaq::EventDump::EventDump(fhicl::ParameterSet const& pset)
67  : EDAnalyzer(pset)
68  , raw_data_label_(pset.get<std::string>("raw_data_label", "daq"))
69  , verbosity_(pset.get<int>("verbosity", 0)) {}
70 
71 void artdaq::EventDump::analyze(art::Event const& e)
72 {
73  if (verbosity_ > 0)
74  {
75  std::cout << "***** Start of EventDump for event " << e.event() << " *****" << std::endl;
76 
77  std::vector<art::Handle<std::vector<artdaq::Fragment> > > fragmentHandles;
78  e.getManyByType(fragmentHandles);
79 
80  for (auto const& handle : fragmentHandles)
81  {
82  if (handle->size() > 0)
83  {
84  std::string instance_name = handle.provenance()->productInstanceName();
85  std::cout << instance_name << " fragments: " << std::endl;
86 
87  int jdx = 1;
88  for (auto const& frag : *handle)
89  {
90  std::cout << " " << jdx << ") fragment ID " << frag.fragmentID() << " has type "
91  << (int)frag.type() << ", timestamp " << frag.timestamp()
92  << ", has metadata " << std::boolalpha << frag.hasMetadata()
93  << ", and sizeBytes " << frag.sizeBytes()
94  << " (hdr=" << frag.headerSizeBytes()
95  << ", data=" << frag.dataSizeBytes()
96  << ", meta (calculated)=" << (frag.sizeBytes() - frag.headerSizeBytes() - frag.dataSizeBytes())
97  << ")";
98 
99  if (instance_name.compare(0, 9, "Container") == 0)
100  {
101  artdaq::ContainerFragment cf(frag);
102  std::cout << " (contents: type = " << (int)cf.fragment_type() << ", count = "
103  << cf.block_count() << ", missing data = " << cf.missing_data()
104  << ")" << std::endl;
105  ;
106  if (verbosity_ > 1)
107  {
108  for (size_t idx = 0; idx < cf.block_count(); ++idx)
109  {
110  auto thisFrag = cf.at(idx);
111  std::cout << " " << (idx + 1) << ") fragment type " << (int)thisFrag->type()
112  << ", timestamp " << thisFrag->timestamp()
113  << ", has metadata " << std::boolalpha << thisFrag->hasMetadata()
114  << ", and sizeBytes " << thisFrag->sizeBytes()
115  << " (hdr=" << thisFrag->headerSizeBytes()
116  << ", data=" << thisFrag->dataSizeBytes()
117  << ", meta (calculated)=" << (thisFrag->sizeBytes() - thisFrag->headerSizeBytes() - thisFrag->dataSizeBytes())
118  << ")" << std::endl;
119  }
120  }
121  }
122  else
123  {
124  std::cout << std::endl;
125  }
126  ++jdx;
127  }
128  }
129  }
130 
131  std::cout << "***** End of EventDump for event " << e.event() << " *****" << std::endl;
132  }
133 }
134 
135 DEFINE_ART_MODULE(artdaq::EventDump)
void analyze(art::Event const &e) override
This method is called for each art::Event in a file or run.
EventDump(fhicl::ParameterSet const &pset)
EventDump Constructor.
Write Event information to the console.
virtual ~EventDump()=default
Default virtual Destructor.