ATLAS Offline Software
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 
13 #include "RootUtils/TSMethodCall.h"
14 #include "TMethod.h"
15 #include "TError.h"
16 #include "TInterpreter.h"
18 
19 
20 namespace 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 
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 
109 TMethodCall* 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
TSMethodCall.h
Helper for thread-safe TMethodCall. Extracted from Type.
RootUtils
Definition: ILogger.h:20
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
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::operator=
TSMethodCall & operator=(const TSMethodCall &other)
Assignment.
Definition: TSMethodCall.cxx:53
RootUtils::TSMethodCall::m_fname
std::string m_fname
Name of the function we're calling.
Definition: TSMethodCall.h:75
RootUtils::TSMethodCall
Helper for making a thread-safe function call.
Definition: TSMethodCall.h:33
RootUtils::TSMethodCall::TSMethodCall
TSMethodCall()
Constructor.
Definition: TSMethodCall.cxx:26
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::call
TMethodCall * call()
Return a pointer to the thread-specific TMethodCall.
Definition: TSMethodCall.cxx:109
RootUtils::TSMethodCall::setProto
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.
Definition: TSMethodCall.cxx:90
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
checker_macros.h
Define macros for attributes used to control the static checker.
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
ROOT
Definition: ViewVectorBaseStreamer.cxx:43
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
RootUtils::TSMethodCall::~TSMethodCall
~TSMethodCall()
Destructor.
Definition: TSMethodCall.cxx:72