ROOT logo
//*-- AUTHOR : Ilse Koenig
//*-- Last modified : 10/11/03 by Ilse Koenig

//_HADES_CLASS_DESCRIPTION 
///////////////////////////////////////////////////////////////////////////////
// HGeomMedia
//
// Class for materials and media
//
///////////////////////////////////////////////////////////////////////////////

#include "hgeommedia.h"
#include "hgeommedium.h"
#include <iostream>
#include <iomanip>

ClassImp(HGeomMedia)

HGeomMedia::HGeomMedia() {
  // Constructor
  media=new TList();
}

HGeomMedia::~HGeomMedia() {
  // Destructor
  if (media) {
    media->Delete();
    delete media;
    media=0;
  }
}

HGeomMedium* HGeomMedia::getMedium(const Char_t* mediumName) {
  // Returns the medium with name mediumName
  return (HGeomMedium*)media->FindObject(mediumName);
}

void HGeomMedia::addMedium(HGeomMedium* m) {
  // Adds a medium to the list of media
  media->Add(m);
}

void HGeomMedia::list() {
  // Lists all media
  cout<<"********************************************************************\n";
  cout<<"List of media:\n";
  TListIter iter(media);
  HGeomMedium* medium;
  while((medium=(HGeomMedium*)iter.Next())) {
    cout<<"  "<<medium->GetName()<<"\n";
  }
}

void HGeomMedia::print() {
  // Prints the media
  if (!author.IsNull())      cout<<"//Author:      "<<author<<'\n';
  if (!description.IsNull()) cout<<"//Description: "<<description<<'\n';
  cout<<"//----------------------------------------------------------\n";
  TListIter iter(media);
  HGeomMedium* medium;
  Int_t i=0;
  while((medium=(HGeomMedium*)iter.Next())) {
    if (medium->getAutoFlag()!=0){
      medium->print();
      i++;
    }
  }
  if (i!=media->GetSize()) {
    iter.Reset();
    cout<<"//----------------------------------------------\n";
    cout<<"AUTONULL\n";
    cout<<"//----------------------------------------------\n";
    while((medium=(HGeomMedium*)iter.Next())) {
      if (medium->getAutoFlag()==0) medium->print();
    }
  }
}

void HGeomMedia::read(fstream& fin) {
  // Reads the media from file
  cout<<"Read media"<<endl;
  const Int_t maxBuf=256;
  Char_t buf[maxBuf];
  Int_t autoflag=1;
  while(!fin.eof()) {
    fin>>buf;
    if (buf[0]=='\0' || buf[0]=='/') fin.getline(buf,maxBuf);
    else if (fin.eof()) break;
    else {
      TString eleName(buf);
      if (eleName.CompareTo("AUTONULL")!=0) {
        HGeomMedium* medium=new HGeomMedium(eleName);
        medium->read(fin,autoflag);
        media->Add(medium); 
      } else autoflag=0;
    }
  }
}

