LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
OutputFileGranularity.h
Go to the documentation of this file.
1 #ifndef art_Framework_Core_OutputFileGranularity_h
2 #define art_Framework_Core_OutputFileGranularity_h
3 
5 
6 #include <atomic>
7 #include <cstddef>
8 #include <stdexcept>
9 #include <string>
10 #include <type_traits>
11 
12 namespace art {
13  class Granularity {
14  public: // Types
15  enum BT { Event, SubRun, Run, InputFile, Job, Unset };
16 
17  public: // Static Api
18  static constexpr std::size_t
20  {
21  return Unset;
22  }
23  static BT
24  value(std::string const& spec)
25  {
26  if (spec == "Event") {
27  return Event;
28  } else if (spec == "SubRun") {
29  return SubRun;
30  } else if (spec == "Run") {
31  return Run;
32  } else if (spec == "InputFile") {
33  return InputFile;
34  } else if (spec == "Job") {
35  return Job;
36  } else if (spec == "Unset") {
37  return Unset;
38  } else {
40  << "Specified output-file switching boundary (\"" << spec
41  << "\") not supported.\n"
42  "Please choose from:\n"
43  " \"Event\"\n"
44  " \"SubRun\"\n"
45  " \"Run\"\n"
46  " \"InputFile\"\n"
47  " \"Job\"\n"
48  " \"Unset\"";
49  }
50  }
51 
52  public: // Special Member Functions
53  ~Granularity() noexcept {}
54  Granularity(BT const b) noexcept : b_{b} {}
55  Granularity(Granularity const& rhs) noexcept : b_{rhs.b_.load()} {}
56  Granularity(Granularity&& rhs) noexcept : b_{rhs.b_.load()} {}
58  operator=(Granularity const& rhs) noexcept
59  {
60  if (this != &rhs) {
61  b_ = rhs.b_.load();
62  }
63  return *this;
64  }
66  operator=(Granularity&& rhs) noexcept
67  {
68  b_ = rhs.b_.load();
69  return *this;
70  }
71 
72  public: // API
73  BT
74  operator()() const
75  {
76  return b_.load();
77  }
78  operator std::size_t() const { return static_cast<std::size_t>(b_.load()); }
79 
80  private: // Data Members
81  std::atomic<BT> b_;
82  };
83 
84  inline std::ostream&
85  operator<<(std::ostream& os, Granularity const& b)
86  {
87  std::string token{"Unset"};
88  switch (b()) {
89  case Granularity::Event:
90  token = "Event";
91  break;
93  token = "SubRun";
94  break;
95  case Granularity::Run:
96  token = "Run";
97  break;
99  token = "InputFile";
100  break;
101  case Granularity::Job:
102  token = "Job";
103  break;
104  case Granularity::Unset:;
105  }
106  os << token;
107  return os;
108  }
109 
110 } // namespace art
111 
112 #endif /* art_Framework_Core_OutputFileGranularity_h */
113 
114 // Local variables:
115 // mode: c++
116 // End:
Granularity & operator=(Granularity const &rhs) noexcept
static constexpr std::size_t NBoundaries()
Granularity & operator=(Granularity &&rhs) noexcept
Granularity(BT const b) noexcept
Granularity(Granularity &&rhs) noexcept
std::atomic< BT > b_
static BT value(std::string const &spec)
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Definition: MVAAlg.h:12
Granularity(Granularity const &rhs) noexcept