Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:24

0001 #ifndef PerformancePayloadFromTFormula_h
0002 #define PerformancePayloadFromTFormula_h
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include "CondFormats/PhysicsToolsObjects/interface/PhysicsTFormulaPayload.h"
0007 #include "CondFormats/PhysicsToolsObjects/interface/PerformancePayload.h"
0008 
0009 #include <algorithm>
0010 #include <string>
0011 #include <vector>
0012 #include <memory>
0013 #include <iostream>
0014 #include "TFormula.h"
0015 #include "CondFormats/PhysicsToolsObjects/interface/BinningPointByMap.h"
0016 
0017 class PerformancePayloadFromTFormula : public PerformancePayload {
0018   //  class PerformancePayloadFromTFormula : public PerformancePayload, public PhysicsPerformancePayload {
0019 public:
0020   static const int InvalidPos;
0021 
0022   PerformancePayloadFromTFormula(const std::vector<PerformanceResult::ResultType>& r,
0023                                  const std::vector<BinningVariables::BinningVariablesType>& b,
0024                                  PhysicsTFormulaPayload& in)
0025       : pl(in), results_(r), variables_(b) {
0026     initialize();
0027   }
0028 
0029   PerformancePayloadFromTFormula() {}
0030 
0031   void initialize() override;
0032 
0033   PerformancePayloadFromTFormula(const PerformancePayloadFromTFormula& b)
0034       : pl(b.pl), results_(b.results_), variables_(b.variables_), compiledFormulas_(b.compiledFormulas_) {}
0035 
0036   ~PerformancePayloadFromTFormula() override { compiledFormulas_.clear(); }
0037 
0038   float getResult(PerformanceResult::ResultType,
0039                   const BinningPointByMap&) const override;  // gets from the full payload
0040 
0041   virtual bool isParametrizedInVariable(const BinningVariables::BinningVariablesType p) const {
0042     return (limitPos(p) != PerformancePayloadFromTFormula::InvalidPos);
0043   }
0044 
0045   bool isInPayload(PerformanceResult::ResultType, const BinningPointByMap&) const override;
0046 
0047   const PhysicsTFormulaPayload& formulaPayload() const { return pl; }
0048 
0049   void printFormula(PerformanceResult::ResultType res) const;
0050 
0051 protected:
0052   virtual std::vector<BinningVariables::BinningVariablesType> myBinning() const { return variables_; }
0053 
0054   virtual int limitPos(const BinningVariables::BinningVariablesType b) const {
0055     std::vector<BinningVariables::BinningVariablesType>::const_iterator p;
0056     p = find(variables_.begin(), variables_.end(), b);
0057     if (p == variables_.end())
0058       return PerformancePayloadFromTFormula::InvalidPos;
0059     return ((p - variables_.begin()));
0060   }
0061 
0062   virtual int resultPos(PerformanceResult::ResultType r) const {
0063     std::vector<PerformanceResult::ResultType>::const_iterator p;
0064     p = find(results_.begin(), results_.end(), r);
0065     if (p == results_.end())
0066       return PerformancePayloadFromTFormula::InvalidPos;
0067     return ((p - results_.begin()));
0068   }
0069 
0070   bool isOk(const BinningPointByMap& p) const;
0071 
0072   PhysicsTFormulaPayload pl;
0073   //
0074   // the variable mapping
0075   //
0076   std::vector<PerformanceResult::ResultType> results_;
0077   std::vector<BinningVariables::BinningVariablesType> variables_;
0078   //
0079   // the transient part
0080   //
0081   std::vector<std::shared_ptr<const TFormula> > compiledFormulas_ COND_TRANSIENT;
0082 
0083   COND_SERIALIZABLE;
0084 };
0085 
0086 #endif