KaliVeda
Toolkit for HIC analysis
run_index.h
1 #pragma once
2 
3 #include "Rtypes.h"
4 #include <optional>
5 #include <iostream>
6 #include "KVString.h"
7 #include <set>
8 #include "KVNumberList.h"
9 
33 class run_index_t : public std::pair<int, std::optional<int>> {
34 public:
35  run_index_t(int run, std::optional<int> index)
36  : std::pair<int, std::optional<int>>(run, index)
37  {
38  if (index.has_value() && index.value() == -1)
39  second = std::nullopt;
40  }
41  run_index_t() = default;
42  run_index_t(const run_index_t&) = default;
43  run_index_t(run_index_t&&) = default;
44  run_index_t& operator=(const run_index_t&) = default;
46  run_index_t(const TString &rs)
47  {
48  set(rs);
49  }
50 
52  int run() const
53  {
54  return first;
55  }
57  int index(int no_index = -1) const
58  {
59  return second.value_or(no_index);
60  }
61  bool has_index() const
62  {
63  return second.has_value();
64  }
65  void set_run(int r)
66  {
67  first = r;
68  }
69  void set_index(int i)
70  {
71  second = i;
72  }
73 
75  void clear()
76  {
77  first = 0;
78  second = std::nullopt;
79  }
81  void set(const TString& rs)
82  {
83  clear();
84  KVString n(rs);
85  n.Begin(".");
86  while (!n.End()) {
87  if (!run())
88  set_run(n.Next().Atoi());
89  else
90  set_index(n.Next().Atoi());
91  }
92  }
95  {
96  TString s = Form("%d", run());
97  if (has_index()) s += "." + TString(Form("%d", index()));
98  return s;
99  }
102  {
103  if (has_index()) return Form("%d", index());
104  return "-";
105  }
106  friend std::ostream& operator<<(std::ostream& out, const run_index_t& rndx)
107  {
108  return out << rndx.as_string();
109  }
110 
118  friend bool operator<(const run_index_t& A, const run_index_t& B)
119  {
120  if (A.run() < B.run()) return true;
121  if (A.run() > B.run()) return false;
122  return A.index() < B.index();
123  }
127  friend bool operator==(const run_index_t& A, const run_index_t& B)
128  {
129  return (A.run() == B.run()) && (A.index() == B.index());
130  }
131 
133 };
134 
158 class run_index_list {
159  std::set<run_index_t> fRunList;
160 public:
161  run_index_list(const TString& l)
162  {
163  SetList(l);
164  }
165  run_index_list() = default;
166  run_index_list(const run_index_list&) = default;
167  run_index_list(run_index_list&&) = default;
168  run_index_list& operator=(const run_index_list&) = default;
169  run_index_list& operator=(run_index_list&&) = default;
170 
171  auto begin() const
172  {
173  return std::begin(fRunList);
174  }
175  auto end() const
176  {
177  return std::end(fRunList);
178  }
179 
180  void Add(const run_index_t& r)
181  {
182  fRunList.insert(r);
183  }
184  void Add(const run_index_list&);
185  void Remove(const run_index_t& r)
186  {
187  fRunList.erase(r);
188  }
189  void Remove(const run_index_list&);
190 
191  bool Contains(const run_index_t& r) const
192  {
193  return fRunList.count(r) > 0;
194  }
195  bool IsEmpty() const
196  {
197  return fRunList.empty();
198  }
199  TString GetList(bool no_commas=true) const;
200  void SetList(const TString& slist);
201  TString AsString(Int_t maxlen = 0) const;
202  Int_t GetNValues() const
203  {
204  return fRunList.size();
205  }
206  Int_t GetEntries() const
207  {
208  return GetNValues();
209  }
210  void Clear()
211  {
212  fRunList.clear();
213  }
214  void ls() const
215  {
216  std::cout << AsString() << std::endl;
217  }
218  void Inter(const run_index_list&);
219  KVNumberList GetRunNumberList() const;
220 
221  friend run_index_list operator-(const run_index_list& A, const run_index_list& B)
222  {
223  auto tmp = A;
224  tmp.Remove(B);
225  return tmp;
226  }
227 
228  friend run_index_list operator+(const run_index_list& A, const run_index_list& B)
229  {
230  auto tmp = A;
231  tmp.Add(B);
232  return tmp;
233  }
234 
235  const run_index_t& First() const
236  {
238  auto it = fRunList.cbegin();
239  return *it;
240  }
241  const run_index_t& Last() const
242  {
244  auto it = fRunList.crbegin();
245  return *it;
246  }
247 
248  ClassDef(run_index_list, 0)
249 };
int Int_t
ROOT::R::TRInterface & r
#define ClassDef(name, id)
Binding & operator=(OUT(*fun)(U0 u0))
char * Form(const char *fmt,...)
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:33
friend bool operator==(const run_index_t &A, const run_index_t &B)
Definition: run_index.h:127
void set_run(int r)
Definition: run_index.h:65
run_index_t()=default
run_index_t & operator=(run_index_t &&)=default
int run() const
Definition: run_index.h:52
TString as_string() const
Definition: run_index.h:94
int index(int no_index=-1) const
Definition: run_index.h:57
friend std::ostream & operator<<(std::ostream &out, const run_index_t &rndx)
Definition: run_index.h:106
run_index_t(int run, std::optional< int > index)
Definition: run_index.h:35
run_index_t(const TString &rs)
Definition: run_index.h:46
void set(const TString &rs)
Definition: run_index.h:81
run_index_t(const run_index_t &)=default
run_index_t(run_index_t &&)=default
void clear()
Definition: run_index.h:75
run_index_t & operator=(const run_index_t &)=default
bool has_index() const
Definition: run_index.h:61
TString index_string() const
Definition: run_index.h:101
void set_index(int i)
Definition: run_index.h:69
friend bool operator<(const run_index_t &A, const run_index_t &B)
Definition: run_index.h:118
Expr< BinaryOpCopyL< MinOp< T >, Constant< A >, SMatrix< T, D, D2, R >, T >, T, D, D2, R > operator-(const A &lhs, const SMatrix< T, D, D2, R > &rhs)
Expr< BinaryOpCopyL< AddOp< T >, Constant< A >, SMatrix< T, D, D2, R >, T >, T, D, D2, R > operator+(const A &lhs, const SMatrix< T, D, D2, R > &rhs)
const Int_t n
Add
out
end