ATLAS Offline Software
Loading...
Searching...
No Matches
TSMethodCall.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12
14#include "TMethod.h"
15#include "TError.h"
16#include "TInterpreter.h"
18
19
20namespace RootUtils {
21
22
27 : m_cls(nullptr),
28 m_mode (ROOT::kExactMatch),
29 m_meth (std::make_unique<TMethodCall>()),
30 m_initialized(false)
31{
32}
33
34
39 : m_cls (other.m_cls),
40 m_fname (other.m_fname),
41 m_args (other.m_args),
42 m_mode (other.m_mode),
43 m_meth (std::make_unique<TMethodCall> (*other.m_meth)),
44 m_initialized (false)
45{
46 // Don't copy m_tsMeth.
47}
48
49
54{
55 if (this != &other) {
56 m_cls = other.m_cls;
57 m_fname = other.m_fname;
58 m_args = other.m_args;
59 *m_meth = *other.m_meth;
60 m_mode = other.m_mode;
61 m_initialized = false;
62
63 // Don't copy m_tsMeth.
64 }
65 return *this;
66}
67
68
73{
74 // Don't try to run the TMethodCall destructor if gCling is gone.
75 TInterpreter* cling ATLAS_THREAD_SAFE = gCling;
76 if (!cling) {
77 (void)m_meth.release();
78 m_tsMeth.release();
79 }
80}
81
82
90void TSMethodCall::setProto (TClass* cls,
91 const std::string& fname,
92 const std::string& args,
93 ROOT::EFunctionMatchMode mode /*=ROOT::kExactMatch*/)
94{
95 m_cls = cls;
96 m_fname = fname;
97 m_args = args;
98 m_mode = mode;
99 m_initialized = false;
100}
101
102
109TMethodCall* TSMethodCall::call()
110{
111 // Fail if this isn't a class type.
112 if (m_cls == 0) return nullptr;
113
114 if (!m_initialized) {
115 // Not initialized ... try to do so now. First take the lock.
116 std::lock_guard<std::mutex> lock (m_mutex);
117 // cppcheck-suppress identicalInnerCondition; false positive
118 if (!m_initialized) {
119 m_meth->InitWithPrototype (m_cls, m_fname.c_str(), m_args.c_str(),
120 false, m_mode);
121 if (!m_meth->IsValid()) {
122 ::Warning ("RootUtils::Type",
123 "Can't get method for type `%s': %s (%s).",
124 m_cls->GetName(), m_fname.c_str(), m_args.c_str());
125 }
126 m_initialized = true;
127 }
128 }
129
130 if (!m_meth->IsValid()) return nullptr;
131
132 if (m_tsMeth.get() == 0)
133 m_tsMeth.reset (new TMethodCall (*m_meth));
134
135 return m_tsMeth.get();
136}
137
138
139} // namespace RootUtils
Helper for thread-safe TMethodCall. Extracted from Type.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
ROOT::EFunctionMatchMode m_mode
Matching mode.
TSMethodCall & operator=(const TSMethodCall &other)
Assignment.
boost::thread_specific_ptr< TMethodCall > m_tsMeth
Objects used to call the method on the payload object.
std::string m_fname
Name of the function we're calling.
std::atomic< bool > m_initialized
Flag whether or not m_meth has been initialized.
TMethodCall * call()
Return a pointer to the thread-specific TMethodCall.
void setProto(TClass *cls, const std::string &fname, const std::string &args, ROOT::EFunctionMatchMode mode=ROOT::kExactMatch)
Set the function that we're to call.
std::unique_ptr< TMethodCall > m_meth
Object to call the method on the payload type.
TClass * m_cls
Class that we're calling.
std::string m_args
Argument list.
std::mutex m_mutex
Control access to m_assign for initialization.
Selection rules: declare transient members.
Definition DataVector.h:581
STL namespace.