Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:00

0001 //
0002 // ********************************************************************
0003 // * DISCLAIMER                                                       *
0004 // *                                                                  *
0005 // * The following disclaimer summarizes all the specific disclaimers *
0006 // * of contributors to this software. The specific disclaimers,which *
0007 // * govern, are listed with their locations in:                      *
0008 // *   http://cern.ch/geant4/license                                  *
0009 // *                                                                  *
0010 // * Neither the authors of this software system, nor their employing *
0011 // * institutes,nor the agencies providing financial support for this *
0012 // * work  make  any representation or  warranty, express or implied, *
0013 // * regarding  this  software system or assume any liability for its *
0014 // * use.                                                             *
0015 // *                                                                  *
0016 // * This  code  implementation is the  intellectual property  of the *
0017 // * GEANT4 collaboration.                                            *
0018 // * By copying,  distributing  or modifying the Program (or any work *
0019 // * based  on  the Program)  you indicate  your  acceptance of  this *
0020 // * statement, and all its terms.                                    *
0021 // ********************************************************************
0022 //
0023 // -----------------------------------------------------------------
0024 //
0025 //      ------------------- class ALIUnitsTable -----------------
0026 //
0027 // Class description:
0028 //
0029 // This class maintains a table of Units.
0030 // A Unit has a name, a symbol, a value and belong to a category (i.e. its
0031 // dimensional definition): Length, Time, Energy, etc...
0032 // The Units are grouped by category. The TableOfUnits is a list of categories.
0033 // The class G4BestUnit allows to convert automaticaly a physical quantity
0034 // from its internal value into the most appropriate Unit of the same category.
0035 //
0036 
0037 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0038 
0039 #ifndef ALIUnitsTable_HH
0040 #define ALIUnitsTable_HH
0041 
0042 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
0043 #include <vector>
0044 #include <memory>
0045 #include <CLHEP/Vector/ThreeVector.h>
0046 
0047 class ALIUnitsCategory;
0048 typedef std::vector<ALIUnitsCategory*> ALIUnitsTable;
0049 
0050 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0051 
0052 class ALIUnitDefinition : public std::enable_shared_from_this<ALIUnitDefinition> {
0053 public:  // with description
0054   ALIUnitDefinition(ALIstring name, ALIstring symbol, ALIstring category, ALIdouble value);
0055 
0056 public:  // without description
0057   ~ALIUnitDefinition();
0058   ALIint operator==(const ALIUnitDefinition&) const;
0059   ALIint operator!=(const ALIUnitDefinition&) const;
0060 
0061 private:
0062   ALIUnitDefinition(ALIUnitDefinition&);
0063   ALIUnitDefinition& operator=(const ALIUnitDefinition&);
0064 
0065 public:  // with description
0066   ALIstring GetName() const { return Name; }
0067   ALIstring GetSymbol() const { return SymbolName; }
0068   ALIdouble GetValue() const { return Value; }
0069 
0070   void PrintDefinition();
0071 
0072   static void BuildUnitsTable();
0073   static void PrintUnitsTable();
0074 
0075   static ALIUnitsTable& GetUnitsTable() { return theUnitsTable; }
0076 
0077   static ALIdouble GetValueOf(ALIstring);
0078   static ALIstring GetCategory(ALIstring);
0079 
0080 private:
0081   ALIstring Name;        // SI name
0082   ALIstring SymbolName;  // SI symbol
0083   ALIdouble Value;       // value in the internal system of units
0084 
0085   static ALIUnitsTable theUnitsTable;  // table of Units
0086 
0087   size_t CategoryIndex;  // category index of this unit
0088 };
0089 
0090 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0091 
0092 using ALIUnitsContainer = std::vector<std::shared_ptr<ALIUnitDefinition>>;
0093 
0094 class ALIUnitsCategory {
0095 public:  // without description
0096   ALIUnitsCategory(ALIstring name);
0097   ~ALIUnitsCategory();
0098   ALIint operator==(const ALIUnitsCategory&) const;
0099   ALIint operator!=(const ALIUnitsCategory&) const;
0100 
0101 private:
0102   ALIUnitsCategory(ALIUnitsCategory&);
0103   ALIUnitsCategory& operator=(const ALIUnitsCategory&);
0104 
0105 public:  // without description
0106   ALIstring GetName() const { return Name; }
0107   ALIUnitsContainer& GetUnitsList() { return UnitsList; }
0108   ALIint GetNameMxLen() const { return NameMxLen; }
0109   ALIint GetSymbMxLen() const { return SymbMxLen; }
0110   void UpdateNameMxLen(ALIint len) {
0111     if (NameMxLen < len)
0112       NameMxLen = len;
0113   }
0114   void UpdateSymbMxLen(ALIint len) {
0115     if (SymbMxLen < len)
0116       SymbMxLen = len;
0117   }
0118   void PrintCategory();
0119 
0120 private:
0121   ALIstring Name;               // dimensional family: Length,Volume,Energy ...
0122   ALIUnitsContainer UnitsList;  // List of units in this family
0123   ALIint NameMxLen;             // max length of the units name
0124   ALIint SymbMxLen;             // max length of the units symbol
0125 };
0126 
0127 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0128 
0129 class ALIBestUnit {
0130 public:  // with description
0131   ALIBestUnit(ALIdouble internalValue, ALIstring category);
0132   ALIBestUnit(const CLHEP::Hep3Vector& internalValue, ALIstring category);
0133   // These constructors convert a physical quantity from its internalValue
0134   // into the most appropriate unit of the same category.
0135   // In practice it builds an object VU = (newValue, newUnit)
0136 
0137   ~ALIBestUnit();
0138 
0139 public:  // without description
0140   ALIdouble* GetValue() { return Value; }
0141   ALIstring GetCategory() const { return Category; }
0142   size_t GetIndexOfCategory() const { return IndexOfCategory; }
0143 
0144 public:  // with description
0145   friend std::ostream& operator<<(std::ostream&, ALIBestUnit VU);
0146   // Default format to print the objet VU above.
0147 
0148 private:
0149   ALIdouble Value[3];      // value in the internal system of units
0150   ALIint nbOfVals;         // ALIdouble=1; CLHEP::Hep3Vector=3
0151   ALIstring Category;      // dimensional family: Length,Volume,Energy ...
0152   size_t IndexOfCategory;  // position of Category in UnitsTable
0153 };
0154 
0155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0156 
0157 #endif