The Gaudi Framework  master (d98a2936)
SmartDataStorePtr.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
14 
41 template <class TYPE, class LOADER>
43 public:
52  SmartDataStorePtr( IDataProviderSvc* pService, IRegistry* pRegistry, std::string path )
53  : SmartDataObjectPtr( LOADER::access(), pService, pRegistry, std::move( path ) ), m_pObject( nullptr ) {}
58 
60  virtual ~SmartDataStorePtr() = default;
61 
64  m_pObject = dynamic_cast<TYPE*>( pObj );
65  return *this;
66  }
67 
70  m_pObject = dynamic_cast<TYPE*>( const_cast<DataObject*>( pObj ) );
71  return *this;
72  }
73 
75  SmartDataStorePtr& operator=( const SmartDataObjectPtr& copy ) override {
76  this->m_pObject = dynamic_cast<TYPE*>( const_cast<SmartDataObjectPtr*>( &copy ) );
77  return *this;
78  }
79 
81  TYPE* ptr() { return accessTypeSafeData(); }
82 
84  TYPE* operator->() { return accessTypeSafeData(); }
85 
87  TYPE& operator*() {
88  TYPE* result = accessTypeSafeData();
89  return *result;
90  }
91 
93  operator TYPE*() { return accessTypeSafeData(); }
94 
96  operator TYPE&() {
97  TYPE* result = accessTypeSafeData();
98  return *result;
99  }
100 
102  operator int() { return 0 != accessTypeSafeData(); }
103 
105  bool operator!() { return 0 == accessTypeSafeData(); }
106 
109  if ( 0 == m_pObject ) { m_pObject = dynamic_cast<TYPE*>( accessData() ); }
110  return m_pObject;
111  }
112 
113 protected:
115  mutable TYPE* m_pObject;
116 };
117 
128 template <class A, class LDA, class B, class LDB>
130  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
131  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
132  return true; // Fine: Both objects exist
133  }
134  }
135  return false; // Tough luck: One is missing.
136 }
137 
148 template <class B, class LDB>
150  if ( test ) { // Test existence of the first object
151  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
152  return true; // Fine: Both objects exist
153  }
154  }
155  return false; // Tough luck: One is missing.
156 }
157 
168 template <class B, class LDB>
170  if ( test ) { // Test existence of the first object
171  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
172  return true; // Fine: Both objects exist
173  }
174  }
175  return false; // Tough luck: One is missing.
176 }
177 
192 template <class A, class LDA, class B, class LDB>
194  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
195  return true;
196  }
197  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
198  return true;
199  }
200  return false; // Tough luck: Both are missing.
201 }
202 
213 template <class B, class LDB>
215  if ( test ) { // Test existence of the first object
216  return true;
217  }
218  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
219  return true; // Fine: Both objects exist
220  }
221  return false; // Tough luck: One is missing.
222 }
223 
234 template <class B, class LDB>
236  if ( test ) { // Test existence of the first object
237  return true;
238  }
239  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
240  return true; // Fine: Both objects exist
241  }
242  return false; // Tough luck: One is missing.
243 }
SmartDataStorePtr::operator!
bool operator!()
operator ! for statements like: if ( !SmartDataStorePtr<XXX>(...) ) {}
Definition: SmartDataStorePtr.h:105
GaudiPartProp.decorators.std
std
Definition: decorators.py:32
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const SmartDataObjectPtr &copy) override
unhides assignment operator of base class
Definition: SmartDataStorePtr.h:75
SmartDataStorePtr::~SmartDataStorePtr
virtual ~SmartDataStorePtr()=default
Standard Destructor.
IRegistry
Definition: IRegistry.h:29
SmartDataStorePtr::operator*
TYPE & operator*()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:87
SmartDataObjectPtr.h
SmartDataStorePtr::accessTypeSafeData
TYPE * accessTypeSafeData()
Internal type safe accessor to data.
Definition: SmartDataStorePtr.h:108
SmartDataObjectPtr
Definition: SmartDataObjectPtr.h:37
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:63
SmartDataStorePtr::m_pObject
TYPE * m_pObject
Pointer to data store object.
Definition: SmartDataStorePtr.h:115
SmartDataStorePtr::SmartDataStorePtr
SmartDataStorePtr(IDataProviderSvc *pService, IRegistry *pRegistry, std::string path)
Standard constructor: Construct an SmartDataStorePtr instance which is able to connect to a DataObjec...
Definition: SmartDataStorePtr.h:52
SmartDataStorePtr::SmartDataStorePtr
SmartDataStorePtr(const SmartDataObjectPtr &copy)
Copy constructor: Construct a copy of a SmartDataStorePtr instance.
Definition: SmartDataStorePtr.h:57
operator||
bool operator||(SmartDataStorePtr< A, LDA > &object_1, SmartDataStorePtr< B, LDB > &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartDataPtr<MCV...
Definition: SmartDataStorePtr.h:193
SmartDataStorePtr::ptr
TYPE * ptr()
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:81
SmartDataStorePtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition: SmartDataStorePtr.h:42
DataObject
Definition: DataObject.h:37
compareRootHistos.test
test
Definition: compareRootHistos.py:28
IDataProviderSvc
Definition: IDataProviderSvc.h:48
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:76
operator&&
bool operator&&(SmartDataStorePtr< A, LDA > &object_1, SmartDataStorePtr< B, LDB > &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartDataPtr<MCV...
Definition: SmartDataStorePtr.h:129
SmartDataStorePtr::operator->
TYPE * operator->()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:84
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:69
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:91