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 <map>
12 #include <vector>
13 
14 #include "tbb/concurrent_unordered_map.h"
15 
16 namespace edm {
17  struct TypeIDHasher {
18  size_t operator()(TypeID const& tid) const { return std::hash<std::string>{}(std::string(tid.name())); }
19  };
20 } // namespace edm
21 
22 namespace reco {
23  namespace parser {
24 
25  class MethodInvoker {
26  private: // Private Data Members
29  std::vector<AnyMethodArgument> ints_; // already fixed to the correct type
30  std::vector<void*> args_;
31 
34 
35  private: // Private Function Members
36  void setArgs();
37 
38  public: // Public Function Members
40  const std::vector<AnyMethodArgument>& ints = std::vector<AnyMethodArgument>());
41  explicit MethodInvoker(const edm::MemberWithDict&);
44 
45  edm::FunctionWithDict const method() const { return method_; }
46  edm::MemberWithDict const member() const { return member_; }
47  bool isFunction() const { return isFunction_; }
48  std::string methodName() const;
50 
57  };
58 
63  struct SingleInvoker {
64  private: // Private Data Members
66  std::vector<MethodInvoker> invokers_;
70  bool isRefGet_;
71 
72  public:
73  SingleInvoker(const SingleInvoker&) = delete;
74  SingleInvoker& operator=(const SingleInvoker&) = delete;
75 
76  SingleInvoker(const edm::TypeWithDict&, const std::string& name, const std::vector<AnyMethodArgument>& args);
78 
86  std::pair<edm::ObjectWithDict, bool> invoke(const edm::ObjectWithDict& o,
87  std::vector<edm::ObjectWithDict>& v) const;
88 
90  double retToDouble(const edm::ObjectWithDict&) const;
91 
92  void throwFailedConversion(const edm::ObjectWithDict&) const;
93  };
94 
96  struct LazyInvoker {
97  typedef std::shared_ptr<SingleInvoker> SingleInvokerPtr;
98  typedef tbb::concurrent_unordered_map<edm::TypeID, SingleInvokerPtr, edm::TypeIDHasher> InvokerMap;
99 
100  private: // Private Data Members
102  std::vector<AnyMethodArgument> argsBeforeFixups_;
103  // the shared ptr is only to make the code exception safe
104  // otherwise I think it could leak if the constructor of
105  // SingleInvoker throws an exception (which can happen)
107 
108  private: // Private Function Members
109  const SingleInvoker& invoker(const edm::TypeWithDict&) const;
110 
111  public: // Public Function Members
112  explicit LazyInvoker(const std::string& name, const std::vector<AnyMethodArgument>& args);
113  ~LazyInvoker();
114 
121  edm::ObjectWithDict invoke(const edm::ObjectWithDict& o, std::vector<edm::ObjectWithDict>& v) const;
122 
124  double invokeLast(const edm::ObjectWithDict& o, std::vector<edm::ObjectWithDict>& v) const;
125  };
126 
127  } // namespace parser
128 } // namespace reco
129 
130 #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:17
AnyMethodArgument.h
reco::parser::MethodInvoker::retTypeFinal_
edm::TypeWithDict retTypeFinal_
Definition: MethodInvoker.h:33
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:63
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:46
TypeID.h
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
TypeCode.h
reco::parser::MethodInvoker::method_
edm::FunctionWithDict method_
Definition: MethodInvoker.h:27
reco::parser::MethodInvoker
Definition: MethodInvoker.h:25
reco::parser::SingleInvoker::storage_
edm::ObjectWithDict storage_
Definition: MethodInvoker.h:67
reco::parser::SingleInvoker::storageNeedsDestructor_
bool storageNeedsDestructor_
Definition: MethodInvoker.h:68
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:102
reco::parser::MethodInvoker::isFunction
bool isFunction() const
Definition: MethodInvoker.h:47
reco::parser::MethodInvoker::method
const edm::FunctionWithDict method() const
Definition: MethodInvoker.h:45
reco::parser::MethodInvoker::isFunction_
bool isFunction_
Definition: MethodInvoker.h:32
edm::TypeIDHasher::operator()
size_t operator()(TypeID const &tid) const
Definition: MethodInvoker.h:18
reco::parser::LazyInvoker::InvokerMap
tbb::concurrent_unordered_map< edm::TypeID, SingleInvokerPtr, edm::TypeIDHasher > InvokerMap
Definition: MethodInvoker.h:98
reco::parser::SingleInvoker::invokers_
std::vector< MethodInvoker > invokers_
Definition: MethodInvoker.h:66
reco::parser::SingleInvoker::isRefGet_
bool isRefGet_
true if this invoker just pops out a ref and returns (ref.get(), false)
Definition: MethodInvoker.h:70
reco::parser::MethodInvoker::args_
std::vector< void * > args_
Definition: MethodInvoker.h:30
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::LazyInvoker::name_
std::string name_
Definition: MethodInvoker.h:101
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:106
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:96
edm::MemberWithDict
Definition: MemberWithDict.h:19
reco::parser::LazyInvoker::SingleInvokerPtr
std::shared_ptr< SingleInvoker > SingleInvokerPtr
Definition: MethodInvoker.h:97
reco::parser::SingleInvoker::SingleInvoker
SingleInvoker(const SingleInvoker &)=delete
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:29
edm::TypeID
Definition: TypeID.h:22
reco::parser::SingleInvoker::retType_
method::TypeCode retType_
Definition: MethodInvoker.h:65
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:28
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
reco::parser::LazyInvoker::~LazyInvoker
~LazyInvoker()
Definition: MethodInvoker.cc:147
MemberWithDict.h
reco::parser::SingleInvoker::operator=
SingleInvoker & operator=(const SingleInvoker &)=delete
FunctionWithDict.h