G4tgbRotationMatrixMgr.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id: G4tgbRotationMatrixMgr.cc 69803 2013-05-15 15:24:50Z gcosmo $
00028 //
00029 //
00030 // class G4tgbRotationMatrixMgr
00031 
00032 // History:
00033 // - Created.                                 P.Arce, CIEMAT (November 2007)
00034 // -------------------------------------------------------------------------
00035 
00036 #include "G4tgbRotationMatrixMgr.hh"
00037 
00038 #include "G4SystemOfUnits.hh"
00039 #include "G4tgrRotationMatrixFactory.hh"
00040 #include "G4tgrMessenger.hh"
00041 
00042 // -------------------------------------------------------------------------
00043 
00044 G4tgbRotationMatrixMgr * G4tgbRotationMatrixMgr::theInstance = 0;
00045 
00046 
00047 // -------------------------------------------------------------------------
00048 G4tgbRotationMatrixMgr::G4tgbRotationMatrixMgr()
00049 {
00050 }
00051 
00052 
00053 // -------------------------------------------------------------------------
00054 G4tgbRotationMatrixMgr* G4tgbRotationMatrixMgr::GetInstance()
00055 {
00056   if( !theInstance )
00057   {
00058     theInstance = new G4tgbRotationMatrixMgr;
00059     theInstance->CopyRotMats();
00060   }
00061   return theInstance;
00062 }
00063 
00064 
00065 // -------------------------------------------------------------------------
00066 G4tgbRotationMatrixMgr::~G4tgbRotationMatrixMgr()
00067 {
00068   G4mstgbrotm::const_iterator tgbcite;
00069   for( tgbcite = theTgbRotMats.begin();
00070        tgbcite != theTgbRotMats.end(); tgbcite++)
00071   {
00072     delete (*tgbcite).second;
00073   }
00074   theTgbRotMats.clear();
00075   delete theInstance;
00076 }
00077 
00078 
00079 // -------------------------------------------------------------------------
00080 void G4tgbRotationMatrixMgr::CopyRotMats()
00081 {
00082   G4mstgrrotm tgrRotms =
00083     G4tgrRotationMatrixFactory::GetInstance()->GetRotMatMap();
00084   G4mstgrrotm::iterator cite;
00085   for( cite = tgrRotms.begin(); cite != tgrRotms.end(); cite++ )
00086   {
00087     G4tgrRotationMatrix* tgr = (*cite).second;
00088     G4tgbRotationMatrix* tgb = new G4tgbRotationMatrix( tgr );
00089     theTgbRotMats[tgb->GetName()] = tgb;
00090   }
00091 }
00092 
00093 
00094 // -------------------------------------------------------------------------
00095 G4RotationMatrix*
00096 G4tgbRotationMatrixMgr::FindOrBuildG4RotMatrix(const G4String& name)
00097 {
00098 #ifdef G4VERBOSE
00099   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00100   {
00101     G4cout << " G4tgbRotationMatrixMgr::FindOrBuildG4RotMatrix() - "
00102            << name << G4endl;
00103   }
00104 #endif
00105   G4RotationMatrix* g4rotm = FindG4RotMatrix( name );
00106   if( g4rotm == 0 )
00107   {
00108     G4tgbRotationMatrix* hrotm = FindOrBuildTgbRotMatrix( name );
00109     // GetRotMatrix() never returns 0, otherwise if not found, it crashes
00110     g4rotm = hrotm->BuildG4RotMatrix();
00111   }
00112   return g4rotm;
00113 }        
00114 
00115 
00116 // -------------------------------------------------------------------------
00117 G4RotationMatrix* G4tgbRotationMatrixMgr::FindG4RotMatrix(const G4String& name)
00118 {
00119   G4RotationMatrix* g4rotm = 0;
00120 
00121   G4msg4rotm::const_iterator cite = theG4RotMats.find( name );
00122   if( cite != theG4RotMats.end() )
00123   {
00124     g4rotm = (*cite).second;
00125   } 
00126 
00127 #ifdef G4VERBOSE
00128   if( G4tgrMessenger::GetVerboseLevel() >= 2 )
00129   {
00130     G4cout << " G4tgbRotationMatrixMgr::FindG4RotMatrix(): " << G4endl
00131            << "   Name: " << name << " = " << g4rotm << G4endl;
00132   }
00133 #endif
00134   
00135   return g4rotm;
00136 }
00137 
00138 
00139 // -------------------------------------------------------------------------
00140 G4tgbRotationMatrix*
00141 G4tgbRotationMatrixMgr::FindOrBuildTgbRotMatrix(const G4String& name)
00142 {
00143   G4tgbRotationMatrix* rotm = FindTgbRotMatrix( name );
00144 
00145   if( rotm == 0 )
00146   {
00147     G4String ErrMessage = "Rotation Matrix " + name + " not found !";
00148     G4Exception("G4tgbRotationMatrixFactory::FindOrBuildRotMatrix()",
00149                 "InvalidSetup", FatalException, ErrMessage); 
00150   }
00151   return rotm;
00152 }
00153 
00154 
00155 // -------------------------------------------------------------------------
00156 G4tgbRotationMatrix*
00157 G4tgbRotationMatrixMgr::FindTgbRotMatrix(const G4String& name)
00158 {
00159   G4tgbRotationMatrix* rotm = 0;
00160 
00161   G4mstgbrotm::const_iterator cite = theTgbRotMats.find( name );
00162   if( cite != theTgbRotMats.end() )
00163   {
00164     rotm = (*cite).second;
00165   }
00166   return rotm;
00167 }
00168 
00169 
00170 // -------------------------------------------------------------------------
00171 std::ostream& operator<<(std::ostream& os , const G4RotationMatrix & rot)
00172 {
00173   os << "[ " 
00174      << rot.thetaX()/deg << '\t' << rot.phiX()/deg << '\t'
00175      << rot.thetaY()/deg << '\t' << rot.phiY()/deg << '\t'
00176      << rot.thetaZ()/deg << '\t' << rot.phiZ()/deg << " ]"
00177      << G4endl;
00178   return os;
00179 }

Generated on Mon May 27 17:49:58 2013 for Geant4 by  doxygen 1.4.7