FairMagnet.cxx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* Generated by Together */
  9. #include "FairMagnet.h"
  10. #include "FairGeoInterface.h" // for FairGeoInterface
  11. #include "FairGeoLoader.h" // for FairGeoLoader
  12. #include "FairGeoMagnet.h" // for FairGeoMagnet
  13. #include "FairGeoNode.h" // for FairGeoNode
  14. #include "FairGeoPassivePar.h" // for FairGeoPassivePar
  15. #include "FairGeoVolume.h" // for FairGeoVolume
  16. #include "FairRun.h" // for FairRun
  17. #include "FairRuntimeDb.h" // for FairRuntimeDb
  18. #include <iosfwd> // for ostream
  19. #include "TList.h" // for TListIter, TList (ptr only)
  20. #include "TObjArray.h" // for TObjArray
  21. #include "TString.h" // for TString
  22. #include <stddef.h> // for NULL
  23. #include <iostream> // for operator<<, basic_ostream, etc
  24. FairMagnet::~FairMagnet()
  25. {
  26. }
  27. FairMagnet::FairMagnet()
  28. : FairModule("FairMagnet", "")
  29. {
  30. }
  31. FairMagnet::FairMagnet(const char* name, const char* Title)
  32. : FairModule(name ,Title)
  33. {
  34. }
  35. FairMagnet::FairMagnet(const FairMagnet& rhs)
  36. : FairModule(rhs)
  37. {
  38. }
  39. void FairMagnet::ConstructGeometry()
  40. {
  41. TString fileName=GetGeometryFileName();
  42. if (fileName.EndsWith(".geo")) {
  43. ConstructASCIIGeometry();
  44. } else if(fileName.EndsWith(".root")) {
  45. ConstructRootGeometry();
  46. } else {
  47. std::cout<< "Geometry format not supported " <<std::endl;
  48. }
  49. }
  50. Bool_t FairMagnet::CheckIfSensitive(std::string /*name*/)
  51. {
  52. // just to get rid of the warrning during run, not need this is a passive element!
  53. return kFALSE;
  54. }
  55. void FairMagnet::ConstructASCIIGeometry()
  56. {
  57. FairGeoLoader* loader=FairGeoLoader::Instance();
  58. FairGeoInterface* GeoInterface =loader->getGeoInterface();
  59. FairGeoMagnet* MGeo=new FairGeoMagnet();
  60. MGeo->setGeomFile(GetGeometryFileName());
  61. GeoInterface->addGeoModule(MGeo);
  62. Bool_t rc = GeoInterface->readSet(MGeo);
  63. if ( rc ) { MGeo->create(loader->getGeoBuilder()); }
  64. TList* volList = MGeo->getListOfVolumes();
  65. // store geo parameter
  66. FairRun* fRun = FairRun::Instance();
  67. FairRuntimeDb* rtdb= FairRun::Instance()->GetRuntimeDb();
  68. FairGeoPassivePar* par=static_cast<FairGeoPassivePar*>(rtdb->getContainer("FairGeoPassivePar"));
  69. TObjArray* fSensNodes = par->GetGeoSensitiveNodes();
  70. TObjArray* fPassNodes = par->GetGeoPassiveNodes();
  71. TListIter iter(volList);
  72. FairGeoNode* node = NULL;
  73. FairGeoVolume* aVol=NULL;
  74. while( (node = static_cast<FairGeoNode*>(iter.Next())) ) {
  75. aVol = dynamic_cast<FairGeoVolume*> ( node );
  76. if ( node->isSensitive() ) {
  77. fSensNodes->AddLast( aVol );
  78. } else {
  79. fPassNodes->AddLast( aVol );
  80. }
  81. }
  82. ProcessNodes( volList );
  83. par->setChanged();
  84. par->setInputVersion(fRun->GetRunId(),1);
  85. }
  86. FairModule* FairMagnet::CloneModule() const
  87. {
  88. return new FairMagnet(*this);
  89. }
  90. ClassImp(FairMagnet)