void HGeomMedia::write(fstream& fout) {
  // Writes the media to file
  if (!author.IsNull())      fout<<"//Author:      "<<author<<'\n';
  if (!description.IsNull()) fout<<"//Description: "<<description<<'\n';
  fout<<"//----------------------------------------------------------\n";
  TListIter iter(media);
  HGeomMedium* medium;
  Int_t i=0;
  while((medium=(HGeomMedium*)iter.Next())) {
    if (medium->getAutoFlag()!=0){
      medium->write(fout);
      i++;
    }
  }
  if (i!=media->GetSize()) {
    iter.Reset();
    fout<<"//----------------------------------------------\n";
    fout<<"AUTONULL\n";
    fout<<"//----------------------------------------------\n";
    while((medium=(HGeomMedium*)iter.Next())) {
      if (medium->getAutoFlag()==0) medium->write(fout);
    }
  }
}
 hgeommedia.cc:1
 hgeommedia.cc:2
 hgeommedia.cc:3
 hgeommedia.cc:4
 hgeommedia.cc:5
 hgeommedia.cc:6
 hgeommedia.cc:7
 hgeommedia.cc:8
 hgeommedia.cc:9
 hgeommedia.cc:10
 hgeommedia.cc:11
 hgeommedia.cc:12
 hgeommedia.cc:13
 hgeommedia.cc:14
 hgeommedia.cc:15
 hgeommedia.cc:16
 hgeommedia.cc:17
 hgeommedia.cc:18
 hgeommedia.cc:19
 hgeommedia.cc:20
 hgeommedia.cc:21
 hgeommedia.cc:22
 hgeommedia.cc:23
 hgeommedia.cc:24
 hgeommedia.cc:25
 hgeommedia.cc:26
 hgeommedia.cc:27
 hgeommedia.cc:28
 hgeommedia.cc:29
 hgeommedia.cc:30
 hgeommedia.cc:31
 hgeommedia.cc:32
 hgeommedia.cc:33
 hgeommedia.cc:34
 hgeommedia.cc:35
 hgeommedia.cc:36
 hgeommedia.cc:37
 hgeommedia.cc:38
 hgeommedia.cc:39
 hgeommedia.cc:40
 hgeommedia.cc:41
 hgeommedia.cc:42
 hgeommedia.cc:43
 hgeommedia.cc:44
 hgeommedia.cc:45
 hgeommedia.cc:46
 hgeommedia.cc:47
 hgeommedia.cc:48
 hgeommedia.cc:49
 hgeommedia.cc:50
 hgeommedia.cc:51
 hgeommedia.cc:52
 hgeommedia.cc:53
 hgeommedia.cc:54
 hgeommedia.cc:55
 hgeommedia.cc:56
 hgeommedia.cc:57
 hgeommedia.cc:58
 hgeommedia.cc:59
 hgeommedia.cc:60
 hgeommedia.cc:61
 hgeommedia.cc:62
 hgeommedia.cc:63
 hgeommedia.cc:64
 hgeommedia.cc:65
 hgeommedia.cc:66
 hgeommedia.cc:67
 hgeommedia.cc:68
 hgeommedia.cc:69
 hgeommedia.cc:70
 hgeommedia.cc:71
 hgeommedia.cc:72
 hgeommedia.cc:73
 hgeommedia.cc:74
 hgeommedia.cc:75
 hgeommedia.cc:76
 hgeommedia.cc:77
 hgeommedia.cc:78
 hgeommedia.cc:79
 hgeommedia.cc:80
 hgeommedia.cc:81
 hgeommedia.cc:82
 hgeommedia.cc:83
 hgeommedia.cc:84
 hgeommedia.cc:85
 hgeommedia.cc:86
 hgeommedia.cc:87
 hgeommedia.cc:88
 hgeommedia.cc:89
 hgeommedia.cc:90
 hgeommedia.cc:91
 hgeommedia.cc:92
 hgeommedia.cc:93
 hgeommedia.cc:94
 hgeommedia.cc:95
 hgeommedia.cc:96
 hgeommedia.cc:97
 hgeommedia.cc:98
 hgeommedia.cc:99
 hgeommedia.cc:100
 hgeommedia.cc:101
 hgeommedia.cc:102
 hgeommedia.cc:103
 hgeommedia.cc:104
 hgeommedia.cc:105
 hgeommedia.cc:106
 hgeommedia.cc:107
 hgeommedia.cc:108
 hgeommedia.cc:109
 hgeommedia.cc:110
 hgeommedia.cc:111
 hgeommedia.cc:112
 hgeommedia.cc:113
 hgeommedia.cc:114
 hgeommedia.cc:115
 hgeommedia.cc:116
 hgeommedia.cc:117
 hgeommedia.cc:118
 hgeommedia.cc:119
 hgeommedia.cc:120
 hgeommedia.cc:121
 hgeommedia.cc:122
 hgeommedia.cc:123