Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoBrowseProvider.cxx
Go to the documentation of this file.
1// Author: Sergey Linev, 17.03.2023
2
3/*************************************************************************
4 * Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
15
16#include "TGeoManager.h"
17#include "TGeoVolume.h"
18#include "TGeoNode.h"
19#include "TROOT.h"
20
21
22namespace ROOT {
23namespace Browsable {
24
25////////////////////////////////////////////////////////////
26/// Representing TGeoVolume in browsables
27
29
30public:
31 TGeoVolumeElement(std::unique_ptr<RHolder> &br) : TObjectElement(br) {}
32
34 {
35 if (!CheckObject()) return nullptr;
36 return dynamic_cast<TGeoVolume *>(fObj);
37 }
38
39 bool IsFolder() const override
40 {
41 auto vol = GetVolume();
42 return vol ? vol->GetNdaughters() > 0 : false;
43 }
44
45 /** Get default action */
47 {
48 return kActGeom;
49 }
50
51 /** Check if want to perform action */
52 bool IsCapable(EActionKind action) const override
53 {
54 return action == kActGeom;
55 }
56
57 /** Provide iterator over TGeoVolume */
58 std::unique_ptr<RLevelIter> GetChildsIter() override;
59};
60
61
62////////////////////////////////////////////////////////////
63/// Representing TGeoNode in browsables
64
66
67public:
69
70 TGeoNodeElement(std::unique_ptr<RHolder> &br) : TObjectElement(br) {}
71
73 {
74 if (!CheckObject()) return nullptr;
75 return dynamic_cast<TGeoNode *>(fObj);
76 }
77
78 /** Get default action */
80 {
81 return kActGeom;
82 }
83
84 /** Check if want to perform action */
85 bool IsCapable(EActionKind action) const override
86 {
87 return action == kActGeom;
88 }
89
90 /** Provide iterator over TGeoVolume */
91 std::unique_ptr<RLevelIter> GetChildsIter() override;
92};
93
94
95////////////////////////////////////////////////////////////
96/// Iterating over nodes in the volume
97
98class TGeoVolumeIter : public RLevelIter {
99 TGeoIterator fIter; ///<! iterator
100 TGeoNode *fCurrent{nullptr}; ///<! current node
101
102public:
103 explicit TGeoVolumeIter(TGeoVolume *vol) : fIter(vol)
104 {
105 fIter.SetType(1); // iterate only current level
106 }
107
108 ~TGeoVolumeIter() override = default;
109
110 bool Next() override
111 {
112 fCurrent = fIter.Next();
113 return fCurrent != nullptr;
114 }
115
116 std::string GetItemName() const override { return fCurrent->GetName(); }
117
118 bool CanItemHaveChilds() const override
119 {
120 return fCurrent ? fCurrent->IsFolder() : false;
121 }
122
123 /** Returns full information for current element */
124 std::shared_ptr<RElement> GetElement() override
125 {
126 return std::make_shared<TGeoNodeElement>(fCurrent);
127 }
128
129 /** Returns full item information */
130 std::unique_ptr<RItem> CreateItem() override
131 {
132 auto item = RLevelIter::CreateItem();
133 item->SetIcon("sap-icon://product");
134 return item;
135 }
136};
137
138
139/** Provide iterator over TGeoManager */
140std::unique_ptr<RLevelIter> TGeoVolumeElement::GetChildsIter()
141{
142 auto vol = GetVolume();
143 return vol ? std::make_unique<TGeoVolumeIter>(vol) : nullptr;
144}
145
146/** Provide iterator over TGeoManager */
147std::unique_ptr<RLevelIter> TGeoNodeElement::GetChildsIter()
148{
149 auto node = GetNode();
150 return node ? std::make_unique<TGeoVolumeIter>(node->GetVolume()) : nullptr;
151}
152
153
154////////////////////////////////////////////////////////////
155/// Representing TGeoManager in browsables
156
158
159public:
160 TGeoManagerElement(std::unique_ptr<RHolder> &br) : TObjectElement(br) {}
161
162 const TObject *CheckObject() const override
163 {
164 // during TROOT destructor just forget about file reference
165 if (!gROOT || gROOT->TestBit(TObject::kInvalidObject)) {
166 ForgetObject();
167 return nullptr;
168 }
169
171 }
172
174 {
175 if (!CheckObject()) return nullptr;
176 return dynamic_cast<TGeoManager *>(fObj);
177 }
178
179 Long64_t GetSize() const override
180 {
181 auto mgr = GetMgr();
182 return mgr ? 128 : -1;
183 }
184
185 bool IsFolder() const override { return true; }
186
187 /** Get default action */
189 {
190 return kActGeom;
191 }
192
193 /** Check if want to perform action */
194 bool IsCapable(EActionKind action) const override
195 {
196 return action == kActGeom;
197 }
198
199 /** Provide iterator over TGeoManager */
200 std::unique_ptr<RLevelIter> GetChildsIter() override
201 {
202 auto mgr = GetMgr();
203
204 return mgr ? std::make_unique<TGeoVolumeIter>(mgr->GetMasterVolume()) : nullptr;
205 }
206
207};
208
209
210/////////////////////////////////////////////////////////////////////////////////
211/// Provider for TGeo browsing
212
214
215public:
217 {
218 RegisterBrowse(TGeoManager::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
219 return std::make_shared<TGeoManagerElement>(object);
220 });
221 RegisterBrowse(TGeoVolume::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
222 return std::make_shared<TGeoVolumeElement>(object);
223 });
224 RegisterBrowse(TGeoNode::Class(), [](std::unique_ptr<RHolder> &object) -> std::shared_ptr<RElement> {
225 return std::make_shared<TGeoNodeElement>(object);
226 });
227 }
228
230
231} // namespace Browsable
232} // namespace ROOT
long long Long64_t
Definition RtypesCore.h:69
#define gROOT
Definition TROOT.h:406
EActionKind
Possible actions on double-click.
Definition RElement.hxx:50
@ kActGeom
can be shown in geometry viewer
Definition RElement.hxx:59
Iterator over single level hierarchy like any array, keys list, ...
virtual std::unique_ptr< RItem > CreateItem()
Create generic description item for RBrowser.
Provider of different browsing methods for supported classes.
Definition RProvider.hxx:37
void RegisterBrowse(const TClass *cl, BrowseFunc_t func)
Representing TGeoManager in browsables.
EActionKind GetDefaultAction() const override
Get default action.
bool IsFolder() const override
Check if element can have childs.
std::unique_ptr< RLevelIter > GetChildsIter() override
Provide iterator over TGeoManager.
const TObject * CheckObject() const override
Check if object still exists.
bool IsCapable(EActionKind action) const override
Check if want to perform action.
TGeoManagerElement(std::unique_ptr< RHolder > &br)
Representing TGeoNode in browsables.
TGeoNodeElement(std::unique_ptr< RHolder > &br)
std::unique_ptr< RLevelIter > GetChildsIter() override
Provide iterator over TGeoVolume.
bool IsCapable(EActionKind action) const override
Check if want to perform action.
EActionKind GetDefaultAction() const override
Get default action.
Representing TGeoVolume in browsables.
std::unique_ptr< RLevelIter > GetChildsIter() override
Provide iterator over TGeoVolume.
bool IsCapable(EActionKind action) const override
Check if want to perform action.
bool IsFolder() const override
Check if element can have childs.
EActionKind GetDefaultAction() const override
Get default action.
TGeoVolumeElement(std::unique_ptr< RHolder > &br)
Iterating over nodes in the volume.
std::unique_ptr< RItem > CreateItem() override
Returns full item information.
bool Next() override
Shift to next entry.
std::string GetItemName() const override
Returns current entry name
bool CanItemHaveChilds() const override
Returns true if current item can have childs.
~TGeoVolumeIter() override=default
std::shared_ptr< RElement > GetElement() override
Returns full information for current element.
Access to TObject basic properties for RBrowsable.
virtual const TObject * CheckObject() const
Check if object still exists.
void ForgetObject() const
Forget object, use when it was deleted behind the scene.
A geometry iterator.
Definition TGeoNode.h:248
void SetType(Int_t type)
Definition TGeoNode.h:304
TGeoNode * Next()
Returns next node.
The manager class for any TGeo geometry.
Definition TGeoManager.h:44
static TClass * Class()
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:39
Bool_t IsFolder() const override
Returns kTRUE in case object contains browsable objects (like containers or lists of other objects).
Definition TGeoNode.h:104
static TClass * Class()
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
static TClass * Class()
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Mother of all ROOT objects.
Definition TObject.h:41
@ kInvalidObject
if object ctor succeeded but object should not be used
Definition TObject.h:72
ROOT::Browsable::TGeoBrowseProvider newTGeoBrowseProvider
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...