Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JScale.hh
Go to the documentation of this file.
1#ifndef __JEEP__JSCALE__
2#define __JEEP__JSCALE__
3
4#include <cmath>
5
6#include "JLang/JException.hh"
7
8
9/**
10 * \file
11 * Enumeration for scaling of quantity.
12 * \author mdejong
13 */
14namespace JEEP {}
15namespace JPP { using namespace JEEP; }
16
17namespace JEEP {
18
20
21 /**
22 * Enumeration for scaling of quantity.
23 */
24 enum JScale_t {
25
26 femto_t = -15, //!< femto
27 pico_t = -12, //!< pico
28 nano_t = -9, //!< nano
29 micro_t = -6, //!< micro
30 milli_t = -3, //!< milli
31 unit_t = 0, //!< unit
32 kilo_t = +3, //!< kilo
33 mega_t = +6, //!< mega
34 giga_t = +9, //!< giga
35 tera_t = +12, //!< tera
36 peta_t = +15, //!< peta
37 exa_t = +18 //!< exa
38 };
39
40
41 /**
42 * Get numerical value corresponding to scale.
43 *
44 * \param scale scale
45 * \return value
46 */
47 inline double getValue(const JScale_t scale)
48 {
49 return pow(10.0, scale);
50 }
51
52
53 /**
54 * Get textual unit corresponding to scale.
55 *
56 * \param scale scale
57 * \return textual unit
58 */
59 inline const char* getUnit(const int scale)
60 {
61 switch (scale) {
62
63 case femto_t:
64 return "f";
65
66 case pico_t:
67 return "p";
68
69 case nano_t:
70 return "n";
71
72 case micro_t:
73 return "u";
74
75 case milli_t:
76 return "m";
77
78 case unit_t:
79 return "";
80
81 case kilo_t:
82 return "k";
83
84 case mega_t:
85 return "M";
86
87 case giga_t:
88 return "G";
89
90 case tera_t:
91 return "T";
92
93 case peta_t:
94 return "P";
95
96 case exa_t:
97 return "E";
98
99 default:
100 THROW(JValueOutOfRange, "getUnit(): invalid scale " << scale);
101 };
102 }
103
104
105 /**
106 * Get scale corresponding to textual unit
107 *
108 * \param unit textual unit
109 * \return scale
110 */
111 inline JScale_t getScale(const char unit)
112 {
113 switch (unit) {
114
115 case 'f':
116 return femto_t;
117
118 case 'p':
119 return pico_t;
120
121 case 'n':
122 return nano_t;
123
124 case 'u':
125 return micro_t;
126
127 case 'm':
128 return milli_t;
129
130 case ' ':
131 return unit_t;
132
133 case 'k':
134 return kilo_t;
135
136 case 'M':
137 return mega_t;
138
139 case 'G':
140 return giga_t;
141
142 case 'T':
143 return tera_t;
144
145 case 'P':
146 return peta_t;
147
148 case 'E':
149 return exa_t;
150
151 default:
152 THROW(JValueOutOfRange, "getScale(): invalid unit " << unit);
153 };
154 }
155}
156
157#endif
void scale(vector< double > &v, double c)
scale vector content
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for accessing a value in a collection that is outside of its range.
General puprpose classes and methods.
JScale_t getScale(const char unit)
Get scale corresponding to textual unit.
Definition JScale.hh:111
double getValue(const JScale_t scale)
Get numerical value corresponding to scale.
Definition JScale.hh:47
JScale_t
Enumeration for scaling of quantity.
Definition JScale.hh:24
@ peta_t
peta
Definition JScale.hh:36
@ kilo_t
kilo
Definition JScale.hh:32
@ mega_t
mega
Definition JScale.hh:33
@ exa_t
exa
Definition JScale.hh:37
@ giga_t
giga
Definition JScale.hh:34
@ femto_t
femto
Definition JScale.hh:26
@ tera_t
tera
Definition JScale.hh:35
@ unit_t
unit
Definition JScale.hh:31
@ nano_t
nano
Definition JScale.hh:28
@ pico_t
pico
Definition JScale.hh:27
@ milli_t
milli
Definition JScale.hh:30
@ micro_t
micro
Definition JScale.hh:29
const char * getUnit(const int scale)
Get textual unit corresponding to scale.
Definition JScale.hh:59
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).