LCOV - code coverage report
Current view: top level - ers/plugins - FilterStream.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 4.0 % 25 1
Test Date: 2026-10-11 15:05:20 Functions: 20.0 % 5 1

            Line data    Source code
       1              : /*
       2              :  * DUNE DAQ modification notice:
       3              :  * This file has been modified from the original ATLAS ers source for the DUNE DAQ project.
       4              :  * Fork baseline commit: 8267df82a4f6fe6bf02c4014923eba19eddc4614 (2020-04-14).
       5              :  * Renamed since fork: yes (from src/streams/FilterStream.cxx to plugins/FilterStream.cpp).
       6              :  *
       7              :  * Original copyright:
       8              :  * Copyright (C) 2001-2020 CERN for the benefit of the ATLAS collaboration.
       9              :  * Licensed under the Apache License, Version 2.0.
      10              :  */
      11              : 
      12              : /*
      13              :  *  FilterStream.cxx
      14              :  *  ers
      15              :  *
      16              :  *  Created by Matthias Wiesmann on 31.03.05.
      17              :  *  Modified by Serguei Kolos on 11.08.05.
      18              :  *  Copyright 2005 CERN. All rights reserved.
      19              :  *
      20              :  */
      21              : 
      22              : #include <algorithm>
      23              : #include <ers/StreamFactory.hpp>
      24              : #include <ers/internal/FilterStream.hpp>
      25              : #include <ers/internal/Util.hpp>
      26              : 
      27           43 : ERS_REGISTER_OUTPUT_STREAM(ers::FilterStream, "filter", format)
      28              : 
      29              : namespace {
      30              : const char NOT = '!';
      31              : const char* const SEPARATORS = ",";
      32              : } // anonymous namespace
      33              : 
      34              : /** Constructor that creates a new instance of the filter stream with the given configuration.
      35              :  * Only messages that pass the given filter will go through, the others will be filtered out.
      36              :  * \param format filter expression.
      37              :  */
      38            0 : ers::FilterStream::FilterStream(const std::string& format)
      39              : {
      40            0 :   std::vector<std::string> tokens;
      41            0 :   ers::tokenize(format, SEPARATORS, tokens);
      42            0 :   for (size_t i = 0; i < tokens.size(); i++) {
      43            0 :     if (!tokens[i].empty() && tokens[i][0] == NOT)
      44            0 :       m_exclude.push_back(tokens[i].substr(1));
      45              :     else
      46            0 :       m_include.push_back(tokens[i]);
      47              :   }
      48            0 : }
      49              : 
      50              : /** Filtering method
      51              :  * This method checks if an Issue is to be accepted or not.
      52              :  * \param issue_ptr the issue to check
      53              :  * \return \c true if the Issue passes filtering, \c false otherwise.
      54              :  */
      55              : bool
      56            0 : ers::FilterStream::is_accepted(const ers::Issue& issue)
      57              : {
      58            0 :   const std::vector<std::string>& qualifiers = issue.qualifiers();
      59              : 
      60            0 :   std::vector<std::string>::const_iterator it;
      61            0 :   for (it = m_exclude.begin(); it != m_exclude.end(); ++it) {
      62            0 :     std::vector<std::string>::const_iterator conflict = std::find(qualifiers.begin(), qualifiers.end(), *it);
      63            0 :     if (conflict != qualifiers.end()) {
      64            0 :       return false;
      65              :     }
      66              :   }
      67              : 
      68            0 :   for (it = m_include.begin(); it != m_include.end(); ++it) {
      69            0 :     std::vector<std::string>::const_iterator match = std::find(qualifiers.begin(), qualifiers.end(), *it);
      70            0 :     if (match != qualifiers.end()) {
      71            0 :       return true;
      72              :     }
      73              :   }
      74              : 
      75            0 :   return m_include.empty();
      76              : }
      77              : 
      78              : /** Write method
      79              :  * basically calls \c is_accept to check if the issue is accepted.
      80              :  * If this is the case, the \c write method on the chained stream is called with
      81              :  * \c issue.
      82              :  * \param issue issue to be sent.
      83              :  */
      84              : void
      85            0 : ers::FilterStream::write(const ers::Issue& issue)
      86              : {
      87            0 :   if (is_accepted(issue)) {
      88            0 :     chained().write(issue);
      89              :   }
      90            0 : } // send
        

Generated by: LCOV version 2.0-1