EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairGeoShapes.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairGeoShapes.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Modified : 22/06/2003 by Ilse Koenig
3 
5 //
6 // FairGeoShapes
7 //
8 // Class to manage the GEANT/ROOT geometry shapes
9 //
10 // The 3D geometry in ROOT uses the ROOT library geom.
11 //
12 // This class holds a list of shape classes (type FairGeoBasicShape). They are
13 // used by all detectors when reading or writing geometry parameter containers
14 // to ascii files or to create an event display. This class is instantiated in
15 // the class HSpectrometer inside the function createDetGeomPar(Text_t* name).
16 // Every geometry parameter container gets a pointer to it.
17 //
18 // The individual shape classes are accessible with the selectShape(...)
19 // functions. The functions readPoints(...) and writePoints(...) use it
20 // internally.
21 //
22 // In the current version the following shapes are implemented:
23 // BOX TRAP TRD1 PGON PCON TUBE TUBS CONE CONS SPHE ELTU
24 // TORUS is added 06.11.06 m.al-turany
25 //
27 
28 #include"FairGeoShapes.h"
29 
30 #include "FairGeoVolume.h"
31 #include "FairGeoBasicShape.h"
32 #include "FairGeoBrik.h"
33 #include "FairGeoTrap.h"
34 #include "FairGeoTrd1.h"
35 #include "FairGeoPgon.h"
36 #include "FairGeoPcon.h"
37 #include "FairGeoTube.h"
38 #include "FairGeoTubs.h"
39 #include "FairGeoCone.h"
40 #include "FairGeoCons.h"
41 #include "FairGeoSphe.h"
42 #include "FairGeoEltu.h"
43 #include "FairGeoTorus.h"
44 #include "FairGeoAssembly.h"
45 
46 #include "TList.h"
47 
49 
51  : TObject(),
52  shapes(new TList())
53 {
54  // constructor creates empty list of shapes
55 
56 }
57 
58 
60 {
61  // destructor deletes all shapes
62  shapes->Delete();
63  delete shapes;
64 }
65 
66 
68 {
69  // returns a pointer to the shape used in the given volume
70  // calls internally selectShape(TString&) with the name of the shape
71  // returns NULL if the corresponding shape class is not implemented
72  const TString& name(volu->getShape());
73  return selectShape(name);
74 }
75 
76 
78 {
79  // returns a pointer to the shape given by name
80  // creates a shape object and adds it to the list of shapes if
81  // not existing
82  // returns NULL if the corresponding shape class is not implemented
83  TString allShapes[13]= {"BOX ","TRAP","TRD1","PGON","PCON","TUBE","TUBS",
84  "CONE","CONS","SPHE","ELTU","TORUS", "ASSEMBLY"
85  };
86  TString sName(name);
87  if (sName.Length()==3) { sName+=" "; }
88  FairGeoBasicShape* s=(FairGeoBasicShape*)shapes->FindObject(sName);
89  if (s) { return s; }
90  Int_t no=-1;
91  for(Int_t i=0; i<13; i++) {if (sName.CompareTo(allShapes[i])==0) { no=i; }}
92  switch(no) {
93  case 0:
94  {s= new FairGeoBrik(); break;}
95  case 1:
96  {s= new FairGeoTrap(); break;}
97  case 2:
98  {s= new FairGeoTrd1(); break;}
99  case 3:
100  {s= new FairGeoPgon(); break;}
101  case 4:
102  {s= new FairGeoPcon(); break;}
103  case 5:
104  {s= new FairGeoTube(); break;}
105  case 6:
106  {s= new FairGeoTubs(); break;}
107  case 7:
108  {s= new FairGeoCone(); break;}
109  case 8:
110  {s= new FairGeoCons(); break;}
111  case 9:
112  {s= new FairGeoSphe(); break;}
113  case 10:
114  {s= new FairGeoEltu(); break;}
115  case 11:
116  {s= new FairGeoTorus(); break;}
117  case 12:
118  {s= new FairGeoAssembly(); break;}
119  default: {
120  Error("selectShape","shape %s not implemented",name.Data());
121  }
122  }
123  if (s) { shapes->Add(s); }
124  return s;
125 }
126 
127 
128 Int_t FairGeoShapes::readPoints(std::fstream* pFile,FairGeoVolume* volu)
129 {
130  // reads the points of the given volume from the Ascii file
131  // returns the number of points read
132  // returns 0 if if the corresponding shape class is not implemented
134  if (s) { return s->readPoints(pFile,volu); }
135  else { return 0; }
136 }
137 
138 
139 Bool_t FairGeoShapes::writePoints(std::fstream* pFile,FairGeoVolume* volu)
140 {
141  // writes the points of the given volume to the Ascii file
142  // return kFALSE if the corresponding shape class is not implemented
144  if (s) { return s->writePoints(pFile,volu); }
145  else { return kFALSE; }
146 }
147 
148 
150 {
151  // writes the points of the given volume to the Ascii file
152  // return kFALSE if the corresponding shape class is not implemented
154  if (s) { return s->printPoints(volu); }
155 }