BOSS 7.0.6
BESIII Offline Software System
Loading...
Searching...
No Matches
ers::FilterStream Class Reference

filtering stream More...

#include <FilterStream.h>

+ Inheritance diagram for ers::FilterStream:

Public Member Functions

 FilterStream (Stream *target_ptr, const std::vector< std::string > &include_list, const std::vector< std::string > &exclude_list)
 
 ~FilterStream ()
 destructor
 
virtual bool is_accept (const Issue *issue_ptr)
 filter method
 
virtual void send (const Issue *issue_ptr)
 send method
 
virtual void print_to (std::ostream &stream) const
 
- Public Member Functions inherited from ers::Stream
 Stream ()
 
 Stream (const Stream &other)
 
 operator std::string () const
 
virtual ~Stream ()
 
virtual void send (const Issue *i)
 Sends an issue into the stream.
 
virtual Issuereceive ()
 Receives an issue from the stream.
 
virtual void print_to (std::ostream &stream) const
 

Static Public Member Functions

static FilterStreamfactory (const std::string &include_str, const ::std::string &exclude_str, const std::string &target_str)
 factory method for partially parse information
 
static FilterStreamfactory (const std::string &parameters)
 factory method for unparsed information
 

Static Public Attributes

static const char *const FILTER_STREAM_TAG = "filter"
 tag used to identity this stream
 
static const char *const INCLUDE_TAG = "?"
 tag used to mark the start of the include list
 
static const char *const EXCLUDE_TAG = "!"
 tag used to mark the start of the exclude list
 
static const char *const TARGET_TAG = "@"
 tag used to mark the target stream
 
static const char *const SEPARATORS = ","
 separators between include and exclude qualifiers
 
- Static Public Attributes inherited from ers::Stream
static const char *const NULL_STREAM_KEY = "null"
 

Protected Member Functions

 FilterStream ()
 
 FilterStream (const FilterStream &other)
 

Protected Attributes

Streamm_target_stream_ptr
 chained target stream
 
std::vector< std::string > m_include
 include list
 
std::vector< std::string > m_exclude
 exclude list
 

Detailed Description

filtering stream

This stream offers basic filtering capacities It basically hooks up in front of another stream and filters the data output. Filtering is based on two list and include list and and exclude list To be accepted an Issue needs two match two criteria

  • No qualifier in the issue should match strings in the exclude list
  • At least one qualifier in the issue should match a string in the include list

If the include list is empty, the second condition is not applied. This stream should only be used for severity levels where filtering makes sense, i.e warning, debugs, etc... The syntax to request a filter stream is the following:
filter:filter:?include_qualifier1,include_qualifier2!exclude_qualifier1,exclude_qualifier2@stream_identifier The stream_identifier can be any stream_key used by the ERS system (including a second filter).

For more information on associating a stream to a severity level, see the documentation on the StreamFactory class.

See also
ers::StreamFactory
Author
Matthias Wiesmann
Version
1.0

Definition at line 38 of file FilterStream.h.

Constructor & Destructor Documentation

◆ FilterStream() [1/3]

ers::FilterStream::FilterStream ( )
protected

Disabled empty constructor

Definition at line 72 of file FilterStream.cxx.

72 : ers::Stream() {
73} // FilterStream
Root/Null issue stream.
Definition: Stream.h:35

Referenced by factory().

◆ FilterStream() [2/3]

ers::FilterStream::FilterStream ( const FilterStream other)
protected

Disabled copy constructor

Definition at line 79 of file FilterStream.cxx.

79 : ers::Stream(other) {
80} // FilterStream

◆ FilterStream() [3/3]

ers::FilterStream::FilterStream ( ers::Stream target_ptr,
const std::vector< std::string > &  include_list,
const std::vector< std::string > &  exclude_list 
)

Constructor

Parameters
target_ptrpointer to the target stream, the target pointer is assumed to be allocated on the stack and owned by the current object, i.e it will be deleted upon destruction
include_listcollection of strings, at least one of these strings need to be present in the qualifiers in order for the Issue to be accepted.
exclude_listcollection of strings, no qualifier of the Issue must match those in this collection in order for the Issue to be accepted.

Definition at line 92 of file FilterStream.cxx.

