Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-31 02:19:21

0001 #ifndef FWCore_Framework_ProductSelectorRules_h
0002 #define FWCore_Framework_ProductSelectorRules_h
0003 
0004 //////////////////////////////////////////////////////////////////////
0005 //
0006 // Class ProductSelectorRules. Class for rules to select specific products in event.
0007 //
0008 // Author: Bill Tanenbaum, Marc Paterno
0009 //
0010 //////////////////////////////////////////////////////////////////////
0011 
0012 #include <iosfwd>
0013 #include <string>
0014 #include <vector>
0015 
0016 #include <regex>
0017 #include "DataFormats/Provenance/interface/ProductDescriptionFwd.h"
0018 
0019 namespace edm {
0020   class ProductSelector;
0021   class ParameterSet;
0022   class ParameterSetDescription;
0023 
0024   class ProductSelectorRules {
0025   public:
0026     ProductSelectorRules(ParameterSet const& pset,
0027                          std::string const& parameterName,
0028                          std::string const& parameterOwnerName);
0029     //--------------------------------------------------
0030     // BranchSelectState is a struct which associates a ProductDescription
0031     // (*desc) with a bool indicating whether or not the branch with
0032     // that name is to be selected.  Note that desc may not be null.
0033     struct BranchSelectState {
0034       edm::ProductDescription const* desc;
0035       bool selectMe;
0036 
0037       // N.B.: We assume bd is not null.
0038       explicit BranchSelectState(edm::ProductDescription const* bd) : desc(bd), selectMe(false) {}
0039     };
0040 
0041     bool select(edm::ProductDescription const& bd) const;
0042     void applyToAll(std::vector<BranchSelectState>& branchstates) const;
0043 
0044     bool keepAll() const { return keepAll_; }
0045 
0046     static void fillDescription(ParameterSetDescription& desc,
0047                                 char const* parameterName,
0048                                 std::vector<std::string> const& defaultStrings = defaultSelectionStrings());
0049 
0050     static const std::vector<std::string>& defaultSelectionStrings();
0051 
0052   private:
0053     class Rule {
0054     public:
0055       Rule(std::string const& s, std::string const& parameterName, std::string const& owner);
0056 
0057       // Apply the rule to all the given branch states. This may modify
0058       // the given branch states.
0059       void applyToAll(std::vector<BranchSelectState>& branchstates) const;
0060 
0061       // Apply the rule to the given ProductDescription. The return value
0062       // is the value to which the 'select bit' should be set, according
0063       // to application of this rule.
0064       //bool applyToOne(ProductDescription const* branch) const;
0065 
0066       // If this rule applies to the given ProductDescription, then
0067       // modify 'result' to match the rule's select flag. If the rule does
0068       // not apply, do not modify 'result'.
0069       void applyToOne(ProductDescription const* branch, bool& result) const;
0070 
0071       // Return the answer to the question: "Does the rule apply to this
0072       // ProductDescription?"
0073       bool appliesTo(ProductDescription const* branch) const;
0074 
0075     private:
0076       // selectflag_ carries the value to which we should set the 'select
0077       // bit' if this rule matches.
0078       bool selectflag_;
0079       std::regex productType_;
0080       std::regex moduleLabel_;
0081       std::regex instanceName_;
0082       std::regex processName_;
0083     };
0084 
0085   private:
0086     std::vector<Rule> rules_;
0087     std::string parameterName_;
0088     std::string parameterOwnerName_;
0089     bool keepAll_;
0090   };
0091 
0092 }  // namespace edm
0093 
0094 #endif