3434#include < boost/algorithm/string/replace.hpp>
3535
3636#include " DataFormats/Provenance/interface/ProductDescription.h"
37+ #include " DataFormats/Provenance/interface/ProductNamePattern.h"
3738#include " FWCore/Framework/interface/global/EDAnalyzer.h"
3839#include " FWCore/MessageLogger/interface/MessageLogger.h"
3940#include " FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
4041#include " FWCore/ParameterSet/interface/ParameterDescriptionNode.h"
4142#include " FWCore/ParameterSet/interface/ParameterSet.h"
4243#include " FWCore/ParameterSet/interface/ParameterSetDescription.h"
4344
44- namespace {
45- struct ProductBranch {
46- public:
47- ProductBranch (std::string const & label) {
48- static const char kSeparator = ' _' ;
49- static const char kWildcard = ' *' ;
50- static const std::regex kAny {" .*" };
51-
52- // wildcard
53- if (label == kWildcard ) {
54- type_ = kAny ;
55- moduleLabel_ = kAny ;
56- productInstanceName_ = kAny ;
57- processName_ = kAny ;
58- return ;
59- }
60-
61- int fields = std::count (label.begin (), label.end (), kSeparator ) + 1 ;
62- if (fields == 1 ) {
63- // convert the module label into a regular expression
64- type_ = kAny ;
65- moduleLabel_ = glob_to_regex (label);
66- productInstanceName_ = kAny ;
67- processName_ = kAny ;
68- } else if (fields == 4 ) {
69- // split the branch name into <product type>_<module label>_<instance name>_<process name>
70- // and convert the glob expressions into regular expressions
71- size_t first = 0 , last = 0 ;
72- last = label.find (kSeparator , first);
73- type_ = glob_to_regex (label.substr (first, last - first));
74- first = last + 1 ;
75- last = label.find (kSeparator , first);
76- moduleLabel_ = glob_to_regex (label.substr (first, last - first));
77- first = last + 1 ;
78- last = label.find (kSeparator , first);
79- productInstanceName_ = glob_to_regex (label.substr (first, last - first));
80- first = last + 1 ;
81- last = label.find (kSeparator , first);
82- processName_ = glob_to_regex (label.substr (first, last - first));
83- } else {
84- // invalid input
85- throw edm::Exception (edm::errors::Configuration) << " Invalid module label or branch name: \" " << label << " \" " ;
86- }
87- }
88-
89- bool match (edm::ProductDescription const & branch) const {
90- return (std::regex_match (branch.friendlyClassName (), type_) and
91- std::regex_match (branch.moduleLabel (), moduleLabel_) and
92- std::regex_match (branch.productInstanceName (), productInstanceName_) and
93- std::regex_match (branch.processName (), processName_));
94- }
95-
96- private:
97- static std::regex glob_to_regex (std::string pattern) {
98- boost::replace_all (pattern, " *" , " .*" );
99- boost::replace_all (pattern, " ?" , " ." );
100- return std::regex (pattern);
101- }
102-
103- std::regex type_;
104- std::regex moduleLabel_;
105- std::regex productInstanceName_;
106- std::regex processName_;
107- };
108-
109- std::vector<ProductBranch> make_patterns (std::vector<std::string> const & labels) {
110- std::vector<ProductBranch> patterns;
111- patterns.reserve (labels.size ());
112- for (auto const & label : labels)
113- patterns.emplace_back (label);
114- return patterns;
115- }
116- } // namespace
117-
11845namespace edm {
11946 class GenericConsumer : public edm ::global::EDAnalyzer<> {
12047 public:
@@ -126,19 +53,20 @@ namespace edm {
12653 static void fillDescriptions (ConfigurationDescriptions& descriptions);
12754
12855 private:
129- std::vector<ProductBranch > eventProducts_;
130- std::vector<ProductBranch > lumiProducts_;
131- std::vector<ProductBranch > runProducts_;
132- std::vector<ProductBranch > processProducts_;
56+ std::vector<edm::ProductNamePattern > eventProducts_;
57+ std::vector<edm::ProductNamePattern > lumiProducts_;
58+ std::vector<edm::ProductNamePattern > runProducts_;
59+ std::vector<edm::ProductNamePattern > processProducts_;
13360 std::string label_;
13461 bool verbose_;
13562 };
13663
13764 GenericConsumer::GenericConsumer (ParameterSet const & config)
138- : eventProducts_(make_patterns(config.getUntrackedParameter<std::vector<std::string>>(" eventProducts" ))),
139- lumiProducts_ (make_patterns(config.getUntrackedParameter<std::vector<std::string>>(" lumiProducts" ))),
140- runProducts_(make_patterns(config.getUntrackedParameter<std::vector<std::string>>(" runProducts" ))),
141- processProducts_(make_patterns(config.getUntrackedParameter<std::vector<std::string>>(" processProducts" ))),
65+ : eventProducts_(edm::productPatterns(config.getUntrackedParameter<std::vector<std::string>>(" eventProducts" ))),
66+ lumiProducts_ (edm::productPatterns(config.getUntrackedParameter<std::vector<std::string>>(" lumiProducts" ))),
67+ runProducts_(edm::productPatterns(config.getUntrackedParameter<std::vector<std::string>>(" runProducts" ))),
68+ processProducts_(
69+ edm::productPatterns (config.getUntrackedParameter<std::vector<std::string>>(" processProducts" ))),
14270 label_(config.getParameter<std::string>(" @module_label" )),
14371 verbose_(config.getUntrackedParameter<bool >(" verbose" )) {
14472 callWhenNewProductsRegistered ([this ](edm::ProductDescription const & branch) {
0 commit comments