R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BGeoCave.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14#include "R3BGeoCave.h"
15
16#include "FairGeoBasicShape.h"
17#include "FairGeoMedia.h"
18#include "FairGeoMedium.h"
19#include "FairGeoNode.h"
20#include "FairGeoShapes.h"
21#include "FairLogger.h"
22
23#include <TList.h>
24#include <iostream>
25#include <string.h>
26
27using namespace std;
28
30 : FairGeoSet()
31 , name("cave")
32{
33 // Constructor
34 fName = "cave";
35 maxModules = 1;
36}
37
38Bool_t R3BGeoCave::read(fstream& fin, FairGeoMedia* media)
39{
40 // Reads the geometry from file
41 if (!media)
42 {
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 {
52 fin.getline(buf, maxbuf);
53 if (buf[0] != '\0' && buf[0] != '/' && !fin.eof())
54 {
55 if (strcmp(buf, name) == 0)
56 {
57 volu = new FairGeoNode;
58 volu->SetName(buf);
59 volu->setVolumeType(kFairGeoTopNode);
60 volu->setActive();
61 fin.getline(buf, maxbuf);
62 TString shape(buf);
63 FairGeoBasicShape* sh = pShapes->selectShape(shape);
64 if (sh)
65 {
66 volu->setShape(sh);
67 }
68 else
69 {
70 rc = kFALSE;
71 }
72 fin.getline(buf, maxbuf);
73 medium = media->getMedium(buf);
74 if (!medium)
75 {
76 medium = new FairGeoMedium();
77 media->addMedium(medium);
78 }
79 volu->setMedium(medium);
80 Int_t n = 0;
81 if (sh)
82 {
83 n = sh->readPoints(&fin, volu);
84 }
85 if (n <= 0)
86 {
87 rc = kFALSE;
88 }
89 }
90 else
91 {
92 rc = kFALSE;
93 }
94 }
95 } while (rc && !volu && !fin.eof());
96 if (volu && rc)
97 {
98 volumes->Add(volu);
99 masterNodes->Add(new FairGeoNode(*volu));
100 }
101 else
102 {
103 delete volu;
104 volu = 0;
105 rc = kFALSE;
106 }
107 return rc;
108}
109
111{
112 // Adds the reference node
113 FairGeoNode* volu = getVolume(name);
114 if (volu)
115 {
116 masterNodes->Add(new FairGeoNode(*volu));
117 }
118}
119
120void R3BGeoCave::write(fstream& fout)
121{
122 // Writes the geometry to file
123 fout.setf(ios::fixed, ios::floatfield);
124 FairGeoNode* volu = getVolume(name);
125 if (volu)
126 {
127 FairGeoBasicShape* sh = volu->getShapePointer();
128 FairGeoMedium* med = volu->getMedium();
129 if (sh && med)
130 {
131 fout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
132 sh->writePoints(&fout, volu);
133 }
134 }
135}
136
138{
139 // Prints the geometry
140 FairGeoNode* volu = getVolume(name);
141 if (volu)
142 {
143 FairGeoBasicShape* sh = volu->getShapePointer();
144 FairGeoMedium* med = volu->getMedium();
145 if (sh && med)
146 {
147 LOG(info) << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
148 sh->printPoints(volu);
149 }
150 }
151}
152
ClassImp(R3BGeoCave)
TString name
Definition R3BGeoCave.h:29
void addRefNodes()
void write(std::fstream &)
Bool_t read(std::fstream &, FairGeoMedia *)