FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MyGeoCave.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 // -------------------------------------------------------------------------
10 // ----- MyGeoCave file -----
11 // ----- Created 26/03/14 by M. Al-Turany -----
12 // -------------------------------------------------------------------------
13 
15 // MyGeoCave
16 //
17 // Class for the geometry of the detector part CAVE
18 //
20 
21 #include "MyGeoCave.h"
22 
23 #include "FairGeoBasicShape.h" // for FairGeoBasicShape
24 #include "FairGeoMedia.h" // for FairGeoMedia
25 #include "FairGeoMedium.h" // for FairGeoMedium
26 #include "FairGeoNode.h" // for FairGeoNode, etc
27 #include "FairGeoShapes.h" // for FairGeoShapes
28 
29 #include <TList.h> // for TList
30 #include <iostream> // for cout
31 #include <string.h> // for strcmp
32 
33 using namespace std;
35 
37  : FairGeoSet()
38  , name("cave")
39 {
40  // Constructor
41  fName = "cave";
42  maxModules = 1;
43 }
44 
45 Bool_t MyGeoCave::read(fstream& fin, FairGeoMedia* media)
46 {
47  // Reads the geometry from file
48  if (!media) {
49  return kFALSE;
50  }
51  const Int_t maxbuf = 256;
52  char buf[maxbuf];
53  FairGeoNode* volu = 0;
54  FairGeoMedium* medium;
55  Bool_t rc = kTRUE;
56  do {
57  fin.getline(buf, maxbuf);
58  if (buf[0] != '\0' && buf[0] != '/' && !fin.eof()) {
59  if (strcmp(buf, name) == 0) {
60  volu = new FairGeoNode;
61  volu->SetName(buf);
63  volu->setActive();
64  fin.getline(buf, maxbuf);
65  TString shape(buf);
67  if (sh) {
68  volu->setShape(sh);
69  } else {
70  rc = kFALSE;
71  }
72  fin.getline(buf, maxbuf);
73  medium = media->getMedium(buf);
74  if (!medium) {
75  medium = new FairGeoMedium();
76  media->addMedium(medium);
77  }
78  volu->setMedium(medium);
79  Int_t n = 0;
80  if (sh) {
81  n = sh->readPoints(&fin, volu);
82  }
83  if (n <= 0) {
84  rc = kFALSE;
85  }
86  } else {
87  rc = kFALSE;
88  }
89  }
90  } while (rc && !volu && !fin.eof());
91  if (volu && rc) {
92  volumes->Add(volu);
93  masterNodes->Add(new FairGeoNode(*volu));
94  } else {
95  delete volu;
96  volu = 0;
97  rc = kFALSE;
98  }
99  return rc;
100 }
101 
103 {
104  // Adds the reference node
105  FairGeoNode* volu = getVolume(name);
106  if (volu) {
107  masterNodes->Add(new FairGeoNode(*volu));
108  }
109 }
110 
111 void MyGeoCave::write(fstream& fout)
112 {
113  // Writes the geometry to file
114  fout.setf(ios::fixed, ios::floatfield);
115  FairGeoNode* volu = getVolume(name);
116  if (volu) {
117  FairGeoBasicShape* sh = volu->getShapePointer();
118  FairGeoMedium* med = volu->getMedium();
119  if (sh && med) {
120  fout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
121  sh->writePoints(&fout, volu);
122  }
123  }
124 }
125 
126 void MyGeoCave::print()
127 {
128  // Prints the geometry
129  FairGeoNode* volu = getVolume(name);
130  if (volu) {
131  FairGeoBasicShape* sh = volu->getShapePointer();
132  FairGeoMedium* med = volu->getMedium();
133  if (sh && med) {
134  cout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
135  sh->printPoints(volu);
136  }
137  }
138 }
void addRefNodes()
Definition: MyGeoCave.cxx:102
TList * masterNodes
Definition: FairGeoSet.h:54
FairGeoShapes * pShapes
Definition: FairGeoSet.h:59
void addMedium(FairGeoMedium *m)
void write(std::fstream &)
void setActive(Bool_t a=kTRUE)
Definition: FairGeoNode.h:92
virtual Bool_t writePoints(std::fstream *, FairGeoVolume *)
FairGeoMedium * getMedium(const char *)
ClassImp(FairEventBuilder)
void setShape(FairGeoBasicShape *s)
Definition: FairGeoNode.h:127
FairGeoNode * getVolume(const char *name)
Definition: FairGeoSet.h:83
TString name
Definition: MyGeoCave.h:30
FairGeoBasicShape * selectShape(FairGeoVolume *)
Int_t maxModules
Definition: FairGeoSet.h:57
virtual void printPoints(FairGeoVolume *volu)
void setVolumeType(EFairGeoNodeType t)
Definition: FairGeoNode.h:87
void setMedium(FairGeoMedium *med)
Definition: FairGeoNode.h:91
FairGeoMedium * getMedium()
Definition: FairGeoNode.h:74
virtual Int_t readPoints(std::fstream *, FairGeoVolume *)
void print()
Definition: MyGeoCave.cxx:126
FairGeoBasicShape * getShapePointer()
Definition: FairGeoNode.h:72
TList * volumes
Definition: FairGeoSet.h:53
Bool_t read(std::fstream &, FairGeoMedia *)