LCOV - code coverage report
Current view: top level - ers/plugins - RFilterStream.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 3.2 % 31 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/RFilterStream.cxx to plugins/RFilterStream.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              :  *  RFilterStream.cxx
      14              :  *  ers
      15              :  *
      16              :  *  Created by Andrea Negri on 13.11.06 (from FilterStream.cxx)
      17              :  *  Copyright 2005 CERN. All rights reserved.
      18              :  *
      19              :  */
      20              : 
      21              : #include <ers/StreamFactory.hpp>
      22              : #include <ers/internal/RFilterStream.hpp>
      23              : #include <ers/internal/Util.hpp>
      24              : 
      25           43 : ERS_REGISTER_OUTPUT_STREAM(ers::RFilterStream, "rfilter", format)
      26              : 
      27              : namespace {
      28              : const char NOT = '!';
      29              : const char* const SEPARATORS = ",";
      30              : } // anonymous namespace
      31              : 
      32              : /** Constructor
      33              :  * \param chained the chained stream, which will be filtered. Only messages, which pass the filter
      34              :  * will go to the chained stream
      35              :  * on the stack and owned by the current object, i.e it will be deleted upon destruction
      36              :  * \param format describes filter expression.
      37              :  */
      38            0 : ers::RFilterStream::RFilterStream(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_regExclude.push_back(boost::regex(tokens[i].substr(1)));
      45              :     else
      46            0 :       m_regInclude.push_back(boost::regex(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::RFilterStream::is_accepted(const ers::Issue& issue)
      57              : {
      58              :   // Get the function name that will be the input of the pattern search
      59            0 :   std::string s = issue.context().function_name();
      60              :   // Remove the function arguments, which could lead to fake matches
      61            0 :   s = s.substr(0, s.find_first_of('('));
      62              : 
      63            0 :   const std::vector<std::string>& qualifiers = issue.qualifiers();
      64            0 :   std::vector<boost::regex>::const_iterator it;
      65              : 
      66              :   // Check excluded matches
      67            0 :   for (it = m_regExclude.begin(); it != m_regExclude.end(); ++it) {
      68              :     // 1. Check against function name
      69            0 :     if (boost::regex_search(s, *it))
      70            0 :       return false;
      71              : 
      72              :     // 2. Check against qualifiers
      73            0 :     std::vector<std::string>::const_iterator ko;
      74            0 :     for (ko = qualifiers.begin(); ko < qualifiers.end(); ko++)
      75            0 :       if (boost::regex_search(*ko, *it))
      76              :         return false;
      77              :   }
      78              : 
      79              :   // Check included matches (function name, then qualifiers)
      80            0 :   for (it = m_regInclude.begin(); it != m_regInclude.end(); ++it) {
      81              :     // 1. Check against function name
      82            0 :     if (boost::regex_search(s, *it))
      83            0 :       return true;
      84              : 
      85              :     // 2. Check against qualifiers
      86            0 :     std::vector<std::string>::const_iterator ok;
      87            0 :     for (ok = qualifiers.begin(); ok < qualifiers.end(); ok++)
      88            0 :       if (boost::regex_search(*ok, *it))
      89              :         return true;
      90              :   }
      91              : 
      92              :   return false; // m_regInclude.empty();
      93            0 : }
      94              : 
      95              : /** Write method
      96              :  * basically calls \c is_accept to check if the issue is accepted.
      97              :  * If this is the case, the \c write method on the chained stream is called with
      98              :  * \c issue.
      99              :  * \param issue issue to be sent.
     100              :  */
     101              : void
     102            0 : ers::RFilterStream::write(const ers::Issue& issue)
     103              : {
     104            0 :   if (is_accepted(issue)) {
     105            0 :     chained().write(issue);
     106              :   }
     107            0 : } // send
        

Generated by: LCOV version 2.0-1