ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
RootUtils::TSMethodCall Class Reference

Helper for making a thread-safe function call. More...

#include <TSMethodCall.h>

Collaboration diagram for RootUtils::TSMethodCall:

Public Member Functions

 TSMethodCall ()
 Constructor. More...
 
 TSMethodCall (const TSMethodCall &other)
 Copy constructor. More...
 
TSMethodCalloperator= (const TSMethodCall &other)
 Assignment. More...
 
 ~TSMethodCall ()
 Destructor. More...
 
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. More...
 
TMethodCall * call ()
 Return a pointer to the thread-specific TMethodCall. More...
 

Private Attributes

TClass * m_cls
 Class that we're calling. More...
 
std::string m_fname
 Name of the function we're calling. More...
 
std::string m_args
 Argument list. More...
 
ROOT::EFunctionMatchMode m_mode
 Matching mode. More...
 
std::unique_ptr< TMethodCall > m_meth
 Object to call the method on the payload type. More...
 
std::atomic< bool > m_initialized
 Flag whether or not m_meth has been initialized. More...
 
std::mutex m_mutex
 Control access to m_assign for initialization. More...
 
boost::thread_specific_ptr< TMethodCall > m_tsMeth
 Objects used to call the method on the payload object. More...
 

Detailed Description

Helper for making a thread-safe function call.

We can't use TMethodCall directly because we have to change the object state to make a call.

Definition at line 32 of file TSMethodCall.h.

Constructor & Destructor Documentation

◆ TSMethodCall() [1/2]

RootUtils::TSMethodCall::TSMethodCall ( )

Constructor.

Default constructor.

Definition at line 26 of file TSMethodCall.cxx.

27  : m_cls(nullptr),
28  m_mode (ROOT::kExactMatch),
29  m_meth (std::make_unique<TMethodCall>()),
30  m_initialized(false)
31 {
32 }

◆ TSMethodCall() [2/2]

RootUtils::TSMethodCall::TSMethodCall ( const TSMethodCall other)

Copy constructor.

Definition at line 38 of file TSMethodCall.cxx.

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 }

◆ ~TSMethodCall()

RootUtils::TSMethodCall::~TSMethodCall ( )

Destructor.

Definition at line 72 of file TSMethodCall.cxx.

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 }

Member Function Documentation

◆ call()

TMethodCall * RootUtils::TSMethodCall::call ( )

Return a pointer to the thread-specific TMethodCall.

Returns nullptr if setProto hasn't been called or if the method was not found.

Definition at line 109 of file TSMethodCall.cxx.

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 }

◆ operator=()

TSMethodCall & RootUtils::TSMethodCall::operator= ( const TSMethodCall other)

Assignment.

Definition at line 53 of file TSMethodCall.cxx.

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 }

◆ setProto()

void RootUtils::TSMethodCall::setProto ( TClass *  cls,
const std::string &  fname,
const std::string &  args,
ROOT::EFunctionMatchMode  mode = ROOT::kExactMatch 
)

Set the function that we're to call.

Parameters
clsThe class of the object we're calling.
fnameThe name of the function.
argsIts argument list.
modeControls whether to allow for conversions.

Definition at line 90 of file TSMethodCall.cxx.

94 {
95  m_cls = cls;
96  m_fname = fname;
97  m_args = args;
98  m_mode = mode;
99  m_initialized = false;
100 }

Member Data Documentation

◆ m_args

std::string RootUtils::TSMethodCall::m_args
private

Argument list.

Definition at line 78 of file TSMethodCall.h.

◆ m_cls

TClass* RootUtils::TSMethodCall::m_cls
private

Class that we're calling.

Definition at line 72 of file TSMethodCall.h.

◆ m_fname

std::string RootUtils::TSMethodCall::m_fname
private

Name of the function we're calling.

Definition at line 75 of file TSMethodCall.h.

◆ m_initialized

std::atomic<bool> RootUtils::TSMethodCall::m_initialized
private

Flag whether or not m_meth has been initialized.

We don't want to do that before we actually need it, to prevent needless parses with root6.

Definition at line 98 of file TSMethodCall.h.

◆ m_meth

std::unique_ptr<TMethodCall> RootUtils::TSMethodCall::m_meth
private

Object to call the method on the payload type.

This will be left invalid if the payload is not a class type. This instance is not actually used for calls — since we have to change the object state to make a call (registering the arguments), this is not thread-safe. Instead, we use the thread-specific instances accessed through m_tsMeth.

Held by pointer rather than value to work around a ROOT problem where the TMethodCall destructor will crash if gCling has already been destroyed.

Definition at line 93 of file TSMethodCall.h.

◆ m_mode

ROOT::EFunctionMatchMode RootUtils::TSMethodCall::m_mode
private

Matching mode.

Definition at line 81 of file TSMethodCall.h.

◆ m_mutex

std::mutex RootUtils::TSMethodCall::m_mutex
private

Control access to m_assign for initialization.

Definition at line 101 of file TSMethodCall.h.

◆ m_tsMeth

boost::thread_specific_ptr<TMethodCall> RootUtils::TSMethodCall::m_tsMeth
private

Objects used to call the method on the payload object.

Left invalid if the payload does not have class type. Copied from m_meth the first time it's used in a particular thread.

Definition at line 107 of file TSMethodCall.h.


The documentation for this class was generated from the following files:
RootUtils::TSMethodCall::m_meth
std::unique_ptr< TMethodCall > m_meth
Object to call the method on the payload type.
Definition: TSMethodCall.h:93
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
RootUtils::TSMethodCall::m_fname
std::string m_fname
Name of the function we're calling.
Definition: TSMethodCall.h:75
RootUtils::TSMethodCall::m_mutex
std::mutex m_mutex
Control access to m_assign for initialization.
Definition: TSMethodCall.h:101
Preparation.mode
mode
Definition: Preparation.py:94
RootUtils::TSMethodCall::m_mode
ROOT::EFunctionMatchMode m_mode
Matching mode.
Definition: TSMethodCall.h:81
RootUtils::TSMethodCall::m_cls
TClass * m_cls
Class that we're calling.
Definition: TSMethodCall.h:72
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
RootUtils::TSMethodCall::m_initialized
std::atomic< bool > m_initialized
Flag whether or not m_meth has been initialized.
Definition: TSMethodCall.h:98
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
RootUtils::TSMethodCall::m_args
std::string m_args
Argument list.
Definition: TSMethodCall.h:78
RootUtils::TSMethodCall::m_tsMeth
boost::thread_specific_ptr< TMethodCall > m_tsMeth
Objects used to call the method on the payload object.
Definition: TSMethodCall.h:107
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80