Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:02:06

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 
0018 namespace edm {
0019   class BranchDescription;
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 BranchDescription
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::BranchDescription const* desc;
0035       bool selectMe;
0036 
0037       // N.B.: We assume bd is not null.
0038       explicit BranchSelectState(edm::BranchDescription const* bd) : desc(bd), selectMe(false) {}
0039     };
0040 
0041     void applyToAll(std::vector<BranchSelectState>& branchstates) const;
0042 
0043     bool keepAll() const { return keepAll_; }
0044 
0045     static void fillDescription(ParameterSetDescription& desc,
0046                                 char const* parameterName,
0047                                 std::vector<std::string> const& defaultStrings = defaultSelectionStrings());
0048 
0049     static const std::vector<std::string>& defaultSelectionStrings();
0050 
0051   private:
0052     class Rule {
0053     public:
0054       Rule(std::string const& s, std::string const& parameterName, std::string const& owner);
0055 
0056       // Apply the rule to all the given branch states. This may modify
0057       // the given branch states.
0058       void applyToAll(std::vector<BranchSelectState>& branchstates) const;
0059 
0060       // Apply the rule to the given BranchDescription. The return value
0061       // is the value to which the 'select bit' should be set, according
0062       // to application of this rule.
0063       //bool applyToOne(BranchDescription const* branch) const;
0064 
0065       // If this rule applies to the given BranchDescription, then
0066       // modify 'result' to match the rule's select flag. If the rule does
0067       // not apply, do not modify 'result'.
0068       void applyToOne(BranchDescription const* branch, bool& result) const;
0069 
0070       // Return the answer to the question: "Does the rule apply to this
0071       // BranchDescription?"
0072       bool appliesTo(BranchDescription const* branch) const;
0073 
0074     private:
0075       // selectflag_ carries the value to which we should set the 'select
0076       // bit' if this rule matches.
0077       bool selectflag_;
0078       std::regex productType_;
0079       std::regex moduleLabel_;
0080       std::regex instanceName_;
0081       std::regex processName_;
0082     };
0083 
0084   private:
0085     std::vector<Rule> rules_;
0086     std::string parameterName_;
0087     std::string parameterOwnerName_;
0088     bool keepAll_;
0089   };
0090 
0091 }  // namespace edm
0092 
0093 #endif