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