CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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.2 2009/07/09 10:47:23 gpetrucc 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 
00014 template<typename T, bool DefaultLazyness=false>
00015 struct StringObjectFunction {
00016   StringObjectFunction(const std::string & expr, bool lazy=DefaultLazyness) : 
00017     type_(Reflex::Type::ByTypeInfo(typeid(T))) {
00018     if(! reco::parser::expressionParser<T>(expr, expr_, lazy)) {
00019       throw edm::Exception(edm::errors::Configuration,
00020                            "failed to parse \"" + expr + "\"");
00021     }
00022   }
00023   StringObjectFunction(const reco::parser::ExpressionPtr & expr) : 
00024     expr_(expr),
00025     type_(Reflex::Type::ByTypeInfo(typeid(T))) {
00026   }
00027   double operator()(const T & t) const {
00028     using namespace Reflex;
00029     Object o(type_, const_cast<T *>(& t));
00030     return expr_->value(o);  
00031   }
00032 
00033 private:
00034   reco::parser::ExpressionPtr expr_;
00035   Reflex::Type type_;
00036 };
00037 
00038 #endif