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