LCOV - code coverage report
Current view: top level - dfmodules/src - SummaryTextDataWriter.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 95.1 % 41 39
Test Date: 2026-10-11 15:05:20 Functions: 100.0 % 10 10

            Line data    Source code
       1              : /**
       2              :  * @file SummaryTextDataWriter.cpp
       3              :  *
       4              :  * This is part of the DUNE DAQ Software Suite, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "dfmodules/SummaryTextDataWriter.hpp"
      10              : 
      11              : #include <stdexcept>
      12              : #include <string>
      13              : 
      14              : namespace dunedaq::dfmodules {
      15              : 
      16           27 : SummaryTextDataWriter::SummaryTextDataWriter(const std::string& file_name)
      17           27 :   : m_file_name(file_name)
      18           27 :   , m_output_file(file_name, std::ios::out | std::ios::app)
      19           27 :   , m_recorded_size(0)
      20           27 :   , m_uncompressed_raw_data_size(0)
      21           27 :   , m_total_file_size(0)
      22              : {
      23           27 :   if (!m_output_file.is_open()) {
      24            0 :     throw CantOpenFile(ERS_HERE, m_file_name);
      25              :   }
      26           27 : }
      27              : 
      28           27 : SummaryTextDataWriter::~SummaryTextDataWriter()
      29              : {
      30           27 :   if (m_output_file.is_open()) {
      31           27 :     m_output_file.close();
      32              :   }
      33           27 : }
      34              : 
      35              : void
      36           30 : SummaryTextDataWriter::write(const daqdataformats::TriggerRecord& tr)
      37              : {
      38           30 :   const auto trigger_number = tr.get_header_ref().get_trigger_number();
      39           30 :   write_line("TriggerRecord #" + std::to_string(trigger_number));
      40           30 : }
      41              : 
      42              : void
      43            1 : SummaryTextDataWriter::write(const daqdataformats::TimeSlice& ts)
      44              : {
      45            1 :   const auto timeslice_number = ts.get_header().timeslice_number;
      46            1 :   m_written_timeslices.insert(timeslice_number);
      47            1 :   write_line("TimeSlice #" + std::to_string(timeslice_number));
      48            1 : }
      49              : 
      50              : bool
      51            2 : SummaryTextDataWriter::timeslice_already_exists(const daqdataformats::TimeSlice& ts) const
      52              : {
      53            2 :   return m_written_timeslices.count(ts.get_header().timeslice_number) > 0;
      54              : }
      55              : 
      56              : std::string
      57           23 : SummaryTextDataWriter::get_file_name() const
      58              : {
      59           23 :   return m_file_name;
      60              : }
      61              : 
      62              : size_t
      63           31 : SummaryTextDataWriter::get_recorded_size() const noexcept
      64              : {
      65           31 :   return m_recorded_size;
      66              : }
      67              : 
      68              : size_t
      69           31 : SummaryTextDataWriter::get_uncompressed_raw_data_size() const noexcept
      70              : {
      71           31 :   return m_uncompressed_raw_data_size;
      72              : }
      73              : 
      74              : size_t
      75           31 : SummaryTextDataWriter::get_total_file_size() const noexcept
      76              : {
      77           31 :   return m_total_file_size;
      78              : }
      79              : 
      80              : void
      81           31 : SummaryTextDataWriter::write_line(const std::string& line)
      82              : {
      83           31 :   m_output_file << line << '\n';
      84           31 :   if (!m_output_file.good()) {
      85            0 :     throw CantWriteToFile(ERS_HERE, m_file_name);
      86              :   }
      87              : 
      88           31 :   const size_t bytes_written = line.size() + 1;
      89           31 :   m_recorded_size += bytes_written;
      90           31 :   m_uncompressed_raw_data_size += bytes_written;
      91           31 :   m_total_file_size += bytes_written;
      92           31 : }
      93              : 
      94              : } // namespace dunedaq::dfmodules
        

Generated by: LCOV version 2.0-1