Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:17

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4UnitsTable
0027 //
0028 // Class description:
0029 //
0030 // This class maintains a table of Units.
0031 // A Unit has a name, a symbol, a value and belong to a category (i.e. its
0032 // dimensional definition): Length, Time, Energy, etc...
0033 // The Units are grouped by category. The TableOfUnits is a list of categories.
0034 // The class G4BestUnit allows to convert automaticaly a physical quantity
0035 // from its internal value into the most appropriate Unit of the same category.
0036 
0037 // Author: M.Maire, 17.05.1998 - First version
0038 // Revisions: G.Cosmo, 06.03.2001 - Migrated to STL vectors
0039 // --------------------------------------------------------------------
0040 #ifndef G4UnitsTable_hh
0041 #define G4UnitsTable_hh 1
0042 
0043 #include <vector>
0044 
0045 #include "G4ThreeVector.hh"
0046 #include "globals.hh"
0047 
0048 class G4UnitsCategory;
0049 class G4UnitDefinition;
0050 
0051 // --------------------------------------------------------------------
0052 
0053 #ifdef G4MULTITHREADED
0054 
0055 class G4UnitsTable : public std::vector<G4UnitsCategory*>
0056 {
0057  public:
0058   using std::vector<G4UnitsCategory*>::vector;
0059   G4UnitsTable() = default;
0060   ~G4UnitsTable();
0061 
0062  public:
0063   void Synchronize();
0064   G4bool Contains(const G4UnitDefinition*, const G4String&);
0065 };
0066 #else
0067 
0068 using G4UnitsTable = std::vector<G4UnitsCategory*>;
0069 
0070 #endif
0071 
0072 // --------------------------------------------------------------------
0073 
0074 class G4UnitDefinition
0075 {
0076  public:
0077   G4UnitDefinition(const G4String& name, const G4String& symbol,
0078                    const G4String& category, G4double value);
0079 
0080   ~G4UnitDefinition() = default;
0081   G4bool operator==(const G4UnitDefinition&) const;
0082   G4bool operator!=(const G4UnitDefinition&) const;
0083 
0084   inline const G4String& GetName() const;
0085   inline const G4String& GetSymbol() const;
0086   inline G4double GetValue() const;
0087 
0088   void PrintDefinition();
0089 
0090   static void BuildUnitsTable();
0091   static void PrintUnitsTable();
0092   static void ClearUnitsTable();
0093 
0094   static G4UnitsTable& GetUnitsTable();
0095 
0096   static G4bool IsUnitDefined(const G4String&);
0097   static G4double GetValueOf(const G4String&);
0098   static G4String GetCategory(const G4String&);
0099 
0100  private:
0101   G4UnitDefinition(const G4UnitDefinition&);
0102   G4UnitDefinition& operator=(const G4UnitDefinition&);
0103 
0104  private:
0105   G4String Name;         // SI name
0106   G4String SymbolName;   // SI symbol
0107   G4double Value = 0.0;  // value in the internal system of units
0108 
0109   static G4ThreadLocal G4UnitsTable* pUnitsTable;  // table of Units
0110   static G4ThreadLocal G4bool unitsTableDestroyed;
0111 
0112   std::size_t CategoryIndex = 0;  // category index of this unit
0113 
0114 #ifdef G4MULTITHREADED
0115   static G4UnitsTable* pUnitsTableShadow;  // shadow of table of Units
0116 
0117  public:
0118   inline static G4UnitsTable& GetUnitsTableShadow()
0119   {
0120     return *pUnitsTableShadow;
0121   }
0122 #endif
0123 };
0124 
0125 // --------------------------------------------------------------------
0126 
0127 using G4UnitsContainer = std::vector<G4UnitDefinition*>;
0128 
0129 class G4UnitsCategory
0130 {
0131  public:
0132   explicit G4UnitsCategory(const G4String& name);
0133   ~G4UnitsCategory();
0134   G4bool operator==(const G4UnitsCategory&) const;
0135   G4bool operator!=(const G4UnitsCategory&) const;
0136 
0137   inline const G4String& GetName() const;
0138   inline G4UnitsContainer& GetUnitsList();
0139   inline G4int GetNameMxLen() const;
0140   inline G4int GetSymbMxLen() const;
0141   inline void UpdateNameMxLen(G4int len);
0142   inline void UpdateSymbMxLen(G4int len);
0143   void PrintCategory();
0144 
0145  private:
0146   G4UnitsCategory(const G4UnitsCategory&);
0147   G4UnitsCategory& operator=(const G4UnitsCategory&);
0148 
0149  private:
0150   G4String Name;               // dimensional family: Length,Volume,Energy
0151   G4UnitsContainer UnitsList;  // List of units in this family
0152   G4int NameMxLen = 0;         // max length of the units name
0153   G4int SymbMxLen = 0;         // max length of the units symbol
0154 };
0155 
0156 // --------------------------------------------------------------------
0157 
0158 class G4BestUnit
0159 {
0160  public:
0161   G4BestUnit(G4double internalValue, const G4String& category);
0162   G4BestUnit(const G4ThreeVector& internalValue, const G4String& category);
0163   // These constructors convert a physical quantity from its internalValue
0164   // into the most appropriate unit of the same category.
0165   // In practice it builds an object VU = (newValue, newUnit)
0166 
0167   ~G4BestUnit() = default;
0168 
0169   inline G4double* GetValue();
0170   inline const G4String& GetCategory() const;
0171   inline std::size_t GetIndexOfCategory() const;
0172   operator G4String() const;  // Conversion to best string.
0173 
0174   friend std::ostream& operator<<(std::ostream&, const G4BestUnit& VU);
0175   // Default format to print the objet VU above.
0176 
0177  private:
0178   G4double Value[3];   // value in the internal system of units
0179   G4int nbOfVals = 0;  // G4double=1; G4ThreeVector=3
0180   G4String Category;   // dimensional family: Length,Volume,Energy ...
0181   std::size_t IndexOfCategory = 0;  // position of Category in UnitsTable
0182 };
0183 
0184 #include "G4UnitsTable.icc"
0185 
0186 #endif