CMS 3D CMS Logo

StringObjectFunction.h

Go to the documentation of this file.
00001 #ifndef Utilities_StringObjectFunction_h
00002 #define Utilities_StringObjectFunction_h
00003 /* \class StringCutObjectSelector
00004  *
00005  * \author Luca Lista, INFN
00006  *
00007  * $Id: StringObjectFunction.h,v 1.2 2007/12/19 10:26:37 llista Exp $
00008  */
00009 #include "FWCore/Utilities/interface/EDMException.h"
00010 #include "PhysicsTools/Utilities/src/ExpressionPtr.h"
00011 #include "PhysicsTools/Utilities/src/ExpressionBase.h"
00012 #include "PhysicsTools/Utilities/interface/expressionParser.h"
00013 
00014 template<typename T>
00015 struct StringObjectFunction {
00016   StringObjectFunction(const std::string & expr) : 
00017     type_(ROOT::Reflex::Type::ByTypeInfo(typeid(T))) {
00018     if(! reco::parser::expressionParser<T>(expr, expr_)) {
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_(ROOT::Reflex::Type::ByTypeInfo(typeid(T))) {
00026   }
00027   double operator()(const T & t) const {
00028     using namespace ROOT::Reflex;
00029     Object o(type_, const_cast<T *>(& t));
00030     return expr_->value(o);  
00031   }
00032 
00033 private:
00034   reco::parser::ExpressionPtr expr_;
00035   ROOT::Reflex::Type type_;
00036 };
00037 
00038 #endif

Generated on Tue Jun 9 17:42:51 2009 for CMSSW by  doxygen 1.5.4