Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/global/management/src/G4UnitsTable.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/src/G4UnitsTable.cc (Version 11.3.0) and /global/management/src/G4UnitsTable.cc (Version 10.7.p1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4UnitsTable class implementation               26 // G4UnitsTable class implementation
 27 //                                                 27 //
 28 // Author: M.Maire, 17.05.1998 - First version     28 // Author: M.Maire, 17.05.1998 - First version
 29 // Revisions: G.Cosmo, 06.03.2001 - Migrated t     29 // Revisions: G.Cosmo, 06.03.2001 - Migrated to STL vectors
 30 // -------------------------------------------     30 // --------------------------------------------------------------------
 31                                                    31 
 32 #include <iomanip>                                 32 #include <iomanip>
 33 #include <sstream>                                 33 #include <sstream>
 34                                                    34 
 35 #include "G4SystemOfUnits.hh"                      35 #include "G4SystemOfUnits.hh"
 36 #include "G4Threading.hh"                          36 #include "G4Threading.hh"
 37 #include "G4UnitsTable.hh"                         37 #include "G4UnitsTable.hh"
 38                                                    38 
 39 G4ThreadLocal G4UnitsTable* G4UnitDefinition::     39 G4ThreadLocal G4UnitsTable* G4UnitDefinition::pUnitsTable  = nullptr;
 40 G4ThreadLocal G4bool G4UnitDefinition::unitsTa     40 G4ThreadLocal G4bool G4UnitDefinition::unitsTableDestroyed = false;
 41                                                    41 
 42 #ifdef G4MULTITHREADED                             42 #ifdef G4MULTITHREADED
 43 G4UnitsTable* G4UnitDefinition::pUnitsTableSha     43 G4UnitsTable* G4UnitDefinition::pUnitsTableShadow = nullptr;
 44                                                    44 
 45 // -------------------------------------------     45 // --------------------------------------------------------------------
 46                                                    46 
                                                   >>  47 G4UnitsTable::G4UnitsTable() {}
                                                   >>  48 
                                                   >>  49 // --------------------------------------------------------------------
                                                   >>  50 
 47 G4UnitsTable::~G4UnitsTable()                      51 G4UnitsTable::~G4UnitsTable()
 48 {                                                  52 {
 49   for(const auto itr : *this)                  <<  53   for(auto itr = cbegin(); itr != cend(); ++itr)
 50   {                                                54   {
 51     delete itr;                                <<  55     delete *itr;
 52   }                                                56   }
 53   clear();                                         57   clear();
 54 }                                                  58 }
 55                                                    59 
 56 #endif                                             60 #endif
 57                                                    61 
 58 // -------------------------------------------     62 // --------------------------------------------------------------------
 59                                                    63 
 60 G4UnitDefinition::G4UnitDefinition(const G4Str     64 G4UnitDefinition::G4UnitDefinition(const G4String& name, const G4String& symbol,
 61                                    const G4Str     65                                    const G4String& category, G4double value)
 62   : Name(name)                                     66   : Name(name)
 63   , SymbolName(symbol)                             67   , SymbolName(symbol)
 64   , Value(value)                                   68   , Value(value)
 65 {                                                  69 {
 66   if(pUnitsTable == nullptr)                       70   if(pUnitsTable == nullptr)
 67   {                                                71   {
 68     if(unitsTableDestroyed)                        72     if(unitsTableDestroyed)
 69     {                                              73     {
 70       G4Exception("G4UnitDefinition::G4UnitDef     74       G4Exception("G4UnitDefinition::G4UnitDefinition", "UnitsTable0000",
 71                   FatalException, "G4UnitsTabl     75                   FatalException, "G4UnitsTable had already deleted.");
 72     }                                              76     }
 73     pUnitsTable = new G4UnitsTable;                77     pUnitsTable = new G4UnitsTable;
 74 #ifdef G4MULTITHREADED                             78 #ifdef G4MULTITHREADED
 75     if(G4Threading::IsMasterThread())              79     if(G4Threading::IsMasterThread())
 76     {                                              80     {
 77       pUnitsTableShadow = pUnitsTable;             81       pUnitsTableShadow = pUnitsTable;
 78     }                                              82     }
 79 #endif                                             83 #endif
 80   }                                                84   }
 81                                                    85 
 82   // Does the Category objet already exist ?       86   // Does the Category objet already exist ?
 83   //                                               87   //
 84   std::size_t nbCat = pUnitsTable->size();         88   std::size_t nbCat = pUnitsTable->size();
 85   std::size_t i     = 0;                           89   std::size_t i     = 0;
 86   while((i < nbCat) && ((*pUnitsTable)[i]->Get     90   while((i < nbCat) && ((*pUnitsTable)[i]->GetName() != category))
 87   {                                                91   {
 88     ++i;                                           92     ++i;
 89   }                                                93   }
 90   if(i == nbCat)                                   94   if(i == nbCat)
 91   {                                                95   {
 92     pUnitsTable->push_back(new G4UnitsCategory     96     pUnitsTable->push_back(new G4UnitsCategory(category));
 93   }                                                97   }
 94   CategoryIndex = i;                               98   CategoryIndex = i;
 95                                                    99 
 96   // Insert this Unit in the Units table          100   // Insert this Unit in the Units table
 97   //                                              101   //
 98   ((*pUnitsTable)[CategoryIndex]->GetUnitsList    102   ((*pUnitsTable)[CategoryIndex]->GetUnitsList()).push_back(this);
 99                                                   103 
100   // Update string max length for name and sym    104   // Update string max length for name and symbol
101   //                                              105   //
102   (*pUnitsTable)[i]->UpdateNameMxLen((G4int) n    106   (*pUnitsTable)[i]->UpdateNameMxLen((G4int) name.length());
103   (*pUnitsTable)[i]->UpdateSymbMxLen((G4int) s    107   (*pUnitsTable)[i]->UpdateSymbMxLen((G4int) symbol.length());
104 }                                                 108 }
105                                                   109 
106 // -------------------------------------------    110 // --------------------------------------------------------------------
107                                                   111 
                                                   >> 112 G4UnitDefinition::~G4UnitDefinition() {}
                                                   >> 113 
                                                   >> 114 // --------------------------------------------------------------------
                                                   >> 115 
108 G4UnitDefinition::G4UnitDefinition(const G4Uni    116 G4UnitDefinition::G4UnitDefinition(const G4UnitDefinition& right)
109 {                                                 117 {
110   *this = right;                                  118   *this = right;
111 }                                                 119 }
112                                                   120 
113 // -------------------------------------------    121 // --------------------------------------------------------------------
114                                                   122 
115 G4UnitDefinition& G4UnitDefinition::operator=(    123 G4UnitDefinition& G4UnitDefinition::operator=(const G4UnitDefinition& right)
116 {                                                 124 {
117   if(this != &right)                              125   if(this != &right)
118   {                                               126   {
119     Name          = right.Name;                   127     Name          = right.Name;
120     SymbolName    = right.SymbolName;             128     SymbolName    = right.SymbolName;
121     Value         = right.Value;                  129     Value         = right.Value;
122     CategoryIndex = right.CategoryIndex;          130     CategoryIndex = right.CategoryIndex;
123   }                                               131   }
124   return *this;                                   132   return *this;
125 }                                                 133 }
126                                                   134 
127 // -------------------------------------------    135 // --------------------------------------------------------------------
128                                                   136 
129 G4bool G4UnitDefinition::operator==(const G4Un    137 G4bool G4UnitDefinition::operator==(const G4UnitDefinition& right) const
130 {                                                 138 {
131   return (this == (G4UnitDefinition*) &right);    139   return (this == (G4UnitDefinition*) &right);
132 }                                                 140 }
133                                                   141 
134 // -------------------------------------------    142 // --------------------------------------------------------------------
135                                                   143 
136 G4bool G4UnitDefinition::operator!=(const G4Un    144 G4bool G4UnitDefinition::operator!=(const G4UnitDefinition& right) const
137 {                                                 145 {
138   return (this != (G4UnitDefinition*) &right);    146   return (this != (G4UnitDefinition*) &right);
139 }                                                 147 }
140                                                   148 
141 // -------------------------------------------    149 // --------------------------------------------------------------------
142                                                   150 
143 G4UnitsTable& G4UnitDefinition::GetUnitsTable(    151 G4UnitsTable& G4UnitDefinition::GetUnitsTable()
144 {                                                 152 {
145   if(pUnitsTable == nullptr)                      153   if(pUnitsTable == nullptr)
146   {                                               154   {
147     pUnitsTable = new G4UnitsTable;               155     pUnitsTable = new G4UnitsTable;
148   }                                               156   }
149   if(pUnitsTable->empty())                     << 157   if(pUnitsTable->size() == 0)
150   {                                               158   {
151     BuildUnitsTable();                            159     BuildUnitsTable();
152   }                                               160   }
153 #ifdef G4MULTITHREADED                            161 #ifdef G4MULTITHREADED
154   if(G4Threading::IsMasterThread() && pUnitsTa    162   if(G4Threading::IsMasterThread() && pUnitsTableShadow == nullptr)
155   {                                               163   {
156     pUnitsTableShadow = pUnitsTable;              164     pUnitsTableShadow = pUnitsTable;
157   }                                               165   }
158 #endif                                            166 #endif
159   return *pUnitsTable;                            167   return *pUnitsTable;
160 }                                                 168 }
161                                                   169 
162 // -------------------------------------------    170 // --------------------------------------------------------------------
163                                                   171 
164 G4bool G4UnitDefinition::IsUnitDefined(const G    172 G4bool G4UnitDefinition::IsUnitDefined(const G4String& str)
165 {                                                 173 {
166   G4String name, symbol;                          174   G4String name, symbol;
167   for(std::size_t i = 0; i < (GetUnitsTable())    175   for(std::size_t i = 0; i < (GetUnitsTable()).size(); ++i)
168   {                                               176   {
169     G4UnitsContainer& units = (*pUnitsTable)[i    177     G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
170     for(auto& unit : units)                    << 178     for(std::size_t j = 0; j < units.size(); ++j)
171     {                                             179     {
172       name   = unit->GetName();                << 180       name   = units[j]->GetName();
173       symbol = unit->GetSymbol();              << 181       symbol = units[j]->GetSymbol();
174       if(str == name || str == symbol)            182       if(str == name || str == symbol)
175       {                                           183       {
176         return true;                              184         return true;
177       }                                           185       }
178     }                                             186     }
179   }                                               187   }
180   return false;                                   188   return false;
181 }                                                 189 }
182                                                   190 
183 // -------------------------------------------    191 // --------------------------------------------------------------------
184                                                   192 
185 G4double G4UnitDefinition::GetValueOf(const G4    193 G4double G4UnitDefinition::GetValueOf(const G4String& str)
186 {                                                 194 {
187   G4String name, symbol;                          195   G4String name, symbol;
188   for(std::size_t i = 0; i < (GetUnitsTable())    196   for(std::size_t i = 0; i < (GetUnitsTable()).size(); ++i)
189   {                                               197   {
190     G4UnitsContainer& units = (*pUnitsTable)[i    198     G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
191     for(auto& unit : units)                    << 199     for(std::size_t j = 0; j < units.size(); ++j)
192     {                                             200     {
193       name   = unit->GetName();                << 201       name   = units[j]->GetName();
194       symbol = unit->GetSymbol();              << 202       symbol = units[j]->GetSymbol();
195       if(str == name || str == symbol)            203       if(str == name || str == symbol)
196       {                                           204       {
197         return unit->GetValue();               << 205         return units[j]->GetValue();
198       }                                           206       }
199     }                                             207     }
200   }                                               208   }
201   std::ostringstream message;                     209   std::ostringstream message;
202   message << "The unit '" << str << "' does no    210   message << "The unit '" << str << "' does not exist in the Units Table!";
203   G4Exception("G4UnitDefinition::GetValueOf()"    211   G4Exception("G4UnitDefinition::GetValueOf()", "InvalidUnit", FatalException,
204               message);                           212               message);
205   return 0.;                                      213   return 0.;
206 }                                                 214 }
207                                                   215 
208 // -------------------------------------------    216 // --------------------------------------------------------------------
209                                                   217 
210 G4String G4UnitDefinition::GetCategory(const G    218 G4String G4UnitDefinition::GetCategory(const G4String& str)
211 {                                                 219 {
212   G4String name, symbol;                          220   G4String name, symbol;
213   for(std::size_t i = 0; i < (GetUnitsTable())    221   for(std::size_t i = 0; i < (GetUnitsTable()).size(); ++i)
214   {                                               222   {
215     G4UnitsContainer& units = (*pUnitsTable)[i    223     G4UnitsContainer& units = (*pUnitsTable)[i]->GetUnitsList();
216     for(auto& unit : units)                    << 224     for(std::size_t j = 0; j < units.size(); ++j)
217     {                                             225     {
218       name   = unit->GetName();                << 226       name   = units[j]->GetName();
219       symbol = unit->GetSymbol();              << 227       symbol = units[j]->GetSymbol();
220       if(str == name || str == symbol)            228       if(str == name || str == symbol)
221       {                                           229       {
222         return (*pUnitsTable)[i]->GetName();      230         return (*pUnitsTable)[i]->GetName();
223       }                                           231       }
224     }                                             232     }
225   }                                               233   }
226   std::ostringstream message;                     234   std::ostringstream message;
227   message << "The unit '" << str << "' does no    235   message << "The unit '" << str << "' does not exist in the Units Table!";
228   G4Exception("G4UnitDefinition::GetCategory()    236   G4Exception("G4UnitDefinition::GetCategory()", "InvalidUnit", FatalException,
229               message);                           237               message);
230   name = "None";                                  238   name = "None";
231   return name;                                    239   return name;
232 }                                                 240 }
233                                                   241 
234 // -------------------------------------------    242 // --------------------------------------------------------------------
235                                                   243 
236 void G4UnitDefinition::PrintDefinition()          244 void G4UnitDefinition::PrintDefinition()
237 {                                                 245 {
238   G4int nameL = (*pUnitsTable)[CategoryIndex]-    246   G4int nameL = (*pUnitsTable)[CategoryIndex]->GetNameMxLen();
239   G4int symbL = (*pUnitsTable)[CategoryIndex]-    247   G4int symbL = (*pUnitsTable)[CategoryIndex]->GetSymbMxLen();
240   G4cout << std::setw(nameL) << Name << " (" <    248   G4cout << std::setw(nameL) << Name << " (" << std::setw(symbL) << SymbolName
241          << ") = " << Value << G4endl;            249          << ") = " << Value << G4endl;
242 }                                                 250 }
243                                                   251 
244 // -------------------------------------------    252 // --------------------------------------------------------------------
245                                                   253 
246 void G4UnitDefinition::BuildUnitsTable()          254 void G4UnitDefinition::BuildUnitsTable()
247 {                                                 255 {
248   // Length                                       256   // Length
249   new G4UnitDefinition("parsec", "pc", "Length    257   new G4UnitDefinition("parsec", "pc", "Length", parsec);
250   new G4UnitDefinition("kilometer", "km", "Len    258   new G4UnitDefinition("kilometer", "km", "Length", kilometer);
251   new G4UnitDefinition("meter", "m", "Length",    259   new G4UnitDefinition("meter", "m", "Length", meter);
252   new G4UnitDefinition("centimeter", "cm", "Le    260   new G4UnitDefinition("centimeter", "cm", "Length", centimeter);
253   new G4UnitDefinition("millimeter", "mm", "Le    261   new G4UnitDefinition("millimeter", "mm", "Length", millimeter);
254   new G4UnitDefinition("micrometer", "um", "Le    262   new G4UnitDefinition("micrometer", "um", "Length", micrometer);
255   new G4UnitDefinition("nanometer", "nm", "Len    263   new G4UnitDefinition("nanometer", "nm", "Length", nanometer);
256   new G4UnitDefinition("angstrom", "Ang", "Len    264   new G4UnitDefinition("angstrom", "Ang", "Length", angstrom);
257   new G4UnitDefinition("fermi", "fm", "Length"    265   new G4UnitDefinition("fermi", "fm", "Length", fermi);
258                                                   266 
259   // Surface                                      267   // Surface
260   new G4UnitDefinition("kilometer2", "km2", "S    268   new G4UnitDefinition("kilometer2", "km2", "Surface", kilometer2);
261   new G4UnitDefinition("meter2", "m2", "Surfac    269   new G4UnitDefinition("meter2", "m2", "Surface", meter2);
262   new G4UnitDefinition("centimeter2", "cm2", "    270   new G4UnitDefinition("centimeter2", "cm2", "Surface", centimeter2);
263   new G4UnitDefinition("millimeter2", "mm2", "    271   new G4UnitDefinition("millimeter2", "mm2", "Surface", millimeter2);
264   new G4UnitDefinition("barn", "barn", "Surfac    272   new G4UnitDefinition("barn", "barn", "Surface", barn);
265   new G4UnitDefinition("millibarn", "mbarn", "    273   new G4UnitDefinition("millibarn", "mbarn", "Surface", millibarn);
266   new G4UnitDefinition("microbarn", "mubarn",     274   new G4UnitDefinition("microbarn", "mubarn", "Surface", microbarn);
267   new G4UnitDefinition("nanobarn", "nbarn", "S    275   new G4UnitDefinition("nanobarn", "nbarn", "Surface", nanobarn);
268   new G4UnitDefinition("picobarn", "pbarn", "S    276   new G4UnitDefinition("picobarn", "pbarn", "Surface", picobarn);
269                                                   277 
270   // Volume                                       278   // Volume
271   new G4UnitDefinition("kilometer3", "km3", "V    279   new G4UnitDefinition("kilometer3", "km3", "Volume", kilometer3);
272   new G4UnitDefinition("meter3", "m3", "Volume    280   new G4UnitDefinition("meter3", "m3", "Volume", meter3);
273   new G4UnitDefinition("centimeter3", "cm3", "    281   new G4UnitDefinition("centimeter3", "cm3", "Volume", centimeter3);
274   new G4UnitDefinition("millimeter3", "mm3", "    282   new G4UnitDefinition("millimeter3", "mm3", "Volume", millimeter3);
275                                                   283 
276   new G4UnitDefinition("liter", "L", "Volume",    284   new G4UnitDefinition("liter", "L", "Volume", liter);
277   new G4UnitDefinition("dL", "dL", "Volume", d    285   new G4UnitDefinition("dL", "dL", "Volume", dL);
278   new G4UnitDefinition("cL", "cL", "Volume", c    286   new G4UnitDefinition("cL", "cL", "Volume", cL);
279   new G4UnitDefinition("mL", "mL", "Volume", m    287   new G4UnitDefinition("mL", "mL", "Volume", mL);
280                                                   288 
281   // Angle                                        289   // Angle
282   new G4UnitDefinition("radian", "rad", "Angle    290   new G4UnitDefinition("radian", "rad", "Angle", radian);
283   new G4UnitDefinition("milliradian", "mrad",     291   new G4UnitDefinition("milliradian", "mrad", "Angle", milliradian);
284   new G4UnitDefinition("degree", "deg", "Angle    292   new G4UnitDefinition("degree", "deg", "Angle", degree);
285                                                   293 
286   // Solid angle                                  294   // Solid angle
287   new G4UnitDefinition("steradian", "sr", "Sol    295   new G4UnitDefinition("steradian", "sr", "Solid angle", steradian);
288   new G4UnitDefinition("millisteradian", "msr"    296   new G4UnitDefinition("millisteradian", "msr", "Solid angle",
289                        steradian * 0.001);        297                        steradian * 0.001);
290                                                   298 
291   // Time                                         299   // Time
292   new G4UnitDefinition("second", "s", "Time",     300   new G4UnitDefinition("second", "s", "Time", second);
293   new G4UnitDefinition("millisecond", "ms", "T    301   new G4UnitDefinition("millisecond", "ms", "Time", millisecond);
294   new G4UnitDefinition("microsecond", "us", "T    302   new G4UnitDefinition("microsecond", "us", "Time", microsecond);
295   new G4UnitDefinition("nanosecond", "ns", "Ti    303   new G4UnitDefinition("nanosecond", "ns", "Time", nanosecond);
296   new G4UnitDefinition("picosecond", "ps", "Ti    304   new G4UnitDefinition("picosecond", "ps", "Time", picosecond);
297   new G4UnitDefinition("minute", "min", "Time" << 
298   new G4UnitDefinition("hour",   "h",   "Time" << 
299   new G4UnitDefinition("day",    "d",   "Time" << 
300   new G4UnitDefinition("year",   "y",   "Time" << 
301                                                   305 
302   // Frequency                                    306   // Frequency
303   new G4UnitDefinition("hertz", "Hz", "Frequen    307   new G4UnitDefinition("hertz", "Hz", "Frequency", hertz);
304   new G4UnitDefinition("kilohertz", "kHz", "Fr    308   new G4UnitDefinition("kilohertz", "kHz", "Frequency", kilohertz);
305   new G4UnitDefinition("megahertz", "MHz", "Fr    309   new G4UnitDefinition("megahertz", "MHz", "Frequency", megahertz);
306                                                << 
307   // Velocity                                  << 
308   new G4UnitDefinition("cm/ns", "cm/ns", "Velo << 
309   new G4UnitDefinition("mm/ns", "mm/ns", "Velo << 
310   new G4UnitDefinition("cm/us", "cm/us", "Velo << 
311   new G4UnitDefinition("km/s" , "km/s" , "Velo << 
312   new G4UnitDefinition("cm/ms", "cm/ms", "Velo << 
313   new G4UnitDefinition( "m/s" ,  "m/s" , "Velo << 
314   new G4UnitDefinition("cm/s" , "cm/s" , "Velo << 
315   new G4UnitDefinition("mm/s" , "mm/s" , "Velo << 
316                                                   310 
317   // Electric charge                              311   // Electric charge
318   new G4UnitDefinition("eplus", "e+", "Electri    312   new G4UnitDefinition("eplus", "e+", "Electric charge", eplus);
319   new G4UnitDefinition("coulomb", "C", "Electr    313   new G4UnitDefinition("coulomb", "C", "Electric charge", coulomb);
320                                                   314 
321   // Energy                                       315   // Energy
322   new G4UnitDefinition("electronvolt", "eV", "    316   new G4UnitDefinition("electronvolt", "eV", "Energy", electronvolt);
323   new G4UnitDefinition("kiloelectronvolt", "ke    317   new G4UnitDefinition("kiloelectronvolt", "keV", "Energy", kiloelectronvolt);
324   new G4UnitDefinition("megaelectronvolt", "Me    318   new G4UnitDefinition("megaelectronvolt", "MeV", "Energy", megaelectronvolt);
325   new G4UnitDefinition("gigaelectronvolt", "Ge    319   new G4UnitDefinition("gigaelectronvolt", "GeV", "Energy", gigaelectronvolt);
326   new G4UnitDefinition("teraelectronvolt", "Te    320   new G4UnitDefinition("teraelectronvolt", "TeV", "Energy", teraelectronvolt);
327   new G4UnitDefinition("petaelectronvolt", "Pe    321   new G4UnitDefinition("petaelectronvolt", "PeV", "Energy", petaelectronvolt);
328   new G4UnitDefinition("millielectronVolt", "m << 
329   new G4UnitDefinition("joule", "J", "Energy",    322   new G4UnitDefinition("joule", "J", "Energy", joule);
330                                                << 323 
331   //Momentum                                   << 
332   new G4UnitDefinition( "eV/c",  "eV/c", "Mome << 
333   new G4UnitDefinition("keV/c", "keV/c", "Mome << 
334   new G4UnitDefinition("MeV/c", "MeV/c", "Mome << 
335   new G4UnitDefinition("GeV/c", "GeV/c", "Mome << 
336   new G4UnitDefinition("TeV/c", "TeV/c", "Mome << 
337                                                << 
338   // Energy/Length                                324   // Energy/Length
339   new G4UnitDefinition("GeV/cm", "GeV/cm", "En    325   new G4UnitDefinition("GeV/cm", "GeV/cm", "Energy/Length", GeV / cm);
340   new G4UnitDefinition("MeV/cm", "MeV/cm", "En    326   new G4UnitDefinition("MeV/cm", "MeV/cm", "Energy/Length", MeV / cm);
341   new G4UnitDefinition("keV/cm", "keV/cm", "En    327   new G4UnitDefinition("keV/cm", "keV/cm", "Energy/Length", keV / cm);
342   new G4UnitDefinition("eV/cm", "eV/cm", "Ener    328   new G4UnitDefinition("eV/cm", "eV/cm", "Energy/Length", eV / cm);
343                                                   329 
344   // Mass                                         330   // Mass
345   new G4UnitDefinition("milligram", "mg", "Mas    331   new G4UnitDefinition("milligram", "mg", "Mass", milligram);
346   new G4UnitDefinition("gram", "g", "Mass", gr    332   new G4UnitDefinition("gram", "g", "Mass", gram);
347   new G4UnitDefinition("kilogram", "kg", "Mass    333   new G4UnitDefinition("kilogram", "kg", "Mass", kilogram);
348                                                   334 
349   // Volumic Mass                                 335   // Volumic Mass
350   new G4UnitDefinition("g/cm3", "g/cm3", "Volu    336   new G4UnitDefinition("g/cm3", "g/cm3", "Volumic Mass", g / cm3);
351   new G4UnitDefinition("mg/cm3", "mg/cm3", "Vo    337   new G4UnitDefinition("mg/cm3", "mg/cm3", "Volumic Mass", mg / cm3);
352   new G4UnitDefinition("kg/m3", "kg/m3", "Volu    338   new G4UnitDefinition("kg/m3", "kg/m3", "Volumic Mass", kg / m3);
353                                                   339 
354   // Mass/Surface                                 340   // Mass/Surface
355   new G4UnitDefinition("g/cm2", "g/cm2", "Mass    341   new G4UnitDefinition("g/cm2", "g/cm2", "Mass/Surface", g / cm2);
356   new G4UnitDefinition("mg/cm2", "mg/cm2", "Ma    342   new G4UnitDefinition("mg/cm2", "mg/cm2", "Mass/Surface", mg / cm2);
357   new G4UnitDefinition("kg/cm2", "kg/cm2", "Ma    343   new G4UnitDefinition("kg/cm2", "kg/cm2", "Mass/Surface", kg / cm2);
358                                                   344 
359   // Surface/Mass                                 345   // Surface/Mass
360   new G4UnitDefinition("cm2/g", "cm2/g", "Surf    346   new G4UnitDefinition("cm2/g", "cm2/g", "Surface/Mass", cm2 / g);
361                                                   347 
362   // Energy.Surface/Mass                          348   // Energy.Surface/Mass
363   new G4UnitDefinition("eV*cm2/g", " eV*cm2/g"    349   new G4UnitDefinition("eV*cm2/g", " eV*cm2/g", "Energy*Surface/Mass",
364                        eV * cm2 / g);             350                        eV * cm2 / g);
365   new G4UnitDefinition("keV*cm2/g", "keV*cm2/g    351   new G4UnitDefinition("keV*cm2/g", "keV*cm2/g", "Energy*Surface/Mass",
366                        keV * cm2 / g);            352                        keV * cm2 / g);
367   new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g    353   new G4UnitDefinition("MeV*cm2/g", "MeV*cm2/g", "Energy*Surface/Mass",
368                        MeV * cm2 / g);            354                        MeV * cm2 / g);
369   new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g    355   new G4UnitDefinition("GeV*cm2/g", "GeV*cm2/g", "Energy*Surface/Mass",
370                        GeV * cm2 / g);            356                        GeV * cm2 / g);
371                                                   357 
372   // Power                                        358   // Power
373   new G4UnitDefinition("watt", "W", "Power", w    359   new G4UnitDefinition("watt", "W", "Power", watt);
374                                                   360 
375   // Force                                        361   // Force
376   new G4UnitDefinition("newton", "N", "Force",    362   new G4UnitDefinition("newton", "N", "Force", newton);
377                                                   363 
378   // Pressure                                     364   // Pressure
379   new G4UnitDefinition("pascal", "Pa", "Pressu    365   new G4UnitDefinition("pascal", "Pa", "Pressure", hep_pascal);
380   new G4UnitDefinition("bar", "bar", "Pressure    366   new G4UnitDefinition("bar", "bar", "Pressure", bar);
381   new G4UnitDefinition("atmosphere", "atm", "P    367   new G4UnitDefinition("atmosphere", "atm", "Pressure", atmosphere);
382                                                   368 
383   // Electric current                             369   // Electric current
384   new G4UnitDefinition("ampere", "A", "Electri    370   new G4UnitDefinition("ampere", "A", "Electric current", ampere);
385   new G4UnitDefinition("milliampere", "mA", "E    371   new G4UnitDefinition("milliampere", "mA", "Electric current", milliampere);
386   new G4UnitDefinition("microampere", "muA", "    372   new G4UnitDefinition("microampere", "muA", "Electric current", microampere);
387   new G4UnitDefinition("nanoampere", "nA", "El    373   new G4UnitDefinition("nanoampere", "nA", "Electric current", nanoampere);
388                                                   374 
389   // Electric potential                           375   // Electric potential
390   new G4UnitDefinition("volt", "V", "Electric     376   new G4UnitDefinition("volt", "V", "Electric potential", volt);
391   new G4UnitDefinition("kilovolt", "kV", "Elec    377   new G4UnitDefinition("kilovolt", "kV", "Electric potential", kilovolt);
392   new G4UnitDefinition("megavolt", "MV", "Elec    378   new G4UnitDefinition("megavolt", "MV", "Electric potential", megavolt);
393                                                   379 
394   // Electric field                               380   // Electric field
395   new G4UnitDefinition("volt/m", "V/m", "Elect    381   new G4UnitDefinition("volt/m", "V/m", "Electric field", volt / m);
396   new G4UnitDefinition("kilovolt/m", "kV/m", "    382   new G4UnitDefinition("kilovolt/m", "kV/m", "Electric field", kilovolt / m);
397   new G4UnitDefinition("megavolt/m", "MV/m", "    383   new G4UnitDefinition("megavolt/m", "MV/m", "Electric field", megavolt / m);
398                                                   384 
399   // Magnetic flux                                385   // Magnetic flux
400   new G4UnitDefinition("weber", "Wb", "Magneti    386   new G4UnitDefinition("weber", "Wb", "Magnetic flux", weber);
401                                                   387 
402   // Magnetic flux density                        388   // Magnetic flux density
403   new G4UnitDefinition("tesla", "T", "Magnetic    389   new G4UnitDefinition("tesla", "T", "Magnetic flux density", tesla);
404   new G4UnitDefinition("kilogauss", "kG", "Mag    390   new G4UnitDefinition("kilogauss", "kG", "Magnetic flux density", kilogauss);
405   new G4UnitDefinition("gauss", "G", "Magnetic    391   new G4UnitDefinition("gauss", "G", "Magnetic flux density", gauss);
406                                                   392 
407   // Temperature                                  393   // Temperature
408   new G4UnitDefinition("kelvin", "K", "Tempera    394   new G4UnitDefinition("kelvin", "K", "Temperature", kelvin);
409                                                   395 
410   // Amount of substance                          396   // Amount of substance
411   new G4UnitDefinition("mole", "mol", "Amount     397   new G4UnitDefinition("mole", "mol", "Amount of substance", mole);
412   new G4UnitDefinition("g/mole", "g/mol", "Mol    398   new G4UnitDefinition("g/mole", "g/mol", "Molar mass", g / mole);
413                                                   399 
414   // Activity                                     400   // Activity
415   new G4UnitDefinition("becquerel", "Bq", "Act    401   new G4UnitDefinition("becquerel", "Bq", "Activity", becquerel);
416   new G4UnitDefinition("curie", "Ci", "Activit    402   new G4UnitDefinition("curie", "Ci", "Activity", curie);
417                                                   403 
418   // Dose                                         404   // Dose
419   new G4UnitDefinition("gray", "Gy", "Dose", g    405   new G4UnitDefinition("gray", "Gy", "Dose", gray);
420 }                                                 406 }
421                                                   407 
422 // -------------------------------------------    408 // --------------------------------------------------------------------
423                                                   409 
424 void G4UnitDefinition::PrintUnitsTable()          410 void G4UnitDefinition::PrintUnitsTable()
425 {                                                 411 {
426   G4cout << "\n          ----- The Table of Un    412   G4cout << "\n          ----- The Table of Units ----- \n";
427   if(pUnitsTable == nullptr)                      413   if(pUnitsTable == nullptr)
428   {                                               414   {
429     pUnitsTable = new G4UnitsTable;               415     pUnitsTable = new G4UnitsTable;
430   }                                               416   }
431   for(std::size_t i = 0; i < pUnitsTable->size    417   for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
432   {                                               418   {
433     (*pUnitsTable)[i]->PrintCategory();           419     (*pUnitsTable)[i]->PrintCategory();
434   }                                               420   }
435 }                                                 421 }
436                                                   422 
437 // -------------------------------------------    423 // --------------------------------------------------------------------
438                                                   424 
439 void G4UnitDefinition::ClearUnitsTable()          425 void G4UnitDefinition::ClearUnitsTable()
440 {                                                 426 {
441 #ifdef G4MULTITHREADED                            427 #ifdef G4MULTITHREADED
442   delete pUnitsTable;                             428   delete pUnitsTable;
443   pUnitsTable = nullptr;                          429   pUnitsTable = nullptr;
444   if(G4Threading::IsMasterThread())               430   if(G4Threading::IsMasterThread())
445   {                                               431   {
446     pUnitsTableShadow = nullptr;                  432     pUnitsTableShadow = nullptr;
447   }                                               433   }
448 #else                                             434 #else
449   for(std::size_t i = 0; i < pUnitsTable->size    435   for(std::size_t i = 0; i < pUnitsTable->size(); ++i)
450   {                                               436   {
451     delete(*pUnitsTable)[i];                      437     delete(*pUnitsTable)[i];
452   }                                               438   }
453   pUnitsTable->clear();                           439   pUnitsTable->clear();
454 #endif                                            440 #endif
455   unitsTableDestroyed = true;                     441   unitsTableDestroyed = true;
456 }                                                 442 }
457                                                   443 
458 // -------------------------------------------    444 // --------------------------------------------------------------------
459                                                   445 
460 G4UnitsCategory::G4UnitsCategory(const G4Strin    446 G4UnitsCategory::G4UnitsCategory(const G4String& name)
461   : Name(name)                                    447   : Name(name)
                                                   >> 448   , UnitsList()
462 {}                                                449 {}
463                                                   450 
464 // -------------------------------------------    451 // --------------------------------------------------------------------
465                                                   452 
466 G4UnitsCategory::~G4UnitsCategory()               453 G4UnitsCategory::~G4UnitsCategory()
467 {                                                 454 {
468   for(auto& i : UnitsList)                     << 455   for(std::size_t i = 0; i < UnitsList.size(); ++i)
469   {                                               456   {
470     delete i;                                  << 457     delete UnitsList[i];
471   }                                               458   }
472   UnitsList.clear();                              459   UnitsList.clear();
473 }                                                 460 }
474                                                   461 
475 // -------------------------------------------    462 // --------------------------------------------------------------------
476                                                   463 
477 G4UnitsCategory::G4UnitsCategory(const G4Units    464 G4UnitsCategory::G4UnitsCategory(const G4UnitsCategory& right)
478 {                                                 465 {
479   *this = right;                                  466   *this = right;
480 }                                                 467 }
481                                                   468 
482 // -------------------------------------------    469 // --------------------------------------------------------------------
483                                                   470 
484 G4UnitsCategory& G4UnitsCategory::operator=(co    471 G4UnitsCategory& G4UnitsCategory::operator=(const G4UnitsCategory& right)
485 {                                                 472 {
486   if(this != &right)                              473   if(this != &right)
487   {                                               474   {
488     Name      = right.Name;                       475     Name      = right.Name;
489     UnitsList = right.UnitsList;                  476     UnitsList = right.UnitsList;
490     NameMxLen = right.NameMxLen;                  477     NameMxLen = right.NameMxLen;
491     SymbMxLen = right.SymbMxLen;                  478     SymbMxLen = right.SymbMxLen;
492   }                                               479   }
493   return *this;                                   480   return *this;
494 }                                                 481 }
495                                                   482 
496 // -------------------------------------------    483 // --------------------------------------------------------------------
497                                                   484 
498 G4bool G4UnitsCategory::operator==(const G4Uni    485 G4bool G4UnitsCategory::operator==(const G4UnitsCategory& right) const
499 {                                                 486 {
500   return (this == (G4UnitsCategory*) &right);     487   return (this == (G4UnitsCategory*) &right);
501 }                                                 488 }
502                                                   489 
503 // -------------------------------------------    490 // --------------------------------------------------------------------
504                                                   491 
505 G4bool G4UnitsCategory::operator!=(const G4Uni    492 G4bool G4UnitsCategory::operator!=(const G4UnitsCategory& right) const
506 {                                                 493 {
507   return (this != (G4UnitsCategory*) &right);     494   return (this != (G4UnitsCategory*) &right);
508 }                                                 495 }
509                                                   496 
510 // -------------------------------------------    497 // --------------------------------------------------------------------
511                                                   498 
512 void G4UnitsCategory::PrintCategory()             499 void G4UnitsCategory::PrintCategory()
513 {                                                 500 {
514   G4cout << "\n  category: " << Name << G4endl    501   G4cout << "\n  category: " << Name << G4endl;
515   for(auto& i : UnitsList)                     << 502   for(std::size_t i = 0; i < UnitsList.size(); ++i)
516   {                                               503   {
517     i->PrintDefinition();                      << 504     UnitsList[i]->PrintDefinition();
518   }                                               505   }
519 }                                                 506 }
520                                                   507 
521 // -------------------------------------------    508 // --------------------------------------------------------------------
522                                                   509 
523 G4BestUnit::G4BestUnit(G4double value, const G    510 G4BestUnit::G4BestUnit(G4double value, const G4String& category)
524   : nbOfVals(1)                                   511   : nbOfVals(1)
525 {                                                 512 {
526   // find the category                            513   // find the category
527   G4UnitsTable& theUnitsTable = G4UnitDefiniti    514   G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable();
528   std::size_t nbCat           = theUnitsTable.    515   std::size_t nbCat           = theUnitsTable.size();
529   std::size_t i               = 0;                516   std::size_t i               = 0;
530   while((i < nbCat) && (theUnitsTable[i]->GetN    517   while((i < nbCat) && (theUnitsTable[i]->GetName() != category))
531   {                                               518   {
532     ++i;                                          519     ++i;
533   }                                               520   }
534   if(i == nbCat)                                  521   if(i == nbCat)
535   {                                               522   {
536     G4cout << " G4BestUnit: the category " <<     523     G4cout << " G4BestUnit: the category " << category << " does not exist !!"
537            << G4endl;                             524            << G4endl;
538     G4Exception("G4BestUnit::G4BestUnit()", "I    525     G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", FatalException,
539                 "Missing unit category !");       526                 "Missing unit category !");
540   }                                               527   }
541                                                   528 
542   Value[0]        = value;                        529   Value[0]        = value;
543   Value[1]        = 0.;                           530   Value[1]        = 0.;
544   Value[2]        = 0.;                           531   Value[2]        = 0.;
545   Category        = category;                  << 
546   IndexOfCategory = i;                            532   IndexOfCategory = i;
547 }                                                 533 }
548                                                   534 
549 // -------------------------------------------    535 // --------------------------------------------------------------------
550                                                   536 
551 G4BestUnit::G4BestUnit(const G4ThreeVector& va    537 G4BestUnit::G4BestUnit(const G4ThreeVector& value, const G4String& category)
552   : nbOfVals(3)                                   538   : nbOfVals(3)
553 {                                                 539 {
554   // find the category                            540   // find the category
555   G4UnitsTable& theUnitsTable = G4UnitDefiniti    541   G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable();
556   std::size_t nbCat           = theUnitsTable.    542   std::size_t nbCat           = theUnitsTable.size();
557   std::size_t i               = 0;                543   std::size_t i               = 0;
558   while((i < nbCat) && (theUnitsTable[i]->GetN    544   while((i < nbCat) && (theUnitsTable[i]->GetName() != category))
559   {                                               545   {
560     ++i;                                          546     ++i;
561   }                                               547   }
562   if(i == nbCat)                                  548   if(i == nbCat)
563   {                                               549   {
564     G4cerr << " G4BestUnit: the category " <<     550     G4cerr << " G4BestUnit: the category " << category << " does not exist."
565            << G4endl;                             551            << G4endl;
566     G4Exception("G4BestUnit::G4BestUnit()", "I    552     G4Exception("G4BestUnit::G4BestUnit()", "InvalidCall", FatalException,
567                 "Missing unit category !");       553                 "Missing unit category !");
568   }                                               554   }
569                                                   555 
570   Value[0]        = value.x();                    556   Value[0]        = value.x();
571   Value[1]        = value.y();                    557   Value[1]        = value.y();
572   Value[2]        = value.z();                    558   Value[2]        = value.z();
573   Category        = category;                  << 
574   IndexOfCategory = i;                            559   IndexOfCategory = i;
575 }                                                 560 }
576                                                   561 
577 // -------------------------------------------    562 // --------------------------------------------------------------------
578                                                   563 
                                                   >> 564 G4BestUnit::~G4BestUnit() {}
                                                   >> 565 
                                                   >> 566 // --------------------------------------------------------------------
                                                   >> 567 
579 G4BestUnit::operator G4String() const             568 G4BestUnit::operator G4String() const
580 {                                                 569 {
581   std::ostringstream oss;                         570   std::ostringstream oss;
582   oss << *this;                                   571   oss << *this;
583   return oss.str();                               572   return oss.str();
584 }                                                 573 }
585                                                   574 
586 // -------------------------------------------    575 // --------------------------------------------------------------------
587                                                   576 
588 std::ostream& operator<<(std::ostream& flux, c << 577 std::ostream& operator<<(std::ostream& flux, G4BestUnit a)
589 {                                                 578 {
590   G4UnitsTable& theUnitsTable = G4UnitDefiniti    579   G4UnitsTable& theUnitsTable = G4UnitDefinition::GetUnitsTable();
591   G4UnitsContainer& List = theUnitsTable[a.Ind    580   G4UnitsContainer& List = theUnitsTable[a.IndexOfCategory]->GetUnitsList();
592   G4int len              = theUnitsTable[a.Ind    581   G4int len              = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
593                                                   582 
594   G4long ksup(-1), kinf(-1);                   << 583   G4int ksup(-1), kinf(-1);
595   G4double umax(0.), umin(DBL_MAX);               584   G4double umax(0.), umin(DBL_MAX);
596   G4double rsup(DBL_MAX), rinf(0.);               585   G4double rsup(DBL_MAX), rinf(0.);
597                                                   586 
598   // for a ThreeVector, choose the best unit f    587   // for a ThreeVector, choose the best unit for the biggest value
599   G4double value =                                588   G4double value =
600     std::max(std::max(std::fabs(a.Value[0]), s    589     std::max(std::max(std::fabs(a.Value[0]), std::fabs(a.Value[1])),
601              std::fabs(a.Value[2]));              590              std::fabs(a.Value[2]));
602                                                   591 
603   //special treatement for Energy.             << 
604   if ((a.Category == "Energy") && (value == 0. << 
605     for (G4int j = 0; j < a.nbOfVals; ++j) {   << 
606        flux << a.Value[j] << " ";              << 
607     }                                          << 
608     std::ios::fmtflags oldform = flux.flags(); << 
609     flux.setf(std::ios::left, std::ios::adjust << 
610     flux << std::setw(len) << "eV";            << 
611     flux.flags(oldform);                       << 
612     return flux;                               << 
613   }                                            << 
614                                                << 
615   //here, value != 0.                          << 
616   for(std::size_t k = 0; k < List.size(); ++k)    592   for(std::size_t k = 0; k < List.size(); ++k)
617   {                                               593   {
618     G4double unit = List[k]->GetValue();          594     G4double unit = List[k]->GetValue();
619     if(!(value != DBL_MAX))                       595     if(!(value != DBL_MAX))
620     {                                             596     {
621       if(unit > umax)                             597       if(unit > umax)
622       {                                           598       {
623         umax = unit;                              599         umax = unit;
624         ksup = k;                                 600         ksup = k;
625       }                                           601       }
626     }                                             602     }
627     else if(value <= DBL_MIN)                     603     else if(value <= DBL_MIN)
628     {                                             604     {
629       if(unit < umin)                             605       if(unit < umin)
630       {                                           606       {
631         umin = unit;                              607         umin = unit;
632         kinf = k;                                 608         kinf = k;
633       }                                           609       }
634     }                                             610     }
635     else                                          611     else
636     {                                             612     {
637       G4double ratio = value / unit;              613       G4double ratio = value / unit;
638       if((ratio >= 1.) && (ratio < rsup))         614       if((ratio >= 1.) && (ratio < rsup))
639       {                                           615       {
640         rsup = ratio;                             616         rsup = ratio;
641         ksup = k;                                 617         ksup = k;
642       }                                           618       }
643       if((ratio < 1.) && (ratio > rinf))          619       if((ratio < 1.) && (ratio > rinf))
644       {                                           620       {
645         rinf = ratio;                             621         rinf = ratio;
646         kinf = k;                                 622         kinf = k;
647       }                                           623       }
648     }                                             624     }
649   }                                               625   }
650                                                   626 
651   G4long index = ksup;                         << 627   G4int index = ksup;
652   if(index == -1)                                 628   if(index == -1)
653   {                                               629   {
654     index = kinf;                                 630     index = kinf;
655   }                                               631   }
656   if(index == -1)                                 632   if(index == -1)
657   {                                               633   {
658     index = 0;                                    634     index = 0;
659   }                                               635   }
660                                                   636 
661   for(G4int j = 0; j < a.nbOfVals; ++j)           637   for(G4int j = 0; j < a.nbOfVals; ++j)
662   {                                               638   {
663     flux << a.Value[j] / (List[index]->GetValu    639     flux << a.Value[j] / (List[index]->GetValue()) << " ";
664   }                                               640   }
665                                                   641 
666   std::ios::fmtflags oldform = flux.flags();      642   std::ios::fmtflags oldform = flux.flags();
667                                                   643 
668   flux.setf(std::ios::left, std::ios::adjustfi    644   flux.setf(std::ios::left, std::ios::adjustfield);
669   flux << std::setw(len) << List[index]->GetSy    645   flux << std::setw(len) << List[index]->GetSymbol();
670   flux.flags(oldform);                            646   flux.flags(oldform);
671                                                   647 
672   return flux;                                    648   return flux;
673 }                                                 649 }
674                                                   650 
675 // -------------------------------------------    651 // --------------------------------------------------------------------
676                                                   652 
677 #ifdef G4MULTITHREADED                            653 #ifdef G4MULTITHREADED
678                                                   654 
679 void G4UnitsTable::Synchronize()                  655 void G4UnitsTable::Synchronize()
680 {                                                 656 {
681   G4UnitsTable* orig = &(G4UnitDefinition::Get    657   G4UnitsTable* orig = &(G4UnitDefinition::GetUnitsTableShadow());
682   if(this == orig)                                658   if(this == orig)
683   {                                            << 
684     return;                                       659     return;
685   }                                            << 
686                                                   660 
687   for(const auto category : *orig)             << 661   for(auto utItr = orig->cbegin(); utItr != orig->cend(); ++utItr)
688   {                                               662   {
                                                   >> 663     G4UnitsCategory* category = *utItr;
689     G4String catName          = category->GetN    664     G4String catName          = category->GetName();
690     G4UnitsContainer* units   = &(category->Ge    665     G4UnitsContainer* units   = &(category->GetUnitsList());
691     for(const auto unit : *units)              << 666     for(auto ucItr = units->cbegin(); ucItr != units->cend(); ++ucItr)
692     {                                             667     {
                                                   >> 668       G4UnitDefinition* unit = *ucItr;
693       if(!Contains(unit, catName))                669       if(!Contains(unit, catName))
694       {                                           670       {
695         new G4UnitDefinition(unit->GetName(),     671         new G4UnitDefinition(unit->GetName(), unit->GetSymbol(), catName,
696                              unit->GetValue())    672                              unit->GetValue());
697       }                                           673       }
698     }                                             674     }
699   }                                               675   }
700 }                                                 676 }
701                                                   677 
702 // -------------------------------------------    678 // --------------------------------------------------------------------
703                                                   679 
704 G4bool G4UnitsTable::Contains(const G4UnitDefi    680 G4bool G4UnitsTable::Contains(const G4UnitDefinition* unit,
705                               const G4String&     681                               const G4String& categoryName)
706 {                                                 682 {
707   for(const auto category : *this)             << 683   for(auto utItr = cbegin(); utItr != cend(); ++utItr)
708   {                                               684   {
709     G4String catName = category->GetName();    << 685     G4UnitsCategory* category = *utItr;
                                                   >> 686     G4String catName          = category->GetName();
710     if(catName != categoryName)                   687     if(catName != categoryName)
711     {                                          << 
712       continue;                                   688       continue;
713     }                                          << 
714     G4UnitsContainer* units = &(category->GetU    689     G4UnitsContainer* units = &(category->GetUnitsList());
715     for(const auto ucItr : *units)             << 690     for(auto ucItr = units->cbegin(); ucItr != units->cend(); ++ucItr)
716     {                                             691     {
717       if(ucItr->GetName() == unit->GetName() & << 692       if((*ucItr)->GetName() == unit->GetName() &&
718          ucItr->GetSymbol() == unit->GetSymbol << 693          (*ucItr)->GetSymbol() == unit->GetSymbol())
719       {                                           694       {
720         return true;                              695         return true;
721       }                                           696       }
722     }                                             697     }
723   }                                               698   }
724   return false;                                   699   return false;
725 }                                                 700 }
726                                                   701 
727 #endif                                            702 #endif
728                                                   703