All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WeakCurrentType.h
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Utilities/WeakCurrentType.h
3  * @brief A C++ type to describe the type of weak current.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date August 8, 2019
6  * @see `icarusalg/Utilities/WeakCurrentType.cxx`
7  */
8 
9 #ifndef ICARUSALG_UTILITIES_WEAKCURRENTTYPE_H
10 #define ICARUSALG_UTILITIES_WEAKCURRENTTYPE_H
11 
12 
13 // framework libraries
14 #include "cetlib_except/exception.h"
15 
16 // C/C++ standard library
17 #include <string>
18 
19 
20 // --- BEGIN -- Weak current types ---------------------------------------------
21 /**
22  * @defgroup ICARUS_WeakCurrentTypes Weak current types
23  *
24  * Data structures and constants to represent weak current types.
25  */
26 /// @{
27 
28 //------------------------------------------------------------------------------
29 namespace icarus { class WeakCurrentType; }
30 /**
31  * @brief Represents a type of weak current.
32  *
33  * This type can be initialised with a string (see `parse()`) or a mnemonic
34  * value (`CurrentType`).
35  *
36  * Example of usage:
37  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
38  * icarus::WeakCurrentType const current { "neutral" };
39  *
40  * std::cout << "Current type: " << std::string(current) << std::endl;
41  * if (current == icarus::NeutralCurrentType) {
42  * std::cout << "Well, yeah." << std::endl;
43  * }
44  *
45  * // use WeakCurrentType::CurrentType in switch statements:
46  * std::string boson;
47  * switch (current) {
48  * case WeakCurrentType::CC: boson = "W"; break;
49  * case WeakCurrentType::NC: boson = "Z"; break;
50  * case WeakCurrentType::any: boson = "V"; break;
51  * } // switch
52  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53  */
55 
56  public:
57 
58  /// Type of weak current.
59  enum CurrentType {
60  CC, ///< Charged current.
61  NC, ///< Neutral current.
62  any ///< Any interaction.
63  }; // enum CurrentType
64 
65 
66  // --- BEGIN -- Constructors -------------------------------------------------
67 
68  /// Default constructor: matches any current type.
69  constexpr WeakCurrentType() = default;
70 
71  /// Constructor: assigns the specified current type.
72  constexpr WeakCurrentType(CurrentType type): fType(type) {}
73 
74  /// Constructor: assigns the value interpreting the specification `spec`.
75  /// @see `WeakCurrentType::parse()`
76  explicit WeakCurrentType(std::string const& spec)
77  : WeakCurrentType(parse(spec)) {}
78 
79  // --- END -- Constructors ---------------------------------------------------
80 
81 
82 
83  // --- BEGIN -- String operations --------------------------------------------
84  /// @name String operations
85  /// @{
86 
87  /// Returns a string with the name of the current (`"charged"`, `"neutral"`,
88  /// `"any"`).
89  std::string name() const;
90 
91  /// Returns a string with the short name of the current
92  /// (`"CC"`, `"NC"`, `"any"`).
93  std::string shortName() const;
94 
95  /// Converts to the `name()` of the current.
96  operator std::string() const { return name(); }
97 
98  /// @}
99  // --- END -- String operations ----------------------------------------------
100 
101 
102  // --- BEGIN -- Comparisons --------------------------------------------------
103  /// @name Comparisons
104  /// @{
105 
106  /// Returns whether this current type is the same as the `other`.
107  constexpr bool operator== (WeakCurrentType const& other) const
108  { return fType == other.fType; }
109 
110  /// Returns whether this current type is different than the `other`.
111  constexpr bool operator!= (WeakCurrentType const& other) const
112  { return fType != other.fType; }
113 
114  /// @}
115  // --- END -- Comparisons ----------------------------------------------------
116 
117 
118  // this allows using `switch` on `WeakCurrentType` objects
119  operator int() const { return static_cast<int>(fType); }
120 
121 
122  /**
123  * @brief Converts a string into a `WeakCurrentType`.
124  * @param spec the specification string to be converted
125  * @throws cet::exception (category `"WeakCurrentType"`) if `spec` is not
126  * supported
127  *
128  * The case of `spec` is irrelevant.
129  * Accepted values include the shortened name (`"CC"`; see `shortName()`),
130  * and the full name (`"charged"`; see `name()`).
131  * Also the empty string is converted to a `CurrentType` of `any`.
132  */
133  static CurrentType parse(std::string const& spec);
134 
135 
136  private:
137 
138  CurrentType fType = any; ///< Type of current stored.
139 
140  /// Returns a upper-case copy of `s`.
141  static std::string to_upper(std::string const& s);
142 
143 }; // class icarus::WeakCurrentType
144 
145 
146 //------------------------------------------------------------------------------
147 namespace icarus {
148 
149  /// Constant value for a weak neutral current type.
151 
152  /// Constant value for a weak charged current type.
154 
155  /// Constant value for any weak current type.
157 
158 } // namespace icarus
159 
160 
161 // --- END -- Weak current types -----------------------------------------------
162 /// @}
163 
164 //------------------------------------------------------------------------------
165 
166 
167 #endif // ICARUSALG_UTILITIES_WEAKCURRENTTYPE_H
WeakCurrentType(std::string const &spec)
constexpr WeakCurrentType NeutralCurrentType
Constant value for a weak neutral current type.
constexpr WeakCurrentType()=default
Default constructor: matches any current type.
Represents a type of weak current.
constexpr bool operator==(WeakCurrentType const &other) const
Returns whether this current type is the same as the other.
CurrentType fType
Type of current stored.
static CurrentType parse(std::string const &spec)
Converts a string into a WeakCurrentType.
std::string name() const
constexpr WeakCurrentType ChargedCurrentType
Constant value for a weak charged current type.
CurrentType
Type of weak current.
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
static std::string to_upper(std::string const &s)
Returns a upper-case copy of s.
std::string shortName() const
constexpr bool operator!=(WeakCurrentType const &other) const
Returns whether this current type is different than the other.
constexpr WeakCurrentType AnyWeakCurrentType
Constant value for any weak current type.
constexpr WeakCurrentType(CurrentType type)
Constructor: assigns the specified current type.