Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGeoVGConverter.cxx
Go to the documentation of this file.
1// @(#)root/vecgeom:$Id:$
2// Author: Mihaela Gheata 30/03/16
3/*************************************************************************
4 * Copyright (C) 1995-2016, 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
11/** \class TGeoVGConverter
12\ingroup Geometry_classes
13
14Geometry converter to VecGeom
15*/
16
17#include "TGeoVGConverter.h"
18#include "TGeoVGShape.h"
19#include "TGeoBBox.h"
20#include "TClass.h"
21
22#include <iostream>
23
24namespace {
25
26Bool_t isInSelection(const TGeoShape *shape, const std::set<TGeoShape::EShapeType> &selection)
27{
28 for (auto element : selection) {
29
30 // Special treatment of TGeo::kGeoBox, which is base class for all other shapes
32 if (typeid(*shape) == typeid(TGeoBBox)) {
33 return true;
34 } else {
35 continue;
36 }
37 }
38
39 // Just test bit for other shapes
40 if (shape->TestShapeBit(element)) {
41 return true;
42 }
43 }
44 return false;
45}
46
47} // namespace
48
49////////////////////////////////////////////////////////////////////////////////
50/// Default constructor.
51
56
57////////////////////////////////////////////////////////////////////////////////
58/// Default destructor.
59
61
62////////////////////////////////////////////////////////////////////////////////
63/// Main geometry conversion method.
64/// Convert all geometry shapes connected to volumes to VecGeom shapes
65
67{
68 // First convert the top volume
70 TGeoVGShape *vgshape = nullptr;
71 if (!top->GetShape()->IsVecGeom())
73 Int_t nconverted = 0;
74 // If shape of top volume not known by VecGeom, keep old one
75 if (vgshape) {
76 nconverted++;
77 top->SetShape(vgshape);
78 }
79
80 // Print info about selected/excluded shapes
81 if (gGeoManager->GetVerboseLevel() > 1) {
82 if (!fSelectedShapeTypes.empty()) {
83 Info("ConvertGeometry", "# %zu selected shape type for conversion \n", fSelectedShapeTypes.size());
84 }
85 if (!fExcludedShapeTypes.empty()) {
86 Info("ConvertGeometry", "# %zu shape types excluded from conversion \n", fExcludedShapeTypes.size());
87 }
88 }
89
90 // Now iterate the active geometry tree
92 TGeoNode *node;
93 while ((node = next.Next())) {
94 TGeoVolume *vol = node->GetVolume();
95 // Skip shape if already converted
96 if (vol->GetShape()->IsVecGeom())
97 continue;
98
99 // If fSelectedShapeTypes is not empty, convert only selected shapes
100 if ((!fSelectedShapeTypes.empty()) && (!isInSelection(vol->GetShape(), fSelectedShapeTypes))) {
101 if (gGeoManager->GetVerboseLevel() > 1) {
102 Info("ConvertGeometry", "# Shape type %s is not selected for conversion\n",
103 vol->GetShape()->IsA()->GetName());
104 }
105 continue;
106 }
107
108 // Skip shapes excluded from conversion
110 if (gGeoManager->GetVerboseLevel() > 1) {
111 Info("ConvertGeometry", "# Shape type %s is excluded from conversion\n", vol->GetShape()->IsA()->GetName());
112 }
113 continue;
114 }
115
116 // Info("ConvertGeometry","Converting %s\n", vol->GetName());
118 if (vgshape) {
119 nconverted++;
120 vol->SetShape(vgshape);
121 }
122 }
123 if (gGeoManager->GetVerboseLevel() > 0) {
124 Info("ConvertGeometry", "# Converted %d shapes to VecGeom ones\n", nconverted);
125 }
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Select shape(s) for conversion.
130/// Conversion is performed only on selected shapes. If unset, all solid types
131/// will be converted.
132
137
138////////////////////////////////////////////////////////////////////////////////
139/// Exclude shape(s) from conversion.
140/// Excluded types have precedence in case a type is also selected.
141
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:77
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TGeoManager * gGeoManager
Box class.
Definition TGeoBBox.h:17
A geometry iterator.
Definition TGeoNode.h:248
TGeoNode * Next()
Returns next node.
The manager class for any TGeo geometry.
Definition TGeoManager.h:45
TGeoVolume * GetMasterVolume() const
static Int_t GetVerboseLevel()
Set verbosity level (static function).
TGeoVolume * GetTopVolume() const
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:39
TGeoVolume * GetVolume() const
Definition TGeoNode.h:99
Base abstract class for all shapes.
Definition TGeoShape.h:25
virtual Bool_t IsVecGeom() const
Definition TGeoShape.h:150
TClass * IsA() const override
Definition TGeoShape.h:180
Bool_t TestShapeBit(UInt_t f) const
Definition TGeoShape.h:176
std::set< TGeoShape::EShapeType > fExcludedShapeTypes
void SelectShapeType(TGeoShape::EShapeType) override
Select shape(s) for conversion.
TGeoVGConverter(TGeoManager *manager)
Default constructor.
void ConvertGeometry() override
Main geometry conversion method.
void ExcludeShapeType(TGeoShape::EShapeType) override
Exclude shape(s) from conversion.
~TGeoVGConverter() override
Default destructor.
std::set< TGeoShape::EShapeType > fSelectedShapeTypes
Bridge class for using a VecGeom solid as TGeoShape.
Definition TGeoVGShape.h:30
static TGeoVGShape * Create(TGeoShape *shape)
Factory creating TGeoVGShape from a Root shape.
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:43
void SetShape(const TGeoShape *shape)
set the shape associated with this volume
TGeoShape * GetShape() const
Definition TGeoVolume.h:190
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1062
Abstract class for geometry converters.
static void SetConverter(const TVirtualGeoConverter *conv)
Static function to set an alternative converter.