ATLAS Offline Software
SurfaceHolderImpl.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRKEVENTPRIMITIVES_SURFACEHOLDER_H
6 #define TRKEVENTPRIMITIVES_SURFACEHOLDER_H
7 
9 
60 namespace Trk {
61 
62 /* Helper to avoid repeating code
63  */
64 template<typename S>
66 {
67 protected:
68  // protected we can not create instances of this object
69  // is to be used as helper
71 };
72 
73 /*
74  * Implementation based on plain ptr and
75  * isFree semantics
76  */
77 template<typename S>
79 {
80 public:
82  SurfacePtrHolderImpl() = default;
84  explicit SurfacePtrHolderImpl(const S& s)
86  {}
88  explicit SurfacePtrHolderImpl(const S* s)
90  {}
94  {}
98  {
99  // tranfer ownership and leave other nullptr
100  m_associatedSurface = other.m_associatedSurface;
101  other.m_associatedSurface = nullptr;
102  }
106  {
107  if (this != &other) {
108  destroySurface(); // clean up ourselves
109  m_associatedSurface = cloneHelper(other.m_associatedSurface);
110  }
111  return *this;
112  }
113 
117  {
118  // destroy current surface
119  destroySurface();
120  // steal payload of other and leave it to nullptr
121  this->m_associatedSurface = other.m_associatedSurface;
122  other.m_associatedSurface = nullptr;
123  return *this;
124  }
128  void destroySurface() noexcept
129  {
130  if (m_associatedSurface && m_associatedSurface->isFree()) {
131  delete m_associatedSurface;
132  }
133  //
134  m_associatedSurface = nullptr;
135  }
137  const S* surfacePtr() { return m_associatedSurface; }
139  const S* release() noexcept
140  {
141  const S* tmp = m_associatedSurface;
142  m_associatedSurface = nullptr;
143  return tmp;
144  }
147  static const S* cloneHelper(const S* input)
148  {
149  return (input && input->isFree() ? input->clone() : input);
150  }
151 
152 protected:
153  const S* m_associatedSurface = nullptr;
154  // protected we can not create instances of this object
155  // is to be used as helper
157 };
158 
159 /*
160  * Implementation based on plain ptr and
161  * has detector Element Semantics
162  */
163 template<typename S>
165 {
166 
167 public:
171  explicit SurfacePtrHolderImplDetEl(const S& s)
173  {}
175  explicit SurfacePtrHolderImplDetEl(const S* s)
177  {}
181  {}
185  {
186  // tranfer ownership and leave other nullptr
187  m_associatedSurface = other.m_associatedSurface;
188  other.m_associatedSurface = nullptr;
189  }
193  {
194  if (this != &other) {
195  destroySurface(); // clean up ourselves
196  m_associatedSurface = cloneHelper(other.m_associatedSurface);
197  }
198  return *this;
199  }
203  SurfacePtrHolderImplDetEl&& other) noexcept
204  {
205  // destroy current surface
206  destroySurface();
207  // steal payload of other and leave it to nullptr
208  this->m_associatedSurface = other.m_associatedSurface;
209  other.m_associatedSurface = nullptr;
210  return *this;
211  }
213  const S* surfacePtr() { return m_associatedSurface; }
215  const S* release() noexcept
216  {
217  const S* tmp = m_associatedSurface;
218  m_associatedSurface = nullptr;
219  return tmp;
220  }
224  void destroySurface() noexcept
225  {
226  if (m_associatedSurface &&
227  m_associatedSurface->associatedDetectorElement() == nullptr) {
228  delete m_associatedSurface;
229  }
230  //
231  m_associatedSurface = nullptr;
232  }
233 
236  static const S* cloneHelper(const S* input)
237  {
238  return (input && input->associatedDetectorElement() == nullptr
239  ? input->clone()
240  : input);
241  }
242 
243 protected:
244  const S* m_associatedSurface = nullptr;
245  // protected we can not create instances of this object
246  // is to be used as helper
248 };
249 
250 /*
251  * Implementation based on SurfaceUniquePtr
252  */
253 template<typename S>
255 {
256 public:
259 
262 
263  explicit SurfaceUniqHolderImpl(const S& s)
264  : m_associatedSurface(s.isFree() ? s.clone() : &s)
265  {}
266 
268  explicit SurfaceUniqHolderImpl(const S* s)
270  {}
271 
276  other.m_associatedSurface->isFree()
279  {}
280 
283 
287  {
288  if (this != &other) {
289  m_associatedSurface.reset(
290  (other.m_associatedSurface && other.m_associatedSurface->isFree())
291  ? other.m_associatedSurface->clone()
292  : other.m_associatedSurface.get());
293  }
294  return *this;
295  }
296 
299 
301  const S* surfacePtr() { return m_associatedSurface.get(); }
302 
305  void destroySurface() noexcept { m_associatedSurface.reset(); }
306 
308  const S* release() noexcept { return m_associatedSurface.release(); }
309 
310 protected:
312  // protected we can not create instances of this object
313  // is to be used as helper
315 };
316 }
317 
318 #endif
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(const SurfacePtrHolderImplDetEl &other)
copy ctor
Definition: SurfaceHolderImpl.h:179
Trk::SurfacePtrHolderImplDetEl::operator=
SurfacePtrHolderImplDetEl & operator=(const SurfacePtrHolderImplDetEl &other)
copy assingmemnt if surface is free we clone/copy.
Definition: SurfaceHolderImpl.h:192
Trk::SurfacePtrHolderImpl::cloneHelper
static const S * cloneHelper(const S *input)
Helper for cloning or not when we need depending on if the surface isFree.
Definition: SurfaceHolderImpl.h:147
SurfaceUniquePtrT.h
Handle conditional ownership of surfaces.
Trk::SurfacePtrHolderImpl::surfacePtr
const S * surfacePtr()
return the ptr we hold useful for tests
Definition: SurfaceHolderImpl.h:137
Trk::SurfacePtrHolderImplDetEl::operator=
SurfacePtrHolderImplDetEl & operator=(SurfacePtrHolderImplDetEl &&other) noexcept
Move assignement we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:202
Trk::SurfacePtrHolderImplBase
Definition: SurfaceHolderImpl.h:66
Trk::SurfacePtrHolderImplBase::~SurfacePtrHolderImplBase
~SurfacePtrHolderImplBase()=default
Trk::SurfacePtrHolderImplDetEl::release
const S * release() noexcept
release ala unique_ptr release
Definition: SurfaceHolderImpl.h:215
Trk::SurfacePtrHolderImpl::destroySurface
void destroySurface() noexcept
destroySurface deletes the ptr if not null and the surface isFree Usefull also for testing
Definition: SurfaceHolderImpl.h:128
Trk::SurfacePtrHolderImpl
Definition: SurfaceHolderImpl.h:79
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:562
JetTiledMap::S
@ S
Definition: TiledEtaPhiMap.h:44
Trk::SurfacePtrHolderImpl::release
const S * release() noexcept
release ala unique_ptr release
Definition: SurfaceHolderImpl.h:139
Trk::SurfacePtrHolderImplDetEl::m_associatedSurface
const S * m_associatedSurface
Definition: SurfaceHolderImpl.h:244
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(const S *s)
ctor from const Surface ptr. Takes ownership
Definition: SurfaceHolderImpl.h:268
python.Utilities.clone
clone
Definition: Utilities.py:134
Trk::SurfacePtrHolderImplDetEl::destroySurface
void destroySurface() noexcept
destroySurface deletes the ptr if not null and the surface has not a associatedDetectorElement Useful...
Definition: SurfaceHolderImpl.h:224
Trk::SurfaceUniqHolderImpl::~SurfaceUniqHolderImpl
~SurfaceUniqHolderImpl()=default
Trk::SurfacePtrHolderImplDetEl::~SurfacePtrHolderImplDetEl
~SurfacePtrHolderImplDetEl()
Definition: SurfaceHolderImpl.h:247
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(const SurfaceUniqHolderImpl &other)
copy ctor, if surface is free we clone/copy.
Definition: SurfaceHolderImpl.h:274
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(SurfaceUniqHolderImpl &&) noexcept=default
default move ctor
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(SurfacePtrHolderImpl &&other) noexcept
Move constructor we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:97
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(const S &s)
ctor from const Surface ref.
Definition: SurfaceHolderImpl.h:171
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
Trk::SurfacePtrHolderImpl::operator=
SurfacePtrHolderImpl & operator=(SurfacePtrHolderImpl &&other) noexcept
Move assignement we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:116
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl(const S &s)
ctor from const Surface ref.
Definition: SurfaceHolderImpl.h:263
Trk::SurfacePtrHolderImpl::m_associatedSurface
const S * m_associatedSurface
Definition: SurfaceHolderImpl.h:153
Trk::SurfaceUniqHolderImpl::operator=
SurfaceUniqHolderImpl & operator=(SurfaceUniqHolderImpl &&) noexcept=default
default move assignement
Trk::SurfacePtrHolderImplDetEl::surfacePtr
const S * surfacePtr()
return the ptr we hold useful for tests
Definition: SurfaceHolderImpl.h:213
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(SurfacePtrHolderImplDetEl &&other) noexcept
Move constructor we just steal the resource and leave other to point to nullptr.
Definition: SurfaceHolderImpl.h:184
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(const S *s)
ctor from const Surface ptr. Takes ownership
Definition: SurfaceHolderImpl.h:88
Trk::SurfacePtrHolderImplDetEl::cloneHelper
static const S * cloneHelper(const S *input)
Helper for cloning or not when we need depending on if we have an associatedDetectorElement.
Definition: SurfaceHolderImpl.h:236
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::SurfaceUniqHolderImpl::surfacePtr
const S * surfacePtr()
return the ptr we hold
Definition: SurfaceHolderImpl.h:301
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl(const S *s)
ctor from const Surface ptr. Takes ownership
Definition: SurfaceHolderImpl.h:175
Trk::SurfaceUniquePtrT
std::unique_ptr< S, SurfaceDeleter< S > > SurfaceUniquePtrT
Definition: SurfaceUniquePtrT.h:32
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl()=default
default ctor
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
Trk::SurfacePtrHolderImpl::~SurfacePtrHolderImpl
~SurfacePtrHolderImpl()
Definition: SurfaceHolderImpl.h:156
Trk::SurfaceUniqHolderImpl
Definition: SurfaceHolderImpl.h:255
Trk::SurfacePtrHolderImplDetEl::SurfacePtrHolderImplDetEl
SurfacePtrHolderImplDetEl()=default
default ctor
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(const SurfacePtrHolderImpl &other)
copy ctor
Definition: SurfaceHolderImpl.h:92
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
Trk::SurfacePtrHolderImplDetEl
Definition: SurfaceHolderImpl.h:165
Trk::SurfaceUniqHolderImpl::m_associatedSurface
SurfaceUniquePtrT< const S > m_associatedSurface
Definition: SurfaceHolderImpl.h:311
python.CaloScaleNoiseConfig.default
default
Definition: CaloScaleNoiseConfig.py:79
Trk::SurfacePtrHolderImpl::operator=
SurfacePtrHolderImpl & operator=(const SurfacePtrHolderImpl &other)
copy assingmemnt if surface is free we clone/copy.
Definition: SurfaceHolderImpl.h:105
Trk::SurfaceUniqHolderImpl::release
const S * release() noexcept
release , release the unique_ptr we hold
Definition: SurfaceHolderImpl.h:308
Trk::SurfaceUniqHolderImpl::destroySurface
void destroySurface() noexcept
destroySurface deletes the ptr if not null and is free usefull also for testing
Definition: SurfaceHolderImpl.h:305
Trk::SurfacePtrHolderImpl::SurfacePtrHolderImpl
SurfacePtrHolderImpl(const S &s)
ctor from const Surface ref.
Definition: SurfaceHolderImpl.h:84
Trk::SurfaceUniqHolderImpl::SurfaceUniqHolderImpl
SurfaceUniqHolderImpl()=default
default ctor