FairGeoCave.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. //*-- AUTHOR : Ilse Koenig
  9. //*-- Created : 10/11/2003
  10. /////////////////////////////////////////////////////////////
  11. // FairGeoCave
  12. //
  13. // Class for the geometry of the detector part CAVE
  14. //
  15. /////////////////////////////////////////////////////////////
  16. #include "FairGeoCave.h"
  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. #include <string.h> // for strcmp
  24. #include <iostream> // for cout
  25. using namespace std;
  26. ClassImp(FairGeoCave)
  27. FairGeoCave::FairGeoCave()
  28. : FairGeoSet(),
  29. name("cave")
  30. {
  31. // Constructor
  32. fName="cave";
  33. name="cave";
  34. maxModules=1;
  35. }
  36. Bool_t FairGeoCave::read(std::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 { rc=kFALSE; }
  58. fin.getline(buf,maxbuf);
  59. medium=media->getMedium(buf);
  60. if (!medium) {
  61. medium=new FairGeoMedium();
  62. media->addMedium(medium);
  63. }
  64. volu->setMedium(medium);
  65. Int_t n=0;
  66. if (sh) { n=sh->readPoints(&fin,volu); }
  67. if (n<=0) { rc=kFALSE; }
  68. } else { rc=kFALSE; }
  69. }
  70. } while (rc && !volu && !fin.eof());
  71. if (volu && rc) {
  72. volumes->Add(volu);
  73. masterNodes->Add(new FairGeoNode(*volu));
  74. } else {
  75. delete volu;
  76. volu=0;
  77. rc=kFALSE;
  78. }
  79. return rc;
  80. }
  81. void FairGeoCave::addRefNodes()
  82. {
  83. // Adds the reference node
  84. FairGeoNode* volu=getVolume(name);
  85. if (volu) { masterNodes->Add(new FairGeoNode(*volu)); }
  86. }
  87. void FairGeoCave::write(std::fstream& fout)
  88. {
  89. // Writes the geometry to file
  90. std::ios_base::fmtflags tmp = fout.setf(ios::fixed,ios::floatfield);
  91. FairGeoNode* volu=getVolume(name);
  92. if (volu) {
  93. FairGeoBasicShape* sh=volu->getShapePointer();
  94. FairGeoMedium* med=volu->getMedium();
  95. if (sh&&med) {
  96. fout<<volu->GetName()<<'\n'<<sh->GetName()<<'\n'<<med->GetName()<<'\n';
  97. sh->writePoints(&fout,volu);
  98. }
  99. }
  100. fout.setf(tmp);
  101. }
  102. void FairGeoCave::print()
  103. {
  104. // Prints the geometry
  105. FairGeoNode* volu=getVolume(name);
  106. if (volu) {
  107. FairGeoBasicShape* sh=volu->getShapePointer();
  108. FairGeoMedium* med=volu->getMedium();
  109. if (sh&&med) {
  110. cout<<volu->GetName()<<'\n'<<sh->GetName()<<'\n'<<med->GetName()<<'\n';
  111. sh->printPoints(volu);
  112. }
  113. }
  114. }