Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-17 23:10:25

0001 #ifndef CommonTools_Utils_ExpressionVar_h
0002 #define CommonTools_Utils_ExpressionVar_h
0003 
0004 /* \class reco::parser::ExpressionVar
0005  *
0006  * Variable expression
0007  *
0008  * \author original version: Chris Jones, Cornell,
0009  *         adapted by Luca Lista, INFN
0010  *
0011  */
0012 
0013 #include "CommonTools/Utils/interface/ExpressionBase.h"
0014 #include "CommonTools/Utils/interface/MethodInvoker.h"
0015 #include "CommonTools/Utils/interface/TypeCode.h"
0016 
0017 #include <vector>
0018 
0019 namespace reco {
0020   namespace parser {
0021 
0022     /// Evaluate an object's method or datamember (or chain of them) to get a number
0023     class ExpressionVar : public ExpressionBase {
0024     private:  // Private Data Members
0025       std::vector<MethodInvoker> methods_;
0026       mutable std::vector<edm::ObjectWithDict> objects_;
0027       mutable std::vector<bool> needsDestructor_;
0028       method::TypeCode retType_;
0029 
0030     private:  // Private Methods
0031       void initObjects_();
0032 
0033     public:  // Public Static Methods
0034       static bool isValidReturnType(method::TypeCode);
0035 
0036       /// performs the needed conversion from void* to double
0037       /// this method is used also from the ExpressionLazyVar code
0038       static double objToDouble(const edm::ObjectWithDict& obj, method::TypeCode type);
0039 
0040       /// allocate an object to hold the result of a given member (if needed)
0041       /// this method is used also from the LazyInvoker code
0042       /// returns true if objects returned from this will require a destructor
0043       static bool makeStorage(edm::ObjectWithDict& obj, const edm::TypeWithDict& retType);
0044 
0045       /// delete an objecty, if needed
0046       /// this method is used also from the LazyInvoker code
0047       static void delStorage(edm::ObjectWithDict&);
0048 
0049     public:  // Public Methods
0050       ExpressionVar(const std::vector<MethodInvoker>& methods, method::TypeCode retType);
0051       ExpressionVar(const ExpressionVar&);
0052       ~ExpressionVar() override;
0053       double value(const edm::ObjectWithDict&) const override;
0054     };
0055 
0056     /// Same as ExpressionVar but with lazy resolution of object methods
0057     /// using the dynamic type of the object, and not the one fixed at compile time
0058     class ExpressionLazyVar : public ExpressionBase {
0059     private:  // Private Data Members
0060       std::vector<LazyInvoker> methods_;
0061       mutable std::vector<edm::ObjectWithDict> objects_;
0062 
0063     public:
0064       ExpressionLazyVar(const std::vector<LazyInvoker>& methods);
0065       ~ExpressionLazyVar() override;
0066       double value(const edm::ObjectWithDict&) const override;
0067     };
0068 
0069   }  // namespace parser
0070 }  // namespace reco
0071 
0072 #endif  // CommonTools_Utils_ExpressionVar_h