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  }
80  void set(const TString& rs)
81  {
82  clear();
83  KVString n(rs);
84  n.Begin(".");
85  while (!n.End()) {
86  if (!run())
87  set_run(n.Next().Atoi());
88  else {
89  auto ind = n.Next().Atoi();
90  if (ind > 0) set_index(ind);
91  }
92  }
93  }
96  {
97  TString s = Form("%d", run());
98  if (has_index()) s += "." + TString(Form("%d", index()));
99  return s;
100  }
103  {
104  if (has_index()) return Form("%d", index());
105  return "-";
106  }
107  friend std::ostream& operator<<(std::ostream& out, const run_index_t& rndx)
108  {
109  return out << rndx.as_string();
110  }
111 
119  friend bool operator<(const run_index_t& A, const run_index_t& B)
120  {
121  if (A.run() < B.run()) return true;
122  if (A.run() > B.run()) return false;
123  return A.index() < B.index();
124  }
128  friend bool operator==(const run_index_t& A, const run_index_t& B)
129  {
130  return (A.run() == B.run()) && (A.index() == B.index());
131  }
132 
134 };
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:128
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:95
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:107
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:80
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:102
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:119
const Int_t n
out