FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairGeoMedia.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 //*-- Last modified : 10/11/03 by Ilse Koenig
10 
12 // FairGeoMedia
13 //
14 // Class for materials and media
15 //
17 
18 #include "FairGeoMedia.h"
19 
20 #include "FairGeoMedium.h"
21 #include "FairLogger.h"
22 
23 #include <TList.h>
24 #include <iostream>
25 
26 using std::cout;
27 using std::endl;
28 
30 
32  : TNamed()
33  , media(new TList())
34  , inputFile("")
35  , author("")
36  , description("")
37 {
38  // Constructor
39 }
40 
42 {
43  // Destructor
44  if (media) {
45  media->Delete();
46  delete media;
47  media = 0;
48  }
49 }
50 
51 FairGeoMedium* FairGeoMedia::getMedium(const char* mediumName)
52 {
53  // Returns the medium with name mediumName
54  return static_cast<FairGeoMedium*>(media->FindObject(mediumName));
55 }
56 
58 {
59  // Adds a medium to the list of media
60  media->Add(m);
61 }
62 
64 {
65  // Lists all media
66  cout << "********************************************************************\n";
67  cout << "List of media:\n";
68  TListIter iter(media);
69  FairGeoMedium* medium;
70  while ((medium = static_cast<FairGeoMedium*>(iter.Next()))) {
71  cout << " " << medium->GetName() << "\n";
72  }
73 }
74 
76 {
77  // Prints the media
78  if (!author.IsNull()) {
79  cout << "//Author: " << author << '\n';
80  }
81  if (!description.IsNull()) {
82  cout << "//Description: " << description << '\n';
83  }
84  cout << "//----------------------------------------------------------\n";
85  TListIter iter(media);
86  FairGeoMedium* medium;
87  Int_t i = 0;
88  while ((medium = static_cast<FairGeoMedium*>(iter.Next()))) {
89  if (medium->getAutoFlag() != 0) {
90  medium->print();
91  i++;
92  }
93  }
94  if (i != media->GetSize()) {
95  iter.Reset();
96  cout << "//----------------------------------------------\n";
97  cout << "AUTONULL\n";
98  cout << "//----------------------------------------------\n";
99  while ((medium = static_cast<FairGeoMedium*>(iter.Next()))) {
100  if (medium->getAutoFlag() == 0) {
101  medium->print();
102  }
103  }
104  }
105 }
106 
107 void FairGeoMedia::read(std::fstream& fin)
108 {
109  // Reads the media from file
110  LOG(info) << "FairGeoMedia: Read media ";
111  const Int_t maxBuf = 256;
112  char buf[maxBuf];
113  Int_t autoflag = 1;
114  while (!fin.eof()) {
115  fin >> buf;
116  if (buf[0] == '\0' || buf[0] == '/') {
117  fin.getline(buf, maxBuf);
118  } else if (fin.eof()) {
119  break;
120  } else {
121  TString eleName(buf);
122  if (eleName.CompareTo("AUTONULL") != 0) {
123  FairGeoMedium* medium = new FairGeoMedium(eleName);
124  medium->read(fin, autoflag);
125  media->Add(medium);
126  } else {
127  autoflag = 0;
128  }
129  }
130  }
131 }
132 
133 void FairGeoMedia::write(std::fstream& fout)
134 {
135  // Writes the media to file
136  if (!author.IsNull()) {
137  fout << "//Author: " << author << '\n';
138  }
139  if (!description.IsNull()) {
140  fout << "//Description: " << description << '\n';
141  }
142  fout << "//----------------------------------------------------------\n";
143  TListIter iter(media);
144  FairGeoMedium* medium;
145  Int_t i = 0;
146  while ((medium = static_cast<FairGeoMedium*>(iter.Next()))) {
147  if (medium->getAutoFlag() != 0) {
148  medium->write(fout);
149  i++;
150  }
151  }
152  if (i != media->GetSize()) {
153  iter.Reset();
154  fout << "//----------------------------------------------\n";
155  fout << "AUTONULL\n";
156  fout << "//----------------------------------------------\n";
157  while ((medium = static_cast<FairGeoMedium*>(iter.Next()))) {
158  if (medium->getAutoFlag() == 0) {
159  medium->write(fout);
160  }
161  }
162  }
163 }
void addMedium(FairGeoMedium *m)
void write(std::fstream &)
FairGeoMedium * getMedium(const char *)
ClassImp(FairEventBuilder)
void read(std::fstream &)
void read(std::fstream &, Int_t autoflag)
void write(std::fstream &)
Int_t getAutoFlag()
Definition: FairGeoMedium.h:51