LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Level.h
Go to the documentation of this file.
1 #ifndef canvas_Utilities_Level_h
2 #define canvas_Utilities_Level_h
3 
4 #include <cassert>
5 #include <cstdint>
6 #include <ostream>
7 #include <type_traits>
8 
9 namespace art {
10 
11  // The outer-most level must be 0.
12  enum class Level {
13  Job = 0,
14  InputFile,
15  Run,
16  SubRun,
17  Event,
20  };
21 
22  // The following facility is to translate from the scoped enumerator
23  // to the value represented by the underlying type.
24  constexpr auto
25  underlying_value(Level const l) noexcept
26  {
27  return static_cast<std::underlying_type_t<Level>>(l);
28  }
29 
30  // Unfortunately, with C++14 we are not able to create a scoped
31  // enumerator via:
32  //
33  // Level l {2}; // l == Level::Run
34  //
35  // Such support will be available with C++17, but until then, we are
36  // forced to resort to static_cast's.
37 
38  constexpr auto
39  highest_level() noexcept
40  {
41  return static_cast<Level>(0);
42  }
43 
44  constexpr auto
45  level_up(Level const l) noexcept
46  {
47  return static_cast<Level>(underlying_value(l) - 1);
48  }
49 
50  constexpr auto
52  {
54  }
55 
56  constexpr auto
57  level_down(Level const l) noexcept
58  {
59  return static_cast<Level>(underlying_value(l) + 1);
60  }
61 
62  constexpr bool
64  {
66  }
67 
68  constexpr bool
70  {
71  return l == most_deeply_nested_level();
72  }
73 
74  constexpr bool
75  is_highest_level(Level const l) noexcept
76  {
77  return l == highest_level();
78  }
79 
80  constexpr bool
81  is_level_contained_by(Level const l1, Level const l2) noexcept
82  {
83  return underlying_value(l1) > underlying_value(l2);
84  }
85 
86  inline std::ostream&
87  operator<<(std::ostream& os, Level const l)
88  {
89  switch (l) {
90  case Level::Job:
91  os << "Job";
92  break;
93  case Level::InputFile:
94  os << "InputFile";
95  break;
96  case Level::Run:
97  os << "Run";
98  break;
99  case Level::SubRun:
100  os << "SubRun";
101  break;
102  case Level::Event:
103  os << "Event";
104  break;
107  break;
109  os << "ReadyToAdvance";
110  break;
111  }
112  return os;
113  }
114 }
115 
116 #endif /* canvas_Utilities_Level_h */
117 
118 // Local variables:
119 // mode: c++
120 // End:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
constexpr auto most_deeply_nested_level() noexcept
Definition: Level.h:51
constexpr auto underlying_value(Level const l) noexcept
Definition: Level.h:25
Level
Definition: Level.h:12
constexpr bool is_most_deeply_nested_level(Level const l) noexcept
Definition: Level.h:69
constexpr auto level_up(Level const l) noexcept
Definition: Level.h:45
constexpr bool is_above_most_deeply_nested_level(Level const l) noexcept
Definition: Level.h:63
constexpr bool is_level_contained_by(Level const l1, Level const l2) noexcept
Definition: Level.h:81
HLT enums.
constexpr auto highest_level() noexcept
Definition: Level.h:39
constexpr bool is_highest_level(Level const l) noexcept
Definition: Level.h:75
constexpr auto level_down(Level const l) noexcept
Definition: Level.h:57