The Gaudi Framework  master (37c0b60a)
SmartDataStorePtr.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 // ====================================================================
12 // SmartDataStorePtr.h
13 // --------------------------------------------------------------------
14 //
15 // Package : GaudiKernel ( The LHCb Offline System)
16 //
17 // Description: Implementation of a smart pointer class to access
18 // easily (and efficiently) data stores.
19 //
20 // Author : M.Frank
21 // ====================================================================
22 #ifndef GAUDIKERNEL_SMARTDATASTOREPTR_H
23 #define GAUDIKERNEL_SMARTDATASTOREPTR_H 1
24 
25 // Framework include files
27 
54 template <class TYPE, class LOADER>
56 public:
66  : SmartDataObjectPtr( LOADER::access(), pService, pRegistry, std::move( path ) ), m_pObject( nullptr ) {}
71 
73  virtual ~SmartDataStorePtr() = default;
74 
77  m_pObject = dynamic_cast<TYPE*>( pObj );
78  return *this;
79  }
80 
83  m_pObject = dynamic_cast<TYPE*>( const_cast<DataObject*>( pObj ) );
84  return *this;
85  }
86 
88  SmartDataStorePtr& operator=( const SmartDataObjectPtr& copy ) override {
89  this->m_pObject = dynamic_cast<TYPE*>( const_cast<SmartDataObjectPtr*>( &copy ) );
90  return *this;
91  }
92 
94  TYPE* ptr() { return accessTypeSafeData(); }
95 
97  TYPE* operator->() { return accessTypeSafeData(); }
98 
100  TYPE& operator*() {
101  TYPE* result = accessTypeSafeData();
102  return *result;
103  }
104 
106  operator TYPE*() { return accessTypeSafeData(); }
107 
109  operator TYPE&() {
110  TYPE* result = accessTypeSafeData();
111  return *result;
112  }
113 
115  operator int() { return 0 != accessTypeSafeData(); }
116 
118  bool operator!() { return 0 == accessTypeSafeData(); }
119 
122  if ( 0 == m_pObject ) { m_pObject = dynamic_cast<TYPE*>( accessData() ); }
123  return m_pObject;
124  }
125 
126 protected:
128  mutable TYPE* m_pObject;
129 };
130 
141 template <class A, class LDA, class B, class LDB>
143  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
144  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
145  return true; // Fine: Both objects exist
146  }
147  }
148  return false; // Tough luck: One is missing.
149 }
150 
161 template <class B, class LDB>
163  if ( test ) { // Test existence of the first object
164  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
165  return true; // Fine: Both objects exist
166  }
167  }
168  return false; // Tough luck: One is missing.
169 }
170 
181 template <class B, class LDB>
183  if ( test ) { // Test existence of the first object
184  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
185  return true; // Fine: Both objects exist
186  }
187  }
188  return false; // Tough luck: One is missing.
189 }
190 
205 template <class A, class LDA, class B, class LDB>
207  if ( 0 != object_1.accessTypeSafeData() ) { // Test existence of the first object
208  return true;
209  }
210  if ( 0 != object_2.accessTypeSafeData() ) { // Test existence of the second object
211  return true;
212  }
213  return false; // Tough luck: Both are missing.
214 }
215 
226 template <class B, class LDB>
228  if ( test ) { // Test existence of the first object
229  return true;
230  }
231  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
232  return true; // Fine: Both objects exist
233  }
234  return false; // Tough luck: One is missing.
235 }
236 
247 template <class B, class LDB>
249  if ( test ) { // Test existence of the first object
250  return true;
251  }
252  if ( 0 != object.accessTypeSafeData() ) { // Test existence of the second object
253  return true; // Fine: Both objects exist
254  }
255  return false; // Tough luck: One is missing.
256 }
257 #endif // GAUDIKERNEL_SMARTDATASTOREPTR_H
std::string
STL class.
SmartDataStorePtr::operator!
bool operator!()
operator ! for statements like: if ( !SmartDataStorePtr<XXX>(...) ) {}
Definition: SmartDataStorePtr.h:118
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const SmartDataObjectPtr &copy) override
unhides assignment operator of base class
Definition: SmartDataStorePtr.h:88
SmartDataStorePtr::~SmartDataStorePtr
virtual ~SmartDataStorePtr()=default
Standard Destructor.
IRegistry
Definition: IRegistry.h:32
SmartDataStorePtr::operator*
TYPE & operator*()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:100
SmartDataObjectPtr.h
SmartDataStorePtr::accessTypeSafeData
TYPE * accessTypeSafeData()
Internal type safe accessor to data.
Definition: SmartDataStorePtr.h:121
SmartDataObjectPtr
Definition: SmartDataObjectPtr.h:42
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:76
SmartDataStorePtr::m_pObject
TYPE * m_pObject
Pointer to data store object.
Definition: SmartDataStorePtr.h:128
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:65
SmartDataStorePtr::SmartDataStorePtr
SmartDataStorePtr(const SmartDataObjectPtr &copy)
Copy constructor: Construct a copy of a SmartDataStorePtr instance.
Definition: SmartDataStorePtr.h:70
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:206
SmartDataStorePtr::ptr
TYPE * ptr()
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:94
std
STL namespace.
SmartDataStorePtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition: SmartDataStorePtr.h:55
DataObject
Definition: DataObject.h:36
compareRootHistos.test
test
Definition: compareRootHistos.py:28
IDataProviderSvc
Definition: IDataProviderSvc.h:53
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:81
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:142
SmartDataStorePtr::operator->
TYPE * operator->()
Dereference operator: the heart of the smart pointer.
Definition: SmartDataStorePtr.h:97
SmartDataStorePtr::operator=
SmartDataStorePtr & operator=(const DataObject *pObj)
Automatic conversion to data type.
Definition: SmartDataStorePtr.h:82
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:96