ATLAS Offline Software
Loading...
Searching...
No Matches
AnaToolHandle.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
9#ifndef ASG_TOOLS__ANA_TOOL_HANDLE_H
10#define ASG_TOOLS__ANA_TOOL_HANDLE_H
11
12// Author: Will Buttinger
13
14
15#include <AsgTools/AsgTool.h>
17#include <AsgTools/ToolHandle.h>
18#include <type_traits>
19#include <atomic>
20#include <list>
21#include <map>
22#include <mutex>
23
24namespace asg
25{
26#ifdef XAOD_STANDALONE
27 typedef INamedInterface parentType_t;
29#else
30 typedef INamedInterface parentType_t;
31 typedef IAlgTool interfaceType_t;
32#endif
33
34 template<class T> class AnaToolHandle;
35
36 namespace detail
37 {
38 class AnaToolShare;
39
40
41
44
69 }
70
71
72
78 template <typename T>
79 std::ostream& operator << (std::ostream& str, const AnaToolHandle<T>& obj);
80
81
164
165 template<class T>
166 class AnaToolHandle final
167 {
168 //
169 // public interface
170 //
171
175 public:
176 void testInvariant () const;
177
178
189 public:
190 explicit AnaToolHandle (const std::string& val_name = "",
191 parentType_t *val_parent = nullptr);
192
193
197 public:
199
200
211 public:
213
214
218 public:
219 ~AnaToolHandle () noexcept;
220
221
232 public:
233 AnaToolHandle& operator = (const AnaToolHandle<T>& that);
234
235
239 public:
240 AnaToolHandle<T>& operator = (AnaToolHandle<T>&& that);
241
242
246 public:
247 void swap (AnaToolHandle<T>& that) noexcept;
248
249
258 public:
259 bool empty () const;
260
264 public:
265 bool isPublic () const noexcept;
266
271 public:
272 bool isInitialized () const noexcept;
273
274
282 public:
283 template<typename T2> void
284 declarePropertyFor (T2 *tool, const std::string& name,
285 const std::string& description = "");
286
290 public:
291 const ToolHandle<T>& getHandle () const noexcept;
292
293
311 public:
312 // ToolHandle and ToolHandleArray have ctors that can accept a single int,
313 // so use enable_if to avoid ambiguities.
314 template <class T2> StatusCode
315 setProperty (const std::string& property, const T2& value);
316 template <class T2>
317 typename std::enable_if<std::is_base_of_v<parentType_t, T2>, StatusCode>::type
318 setProperty (const std::string& property, const ToolHandle<T2>& value);
319 template <class T2> StatusCode
320 setProperty (const std::string& property, const AnaToolHandle<T2>& value);
321 template <class T2>
322 typename std::enable_if<std::is_base_of_v<parentType_t, T2>, StatusCode>::type
323 setProperty (const std::string& property, const ToolHandleArray<T2>& value);
325
326
330 public:
331 const std::string& type () const noexcept;
332
337 public:
338 void setType (std::string val_type) noexcept;
339
340
344 public:
345 const std::string& name () const noexcept;
346
351 public:
352 void setName (std::string val_name) noexcept;
353
360 public:
361 std::string fullName () const;
362
363
369 public:
371
378 public:
379 void setTypeAndName (const std::string& val_typeAndName);
380
385 public:
386 void setTypeAndName (std::string val_type, std::string val_name) noexcept;
387
388
395 public:
396 StatusCode initialize ();
397
399 public:
400 StatusCode retrieve ();
401
402
409 public:
410 T *operator -> ();
411
418 public:
419 const T *operator -> () const;
420
426 public:
427 T& operator * ();
428
434 public:
435 const T& operator * () const;
436
443 public:
444 T *get ();
445
452 public:
454
455
464 public:
466
467
477 public:
478 detail::AnaToolHandleMode mode () const;
479
480
490 public:
492
493
503 public:
504 bool allowEmpty () const noexcept;
505
506
507
512 public:
513 void setAllowEmpty (bool val_allowEmpty = true) noexcept;
514
515
516
517 //
518 // deprecated interface
519 //
520
534 public:
536
537 public:
538 [[deprecated("please use isInitialized() instead")]]
539 bool inPremakeState () const noexcept {
540 return !isInitialized();}
541
542 public:
543 [[deprecated("please use isInitialized() instead")]]
544 bool inBrokenState () const noexcept {
545 return false;};
546
547 public:
548 [[deprecated("no longer need to call make()")]]
549 StatusCode make () {
550 return StatusCode::SUCCESS;};
551
552 public:
553 [[deprecated("please use setType() or setTypeAndName() instead")]]
554 StatusCode make (const std::string& val_type) noexcept {
555 if (!val_type.empty()) {
556 if (val_type.find ('/') != std::string::npos)
557 setTypeAndName (val_type);
558 else
559 setType (val_type); }
560 return StatusCode::SUCCESS; };
561
562
563
564 //
565 // private interface
566 //
567
576 private:
577 std::vector<std::function<StatusCode ()>> m_extraInit;
578
582 private:
583 std::shared_ptr<void> m_cleanup;
584
586 private:
588
590 private:
591 std::string m_name;
592
594 private:
596
597
608 private:
609 std::shared_ptr<ToolHandle<T>> m_handleUser;
610
615 private:
617
619 private:
620 std::atomic<bool> m_isInitialized {false};
621
631 private:
632 std::atomic<T*> m_toolPtr = nullptr;
633
639 private:
641
654 private:
656 getMode (std::shared_ptr<detail::AnaToolShare>& sharedTool) const;
657
659 private:
661 getMode () const;
662
663
665 private:
666 bool m_allowEmpty = false;
667
668
674 private:
676 (T*& toolPtr, ToolHandle<T>& toolHandle) const;
677
678
684 private:
685 std::recursive_mutex m_initializeMutex;
686 };
687}
688
690#define ASG_MAKE_ANA_TOOL(handle,type) \
691 (ASG_SET_ANA_TOOL_TYPE(handle,type), StatusCode (StatusCode::SUCCESS))
692
694#define ASG_SET_ANA_TOOL_TYPE(handle,type) \
695 (handle).setType (#type)
696
698
699
700#endif
a modified tool handle that allows its owner to configure new tools from the C++ side
const std::string & type() const noexcept
AnaToolHandle(const std::string &val_name="", parentType_t *val_parent=nullptr)
create a tool handle with the given name and parent
~AnaToolHandle() noexcept
standard destructor
void setName(std::string val_name) noexcept
StatusCode setProperty(const std::string &property, const T2 &value)
void testInvariant() const
test the invariant of this object
StatusCode make(const std::string &val_type) noexcept
StatusCode makeToolRetrieve(T *&toolPtr, ToolHandle< T > &toolHandle) const
make a tool by retrieving the ToolHandle
void setType(std::string val_type) noexcept
void setAllowEmpty(bool val_allowEmpty=true) noexcept
AnaToolHandle(AnaToolHandle< T > &&that)
move constructor
void declarePropertyFor(T2 *tool, const std::string &name, const std::string &description="")
bool inBrokenState() const noexcept
std::shared_ptr< ToolHandle< IOverlapRemovalTool > > m_handleUser
std::atomic< IOverlapRemovalTool * > m_toolPtr
detail::AnaToolHandleMode getMode() const
get the mode with which this ToolHandle will be initialized
detail::AnaToolHandleMode mode() const
const std::string & name() const noexcept
void setTypeAndName(const std::string &val_typeAndName)
AnaToolHandle(const AnaToolHandle< T > &that)
copy constructor
void swap(AnaToolHandle< IOverlapRemovalTool > &that) noexcept
const ToolHandle< IOverlapRemovalTool > & getHandle() const noexcept
std::vector< std::function< StatusCode()> > m_extraInit
detail::AnaToolHandleMode getMode(std::shared_ptr< detail::AnaToolShare > &sharedTool) const
get the mode with which this ToolHandle will be initialized
an object that can create a AsgTool
Base class for the dual-use tool interface classes.
Definition IAsgTool.h:41
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:91
AnaToolHandleMode
the mode with which an AnaToolHandle object is initialized
@ USER
retrieve a tool from the user tool handle
@ CREATE_SHARED
create a shared tool normally
@ RETRIEVE_SHARED
retrieve a shared tool
@ EMPTY
do not create a tool
@ CREATE_PRIVATE
create a private tool normally
std::ostream & operator<<(std::ostream &str, const AnaToolHandle< T > &obj)
standard output operator
IAlgTool interfaceType_t
INamedInterface parentType_t
STL namespace.