ROOT
master
Reference Guide
Loading...
Searching...
No Matches
TGeoExtension.cxx
Go to the documentation of this file.
1
// Author: Andrei.Gheata@cern.ch 29/05/2013
2
// Following proposal by Markus Frank
3
4
/*************************************************************************
5
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6
* All rights reserved. *
7
* *
8
* For the licensing terms see $ROOTSYS/LICENSE. *
9
* For the list of contributors see $ROOTSYS/README/CREDITS. *
10
*************************************************************************/
11
12
#include "
TGeoExtension.h
"
13
#include "
Rtypes.h
"
14
#include <cassert>
15
16
17
/** \class TGeoExtension
18
\ingroup Geometry_classes
19
20
ABC for user objects attached to TGeoVolume or TGeoNode.
21
Provides interface for getting a reference (grab) and
22
releasing the extension object (release), allowing for
23
derived classes to implement reference counted sharing.
24
The user who should attach extensions to logical volumes
25
or nodes BEFORE applying misalignment information so that
26
these will be available to all copies.
27
*/
28
29
30
/** \class TGeoRCExtension
31
\ingroup Geometry_classes
32
33
Reference counted extension which has a pointer to and
34
owns a user defined TObject. This class can be used as
35
model for a reference counted derivation from TGeoExtension.
36
37
Note: Creating a TGeoRCExtension with new() automatically grabs it, but the
38
creator has to Release it before the pointer gets out of scope.
39
The following sequence is valid:
40
41
~~~ {.cpp}
42
// producer:
43
TGeoRCExtension *ext = new TGeoRCExtension();
44
some_TGeoVolume->SetUserExtension(ext);
45
ext->Release();
46
// user:
47
TGeoRCExtension *ext = dynamic_cast<TGeoRCExtension*>(some_TGeoVolume->GrabUserExtension());
48
// ... use extension
49
ext->Release();
50
~~~
51
52
The extension is going to be released by the TGeoVolume holder at the destruction
53
or when calling SetUserExtension(0).
54
55
The following usage is not correct:
56
57
~~~ {.cpp}
58
some_TGeoVolume->SetUserExtension(new TGeoRCExtension())
59
~~~
60
61
since the producer code does not release the extension.
62
One cannot call directly "delete ext" nor allocate an extension on the stack,
63
since the destructor is protected. Use Release instead.
64
*/
65
66
void
TGeoRCExtension::Release
()
const
67
{
68
assert
(
fRC
> 0);
69
fRC
--;
70
if
(
fRC
== 0)
71
delete
this
;
72
}
Rtypes.h
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
TGeoExtension.h
TGeoRCExtension::fRC
Int_t fRC
Definition
TGeoExtension.h:55
TGeoRCExtension::Release
void Release() const override
Definition
TGeoExtension.cxx:66
geom
geom
src
TGeoExtension.cxx
ROOT master - Reference Guide Generated on Sun Sep 21 2025 15:07:46 (GVA Time) using Doxygen 1.10.0