CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CommonTools/Utils/interface/StringObjectFunction.h

Go to the documentation of this file.
00001 #ifndef CommonTools_Utils_StringObjectFunction_h
00002 #define CommonTools_Utils_StringObjectFunction_h
00003 /* \class StringCutObjectSelector
00004  *
00005  * \author Luca Lista, INFN
00006  *
00007  * $Id: StringObjectFunction.h,v 1.3 2011/12/05 16:02:30 eulisse Exp $
00008  */
00009 #include "FWCore/Utilities/interface/EDMException.h"
00010 #include "CommonTools/Utils/src/ExpressionPtr.h"
00011 #include "CommonTools/Utils/src/ExpressionBase.h"
00012 #include "CommonTools/Utils/interface/expressionParser.h"
00013 #include "Reflex/Object.h"
00014 
00015 template<typename T, bool DefaultLazyness=false>
00016 struct StringObjectFunction {
00017   StringObjectFunction(const std::string & expr, bool lazy=DefaultLazyness) : 
00018     type_(Reflex::Type::ByTypeInfo(typeid(T))) {
00019     if(! reco::parser::expressionParser<T>(expr, expr_, lazy)) {
00020       throw edm::Exception(edm::errors::Configuration,
00021                            "failed to parse \"" + expr + "\"");
00022     }
00023   }
00024   StringObjectFunction(const reco::parser::ExpressionPtr & expr) : 
00025     expr_(expr),
00026     type_(Reflex::Type::ByTypeInfo(typeid(T))) {
00027   }
00028   double operator()(const T & t) const {
00029     using namespace Reflex;
00030     Object o(type_, const_cast<T *>(& t));
00031     return expr_->value(o);  
00032   }
00033 
00034 private:
00035   reco::parser::ExpressionPtr expr_;
00036   Reflex::Type type_;
00037 };
00038 
00039 #endif