93 : ers::Stream() {
94 ERS_CHECK_PTR(target_ptr);
95 m_target_stream_ptr = target_ptr ;
96 m_include = include_list ;
97 m_exclude = exclude_list ;
98} // FilterStream
#define ERS_CHECK_PTR(p)
std::vector< std::string > m_include
include list
Definition: FilterStream.h:41
std::vector< std::string > m_exclude
exclude list
Definition: FilterStream.h:42
Stream * m_target_stream_ptr
chained target stream
Definition: FilterStream.h:40

◆ ~FilterStream()

ers::FilterStream::~FilterStream ( )

destructor

Destructor

Definition at line 105 of file FilterStream.cxx.

105 {
106 delete(m_target_stream_ptr) ;
107} // FilterStream

Member Function Documentation

◆ factory() [1/2]

ers::FilterStream * ers::FilterStream::factory ( const std::string &  include_str,
const ::std::string &  exclude_str,
const std::string &  target_str 
)
static

factory method for partially parse information

Builds a stream out of a set of parameters

Parameters
include_strstring containing all the coma separated include qualifiers
exclude_strstring containing all the coma separated exclude qualifiers
target_strstring containing the key for the target stream, i.e the stream where accepted Issues are sent.

Definition at line 43 of file FilterStream.cxx.

43 {
44 ers::Stream *target_stream = ers::StreamFactory::instance()->create_stream(target_str);
45 std::vector<std::string> include_list = ers::Core::tokenize(include_str,SEPARATORS);
46 std::vector<std::string> exclude_list = ers::Core::tokenize(exclude_str,SEPARATORS);
47 return new FilterStream(target_stream,include_list,exclude_list);
48} // factory
static std::vector< std::string > tokenize(const std::string &text, const std::string &separators)
Definition: Core.cxx:151
static const char *const SEPARATORS
separators between include and exclude qualifiers
Definition: FilterStream.h:50
Stream * create_stream(severity_t s)
create a stream for severity_t
static StreamFactory * instance()
return the singleton

◆ factory() [2/2]

ers::FilterStream * ers::FilterStream::factory ( const std::string &  params)
static

factory method for unparsed information

Builds a stream out of a key string. This method parses the string and calls a more specialised version of the factory method.

Parameters
paramssingle string describing the requested filter stream
Returns
pointer to newly heap allocated instance of FilterStream

Definition at line 57 of file FilterStream.cxx.

57 {
58 std::string::size_type include_start = params.find(INCLUDE_TAG);
59 std::string::size_type exclude_start = params.find(EXCLUDE_TAG);
60 std::string::size_type target_start = params.find(TARGET_TAG);
61 std::string include_str = params.substr(include_start+1,exclude_start-1);
62 std::string exclude_str = params.substr(exclude_start+1,target_start-exclude_start-1);
63 std::string target_str = params.substr(target_start+1);
64 // ERS_DEBUG_0("include: '%s' exclude: '%s' target '%s'",include_str.c_str(),exclude_str.c_str(), target_str.c_str());
65 return factory(include_str,exclude_str,target_str);
66} // factory
static const char *const EXCLUDE_TAG
tag used to mark the start of the exclude list
Definition: FilterStream.h:48
static const char *const INCLUDE_TAG
tag used to mark the start of the include list
Definition: FilterStream.h:47
static const char *const TARGET_TAG
tag used to mark the target stream
Definition: FilterStream.h:49
efhlt::Interface * factory(void)
Definition: factory.cxx:17

◆ is_accept()

bool ers::FilterStream::is_accept ( const Issue issue_ptr)
virtual

filter method

Filtering method This method checks if an Issue is to be accepted or not.

Parameters
issue_ptrthe issue to check
Returns
true if the Issue passes filtering, false otherwise.

Definition at line 115 of file FilterStream.cxx.

115 {
116 ERS_CHECK_PTR(issue_ptr);
117 std::string qualifiers = issue_ptr->get_value(ers::Issue::QUALIFIER_LIST_KEY) ;
118 if (! qualifiers.empty()) { // we check if qualifiers are in exclude list
119 std::vector<std::string>::const_iterator e_pos ;
120 for(e_pos = m_exclude.begin();e_pos!=m_exclude.end();e_pos++) {
121 std::string::size_type conflict = qualifiers.find(*e_pos) ;
122 if (conflict!=std::string::npos) {
123 return false ;
124 } // found conflict
125 } // for
126 } // there are some qualifiers
127 if (! m_include.empty()) {
128 std::vector<std::string>::const_iterator i_pos ;
129 for(i_pos = m_include.begin();i_pos!=m_include.end();i_pos++) {
130 std::string::size_type match = qualifiers.find(*i_pos) ;
131 if (match!=std::string::npos) {
132 return true ;
133 } // found match
134 } // for
135 return false ;
136 } // include list contains items
137 return true ;
138} // is_accept
static const char *const QUALIFIER_LIST_KEY
key used to store the qualifier list

