BmnRoot
Loading...
Searching...
No Matches
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
32 : FairGeoSet()
33 , name("cave")
34{
35 fName = "cave";
36 maxModules = 1;
37}
38
39Bool_t FairGeoCave::read(std::fstream& fin, FairGeoMedia* media)
40{
41 // Reads the geometry from file
42 if (!media) {
43 return kFALSE;
44 }
45 const Int_t maxbuf = 256;
46 char buf[maxbuf];
47 FairGeoNode* volu = 0;
48 FairGeoMedium* medium;
49 Bool_t rc = kTRUE;
50 do {
51 fin.getline(buf, maxbuf);
52 if (buf[0] != '\0' && buf[0] != '/' && !fin.eof()) {
53 if (strcmp(buf, name) == 0) {
54 volu = new FairGeoNode;
55 volu->SetName(buf);
56 volu->setVolumeType(kFairGeoTopNode);
57 volu->setActive();
58 fin.getline(buf, maxbuf);
59 TString shape(buf);
60 FairGeoBasicShape* sh = pShapes->selectShape(shape);
61 if (sh) {
62 volu->setShape(sh);
63 } else {
64 rc = kFALSE;
65 }
66 fin.getline(buf, maxbuf);
67 medium = media->getMedium(buf);
68 if (!medium) {
69 medium = new FairGeoMedium();
70 media->addMedium(medium);
71 }
72 volu->setMedium(medium);
73 Int_t n = 0;
74 if (sh) {
75 n = sh->readPoints(&fin, volu);
76 }
77 if (n <= 0) {
78 rc = kFALSE;
79 }
80 } else {
81 rc = kFALSE;
82 }
83 }
84 } while (rc && !volu && !fin.eof());
85 if (volu && rc) {
86 volumes->Add(volu);
87 masterNodes->Add(new FairGeoNode(*volu));
88 } else {
89 delete volu;
90 volu = 0;
91 rc = kFALSE;
92 }
93 return rc;
94}
95
97{
98 // Adds the reference node
99 FairGeoNode* volu = getVolume(name);
100 if (volu) {
101 masterNodes->Add(new FairGeoNode(*volu));
102 }
103}
104
105void FairGeoCave::write(std::fstream& fout)
106{
107 // Writes the geometry to file
108 std::ios_base::fmtflags tmp = fout.setf(std::ios::fixed, std::ios::floatfield);
109 FairGeoNode* volu = getVolume(name);
110 if (volu) {
111 FairGeoBasicShape* sh = volu->getShapePointer();
112 FairGeoMedium* med = volu->getMedium();
113 if (sh && med) {
114 fout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
115 sh->writePoints(&fout, volu);
116 }
117 }
118 fout.setf(tmp);
119}
120
122{
123 // Prints the geometry
124 FairGeoNode* volu = getVolume(name);
125 if (volu) {
126 FairGeoBasicShape* sh = volu->getShapePointer();
127 FairGeoMedium* med = volu->getMedium();
128 if (sh && med) {
129 std::cout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
130 sh->printPoints(volu);
131 }
132 }
133}
Bool_t read(std::fstream &, FairGeoMedia *)
void addRefNodes()
void write(std::fstream &)
TString name
Definition FairGeoCave.h:22