source: trunk/source/persistency/ascii/src/G4tgbRotationMatrixMgr.cc @ 1347

Last change on this file since 1347 was 1347, checked in by garnier, 13 years ago

geant4 tag 9.4

File size: 5.7 KB
Line 
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,v 1.3 2010/10/13 07:56:55 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-ref-00 $
29//
30//
31// class G4tgbRotationMatrixMgr
32
33// History:
34// - Created.                                 P.Arce, CIEMAT (November 2007)
35// -------------------------------------------------------------------------
36
37#include "G4tgbRotationMatrixMgr.hh"
38#include "G4tgrRotationMatrixFactory.hh"
39#include "G4tgrMessenger.hh"
40
41// -------------------------------------------------------------------------
42
43G4tgbRotationMatrixMgr * G4tgbRotationMatrixMgr::theInstance = 0;
44
45
46// -------------------------------------------------------------------------
47G4tgbRotationMatrixMgr::G4tgbRotationMatrixMgr()
48{
49}
50
51
52// -------------------------------------------------------------------------
53G4tgbRotationMatrixMgr* G4tgbRotationMatrixMgr::GetInstance()
54{
55  if( !theInstance )
56  {
57    theInstance = new G4tgbRotationMatrixMgr;
58    theInstance->CopyRotMats();
59  }
60  return theInstance;
61}
62
63
64// -------------------------------------------------------------------------
65G4tgbRotationMatrixMgr::~G4tgbRotationMatrixMgr()
66{
67  G4mstgbrotm::const_iterator tgbcite;
68  for( tgbcite = theTgbRotMats.begin();
69       tgbcite != theTgbRotMats.end(); tgbcite++)
70  {
71    delete (*tgbcite).second;
72  }
73  theTgbRotMats.clear();
74  delete theInstance;
75}
76
77
78// -------------------------------------------------------------------------
79void G4tgbRotationMatrixMgr::CopyRotMats()
80{
81  G4mstgrrotm tgrRotms =
82    G4tgrRotationMatrixFactory::GetInstance()->GetRotMatMap();
83  G4mstgrrotm::iterator cite;
84  for( cite = tgrRotms.begin(); cite != tgrRotms.end(); cite++ )
85  {
86    G4tgrRotationMatrix* tgr = (*cite).second;
87    G4tgbRotationMatrix* tgb = new G4tgbRotationMatrix( tgr );
88    theTgbRotMats[tgb->GetName()] = tgb;
89  }
90}
91
92
93// -------------------------------------------------------------------------
94G4RotationMatrix*
95G4tgbRotationMatrixMgr::FindOrBuildG4RotMatrix(const G4String& name)
96{
97#ifdef G4VERBOSE
98  if( G4tgrMessenger::GetVerboseLevel() >= 2 )
99  {
100    G4cout << " G4tgbRotationMatrixMgr::FindOrBuildG4RotMatrix() - "
101           << name << G4endl;
102  }
103#endif
104  G4RotationMatrix* g4rotm = FindG4RotMatrix( name );
105  if( g4rotm == 0 )
106  {
107    G4tgbRotationMatrix* hrotm = FindOrBuildTgbRotMatrix( name );
108    // GetRotMatrix() never returns 0, otherwise if not found, it crashes
109    g4rotm = hrotm->BuildG4RotMatrix();
110  }
111  return g4rotm;
112}       
113
114
115// -------------------------------------------------------------------------
116G4RotationMatrix* G4tgbRotationMatrixMgr::FindG4RotMatrix(const G4String& name)
117{
118  G4RotationMatrix* g4rotm = 0;
119
120  G4msg4rotm::const_iterator cite = theG4RotMats.find( name );
121  if( cite != theG4RotMats.end() )
122  {
123    g4rotm = (*cite).second;
124  } 
125
126#ifdef G4VERBOSE
127  if( G4tgrMessenger::GetVerboseLevel() >= 2 )
128  {
129    G4cout << " G4tgbRotationMatrixMgr::FindG4RotMatrix(): " << G4endl
130           << "   Name: " << name << " = " << g4rotm << G4endl;
131  }
132#endif
133 
134  return g4rotm;
135}
136
137
138// -------------------------------------------------------------------------
139G4tgbRotationMatrix*
140G4tgbRotationMatrixMgr::FindOrBuildTgbRotMatrix(const G4String& name)
141{
142  G4tgbRotationMatrix* rotm = FindTgbRotMatrix( name );
143
144  if( rotm == 0 )
145  {
146    G4String ErrMessage = "Rotation Matrix " + name + " not found !";
147    G4Exception("G4tgbRotationMatrixFactory::FindOrBuildRotMatrix()",
148                "InvalidSetup", FatalException, ErrMessage); 
149  }
150  return rotm;
151}
152
153
154// -------------------------------------------------------------------------
155G4tgbRotationMatrix*
156G4tgbRotationMatrixMgr::FindTgbRotMatrix(const G4String& name)
157{
158  G4tgbRotationMatrix* rotm = 0;
159
160  G4mstgbrotm::const_iterator cite = theTgbRotMats.find( name );
161  if( cite != theTgbRotMats.end() )
162  {
163    rotm = (*cite).second;
164  }
165  return rotm;
166}
167
168
169// -------------------------------------------------------------------------
170std::ostream& operator<<(std::ostream& os , const G4RotationMatrix & rot)
171{
172  os << "[ " 
173     << rot.thetaX()/deg << '\t' << rot.phiX()/deg << '\t'
174     << rot.thetaY()/deg << '\t' << rot.phiY()/deg << '\t'
175     << rot.thetaZ()/deg << '\t' << rot.phiZ()/deg << " ]"
176     << G4endl;
177  return os;
178}
Note: See TracBrowser for help on using the repository browser.