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/internal/RFilterStream.hpp>
22 : #include <ers/internal/Util.hpp>
23 : #include <ers/StreamFactory.hpp>
24 :
25 42 : ERS_REGISTER_OUTPUT_STREAM( ers::RFilterStream, "rfilter", format )
26 :
27 : namespace
28 : {
29 : const char NOT = '!';
30 : const char * const SEPARATORS = ",";
31 : } // anonymous namespace
32 :
33 :
34 :
35 : /** Constructor
36 : * \param chained the chained stream, which will be filtered. Only messages, which pass the filter
37 : * will go to the chained stream
38 : * on the stack and owned by the current object, i.e it will be deleted upon destruction
39 : * \param format describes filter expression.
40 : */
41 0 : ers::RFilterStream::RFilterStream( const std::string & format )
42 : {
43 0 : std::vector<std::string> tokens;
44 0 : ers::tokenize( format, SEPARATORS, tokens );
45 0 : for( size_t i = 0; i < tokens.size(); i++ )
46 : {
47 0 : if ( !tokens[i].empty() && tokens[i][0] == NOT )
48 0 : m_regExclude.push_back( boost::regex(tokens[i].substr( 1 )) );
49 : else
50 0 : m_regInclude.push_back( boost::regex(tokens[i]) );
51 : }
52 0 : }
53 :
54 :
55 : /** Filtering method
56 : * This method checks if an Issue is to be accepted or not.
57 : * \param issue_ptr the issue to check
58 : * \return \c true if the Issue passes filtering, \c false otherwise.
59 : */
60 : bool
61 0 : ers::RFilterStream::is_accepted( const ers::Issue & issue )
62 : {
63 : // Get the function name that will be the input of the pattern search
64 0 : std::string s = issue.context().function_name();
65 : // Remove the function arguments, which could lead to fake matches
66 0 : s = s.substr(0,s.find_first_of('('));
67 :
68 0 : const std::vector<std::string> & qualifiers = issue.qualifiers( );
69 0 : std::vector<boost::regex>::const_iterator it;
70 :
71 : // Check excluded matches
72 0 : for( it = m_regExclude.begin(); it != m_regExclude.end(); ++it )
73 : {
74 : // 1. Check against function name
75 0 : if (boost::regex_search(s, *it))
76 0 : return false;
77 :
78 : // 2. Check against qualifiers
79 0 : std::vector<std::string>::const_iterator ko;
80 0 : for ( ko=qualifiers.begin(); ko<qualifiers.end(); ko++)
81 0 : if ( boost::regex_search(*ko,*it) )
82 : return false;
83 : }
84 :
85 : // Check included matches (function name, then qualifiers)
86 0 : for( it = m_regInclude.begin(); it != m_regInclude.end(); ++it )
87 : {
88 : // 1. Check against function name
89 0 : if (boost::regex_search(s, *it))
90 0 : return true;
91 :
92 : // 2. Check against qualifiers
93 0 : std::vector<std::string>::const_iterator ok;
94 0 : for (ok=qualifiers.begin(); ok<qualifiers.end(); ok++)
95 0 : if ( boost::regex_search(*ok,*it) )
96 : return true;
97 : }
98 :
99 : return false; //m_regInclude.empty();
100 0 : }
101 :
102 : /** Write method
103 : * basically calls \c is_accept to check if the issue is accepted.
104 : * If this is the case, the \c write method on the chained stream is called with
105 : * \c issue.
106 : * \param issue issue to be sent.
107 : */
108 : void
109 0 : ers::RFilterStream::write( const ers::Issue & issue )
110 : {
111 0 : if ( is_accepted( issue ) )
112 : {
113 0 : chained().write( issue );
114 : }
115 0 : } // send
116 :
|