◆ print_to()

void ers::FilterStream::print_to ( std::ostream &  stream) const
virtual

Prints stream description to stream

Parameters
streamSTL target stream

Reimplemented from ers::Stream.

Definition at line 162 of file FilterStream.cxx.

162 {
163 stream << FILTER_STREAM_TAG << ':' ;
164 std::vector<std::string>::const_iterator i_pos ;
165 stream << INCLUDE_TAG ;
166 for(i_pos = m_include.begin();i_pos!=m_include.end();i_pos++) {
167 if (i_pos!=m_include.begin()) {
168 stream << SEPARATORS ;
169 } // if not first
170 stream << *i_pos ;
171 } // for include
172 stream << EXCLUDE_TAG ;
173 std::vector<std::string>::const_iterator e_pos ;
174 for(e_pos = m_exclude.begin();e_pos!=m_exclude.end();e_pos++) {
175 if (e_pos!=m_exclude.begin()) {
176 stream << SEPARATORS ;
177 } // if not first
178 stream << *e_pos ;
179 } // for exclude
180 stream << TARGET_TAG ;
181 stream << *m_target_stream_ptr ;
182} // print_to
static const char *const FILTER_STREAM_TAG
tag used to identity this stream
Definition: FilterStream.h:46

◆ send()

void ers::FilterStream::send ( const Issue issue_ptr)
virtual

send method

Send method basically calls is_accept to check if the issue is accepted. If this is the case, the send method on the target is called with issue_ptr.

Parameters
issue_ptrpointer to the issue to send.

Reimplemented from ers::Stream.

Definition at line 147 of file FilterStream.cxx.

147 {
148 ERS_CHECK_PTR(issue_ptr);
150 if (is_accept(issue_ptr)) {
151 // ERS_DEBUG_3("accepted %s:",issue_ptr->what());
152 m_target_stream_ptr->send(issue_ptr);
153 } else {
154 // ERS_DEBUG_3("rejected %s:",issue_ptr->what());
155 }
156} // send
virtual bool is_accept(const Issue *issue_ptr)
filter method
virtual void send(const Issue *i)
Sends an issue into the stream.
Definition: Stream.cxx:46

Member Data Documentation

◆ EXCLUDE_TAG

const char *const ers::FilterStream::EXCLUDE_TAG = "!"
static

tag used to mark the start of the exclude list

Definition at line 48 of file FilterStream.h.

◆ FILTER_STREAM_TAG

const char *const ers::FilterStream::FILTER_STREAM_TAG = "filter"
static

tag used to identity this stream

Tag used to identify the stream

Definition at line 46 of file FilterStream.h.

◆ INCLUDE_TAG

const char *const ers::FilterStream::INCLUDE_TAG = "?"
static

tag used to mark the start of the include list

Definition at line 47 of file FilterStream.h.

◆ m_exclude

std::vector<std::string> ers::FilterStream::m_exclude
protected

exclude list

Definition at line 42 of file FilterStream.h.

Referenced by FilterStream().

◆ m_include

std::vector<std::string> ers::FilterStream::m_include
protected

include list

Definition at line 41 of file FilterStream.h.

Referenced by FilterStream().

◆ m_target_stream_ptr

Stream* ers::FilterStream::m_target_stream_ptr
protected

chained target stream

Definition at line 40 of file FilterStream.h.

Referenced by FilterStream().

◆ SEPARATORS

const char *const ers::FilterStream::SEPARATORS = ","
static

separators between include and exclude qualifiers

Definition at line 50 of file FilterStream.h.

Referenced by factory().

◆ TARGET_TAG

const char *const ers::FilterStream::TARGET_TAG = "@"
static

tag used to mark the target stream

Definition at line 49 of file FilterStream.h.


The documentation for this class was generated from the following files: