All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
util::RegexDataProductSelector Class Reference

Matches products by regex on process, module label and instance name. More...

#include <ArtDataProductSelectors.h>

Inheritance diagram for util::RegexDataProductSelector:

Classes

struct  ProductRegex
 A pattern on a input tag (empty matches everything). More...
 

Public Member Functions

 RegexDataProductSelector (std::vector< ProductRegex > patterns)
 Initializes the selector with all the supported patterns. More...
 
template<typename SpecColl >
auto makePatterns (SpecColl const &specs) -> std::vector< ProductRegex >
 

Static Public Member Functions

static ProductRegex makePattern (art::InputTag const &spec)
 Parses a input tag to create a single data product pattern. More...
 
template<typename SpecColl >
static std::vector< ProductRegexmakePatterns (SpecColl const &specs)
 Parses a sequence of input tags to create data product patterns. More...
 

Private Member Functions

virtual bool doMatch (art::BranchDescription const &brDescr) const override
 Returns whether data product described by brDescr matches. More...
 
virtual std::string doPrint (std::string const &indent) const override
 Part of the message used when no data product matches. More...
 
bool matchPattern (art::InputTag const &tag, ProductRegex const &ptn) const
 Returns whether the input tag matches the pattern ptn. More...
 

Private Attributes

std::vector< ProductRegexfPatterns
 All the selection patterns. More...
 

Detailed Description

Matches products by regex on process, module label and instance name.

A pattern is matched if all specified subpatterns (process, module, instance) match. Any component of the pattern may be unspecified. A product is selected if it matches any of the configured patterns.

Patterns are matched with std::regex_match(), i.e. the whole string must match.

The patterns may be created from one or a sequence of input-tag-like objects using makePattern() and makePatterns() static functions, respectively.

Definition at line 38 of file ArtDataProductSelectors.h.

Constructor & Destructor Documentation

util::RegexDataProductSelector::RegexDataProductSelector ( std::vector< ProductRegex patterns)

Initializes the selector with all the supported patterns.

Definition at line 24 of file ArtDataProductSelectors.cxx.

25  : fPatterns(std::move(patterns))
26 {}
std::vector< ProductRegex > fPatterns
All the selection patterns.

Member Function Documentation

bool util::RegexDataProductSelector::doMatch ( art::BranchDescription const &  brDescr) const
overrideprivatevirtual

Returns whether data product described by brDescr matches.

Definition at line 48 of file ArtDataProductSelectors.cxx.

49 {
50  art::InputTag const& tag = brDescr.inputTag();
51  for (ProductRegex const& pattern: fPatterns)
52  if (matchPattern(tag, pattern)) return true;
53  return false;
54 } // util::RegexDataProductSelector::doMatch()
std::vector< ProductRegex > fPatterns
All the selection patterns.
bool matchPattern(art::InputTag const &tag, ProductRegex const &ptn) const
Returns whether the input tag matches the pattern ptn.
std::string util::RegexDataProductSelector::doPrint ( std::string const &  indent) const
overrideprivatevirtual

Part of the message used when no data product matches.

Definition at line 59 of file ArtDataProductSelectors.cxx.

60 {
61  return indent
62  + "any of " + std::to_string(fPatterns.size()) + " patterns";
63 } // util::RegexDataProductSelector::doPrint()
std::vector< ProductRegex > fPatterns
All the selection patterns.
std::string to_string(WindowPattern const &pattern)
auto util::RegexDataProductSelector::makePattern ( art::InputTag const &  spec)
static

Parses a input tag to create a single data product pattern.

Parameters
specpattern specification
Returns
a pattern object

A specification is in the form of an art::InputTag, but each element is a regex pattern rather than a standard name.

If the input tag is created from a string, in the usual form <processName>:<moduleLabel>:<instanceName> (with the usual omissions), each element can't contain a : character (no escaping is supported).

An empty tag matches everything.

Definition at line 31 of file ArtDataProductSelectors.cxx.

32 {
33 
34  auto const regexIfNotEmpty = [](std::string const& ptn)
35  { return ptn.empty()? std::nullopt: std::optional{ std::regex{ ptn }}; };
36 
37  return {
38  regexIfNotEmpty(spec.process()) // process
39  , regexIfNotEmpty(spec.label()) // module
40  , regexIfNotEmpty(spec.instance()) // instance
41  };
42 
43 } // util::RegexDataProductSelector::makePattern()
template<typename SpecColl >
static std::vector<ProductRegex> util::RegexDataProductSelector::makePatterns ( SpecColl const &  specs)
static

Parses a sequence of input tags to create data product patterns.

Template Parameters
SpecColltype of collection of specifications
Parameters
specssequence of pattern specifications
Returns
a sequence of pattern objects, one per input specification

Each specification in specs is converted into a pattern via makePattern(). The specification is explicitly converted into an input tag.

template<typename SpecColl >
auto util::RegexDataProductSelector::makePatterns ( SpecColl const &  specs) -> std::vector<ProductRegex>

Definition at line 106 of file ArtDataProductSelectors.h.

107 {
108  using std::size;
109  std::vector<ProductRegex> ptns;
110  ptns.reserve(size(specs));
111  for (auto const& spec: specs)
112  ptns.push_back(makePattern(art::InputTag{ spec }));
113  return ptns;
114 } // util::RegexDataProductSelector::makePatterns()
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
static ProductRegex makePattern(art::InputTag const &spec)
Parses a input tag to create a single data product pattern.
bool util::RegexDataProductSelector::matchPattern ( art::InputTag const &  tag,
ProductRegex const &  ptn 
) const
private

Returns whether the input tag matches the pattern ptn.

Definition at line 68 of file ArtDataProductSelectors.cxx.

69 {
70  if (ptn.process && !std::regex_match(tag.process(), *(ptn.process) ))
71  return false;
72  if (ptn.module && !std::regex_match(tag.label(), *(ptn.module) ))
73  return false;
74  if (ptn.instance && !std::regex_match(tag.instance(), *(ptn.instance)))
75  return false;
76  return true;
77 } // util::RegexDataProductSelector::matchPattern()

Member Data Documentation

std::vector<ProductRegex> util::RegexDataProductSelector::fPatterns
private

All the selection patterns.

Definition at line 84 of file ArtDataProductSelectors.h.


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