test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ALIUnitsTable.cc
Go to the documentation of this file.
1 
3 #include "CLHEP/Units/GlobalSystemOfUnits.h"
4 
5 #include <iomanip>
6 #include <cstdlib>
7 #include <cmath> // include floating-point std::abs functions
8 
10 
11 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
12 
15  : Name(name),SymbolName(symbol),Value(value)
16 {
17  //
18  //does the Category objet already exist ?
19  size_t nbCat = theUnitsTable.size();
20  size_t i = 0;
21  while ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++;
22  if (i == nbCat) theUnitsTable.push_back( new ALIUnitsCategory(category));
23  CategoryIndex = i;
24  //
25  //insert this Unit in the Unitstable
26  (theUnitsTable[CategoryIndex]->GetUnitsList()).push_back(this);
27 
28  //update ALIstring max length for name and symbol
29  theUnitsTable[i]->UpdateNameMxLen((ALIint)name.length());
30  theUnitsTable[i]->UpdateSymbMxLen((ALIint)symbol.length());
31 
32 }
33 
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
35 
37 {}
38 
39 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
40 
42 {
43  *this = right;
44 }
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
47 
49 {
50  if (this != &right)
51  {
52  Name = right.Name;
53  SymbolName = right.SymbolName;
54  Value = right.Value;
56  }
57  return *this;
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
61 
63 {
64  return (this == &right);
65 }
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
68 
70 {
71  return (this != &right);
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
76 {
77  if(theUnitsTable.size()==0) BuildUnitsTable();
78  ALIstring name,symbol;
79  for (size_t i=0;i<theUnitsTable.size();i++)
80  { ALIUnitsContainer& units = theUnitsTable[i]->GetUnitsList();
81  for (size_t j=0;j<units.size();j++)
82  { name=units[j]->GetName(); symbol=units[j]->GetSymbol();
83  if(stri==name||stri==symbol)
84  return units[j]->GetValue();
85  }
86  }
87  std::cout << "Warning from ALIUnitDefinition::GetValueOf(" << stri << ")."
88  << " The unit " << stri << " does not exist in UnitsTable."
89  << " Return Value = 0." << std::endl;
90  return 0.;
91 }
92 
93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
94 
96 {
97  if(theUnitsTable.size()==0) BuildUnitsTable();
98  ALIstring name,symbol;
99  for (size_t i=0;i<theUnitsTable.size();i++)
100  { ALIUnitsContainer& units = theUnitsTable[i]->GetUnitsList();
101  for (size_t j=0;j<units.size();j++)
102  { name=units[j]->GetName(); symbol=units[j]->GetSymbol();
103  if(stri==name||stri==symbol)
104  return theUnitsTable[i]->GetName();
105  }
106  }
107  std::cout << "Warning from ALIUnitDefinition::GetCategory(" << stri << ")."
108  << " The unit " << stri << " does not exist in UnitsTable."
109  << " Return category = None" << std::endl;
110  name = "None";
111  return name;
112 }
113 
114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
115 
117 {
118  ALIint nameL = theUnitsTable[CategoryIndex]->GetNameMxLen();
119  ALIint symbL = theUnitsTable[CategoryIndex]->GetSymbMxLen();
120  std::cout << std::setw(nameL) << Name << " ("
121  << std::setw(symbL) << SymbolName << ") = " << Value << std::endl;
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
125 
127 {
128  //Length
129  new ALIUnitDefinition( "kilometer","km" ,"Length",kilometer);
130  new ALIUnitDefinition( "meter","m" ,"Length",meter);
131  new ALIUnitDefinition("centimeter","cm" ,"Length",centimeter);
132  new ALIUnitDefinition("millimeter","mm" ,"Length",millimeter);
133  new ALIUnitDefinition("micrometer","mum" ,"Length",micrometer);
134  new ALIUnitDefinition( "nanometer","nm" ,"Length",nanometer);
135  new ALIUnitDefinition( "angstrom","Ang" ,"Length",angstrom);
136  new ALIUnitDefinition( "fermi","fm" ,"Length",fermi);
137 
138  //Surface
139  new ALIUnitDefinition( "kilometer2","km2" ,"Surface",kilometer2);
140  new ALIUnitDefinition( "meter2","m2" ,"Surface",meter2);
141  new ALIUnitDefinition("centimeter2","cm2" ,"Surface",centimeter2);
142  new ALIUnitDefinition("millimeter2","mm2" ,"Surface",millimeter2);
143  new ALIUnitDefinition( "barn","barn" ,"Surface",barn);
144  new ALIUnitDefinition( "millibarn","mbarn" ,"Surface",millibarn);
145  new ALIUnitDefinition( "microbarn","mubarn" ,"Surface",microbarn);
146  new ALIUnitDefinition( "nanobarn","nbarn" ,"Surface",nanobarn);
147  new ALIUnitDefinition( "picobarn","pbarn" ,"Surface",picobarn);
148 
149  //Volume
150  new ALIUnitDefinition( "kilometer3","km3" ,"Volume",kilometer3);
151  new ALIUnitDefinition( "meter3","m3" ,"Volume",meter3);
152  new ALIUnitDefinition("centimeter3","cm3" ,"Volume",centimeter3);
153  new ALIUnitDefinition("millimeter3","mm3" ,"Volume",millimeter3);
154 
155  //Angle
156  new ALIUnitDefinition( "radian","rad" ,"Angle",radian);
157  new ALIUnitDefinition("milliradian","mrad" ,"Angle",milliradian);
158  new ALIUnitDefinition("milliradian","murad" ,"Angle",0.001*milliradian);
159  new ALIUnitDefinition( "steradian","sr" ,"Angle",steradian);
160  new ALIUnitDefinition( "degree","deg" ,"Angle",degree);
161 
162  //Time
163  new ALIUnitDefinition( "second","s" ,"Time",second);
164  new ALIUnitDefinition("millisecond","ms" ,"Time",millisecond);
165  new ALIUnitDefinition("microsecond","mus" ,"Time",microsecond);
166  new ALIUnitDefinition( "nanosecond","ns" ,"Time",nanosecond);
167  new ALIUnitDefinition( "picosecond","ps" ,"Time",picosecond);
168 
169  //Frequency
170  new ALIUnitDefinition( "hertz","Hz" ,"Frequency",hertz);
171  new ALIUnitDefinition("kilohertz","kHz" ,"Frequency",kilohertz);
172  new ALIUnitDefinition("megahertz","MHz" ,"Frequency",megahertz);
173 
174  //Electric charge
175  new ALIUnitDefinition( "eplus","e+" ,"Electric charge",eplus);
176  new ALIUnitDefinition("coulomb","C" ,"Electric charge",coulomb);
177 
178  //Energy
179  new ALIUnitDefinition( "electronvolt","eV" ,"Energy",electronvolt);
180  new ALIUnitDefinition("kiloelectronvolt","keV","Energy",kiloelectronvolt);
181  new ALIUnitDefinition("megaelectronvolt","MeV","Energy",megaelectronvolt);
182  new ALIUnitDefinition("gigaelectronvolt","GeV","Energy",gigaelectronvolt);
183  new ALIUnitDefinition("teraelectronvolt","TeV","Energy",teraelectronvolt);
184  new ALIUnitDefinition("petaelectronvolt","PeV","Energy",petaelectronvolt);
185  new ALIUnitDefinition( "joule","J" ,"Energy",joule);
186 
187  //Mass
188  new ALIUnitDefinition("milligram","mg","Mass",milligram);
189  new ALIUnitDefinition( "gram","g" ,"Mass",gram);
190  new ALIUnitDefinition( "kilogram","kg","Mass",kilogram);
191 
192  //Volumic Mass
193  new ALIUnitDefinition( "g/cm3", "g/cm3","Volumic Mass", g/cm3);
194  new ALIUnitDefinition("mg/cm3","mg/cm3","Volumic Mass",mg/cm3);
195  new ALIUnitDefinition("kg/m3", "kg/m3", "Volumic Mass",kg/m3);
196 
197  //Power
198  new ALIUnitDefinition("watt","W","Power",watt);
199 
200  //Force
201  new ALIUnitDefinition("newton","N","Force",newton);
202 
203  //Pressure
204  new ALIUnitDefinition( "pascal","Pa" ,"Pressure",pascal);
205  new ALIUnitDefinition( "bar","bar","Pressure",bar);
206  new ALIUnitDefinition("atmosphere","atm","Pressure",atmosphere);
207 
208  //Electric current
209  new ALIUnitDefinition( "ampere","A" ,"Electric current",ampere);
210  new ALIUnitDefinition("milliampere","mA" ,"Electric current",milliampere);
211  new ALIUnitDefinition("microampere","muA","Electric current",microampere);
212  new ALIUnitDefinition( "nanoampere","nA" ,"Electric current",nanoampere);
213 
214  //Electric potential
215  new ALIUnitDefinition( "volt","V" ,"Electric potential",volt);
216  new ALIUnitDefinition("kilovolt","kV","Electric potential",kilovolt);
217  new ALIUnitDefinition("megavolt","MV","Electric potential",megavolt);
218 
219  //Magnetic flux
220  new ALIUnitDefinition("weber","Wb","Magnetic flux",weber);
221 
222  //Magnetic flux density
223  new ALIUnitDefinition( "tesla","T" ,"Magnetic flux density",tesla);
224  new ALIUnitDefinition("kilogauss","kG","Magnetic flux density",kilogauss);
225  new ALIUnitDefinition( "gauss","G" ,"Magnetic flux density",gauss);
226 
227  //Temperature
228  new ALIUnitDefinition("kelvin","K","Temperature",kelvin);
229 
230  //Amount of substance
231  new ALIUnitDefinition("mole","mol","Amount of substance",mole);
232 
233  //Activity
234  new ALIUnitDefinition("becquerel","Bq","Activity",becquerel);
235  new ALIUnitDefinition( "curie","Ci","Activity",curie);
236 
237  //Dose
238  new ALIUnitDefinition("gray","Gy","Dose",gray);
239 }
240 
241 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
242 
244 {
245  std::cout << "\n ----- The Table of Units ----- \n";
246  for(size_t i=0;i<theUnitsTable.size();i++)
247  theUnitsTable[i]->PrintCategory();
248 }
249 
250 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
251 
253 :Name(name),NameMxLen(0),SymbMxLen(0)
254 {
255  UnitsList = *(new ALIUnitsContainer);
256 }
257 
258 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
259 
261 {}
262 
263 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
264 
266 {
267  *this = right;
268 }
269 
270 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
271 
273 {
274  if (this != &right)
275  {
276  Name = right.Name;
277  UnitsList = right.UnitsList;
278  NameMxLen = right.NameMxLen;
279  SymbMxLen = right.SymbMxLen;
280  }
281  return *this;
282 }
283 
284 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
285 
287 {
288  return (this == &right);
289 }
290 
291 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
292 
294 {
295  return (this != &right);
296 }
297 
298 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
299 
301 {
302  std::cout << "\n category: " << Name << std::endl;
303  for(size_t i=0;i<UnitsList.size();i++)
304  UnitsList[i]->PrintDefinition();
305 }
306 
307 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
308 
310 {
311  // find the category
313  size_t nbCat = theUnitsTable.size();
314  size_t i = 0;
315  while
316  ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++;
317  if (i == nbCat)
318  { std::cout << " ALIBestUnit: the category " << category
319  << " does not exist !!" << std::endl;
320  std::cerr << "Missing unit category !" << std::endl;
321  abort();
322  }
323  //
324  IndexOfCategory = i;
325  nbOfVals = 1;
326  Value[0] = value; Value[1] = 0.; Value[2] = 0.;
327 }
328 
329 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
330 
332 {
333  // find the category
335  size_t nbCat = theUnitsTable.size();
336  size_t i = 0;
337  while
338  ((i<nbCat)&&(theUnitsTable[i]->GetName()!=category)) i++;
339  if (i == nbCat)
340  { std::cerr << " ALIBestUnit: the category " << category
341  << " does not exist." << std::endl;
342  std::cerr << "Unit category not existing !" << std::endl;
343  abort();
344  }
345  //
346  IndexOfCategory = i;
347  nbOfVals = 3;
348  Value[0] = value.x();
349  Value[1] = value.y();
350  Value[2] = value.z();
351 }
352 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
353 
355 {}
356 
357 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
358 
359 std::ostream& operator<<(std::ostream& flux, ALIBestUnit a)
360 {
362  ALIUnitsContainer& List = theUnitsTable[a.IndexOfCategory]
363  ->GetUnitsList();
364  ALIint len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
365 
366  ALIint ksup(-1), kinf(-1);
367  ALIdouble umax(0.), umin(1.E12);
368  ALIdouble rsup(1.E12), rinf(0.);
369 
370  //for a ThreeVector, choose the best unit for the biggest value
372  std::abs(a.Value[2]));
373 
374  for (size_t k=0; k<List.size(); k++)
375  {
376  ALIdouble unit = List[k]->GetValue();
377  if (value==1.E12) {if(unit>umax) {umax=unit; ksup=k;}}
378  else if (value<=-1.E12) {if(unit<umin) {umin=unit; kinf=k;}}
379 
380  else { ALIdouble ratio = value/unit;
381  if ((ratio>=1.)&&(ratio<rsup)) {rsup=ratio; ksup=k;}
382  if ((ratio< 1.)&&(ratio>rinf)) {rinf=ratio; kinf=k;}
383  }
384  }
385 
386  ALIint index=ksup; if(index==-1) index=kinf; if(index==-1) index=0;
387 
388  for (ALIint j=0; j<a.nbOfVals; j++)
389  {flux << a.Value[j]/(List[index]->GetValue()) << " ";}
390 
391  #ifdef ALIUSE_STD_NAMESPACE
392  std::ios::fmtflags oldform = std::cout.flags();
393  #else
394  // ALIint oldform = std::cout.flags();
395  #endif
396 
397  flux.setf(std::ios::left,std::ios::adjustfield);
398  flux << std::setw(len) << List[index]->GetSymbol();
399  //?? flux.flags(oldform);
400 
401  return flux;
402 }
403 
404 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
405 
ALIstring GetName() const
Definition: ALIUnitsTable.h:72
int i
Definition: DBlmapReader.cc:9
long double ALIdouble
Definition: CocoaGlobals.h:11
ALIint operator==(const ALIUnitDefinition &) const
std::vector< ALIUnitsCategory * > ALIUnitsTable
Definition: ALIUnitsTable.h:46
ALIUnitDefinition & operator=(const ALIUnitDefinition &)
ALIstring SymbolName
Definition: ALIUnitsTable.h:89
std::vector< ALIUnitDefinition * > ALIUnitsContainer
ALIint operator!=(const ALIUnitDefinition &) const
ALIBestUnit(ALIdouble internalValue, ALIstring category)
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:188
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
const double fermi
Definition: MathUtil.h:17
U second(std::pair< T, U > const &p)
ALIint operator==(const ALIUnitsCategory &) const
ALIUnitsCategory & operator=(const ALIUnitsCategory &)
static void PrintUnitsTable()
string unit
Definition: csvLumiCalc.py:46
size_t IndexOfCategory
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
ALIUnitsCategory(ALIstring name)
reco::JetExtendedAssociation::JetExtendedData Value
static void BuildUnitsTable()
ALIdouble Value[3]
ALIint operator!=(const ALIUnitsCategory &) const
static ALIdouble GetValueOf(ALIstring)
TString units(TString variable, Char_t axis)
double a
Definition: hdecay.h:121
std::string ALIstring
Definition: CocoaGlobals.h:9
tuple cout
Definition: gather_cfg.py:145
static ALIUnitsTable theUnitsTable
Definition: ALIUnitsTable.h:93
static ALIUnitsTable & GetUnitsTable()
Definition: ALIUnitsTable.h:81