LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
PerScheduleContainer.h
Go to the documentation of this file.
1 #ifndef art_Utilities_PerScheduleContainer_h
2 #define art_Utilities_PerScheduleContainer_h
3 // vim: set sw=2 expandtab :
4 
8 
9 #include <utility>
10 #include <vector>
11 
12 namespace art {
13 
14  template <typename T>
16 
17  static_assert(ScheduleID::first().id() == 0);
18 
19  public:
20  PerScheduleContainer() = default;
22 
23  bool
24  is_valid() const
25  {
26  return !data_.empty();
27  }
28 
29  auto
30  size() const
31  {
32  return data_.size();
33  }
34 
35  auto
36  cbegin() const noexcept
37  {
38  return data_.cbegin();
39  }
40 
41  auto
42  begin() const noexcept
43  {
44  return data_.begin();
45  }
46 
47  auto
48  begin() noexcept
49  {
50  return data_.begin();
51  }
52 
53  auto
54  cend() const noexcept
55  {
56  return data_.cend();
57  }
58 
59  auto
60  end() const noexcept
61  {
62  return data_.end();
63  }
64 
65  auto
66  end() noexcept
67  {
68  return data_.end();
69  }
70 
71  // FIXME: Should remove once we replace this with a mappish thing.
72  void
74  {
75  data_.reserve(sz);
76  }
77 
78  // FIXME: Should replace emplace_back with emplace
79  template <typename... Args>
80  void
81  emplace_back(Args&&... args)
82  {
83  data_.emplace_back(std::forward<Args>(args)...);
84  }
85 
86  void
88  {
89  if (is_valid()) {
91  "An error occurred while calling "
92  "PerScheduleContainer::expand_to_num_schedules"}
93  << "Can only call resize when the container is invalid.\n";
94  }
95  data_.resize(sz);
96  }
97 
98  auto
100  {
101  if (is_valid()) {
103  "An error occurred while calling "
104  "PerScheduleContainer::expand_to_num_schedules"}
105  << "Can only call expand_to_num_schedules when the "
106  "container is invalid.";
107  }
108  auto const n = Globals::instance()->nschedules();
109  data_.resize(n);
110  return n;
111  }
112 
113  T&
115  {
116  return data_[sid.id()];
117  }
118 
119  T const&
120  operator[](ScheduleID const sid) const
121  {
122  return data_[sid.id()];
123  }
124 
125  T&
126  at(ScheduleID const sid)
127  {
128  return data_.at(sid.id());
129  }
130 
131  T const&
132  at(ScheduleID const sid) const
133  {
134  return data_.at(sid.id());
135  }
136 
137  private:
138  std::vector<T> data_;
139  };
140 
141 } // namespace art
142 
143 #endif /* art_Utilities_PerScheduleContainer_h */
144 
145 // Local Variables:
146 // mode: c++
147 // End:
T const & at(ScheduleID const sid) const
void emplace_back(Args &&...args)
static constexpr ScheduleID first()
Definition: ScheduleID.h:50
auto begin() const noexcept
T & at(ScheduleID const sid)
auto cbegin() const noexcept
ScheduleID::size_type nschedules() const
Definition: Globals.cc:24
T const & operator[](ScheduleID const sid) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr id_type id() const noexcept
Definition: ScheduleID.h:77
id_type size_type
Definition: ScheduleID.h:25
void reserve(ScheduleID::size_type const sz)
Definition: MVAAlg.h:12
auto end() const noexcept
Char_t n[5]
PerScheduleContainer(ScheduleID::size_type const n)
static Globals * instance()
Definition: Globals.cc:17
void resize(ScheduleID::size_type const sz)
auto cend() const noexcept
T & operator[](ScheduleID const sid)