Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGeoUnit.cxx
Go to the documentation of this file.
1 // @(#)root/geom:$Id$
2 // Author: Markus Frank 25/06/19
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 /** \class TGeoUnit
13 \ingroup Geometry_classes
14 
15 Base class describing materials.
16 
17 */
18 #include "TError.h"
19 #include "TGeoSystemOfUnits.h"
20 #include "TGeant4SystemOfUnits.h"
21 
22 namespace {
23  static bool s_type_changed = false;
24  union _unit_type {
25  TGeoUnit::UnitType tgeo_unit_type;
26  TGeant4Unit::UnitType tgeant4_unit_type;
27  _unit_type(TGeoUnit::UnitType t) { tgeo_unit_type = t; }
28  } s_unit_type(TGeoUnit::kTGeoUnits);
29 }
30 
31 TGeoUnit::UnitType TGeoUnit::unitType() {
32  return s_unit_type.tgeo_unit_type;
33 }
34 
35 TGeoUnit::UnitType TGeoUnit::setUnitType(UnitType new_type) {
36  UnitType tmp = s_unit_type.tgeo_unit_type;
37  if ( !s_type_changed || new_type == s_unit_type.tgeo_unit_type ) {
38  s_unit_type.tgeo_unit_type = new_type;
39  s_type_changed = true;
40  return tmp;
41  }
42  Fatal("TGeoUnit","The system of units may only be changed once at the beginning of the program!");
43  return tmp;
44 }
45 
46 TGeant4Unit::UnitType TGeant4Unit::unitType() {
47  return s_unit_type.tgeant4_unit_type;
48 }
49 
50 TGeant4Unit::UnitType TGeant4Unit::setUnitType(UnitType new_type) {
51  UnitType tmp = s_unit_type.tgeant4_unit_type;
52  if ( !s_type_changed || new_type == s_unit_type.tgeant4_unit_type ) {
53  s_unit_type.tgeant4_unit_type = new_type;
54  s_type_changed = true;
55  return tmp;
56  }
57  Fatal("TGeoUnit","The system of units may only be changed once at the beginning of the program!");
58  return tmp;
59 }