er  dev
ERGeoCave.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Created : 10/11/2003
3 
5 // FairGeoCave
6 //
7 // Class for the geometry of the detector part CAVE
8 //
10 
11 #include "ERGeoCave.h"
12 #include "FairGeoNode.h"
13 #include "FairGeoShapes.h"
14 #include "FairGeoBasicShape.h"
15 #include "FairGeoMedium.h"
16 
17 using namespace std;
18 ClassImp(ERGeoCave)
19 
21  // Constructor
22  fName="cave";
23  name="cave";
24  maxModules=1;
25 }
26 
27 Bool_t ERGeoCave::read(fstream& fin,FairGeoMedia* media) {
28  // Reads the geometry from file
29  if (!media) return kFALSE;
30  const Int_t maxbuf=256;
31  char buf[maxbuf];
32  FairGeoNode* volu=0;
33  FairGeoMedium* medium;
34  Bool_t rc=kTRUE;
35  do {
36  fin.getline(buf,maxbuf);
37  if (buf[0]!='\0' && buf[0]!='/' && !fin.eof()) {
38  if (strcmp(buf,name)==0) {
39  volu=new FairGeoNode;
40  volu->SetName(buf);
41  volu->setVolumeType(kFairGeoTopNode);
42  volu->setActive();
43  fin.getline(buf,maxbuf);
44  TString shape(buf);
45  FairGeoBasicShape* sh=pShapes->selectShape(shape);
46  if (sh) volu->setShape(sh);
47  else rc=kFALSE;
48  fin.getline(buf,maxbuf);
49  medium=media->getMedium(buf);
50  if (!medium) {
51  medium=new FairGeoMedium();
52  media->addMedium(medium);
53  }
54  volu->setMedium(medium);
55  Int_t n=0;
56  if (sh) n=sh->readPoints(&fin,volu);
57  if (n<=0) rc=kFALSE;
58  } else rc=kFALSE;
59  }
60  } while (rc && !volu && !fin.eof());
61  if (volu && rc) {
62  volumes->Add(volu);
63  masterNodes->Add(new FairGeoNode(*volu));
64  } else {
65  delete volu;
66  volu=0;
67  rc=kFALSE;
68  }
69  return rc;
70 }
71 
72 void ERGeoCave::addRefNodes() {
73  // Adds the reference node
74  FairGeoNode* volu=getVolume(name);
75  if (volu) masterNodes->Add(new FairGeoNode(*volu));
76 }
77 
78 void ERGeoCave::write(fstream& fout) {
79  // Writes the geometry to file
80  fout.setf(ios::fixed,ios::floatfield);
81  FairGeoNode* volu=getVolume(name);
82  if (volu) {
83  FairGeoBasicShape* sh=volu->getShapePointer();
84  FairGeoMedium* med=volu->getMedium();
85  if (sh&&med) {
86  fout<<volu->GetName()<<'\n'<<sh->GetName()<<'\n'<<med->GetName()<<'\n';
87  sh->writePoints(&fout,volu);
88  }
89  }
90 }
91 
92 void ERGeoCave::print() {
93  // Prints the geometry
94  FairGeoNode* volu=getVolume(name);
95  if (volu) {
96  FairGeoBasicShape* sh=volu->getShapePointer();
97  FairGeoMedium* med=volu->getMedium();
98  if (sh&&med) {
99  cout<<volu->GetName()<<'\n'<<sh->GetName()<<'\n'<<med->GetName()<<'\n';
100  sh->printPoints(volu);
101  }
102  }
103 }