FairShip
Loading...
Searching...
No Matches
ShipGeoCave.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
6// ShipGeoCave
7//
8// Class for the geometry of the detector part CAVE
9//
11
12#include "ShipGeoCave.h"
13
14#include <cstring> // for strcmp
15#include <iostream> // for cout
16
17#include "FairGeoBasicShape.h" // for FairGeoBasicShape
18#include "FairGeoMedia.h" // for FairGeoMedia
19#include "FairGeoMedium.h" // for FairGeoMedium
20#include "FairGeoNode.h" // for FairGeoNode, etc
21#include "FairGeoShapes.h" // for FairGeoShapes
22#include "TList.h" // for TList
23
24using std::cout;
25using std::ios;
26
27ShipGeoCave::ShipGeoCave() : FairGeoSet(), name("cave") {
28 // Constructor
29 fName = "cave";
30 name = "cave";
31 maxModules = 1;
32}
33
34Bool_t ShipGeoCave::read(std::fstream& fin, FairGeoMedia* media) {
35 // Reads the geometry from file
36 if (!media) {
37 return kFALSE;
38 }
39 const Int_t maxbuf = 256;
40 char buf[maxbuf];
41 FairGeoNode* volu = nullptr;
42 FairGeoMedium* medium;
43 Bool_t rc = kTRUE;
44 do {
45 fin.getline(buf, maxbuf);
46 if (buf[0] != '\0' && buf[0] != '/' && !fin.eof()) {
47 if (strcmp(buf, name) == 0) {
48 volu = new FairGeoNode;
49 volu->SetName(buf);
50 volu->setVolumeType(kFairGeoTopNode);
51 volu->setActive();
52 fin.getline(buf, maxbuf);
53 TString shape(buf);
54 FairGeoBasicShape* sh = pShapes->selectShape(shape);
55 if (sh) {
56 volu->setShape(sh);
57 } else {
58 rc = kFALSE;
59 }
60 fin.getline(buf, maxbuf);
61 medium = media->getMedium(buf);
62 if (!medium) {
63 medium = new FairGeoMedium();
64 media->addMedium(medium);
65 }
66 volu->setMedium(medium);
67 Int_t n = 0;
68 if (sh) {
69 n = sh->readPoints(&fin, volu);
70 }
71 if (n <= 0) {
72 rc = kFALSE;
73 }
74 } else {
75 rc = kFALSE;
76 }
77 }
78 } while (rc && !volu && !fin.eof());
79 if (volu && rc) {
80 volumes->Add(volu);
81 masterNodes->Add(new FairGeoNode(*volu));
82 } else {
83 delete volu;
84 volu = nullptr;
85 rc = kFALSE;
86 }
87 return rc;
88}
89
91 // Adds the reference node
92 FairGeoNode* volu = getVolume(name);
93 if (volu) {
94 masterNodes->Add(new FairGeoNode(*volu));
95 }
96}
97
98void ShipGeoCave::write(std::fstream& fout) {
99 // Writes the geometry to file
100 fout.setf(ios::fixed, ios::floatfield);
101 FairGeoNode* volu = getVolume(name);
102 if (volu) {
103 FairGeoBasicShape* sh = volu->getShapePointer();
104 FairGeoMedium* med = volu->getMedium();
105 if (sh && med) {
106 fout << volu->GetName() << '\n'
107 << sh->GetName() << '\n'
108 << med->GetName() << '\n';
109 sh->writePoints(&fout, volu);
110 }
111 }
112}
113
115 // Prints the geometry
116 FairGeoNode* volu = getVolume(name);
117 if (volu) {
118 FairGeoBasicShape* sh = volu->getShapePointer();
119 FairGeoMedium* med = volu->getMedium();
120 if (sh && med) {
121 cout << volu->GetName() << '\n'
122 << sh->GetName() << '\n'
123 << med->GetName() << '\n';
124 sh->printPoints(volu);
125 }
126 }
127}
Bool_t read(std::fstream &, FairGeoMedia *) override
TString name
Definition ShipGeoCave.h:19
void print() override
void addRefNodes() override
void write(std::fstream &) override