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 
31 class run_index_t : public std::pair<int, std::optional<int>> {
32 public:
33  run_index_t(int run, std::optional<int> index)
34  : std::pair<int, std::optional<int>>(run, index)
35  {
36  if (index.has_value() && index.value() == -1)
37  second = std::nullopt;
38  }
39  run_index_t() = default;
40  run_index_t(const run_index_t&) = default;
41  run_index_t(run_index_t&&) = default;
42  run_index_t& operator=(const run_index_t&) = default;
44  run_index_t(const TString &rs)
45  {
46  set(rs);
47  }
48 
50  int run() const
51  {
52  return first;
53  }
55  int index(int no_index = -1) const
56  {
57  return second.value_or(no_index);
58  }
59  bool has_index() const
60  {
61  return second.has_value();
62  }
63  void set_run(int r)
64  {
65  first = r;
66  }
67  void set_index(int i)
68  {
69  second = i;
70  }
71 
73  void clear()
74  {
75  first = 0;
76  second = std::nullopt;
77  }
79  void set(const TString& rs)
80  {
81  clear();
82  KVString n(rs);
83  n.Begin(".");
84  while (!n.End()) {
85  if (!run())
86  set_run(n.Next().Atoi());
87  else
88  set_index(n.Next().Atoi());
89  }
90  }
93  {
94  TString s = Form("%d", run());
95  if (has_index()) s += "." + TString(Form("%d", index()));
96  return s;
97  }
100  {
101  if (has_index()) return Form("%d", index());
102  return "-";
103  }
104  friend std::ostream& operator<<(std::ostream& out, const run_index_t& rndx)
105  {
106  return out << rndx.as_string();
107  }
108 
116  friend bool operator<(const run_index_t& A, const run_index_t& B)
117  {
118  if (A.run() < B.run()) return true;
119  if (A.run() > B.run()) return false;
120  return A.index() < B.index();
121  }
125  friend bool operator==(const run_index_t& A, const run_index_t& B)
126  {
127  return (A.run() == B.run()) && (A.index() == B.index());
128  }
129 
131 };
ROOT::R::TRInterface & r
#define ClassDef(name, id)
char * Form(const char *fmt,...)
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:31
friend bool operator==(const run_index_t &A, const run_index_t &B)
Definition: run_index.h:125
void set_run(int r)
Definition: run_index.h:63
run_index_t()=default
run_index_t & operator=(run_index_t &&)=default
int run() const
Definition: run_index.h:50
TString as_string() const
Definition: run_index.h:92
int index(int no_index=-1) const
Definition: run_index.h:55
friend std::ostream & operator<<(std::ostream &out, const run_index_t &rndx)
Definition: run_index.h:104
run_index_t(int run, std::optional< int > index)
Definition: run_index.h:33
run_index_t(const TString &rs)
Definition: run_index.h:44
void set(const TString &rs)
Definition: run_index.h:79
run_index_t(const run_index_t &)=default
run_index_t(run_index_t &&)=default
void clear()
Definition: run_index.h:73
run_index_t & operator=(const run_index_t &)=default
bool has_index() const
Definition: run_index.h:59
TString index_string() const
Definition: run_index.h:99
void set_index(int i)
Definition: run_index.h:67
friend bool operator<(const run_index_t &A, const run_index_t &B)
Definition: run_index.h:116
const Int_t n
out