Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4tgbRotationMatrixMgr.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4tgbRotationMatrixMgr.cc 66872 2013-01-15 01:25:57Z japost $
28 //
29 //
30 // class G4tgbRotationMatrixMgr
31 
32 // History:
33 // - Created. P.Arce, CIEMAT (November 2007)
34 // -------------------------------------------------------------------------
35 
37 
38 #include "G4SystemOfUnits.hh"
40 #include "G4tgrMessenger.hh"
41 
42 // -------------------------------------------------------------------------
43 
44 G4ThreadLocal G4tgbRotationMatrixMgr * G4tgbRotationMatrixMgr::theInstance = 0;
45 
46 
47 // -------------------------------------------------------------------------
48 G4tgbRotationMatrixMgr::G4tgbRotationMatrixMgr()
49 {
50 }
51 
52 
53 // -------------------------------------------------------------------------
55 {
56  if( !theInstance )
57  {
58  theInstance = new G4tgbRotationMatrixMgr;
59  theInstance->CopyRotMats();
60  }
61  return theInstance;
62 }
63 
64 
65 // -------------------------------------------------------------------------
67 {
68  G4mstgbrotm::const_iterator tgbcite;
69  for( tgbcite = theTgbRotMats.begin();
70  tgbcite != theTgbRotMats.end(); tgbcite++)
71  {
72  delete (*tgbcite).second;
73  }
74  theTgbRotMats.clear();
75  delete theInstance;
76 }
77 
78 
79 // -------------------------------------------------------------------------
80 void G4tgbRotationMatrixMgr::CopyRotMats()
81 {
82  G4mstgrrotm tgrRotms =
84  G4mstgrrotm::iterator cite;
85  for( cite = tgrRotms.begin(); cite != tgrRotms.end(); cite++ )
86  {
87  G4tgrRotationMatrix* tgr = (*cite).second;
88  G4tgbRotationMatrix* tgb = new G4tgbRotationMatrix( tgr );
89  theTgbRotMats[tgb->GetName()] = tgb;
90  }
91 }
92 
93 
94 // -------------------------------------------------------------------------
97 {
98 #ifdef G4VERBOSE
100  {
101  G4cout << " G4tgbRotationMatrixMgr::FindOrBuildG4RotMatrix() - "
102  << name << G4endl;
103  }
104 #endif
105  G4RotationMatrix* g4rotm = FindG4RotMatrix( name );
106  if( g4rotm == 0 )
107  {
109  // GetRotMatrix() never returns 0, otherwise if not found, it crashes
110  g4rotm = hrotm->BuildG4RotMatrix();
111  }
112  return g4rotm;
113 }
114 
115 
116 // -------------------------------------------------------------------------
118 {
119  G4RotationMatrix* g4rotm = 0;
120 
121  G4msg4rotm::const_iterator cite = theG4RotMats.find( name );
122  if( cite != theG4RotMats.end() )
123  {
124  g4rotm = (*cite).second;
125  }
126 
127 #ifdef G4VERBOSE
129  {
130  G4cout << " G4tgbRotationMatrixMgr::FindG4RotMatrix(): " << G4endl
131  << " Name: " << name << " = " << g4rotm << G4endl;
132  }
133 #endif
134 
135  return g4rotm;
136 }
137 
138 
139 // -------------------------------------------------------------------------
142 {
143  G4tgbRotationMatrix* rotm = FindTgbRotMatrix( name );
144 
145  if( rotm == 0 )
146  {
147  G4String ErrMessage = "Rotation Matrix " + name + " not found !";
148  G4Exception("G4tgbRotationMatrixFactory::FindOrBuildRotMatrix()",
149  "InvalidSetup", FatalException, ErrMessage);
150  }
151  return rotm;
152 }
153 
154 
155 // -------------------------------------------------------------------------
158 {
159  G4tgbRotationMatrix* rotm = 0;
160 
161  G4mstgbrotm::const_iterator cite = theTgbRotMats.find( name );
162  if( cite != theTgbRotMats.end() )
163  {
164  rotm = (*cite).second;
165  }
166  return rotm;
167 }
168 
169 
170 // -------------------------------------------------------------------------
171 std::ostream& operator<<(std::ostream& os , const G4RotationMatrix & rot)
172 {
173  os << "[ "
174  << rot.thetaX()/deg << '\t' << rot.phiX()/deg << '\t'
175  << rot.thetaY()/deg << '\t' << rot.phiY()/deg << '\t'
176  << rot.thetaZ()/deg << '\t' << rot.phiZ()/deg << " ]"
177  << G4endl;
178  return os;
179 }
const XML_Char * name
Definition: expat.h:151
std::map< G4String, G4tgrRotationMatrix * > G4mstgrrotm
double thetaX() const
Definition: Rotation.cc:141
static G4tgbRotationMatrixMgr * GetInstance()
G4tgbRotationMatrix * FindOrBuildTgbRotMatrix(const G4String &name)
#define G4ThreadLocal
Definition: tls.hh:89
const G4mstgrrotm & GetRotMatMap() const
static G4tgrRotationMatrixFactory * GetInstance()
double phiY() const
Definition: Rotation.cc:133
G4GLOB_DLL std::ostream G4cout
static G4int GetVerboseLevel()
double phiX() const
Definition: Rotation.cc:129
double thetaY() const
Definition: Rotation.cc:145
G4RotationMatrix * FindG4RotMatrix(const G4String &name)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
double thetaZ() const
Definition: Rotation.cc:149
double phiZ() const
Definition: Rotation.cc:137
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
G4RotationMatrix * FindOrBuildG4RotMatrix(const G4String &name)
#define G4endl
Definition: G4ios.hh:61
static constexpr double deg
Definition: G4SIunits.hh:152
G4RotationMatrix * BuildG4RotMatrix()
G4tgbRotationMatrix * FindTgbRotMatrix(const G4String &name)