Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:33:18

0001 #include "CommonTools/Utils/interface/ExpressionEvaluator.h"
0002 #include "CommonTools/Utils/interface/ExpressionEvaluatorTemplates.h"
0003 
0004 #include "PhysicsTools/SelectorUtils/interface/CutApplicatorWithEventContentBase.h"
0005 
0006 class ExpressionEvaluatorCutWithEventContent : public CutApplicatorWithEventContentBase {
0007 public:
0008   ExpressionEvaluatorCutWithEventContent(const edm::ParameterSet& c);
0009   ~ExpressionEvaluatorCutWithEventContent() override{};
0010 
0011   result_type asCandidate(const argument_type& cand) const final { return (*cut_)(cand); }
0012 
0013   void setConsumes(edm::ConsumesCollector& sumes) final { cut_->setConsumes(sumes); }
0014 
0015   void getEventContent(const edm::EventBase& event) final { cut_->getEventContent(event); }
0016 
0017   double value(const reco::CandidatePtr& cand) const final { return cut_->value(cand); }
0018 
0019   const std::string& name() const final { return realname_; }
0020 
0021 private:
0022   const std::string realname_;
0023   CutApplicatorWithEventContentBase* cut_;
0024 };
0025 
0026 ExpressionEvaluatorCutWithEventContent::ExpressionEvaluatorCutWithEventContent(const edm::ParameterSet& c)
0027     : CutApplicatorWithEventContentBase(c), realname_(c.getParameter<std::string>("realCutName")) {
0028   const std::string newline("\n");
0029   const std::string close_function("; };");
0030   const std::string candTypePreamble("CandidateType candidateType() const override final { return ");
0031 
0032   //construct the overload of candidateType()
0033   const std::string& candType = c.getParameter<std::string>("candidateType");
0034   const std::string candTypeExpr = candTypePreamble + candType + close_function;
0035 
0036   // read in the overload of operator()
0037   const std::string& oprExpr = c.getParameter<std::string>("functionDef");
0038 
0039   // read in the overload of value()
0040   const std::string& valExpr = c.getParameter<std::string>("valueDef");
0041 
0042   // read in the overload of setConsumes()
0043   const std::string& setConsumesExpr = c.getParameter<std::string>("setConsumesDef");
0044 
0045   // read in the overload of getEventContent()
0046   const std::string& getEventContentExpr = c.getParameter<std::string>("getEventContentDef");
0047 
0048   // concatenate and evaluate the expression
0049   const std::string total_expr = (candTypeExpr + newline + oprExpr + newline + valExpr + newline + setConsumesExpr +
0050                                   newline + getEventContentExpr);
0051   reco::ExpressionEvaluator eval("PhysicsTools/SelectorUtils", "CutApplicatorWithEventContentBase", total_expr);
0052   cut_ = eval.expr<CutApplicatorWithEventContentBase>();
0053 }
0054 
0055 DEFINE_EDM_PLUGIN(CutApplicatorFactory,
0056                   ExpressionEvaluatorCutWithEventContent,
0057                   "ExpressionEvaluatorCutWithEventContent");