KaliVeda
Toolkit for HIC analysis
run_index.cpp
1 #include "run_index.h"
2 #include "KVString.h"
3 
4 
7 
8 void run_index_list::Add(const run_index_list& list)
9 {
10  // Add all in list to this list
11  for (auto& r : list) Add(r);
12 }
13 
14 
15 
18 
19 void run_index_list::Remove(const run_index_list& list)
20 {
21  // Remove all in list to this list
22  for (auto& r : list) Remove(r);
23 }
24 
25 
26 
35 
36 TString run_index_list::GetList(bool no_commas) const
37 {
38  // Return list of [run.index] as formatted string:
39  //
40  // no_commas=true (default):
41  // "1 1.1 1.2 1.3 2 2.1" etc.
42  //
43  // no_commas=false:
44  // "1, 1.1, 1.2, 1.3, 2, 2.1" etc.
45  TString list;
46  bool first = true;
47  TString separator = (no_commas ? " " : ", ");
48  for (auto& r : fRunList) {
49  if (!first)
50  list += separator;
51  list += r.as_string();
52  first = false;
53  }
54  return list;
55 }
56 
57 
58 
65 
66 void run_index_list::SetList(const TString& slist)
67 {
68  // Set list from formatted string of [run.index]
69  // with or without commas:
70  //
71  // "1, 1.1, 1.2, 1.3, 2, 2.1"
72  // "1 1.1 1.2 1.3 2 2.1" etc.
73 
74  Clear();
75  KVString b(slist);
76  b.Begin(" ,");
77  while (!b.End()) {
78  auto n = b.Next(kTRUE);
79  Add(run_index_t(n));
80  }
81 }
82 
83 
84 
94 
95 TString run_index_list::AsString(Int_t maxlen) const
96 {
97  //Get string containing list.
98  //
99  //If maxlen>0, and if length of resulting string is longer than maxlen,
100  //we truncate the list to show only the beginning and the end of the list,
101  //with "..." in between, i.e. "6000-...-8910". Note that the minimum size of
102  //the resulting string is 5 i.e. "6...0".
103  //
104  //Returns empty string if list is empty.
105 
106  auto tmp = GetList();
107  if (maxlen) {
108  maxlen = TMath::Max(maxlen, 5);
109  if (tmp.Length() > maxlen) {
110  Int_t len_left = maxlen - 3; // 3 for "..."
111  Int_t len_start = len_left / 2;
112  Int_t len_end = len_left - len_start;
113  TString tmp2 = tmp(0, len_start);
114  tmp2 += "...";
115  tmp2 += tmp2(tmp2.Length() - len_end, tmp2.Length() - 1);
116  tmp = tmp2;
117  }
118  }
119  return tmp;
120 }
121 
122 
123 
127 
128 void run_index_list::Inter(const run_index_list& list)
129 {
130  //keep the AND logic operation result between 'list' and this list
131  //i.e. keep only run_index_t which appear in both lists
132 
133  auto tmp = *this;
134  Clear();
135  for (auto& t : tmp) {
136  if (list.Contains(t)) Add(t);
137  }
138 }
139 
140 
141 
144 
145 KVNumberList run_index_list::GetRunNumberList() const
146 {
147  // Returns just the list of run numbers
148  KVNumberList l;
149  for (auto& r : *this) l.Add(r.run());
150  return l;
151 }
152 
153 
155 ClassImp(run_index_list)
156 
int Int_t
ROOT::R::TRInterface & r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
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
Ssiz_t Length() const
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:33
const Int_t n
Add
Double_t Max(Double_t a, Double_t b)
TLine l
ClassImp(TPyArg)