All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WeakCurrentType.cxx
Go to the documentation of this file.
1 /**
2  * @file icarusalg/Utilities/WeakCurrentType.cxx
3  * @brief A C++ type to describe the type of weak current (implementation).
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date August 8, 2019
6  * @see `icarusalg/Utilities/WeakCurrentType.h`
7  */
8 
9 
10 // library header
12 
13 // C/C++ standard library
14 #include <algorithm> // std::transform()
15 #include <iterator> // std::back_inserter()
16 #include <stdexcept> // std::logic_error
17 #include <cctype>
18 
19 
20 //------------------------------------------------------------------------------
21 namespace {
22 
23  // ---------------------------------------------------------------------------
24  bool anyOf(std::string const& value, std::initializer_list<std::string> keys)
25  { return std::find(keys.begin(), keys.end(), value) != keys.end(); }
26 
27 
28  // ---------------------------------------------------------------------------
29 
30 } // local namespace
31 
32 
33 //------------------------------------------------------------------------------
34 std::string icarus::WeakCurrentType::name() const {
35 
36  switch (fType) {
37  case CC: return "charged";
38  case NC: return "neutral";
39  case any: return "any";
40  } // switch
41  throw std::logic_error("icarus::WeakCurrentType::name()");
42 } // icarus::WeakCurrentType::name()
43 
44 
45 //------------------------------------------------------------------------------
47 
48  switch (fType) {
49  case CC: return "CC";
50  case NC: return "NC";
51  case any: return "any";
52  } // switch
53  throw std::logic_error("icarus::WeakCurrentType::shortName()");
54 
55 } // icarus::WeakCurrentType::shortName()
56 
57 
58 //------------------------------------------------------------------------------
59 std::string icarus::WeakCurrentType::to_upper(std::string const& s) {
60 
61  std::string S;
62  S.reserve(s.size());
63 
64  auto char_toupper = [](unsigned char c){ return std::toupper(c); };
65  std::transform(s.begin(), s.end(), std::back_inserter(S), char_toupper);
66 
67  return S;
68 } // icarus::WeakCurrentType::to_upper()
69 
70 
71 //------------------------------------------------------------------------------
72 auto icarus::WeakCurrentType::parse(std::string const& spec) -> CurrentType {
73 
74  std::string const SPEC = to_upper(spec);
75 
76  if (anyOf(SPEC, { "CHARGED", "CC" })) return CC;
77  if (anyOf(SPEC, { "NEUTRAL", "NC" })) return NC;
78  if (anyOf(SPEC, { "", "ANY" })) return any;
79 
80  throw cet::exception("WeakCurrentType")
81  << "Invalid weak current specification: '" << spec << "'\n";
82 
83 } // icarus::WeakCurrentType::parse()
84 
85 
86 //------------------------------------------------------------------------------
see a below echo S(symbol in a section other than those above)
static constexpr Sample_t transform(Sample_t sample)
process_name showerreco Particles Coinciding wih the Vertex services ScanOptions nu_mu NC
CurrentType fType
Type of current stored.
static CurrentType parse(std::string const &spec)
Converts a string into a WeakCurrentType.
std::string name() const
A C++ type to describe the type of weak current.
process_name showerreco Particles Coinciding wih the Vertex services ScanOptions nu_mu CC
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
temporary value