ATLAS Offline Software
TreeFilter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
7 
8 #include <iostream>
9 #include <regex>
10 #include <sstream>
11 #include <iterator>
12 
13 namespace top {
14 
16 
17  TreeFilter::TreeFilter(const std::string& longstring){
18  init(longstring);
19  }
20 
21  void TreeFilter::init(const std::string& longstring){
22  std::vector<std::string> helpvec_str;
23  tokenize(longstring, helpvec_str, ",");
24 
25  m_vecFilters.clear();
26  for (const std::string& x : helpvec_str) {
27  std::istringstream isstr(x);
28  std::copy(std::istream_iterator<std::string>(isstr),
29  std::istream_iterator<std::string>(), std::back_inserter(m_vecFilters));
30  }
31 
32  for (std::string& filter : m_vecFilters) {
33  // replace "*" with ".*"
34  filter = regex_replace(filter, std::regex("\\*"), ".*");
35  }
36 
37 
38  }
39 
40  bool TreeFilter::filterTree(const std::string& treename) const{
41 
42  for (const std::string& filter : m_vecFilters) {
43  // check for a match
44  std::smatch match;
45  std::regex_search(treename, match, std::regex("^"+filter));
46  if (!match.empty()) return false;
47  }
48 
49 
50  return true;
51  }
52 
53 
54 }
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
TreeFilter.h
top::tokenize
void tokenize(const std::string &input, Container &output, const std::string &delimiters=" ", bool trim_empty=false)
Tokenize an input string using a set of delimiters.
Definition: Tokenize.h:24
x
#define x
covarianceTool.filter
filter
Definition: covarianceTool.py:514
PrepareReferenceFile.regex
regex
Definition: PrepareReferenceFile.py:43
top::TreeFilter::init
void init(const std::string &longstring)
Definition: TreeFilter.cxx:21
top::TreeFilter::m_vecFilters
std::vector< std::string > m_vecFilters
Definition: TreeFilter.h:15
top::TreeFilter::TreeFilter
TreeFilter()
Definition: TreeFilter.cxx:15
Tokenize.h
calibdata.copy
bool copy
Definition: calibdata.py:27
top::TreeFilter::filterTree
bool filterTree(const std::string &treename) const
Definition: TreeFilter.cxx:40
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356