ATTPCROOT  0.3.0-alpha
A ROOT-based framework for analyzing data from active target detectors
AtGeoCave.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 version 3 (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 // -------------------------------------------------------------------------
10 // ----- AtGeoCave file -----
11 // ----- Created 26/03/14 by M. Al-Turany -----
12 // -------------------------------------------------------------------------
13 
15 // AtGeoCave
16 //
17 // Class for the geometry of the detector part CAVE
18 //
20 
21 #include "AtGeoCave.h"
22 
23 #include <FairGeoBasicShape.h> // for FairGeoBasicShape
24 #include <FairGeoMedia.h> // for FairGeoMedia
25 #include <FairGeoMedium.h> // for FairGeoMedium
26 #include <FairGeoNode.h> // for FairGeoNode, etc
27 #include <FairGeoSet.h>
28 #include <FairGeoShapes.h> // for FairGeoShapes
29 
30 #include <Rtypes.h>
31 #include <TList.h> // for TList
32 #include <TString.h>
33 
34 #include <cstring> // for strcmp
35 #include <iostream> // for cout
36 
37 using namespace std;
39 
41  : FairGeoSet(), name("cave")
42 {
43  // Constructor
44  fName = "cave";
45 
46  maxModules = 1;
47 }
48 
49 Bool_t AtGeoCave::read(fstream &fin, FairGeoMedia *media)
50 {
51  // Reads the geometry from file
52  if (!media) {
53  return kFALSE;
54  }
55  const Int_t maxbuf = 256;
56  char buf[maxbuf];
57  FairGeoNode *volu = nullptr;
58  FairGeoMedium *medium = nullptr;
59  Bool_t rc = kTRUE;
60  do {
61  fin.getline(buf, maxbuf);
62  if (buf[0] != '\0' && buf[0] != '/' && !fin.eof()) {
63  if (strcmp(buf, name) == 0) {
64  volu = new FairGeoNode;
65  volu->SetName(buf);
66  volu->setVolumeType(kFairGeoTopNode);
67  volu->setActive();
68  fin.getline(buf, maxbuf);
69  TString shape(buf);
70  FairGeoBasicShape *sh = pShapes->selectShape(shape);
71  if (sh) {
72  volu->setShape(sh);
73  } else {
74  rc = kFALSE;
75  }
76  fin.getline(buf, maxbuf);
77  medium = media->getMedium(buf);
78  if (!medium) {
79  medium = new FairGeoMedium();
80  media->addMedium(medium);
81  }
82  volu->setMedium(medium);
83  Int_t n = 0;
84  if (sh) {
85  n = sh->readPoints(&fin, volu);
86  }
87  if (n <= 0) {
88  rc = kFALSE;
89  }
90  } else {
91  rc = kFALSE;
92  }
93  }
94  } while (rc && !volu && !fin.eof());
95  if (volu && rc) {
96  volumes->Add(volu);
97  masterNodes->Add(new FairGeoNode(*volu));
98  } else {
99  delete volu;
100  volu = nullptr;
101  rc = kFALSE;
102  }
103  return rc;
104 }
105 
107 {
108  // Adds the reference node
109  FairGeoNode *volu = getVolume(name);
110  if (volu) {
111  masterNodes->Add(new FairGeoNode(*volu));
112  }
113 }
114 
115 void AtGeoCave::write(fstream &fout)
116 {
117  // Writes the geometry to file
118  fout.setf(ios::fixed, ios::floatfield);
119  FairGeoNode *volu = getVolume(name);
120  if (volu) {
121  FairGeoBasicShape *sh = volu->getShapePointer();
122  FairGeoMedium *med = volu->getMedium();
123  if (sh && med) {
124  fout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
125  sh->writePoints(&fout, volu);
126  }
127  }
128 }
129 
131 {
132  // Prints the geometry
133  FairGeoNode *volu = getVolume(name);
134  if (volu) {
135  FairGeoBasicShape *sh = volu->getShapePointer();
136  FairGeoMedium *med = volu->getMedium();
137  if (sh && med) {
138  cout << volu->GetName() << '\n' << sh->GetName() << '\n' << med->GetName() << '\n';
139  sh->printPoints(volu);
140  }
141  }
142 }
AtGeoCave::name
TString name
Definition: AtGeoCave.h:35
ClassImp
ClassImp(AtGeoCave) AtGeoCave
Definition: AtGeoCave.cxx:38
AtGeoCave::addRefNodes
void addRefNodes()
Definition: AtGeoCave.cxx:106
AtGeoCave::write
void write(fstream &)
Definition: AtGeoCave.cxx:115
AtGeoCave
Definition: AtGeoCave.h:33
AtGeoCave::read
Bool_t read(fstream &, FairGeoMedia *)
Definition: AtGeoCave.cxx:49
AtGeoCave::print
void print()
Definition: AtGeoCave.cxx:130
AtGeoCave.h
AtGeoCave::AtGeoCave
AtGeoCave()