CMS 3D CMS Logo

ALIUnitsTable.h
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * DISCLAIMER *
4 // * *
5 // * The following disclaimer summarizes all the specific disclaimers *
6 // * of contributors to this software. The specific disclaimers,which *
7 // * govern, are listed with their locations in: *
8 // * http://cern.ch/geant4/license *
9 // * *
10 // * Neither the authors of this software system, nor their employing *
11 // * institutes,nor the agencies providing financial support for this *
12 // * work make any representation or warranty, express or implied, *
13 // * regarding this software system or assume any liability for its *
14 // * use. *
15 // * *
16 // * This code implementation is the intellectual property of the *
17 // * GEANT4 collaboration. *
18 // * By copying, distributing or modifying the Program (or any work *
19 // * based on the Program) you indicate your acceptance of this *
20 // * statement, and all its terms. *
21 // ********************************************************************
22 //
23 // -----------------------------------------------------------------
24 //
25 // ------------------- class ALIUnitsTable -----------------
26 //
27 // Class description:
28 //
29 // This class maintains a table of Units.
30 // A Unit has a name, a symbol, a value and belong to a category (i.e. its
31 // dimensional definition): Length, Time, Energy, etc...
32 // The Units are grouped by category. The TableOfUnits is a list of categories.
33 // The class G4BestUnit allows to convert automaticaly a physical quantity
34 // from its internal value into the most appropriate Unit of the same category.
35 //
36 
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
38 
39 #ifndef ALIUnitsTable_HH
40 #define ALIUnitsTable_HH
41 
43 #include <vector>
44 #include <memory>
45 #include <CLHEP/Vector/ThreeVector.h>
46 
48 typedef std::vector<ALIUnitsCategory*> ALIUnitsTable;
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
51 
52 class ALIUnitDefinition : public std::enable_shared_from_this<ALIUnitDefinition> {
53 public: // with description
55 
56 public: // without description
58  ALIint operator==(const ALIUnitDefinition&) const;
59  ALIint operator!=(const ALIUnitDefinition&) const;
60 
61 private:
64 
65 public: // with description
66  ALIstring GetName() const { return Name; }
67  ALIstring GetSymbol() const { return SymbolName; }
68  ALIdouble GetValue() const { return Value; }
69 
70  void PrintDefinition();
71 
72  static void BuildUnitsTable();
73  static void PrintUnitsTable();
74 
76 
79 
80 private:
81  ALIstring Name; // SI name
82  ALIstring SymbolName; // SI symbol
83  ALIdouble Value; // value in the internal system of units
84 
85  static ALIUnitsTable theUnitsTable; // table of Units
86 
87  size_t CategoryIndex; // category index of this unit
88 };
89 
90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
91 
92 using ALIUnitsContainer = std::vector<std::shared_ptr<ALIUnitDefinition>>;
93 
95 public: // without description
98  ALIint operator==(const ALIUnitsCategory&) const;
99  ALIint operator!=(const ALIUnitsCategory&) const;
100 
101 private:
104 
105 public: // without description
106  ALIstring GetName() const { return Name; }
107  ALIUnitsContainer& GetUnitsList() { return UnitsList; }
108  ALIint GetNameMxLen() const { return NameMxLen; }
109  ALIint GetSymbMxLen() const { return SymbMxLen; }
111  if (NameMxLen < len)
112  NameMxLen = len;
113  }
115  if (SymbMxLen < len)
116  SymbMxLen = len;
117  }
118  void PrintCategory();
119 
120 private:
121  ALIstring Name; // dimensional family: Length,Volume,Energy ...
122  ALIUnitsContainer UnitsList; // List of units in this family
123  ALIint NameMxLen; // max length of the units name
124  ALIint SymbMxLen; // max length of the units symbol
125 };
126 
127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
128 
129 class ALIBestUnit {
130 public: // with description
131  ALIBestUnit(ALIdouble internalValue, ALIstring category);
132  ALIBestUnit(const CLHEP::Hep3Vector& internalValue, ALIstring category);
133  // These constructors convert a physical quantity from its internalValue
134  // into the most appropriate unit of the same category.
135  // In practice it builds an object VU = (newValue, newUnit)
136 
137  ~ALIBestUnit();
138 
139 public: // without description
140  ALIdouble* GetValue() { return Value; }
141  ALIstring GetCategory() const { return Category; }
142  size_t GetIndexOfCategory() const { return IndexOfCategory; }
143 
144 public: // with description
145  friend std::ostream& operator<<(std::ostream&, ALIBestUnit VU);
146  // Default format to print the objet VU above.
147 
148 private:
149  ALIdouble Value[3]; // value in the internal system of units
150  ALIint nbOfVals; // ALIdouble=1; CLHEP::Hep3Vector=3
151  ALIstring Category; // dimensional family: Length,Volume,Energy ...
152  size_t IndexOfCategory; // position of Category in UnitsTable
153 };
154 
155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
156 
157 #endif
ALIstring GetName() const
Definition: ALIUnitsTable.h:66
long double ALIdouble
Definition: CocoaGlobals.h:11
ALIstring Category
ALIint operator==(const ALIUnitDefinition &) const
std::vector< ALIUnitsCategory * > ALIUnitsTable
Definition: ALIUnitsTable.h:47
ALIUnitDefinition & operator=(const ALIUnitDefinition &)
ALIstring SymbolName
Definition: ALIUnitsTable.h:82
ALIint operator!=(const ALIUnitDefinition &) const
int ALIint
Definition: CocoaGlobals.h:15
ALIUnitDefinition(ALIstring name, ALIstring symbol, ALIstring category, ALIdouble value)
static ALIstring GetCategory(ALIstring)
ALIint nbOfVals
ALIUnitsContainer UnitsList
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:167
ALIdouble GetValue() const
Definition: ALIUnitsTable.h:68
void UpdateSymbMxLen(ALIint len)
static void PrintUnitsTable()
ALIdouble * GetValue()
size_t IndexOfCategory
size_t GetIndexOfCategory() const
static void BuildUnitsTable()
Definition: value.py:1
void UpdateNameMxLen(ALIint len)
ALIint GetSymbMxLen() const
ALIint GetNameMxLen() const
std::vector< std::shared_ptr< ALIUnitDefinition >> ALIUnitsContainer
Definition: ALIUnitsTable.h:92
ALIstring GetName() const
static ALIdouble GetValueOf(ALIstring)
ALIstring GetCategory() const
std::string ALIstring
Definition: CocoaGlobals.h:9
static ALIUnitsTable theUnitsTable
Definition: ALIUnitsTable.h:85
static ALIUnitsTable & GetUnitsTable()
Definition: ALIUnitsTable.h:75
ALIUnitsContainer & GetUnitsList()
ALIstring GetSymbol() const
Definition: ALIUnitsTable.h:67