CMS 3D CMS Logo

MethodInvoker.h
Go to the documentation of this file.
1 #ifndef CommonTools_Utils_MethodInvoker_h
2 #define CommonTools_Utils_MethodInvoker_h
3 
10 
11 #include <boost/utility.hpp>
12 
13 #include <map>
14 #include <vector>
15 
16 #include "tbb/concurrent_unordered_map.h"
17 
18 namespace edm {
19  struct TypeIDHasher {
20  size_t operator()(TypeID const& tid) const { return std::hash<std::string>{}(std::string(tid.name())); }
21  };
22 } // namespace edm
23 
24 namespace reco {
25  namespace parser {
26 
27  class MethodInvoker {
28  private: // Private Data Members
31  std::vector<AnyMethodArgument> ints_; // already fixed to the correct type
32  std::vector<void*> args_;
33 
36 
37  private: // Private Function Members
38  void setArgs();
39 
40  public: // Public Function Members
42  const std::vector<AnyMethodArgument>& ints = std::vector<AnyMethodArgument>());
43  explicit MethodInvoker(const edm::MemberWithDict&);
46 
47  edm::FunctionWithDict const method() const { return method_; }
48  edm::MemberWithDict const member() const { return member_; }
49  bool isFunction() const { return isFunction_; }
50  std::string methodName() const;
52 
59  };
60 
65  struct SingleInvoker : boost::noncopyable {
66  private: // Private Data Members
68  std::vector<MethodInvoker> invokers_;
72  bool isRefGet_;
73 
74  public:
75  SingleInvoker(const edm::TypeWithDict&, const std::string& name, const std::vector<AnyMethodArgument>& args);
77 
85  std::pair<edm::ObjectWithDict, bool> invoke(const edm::ObjectWithDict& o,
86  std::vector<edm::ObjectWithDict>& v) const;
87 
89  double retToDouble(const edm::ObjectWithDict&) const;
90 
91  void throwFailedConversion(const edm::ObjectWithDict&) const;
92  };
93 
95  struct LazyInvoker {
96  typedef std::shared_ptr<SingleInvoker> SingleInvokerPtr;
97  typedef tbb::concurrent_unordered_map<edm::TypeID, SingleInvokerPtr, edm::TypeIDHasher> InvokerMap;
98 
99  private: // Private Data Members
101  std::vector<AnyMethodArgument> argsBeforeFixups_;
102  // the shared ptr is only to make the code exception safe
103  // otherwise I think it could leak if the constructor of
104  // SingleInvoker throws an exception (which can happen)
106 
107  private: // Private Function Members
108  const SingleInvoker& invoker(const edm::TypeWithDict&) const;
109 
110  public: // Public Function Members
111  explicit LazyInvoker(const std::string& name, const std::vector<AnyMethodArgument>& args);
112  ~LazyInvoker();
113 
120  edm::ObjectWithDict invoke(const edm::ObjectWithDict& o, std::vector<edm::ObjectWithDict>& v) const;
121 
123  double invokeLast(const edm::ObjectWithDict& o, std::vector<edm::ObjectWithDict>& v) const;
124  };
125 
126  } // namespace parser
127 } // namespace reco
128 
129 #endif // CommonTools_Utils_MethodInvoker_h
reco::parser::SingleInvoker::invoke
std::pair< edm::ObjectWithDict, bool > invoke(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
Definition: MethodInvoker.cc:213
writedatasetfile.args
args
Definition: writedatasetfile.py:18
edm::TypeIDHasher
Definition: MethodInvoker.h:19
AnyMethodArgument.h
reco::parser::MethodInvoker::retTypeFinal_
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:35
reco::parser::MethodInvoker::methodName
std::string methodName() const
Definition: MethodInvoker.cc:78
reco::parser::LazyInvoker::LazyInvoker
LazyInvoker(const std::string &name, const std::vector< AnyMethodArgument > &args)
Definition: MethodInvoker.cc:144
reco::parser::SingleInvoker
Definition: MethodInvoker.h:65
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
reco::parser::MethodInvoker::member
const edm::MemberWithDict member() const
Definition: MethodInvoker.h:48
TypeID.h
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
TypeCode.h
reco::parser::MethodInvoker::method_
edm::FunctionWithDict method_
Definition: MethodInvoker.h:29
reco::parser::MethodInvoker
Definition: MethodInvoker.h:27
reco::parser::SingleInvoker::storage_
edm::ObjectWithDict storage_
Definition: MethodInvoker.h:69
reco::parser::SingleInvoker::storageNeedsDestructor_
bool storageNeedsDestructor_
Definition: MethodInvoker.h:70
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
findQualityFiles.v
v
Definition: findQualityFiles.py:179
reco::parser::MethodInvoker::operator=
MethodInvoker & operator=(const MethodInvoker &)
Definition: MethodInvoker.cc:59
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
ObjectWithDict.h
reco::parser::LazyInvoker::invokeLast
double invokeLast(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
invoke and coerce result to double
Definition: MethodInvoker.cc:174
reco::parser::MethodInvoker::returnTypeName
std::string returnTypeName() const
Definition: MethodInvoker.cc:85
reco::parser::LazyInvoker::argsBeforeFixups_
std::vector< AnyMethodArgument > argsBeforeFixups_
Definition: MethodInvoker.h:101
reco::parser::MethodInvoker::isFunction
bool isFunction() const
Definition: MethodInvoker.h:49
reco::parser::MethodInvoker::method
const edm::FunctionWithDict method() const
Definition: MethodInvoker.h:47
reco::parser::MethodInvoker::isFunction_
bool isFunction_
Definition: MethodInvoker.h:34
edm::TypeIDHasher::operator()
size_t operator()(TypeID const &tid) const
Definition: MethodInvoker.h:20
reco::parser::LazyInvoker::InvokerMap
tbb::concurrent_unordered_map< edm::TypeID, SingleInvokerPtr, edm::TypeIDHasher > InvokerMap
Definition: MethodInvoker.h:97
reco::parser::SingleInvoker::invokers_
std::vector< MethodInvoker > invokers_
Definition: MethodInvoker.h:68
reco::parser::SingleInvoker::isRefGet_
bool isRefGet_
true if this invoker just pops out a ref and returns (ref.get(), false)
Definition: MethodInvoker.h:72
reco::parser::MethodInvoker::args_
std::vector< void * > args_
Definition: MethodInvoker.h:32
reco::parser::LazyInvoker::invoker
const SingleInvoker & invoker(const edm::TypeWithDict &) const
Definition: MethodInvoker.cc:149
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::parser::SingleInvoker::SingleInvoker
SingleInvoker(const edm::TypeWithDict &, const std::string &name, const std::vector< AnyMethodArgument > &args)
Definition: MethodInvoker.cc:188
reco::parser::LazyInvoker::name_
std::string name_
Definition: MethodInvoker.h:100
edm::TypeWithDict
Definition: TypeWithDict.h:38
reco::parser::SingleInvoker::retToDouble
double retToDouble(const edm::ObjectWithDict &) const
convert the output of invoke to a double, if possible
Definition: MethodInvoker.cc:230
reco::parser::SingleInvoker::throwFailedConversion
void throwFailedConversion(const edm::ObjectWithDict &) const
Definition: MethodInvoker.cc:237
reco::parser::MethodInvoker::invoke
edm::ObjectWithDict invoke(const edm::ObjectWithDict &obj, edm::ObjectWithDict &retstore) const
Definition: MethodInvoker.cc:92
reco::parser::LazyInvoker::invokers_
InvokerMap invokers_
Definition: MethodInvoker.h:105
reco::parser::MethodInvoker::setArgs
void setArgs()
Definition: MethodInvoker.cc:72
edm::TypeID::name
const char * name() const
Definition: TypeIDBase.h:44
reco::parser::LazyInvoker
Keeps different SingleInvokers for each dynamic type of the objects passed to invoke()
Definition: MethodInvoker.h:95
edm::MemberWithDict
Definition: MemberWithDict.h:19
reco::parser::LazyInvoker::SingleInvokerPtr
std::shared_ptr< SingleInvoker > SingleInvokerPtr
Definition: MethodInvoker.h:96
reco::method::TypeCode
TypeCode
Definition: TypeCode.h:13
reco::parser::MethodInvoker::MethodInvoker
MethodInvoker(const edm::FunctionWithDict &method, const std::vector< AnyMethodArgument > &ints=std::vector< AnyMethodArgument >())
Definition: MethodInvoker.cc:13
reco::parser::LazyInvoker::invoke
edm::ObjectWithDict invoke(const edm::ObjectWithDict &o, std::vector< edm::ObjectWithDict > &v) const
Definition: MethodInvoker.cc:162
reco::parser::MethodInvoker::ints_
std::vector< AnyMethodArgument > ints_
Definition: MethodInvoker.h:31
edm::TypeID
Definition: TypeID.h:22
reco::parser::SingleInvoker::retType_
method::TypeCode retType_
Definition: MethodInvoker.h:67
reco::parser::SingleInvoker::~SingleInvoker
~SingleInvoker()
Definition: MethodInvoker.cc:211
edm::FunctionWithDict
Definition: FunctionWithDict.h:27
reco::parser::MethodInvoker::member_
edm::MemberWithDict member_
Definition: MethodInvoker.h:30
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
reco::parser::LazyInvoker::~LazyInvoker
~LazyInvoker()
Definition: MethodInvoker.cc:147
MemberWithDict.h
FunctionWithDict.h