File indexing completed on 2024-04-06 12:01:18
0001 #ifndef CommonTools_Utils_StringCutObjectSelector_h
0002 #define CommonTools_Utils_StringCutObjectSelector_h
0003
0004
0005
0006
0007
0008
0009 #include "FWCore/Utilities/interface/EDMException.h"
0010 #include "CommonTools/Utils/interface/parser/SelectorPtr.h"
0011 #include "CommonTools/Utils/interface/parser/SelectorBase.h"
0012 #include "CommonTools/Utils/interface/cutParser.h"
0013 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0014
0015 template <typename T, bool DefaultLazyness = false>
0016 struct StringCutObjectSelector {
0017 StringCutObjectSelector(const std::string &cut, bool lazy = DefaultLazyness) : type_(typeid(T)) {
0018 if (!reco::parser::cutParser<T>(cut, select_, lazy)) {
0019 throw edm::Exception(edm::errors::Configuration, "failed to parse \"" + cut + "\"");
0020 }
0021 }
0022 StringCutObjectSelector(const reco::parser::SelectorPtr &select) : select_(select), type_(typeid(T)) {}
0023 bool operator()(const T &t) const {
0024 edm::ObjectWithDict o(type_, const_cast<T *>(&t));
0025 return (*select_)(o);
0026 }
0027
0028 private:
0029 reco::parser::SelectorPtr select_;
0030 edm::TypeWithDict type_;
0031 };
0032
0033 #endif