FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoCave.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 //*-- AUTHOR : Ilse Koenig
9 //*-- Created : 10/11/2003
10 
12 // FairGeoCave
13 //
14 // Class for the geometry of the detector part CAVE
15 //
17 
18 #include "FairGeoCave.h"
19 
20 #include "FairGeoBasicShape.h" // for FairGeoBasicShape
21 #include "FairGeoMedia.h" // for FairGeoMedia
22 #include "FairGeoMedium.h" // for FairGeoMedium
23 #include "FairGeoNode.h" // for FairGeoNode, etc
24 #include "FairGeoShapes.h" // for FairGeoShapes
25 
26 #include <TList.h> // for TList
27 #include <fstream> // for fstream
28 #include <iostream> // for cout
29 #include <string.h> // for strcmp
30 
31 using namespace std;
33 
35  : FairGeoSet()
36  , name("cave")
37 {
38  fName = "cave";
39  maxModules = 1;
40 }
41 
42 Bool_t FairGeoCave::read(std::fstream& fin, FairGeoMedia* media)
43 {
44  // Reads the geometry from file
45  if (!media) {
46  return kFALSE;
47  }
48  const Int_t maxbuf = 256;
49  char buf[maxbuf];
50  FairGeoNode* volu = 0;
51  FairGeoMedium* medium;
52  Bool_t rc = kTRUE;
53  do {
54  fin.getline(buf, maxbuf);
55  if (buf[0] != '\0' && buf[0] != '/' && !fin.eof()) {
56  if (strcmp(buf, name) == 0) {
57  volu = new FairGeoNode;
58  volu->SetName(buf);
60  volu->setActive();
61  fin.getline(buf, maxbuf);
62  TString shape(buf);
64  if (sh) {
65  volu->setShape(sh);
66  } else {
67  rc = kFALSE;
68  }
69  fin.getline(buf, maxbuf);
70  medium = media->getMedium(buf);
71  if (!medium) {
72  medium = new FairGeoMedium();
73  media->addMedium(medium);
74  }
75  volu->setMedium(medium);
76  Int_t n = 0;
77  if (sh) {
78  n = sh->readPoints(&fin, volu);
79  }
80  if (n <= 0) {
81  rc = kFALSE;
82  }
83  } else {
84  rc = kFALSE;
85  }
86  }
87  } while (rc && !volu && !fin.eof());
88  if (volu && rc) {
89  volumes->Add(volu);
90  masterNodes->Add(new FairGeoNode(*volu));
91  } else {
92  delete volu;
93  volu = 0;
94  rc = kFALSE;
95  }
96  return rc;
97 }
98 
100 {
101  // Adds the reference node
102  FairGeoNode* volu = getVolume(name);
103  if (volu) {
104  masterNodes->Add(new FairGeoNode(*volu));
105  }
106 }
107 
108 void FairGeoCave::write(std::fstream& fout)
109 {
110  // Writes the geometry to file
111  std::ios_base::fmtflags tmp = fout.setf(ios::fixed, ios::floatfield);
112  FairGeoNode* volu = getVolume(name);
113  if (volu) {
114  FairGeoBasicShape* sh = volu->getShapePointer();
115  FairGeoMedium* med = volu->getMedium();
116  if (sh && med) {
117  fout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
118  sh->writePoints(&fout, volu);
119  }
120  }
121  fout.setf(tmp);
122 }
123 
125 {
126  // Prints the geometry
127  FairGeoNode* volu = getVolume(name);
128  if (volu) {
129  FairGeoBasicShape* sh = volu->getShapePointer();
130  FairGeoMedium* med = volu->getMedium();
131  if (sh && med) {
132  cout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
133  sh->printPoints(volu);
134  }
135  }
136 }
TList * masterNodes
Definition: FairGeoSet.h:54
FairGeoShapes * pShapes
Definition: FairGeoSet.h:59
void addMedium(FairGeoMedium *m)
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
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 write(std::fstream &)
Bool_t read(std::fstream &, FairGeoMedia *)
Definition: FairGeoCave.cxx:42
FairGeoBasicShape * getShapePointer()
Definition: FairGeoNode.h:72
TList * volumes
Definition: FairGeoSet.h:53
void addRefNodes()
Definition: FairGeoCave.cxx:99
TString name
Definition: FairGeoCave.h:22