LCOV - code coverage report
Current view: top level - artdaq/ArtModules - EventDump_module.cc (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 57 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 9 0

            Line data    Source code
       1              : ////////////////////////////////////////////////////////////////////////
       2              : // Class:       EventDump
       3              : // Module Type: analyzer
       4              : // File:        EventDump_module.cc
       5              : // Description: Prints out information about each event.
       6              : ////////////////////////////////////////////////////////////////////////
       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              : 
      30              : /**
      31              :  * \brief Write Event information to the console
      32              :  */
      33              : class artdaq::EventDump : public art::EDAnalyzer
      34              : {
      35              : public:
      36              :         /**
      37              :          * \brief EventDump Constructor
      38              :          * \param pset ParameterSet used to configure EventDump
      39              :          *
      40              :          * \verbatim
      41              :          * EventDump accepts the following Parameters:
      42              :          * "raw_data_label" (Default: "daq"): The label used to store artdaq data
      43              :          * "verbosity" (Default: 0): verboseness level
      44              :          * \endverbatim
      45              :          */
      46              :         explicit EventDump(fhicl::ParameterSet const& pset);
      47              : 
      48              :         /**
      49              :          * \brief Default virtual Destructor
      50              :          */
      51            0 :         ~EventDump() override = default;
      52              : 
      53              :         /**
      54              :          * \brief This method is called for each art::Event in a file or run
      55              :          * \param e The art::Event to analyze
      56              :          *
      57              :          * This module simply prints the event number, and art by default
      58              :          * prints the products found in the event.
      59              :          */
      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            0 : artdaq::EventDump::EventDump(fhicl::ParameterSet const& pset)
      73              :     : EDAnalyzer(pset)
      74            0 :     , raw_data_label_(pset.get<std::string>("raw_data_label", "daq"))
      75            0 :     , verbosity_(pset.get<int>("verbosity", 0)) {}
      76              : 
      77            0 : void artdaq::EventDump::analyze(art::Event const& e)
      78              : {
      79            0 :         if (verbosity_ > 0)
      80              :         {
      81            0 :                 std::cout << "***** Start of EventDump for event " << e.event() << " *****" << std::endl;
      82              : 
      83            0 :                 std::vector<art::Handle<detail::RawEventHeader>> header_handles;
      84            0 :                 header_handles = e.getMany<detail::RawEventHeader>();
      85              : 
      86            0 :                 for (auto const& header_handle : header_handles)
      87              :                 {
      88            0 :                         std::ostringstream ostr;
      89            0 :                         header_handle->print(ostr);
      90            0 :                         std::cout << "Event Header from " << header_handle.provenance()->processName() << ": " << ostr.str() << std::endl;
      91            0 :                 }
      92            0 :                 if (header_handles.empty())
      93              :                 {
      94            0 :                         std::cout << "Unable to read RawEventHeader for event " << e.event() << std::endl;
      95              :                 }
      96              : 
      97            0 :                 std::vector<art::Handle<std::vector<artdaq::Fragment>>> fragmentHandles;
      98            0 :                 fragmentHandles = e.getMany<std::vector<artdaq::Fragment>>();
      99              : 
     100            0 :                 for (auto const& handle : fragmentHandles)
     101              :                 {
     102            0 :                         if (!handle->empty())
     103              :                         {
     104            0 :                                 std::string instance_name = handle.provenance()->productInstanceName();
     105            0 :                                 std::cout << instance_name << " fragments: " << std::endl;
     106              : 
     107            0 :                                 int jdx = 1;
     108            0 :                                 for (auto const& frag : *handle)
     109              :                                 {
     110            0 :                                         std::cout << "  " << jdx << ") fragment ID " << frag.fragmentID() << " has type "
     111            0 :                                                   << static_cast<int>(frag.type()) << ", timestamp " << frag.timestamp()
     112            0 :                                                   << ", has metadata " << std::boolalpha << frag.hasMetadata()
     113            0 :                                                   << ", and sizeBytes " << frag.sizeBytes()
     114            0 :                                                   << " (hdr=" << frag.headerSizeBytes()
     115            0 :                                                   << ", data=" << frag.dataSizeBytes()
     116            0 :                                                   << ", meta (calculated)=" << (frag.sizeBytes() - frag.headerSizeBytes() - frag.dataSizeBytes())
     117            0 :                                                   << ")";
     118              : 
     119            0 :                                         if (instance_name.compare(0, 9, "Container") == 0)
     120              :                                         {
     121            0 :                                                 artdaq::ContainerFragment cf(frag);
     122            0 :                                                 std::cout << " (contents: type = " << static_cast<int>(cf.fragment_type()) << ", count = "
     123            0 :                                                           << cf.block_count() << ", missing data = " << cf.missing_data()
     124            0 :                                                           << ")" << std::endl;
     125              :                                                 ;
     126            0 :                                                 if (verbosity_ > 1)
     127              :                                                 {
     128            0 :                                                         for (size_t idx = 0; idx < cf.block_count(); ++idx)
     129              :                                                         {
     130            0 :                                                                 auto thisFrag = cf.at(idx);
     131            0 :                                                                 std::cout << "    " << (idx + 1) << ") fragment type " << static_cast<int>(thisFrag->type())
     132            0 :                                                                           << ", timestamp " << thisFrag->timestamp()
     133            0 :                                                                           << ", has metadata " << std::boolalpha << thisFrag->hasMetadata()
     134            0 :                                                                           << ", and sizeBytes " << thisFrag->sizeBytes()
     135            0 :                                                                           << " (hdr=" << thisFrag->headerSizeBytes()
     136            0 :                                                                           << ", data=" << thisFrag->dataSizeBytes()
     137            0 :                                                                           << ", meta (calculated)=" << (thisFrag->sizeBytes() - thisFrag->headerSizeBytes() - thisFrag->dataSizeBytes())
     138            0 :                                                                           << ")" << std::endl;
     139            0 :                                                         }
     140              :                                                 }
     141            0 :                                         }
     142              :                                         else
     143              :                                         {
     144            0 :                                                 std::cout << std::endl;
     145              :                                         }
     146            0 :                                         ++jdx;
     147              :                                 }
     148            0 :                         }
     149              :                 }
     150              : 
     151            0 :                 std::cout << "***** End of EventDump for event " << e.event() << " *****" << std::endl;
     152            0 :         }
     153            0 : }
     154              : 
     155            0 : DEFINE_ART_MODULE(artdaq::EventDump)  // NOLINT(performance-unnecessary-value-param)
        

Generated by: LCOV version 2.0-1