KaliVeda
Toolkit for HIC analysis
run_index_list.cpp
1 #include "run_index_list.h"
2 #include "TMath.h"
3 
5 
6 
7 
10 void run_index_list::Add(const run_index_list& list)
11 {
12  // Add all in list to this list
13  for (auto& r : list) Add(r);
14 }
15 
16 
17 
20 
22 {
23  // Remove all in list to this list
24  for (auto& r : list) Remove(r);
25 }
26 
27 
28 
37 
38 TString run_index_list::GetList(bool no_commas) const
39 {
40  // Return list of [run.index] as formatted string:
41  //
42  // no_commas=true (default):
43  // "1 1.1 1.2 1.3 2 2.1" etc.
44  //
45  // no_commas=false:
46  // "1, 1.1, 1.2, 1.3, 2, 2.1" etc.
47  TString list;
48  bool first = true;
49  TString separator = (no_commas ? " " : ", ");
50  for (auto& r : fRunList) {
51  if (!first)
52  list += separator;
53  list += r.as_string();
54  first = false;
55  }
56  return list;
57 }
58 
59 
60 
67 
68 void run_index_list::SetList(const TString& slist)
69 {
70  // Set list from formatted string of [run.index]
71  // with or without commas:
72  //
73  // "1, 1.1, 1.2, 1.3, 2, 2.1"
74  // "1 1.1 1.2 1.3 2 2.1" etc.
75 
76  Clear();
77  KVString b(slist);
78  b.Begin(" ,");
79  while (!b.End()) {
80  auto n = b.Next(kTRUE);
81  Add(run_index_t(n));
82  }
83 }
84 
85 
86 
106 
107 void run_index_list::SetListSelection(const TString& slist, const run_index_list& full_list)
108 {
109  // \param slist a list of runfile names and/or run number ranges. Runfile names must contain '.',
110  // for the first file of a run use 'r.0'. Just 'r' represents the entire run, i.e. 'r.0', 'r.1', 'r.2', etc.
111  // \param full_list a list of all existing runfiles
112  //
113  // Examples of use:
114  //
115  // Suppose that full_list contains the runfile list {1, 1.1, 1.2, 2, 3, 3.1}
116  //~~~
117  // slist="1 2 3"
118  // slist="1,2,3"
119  // slist="1-3"
120  // slist="1,2-3"
121  // => fill list with {1, 1.1, 1.2, 2, 3, 3.1}
122  //
123  // slist="1.0,3"
124  // slist="1.0 3"
125  // => fill list with {1, 3, 3.1}
126  //~~~
127 
128  Clear();
129  KVNumberList runs_all_files;
130  KVString _list(slist);
131  _list.Begin(", ");
132  while (!_list.End()) {
133  KVString n = _list.Next();
134  if (n.Contains("-")) {
135  // KVNumberList format for run range
136  KVNumberList nl(n);
137  for (auto run : nl) {
138  runs_all_files.Add(run);
139  }
140  }
141  else if (!n.Contains(".")) {
142  runs_all_files.Add(n.Atoi());
143  }
144  else {
145  // individual runfile
146  n.ReplaceAll(".0", ".-1");
147  Add(run_index_t{n});
148  }
149  }
150  if (!runs_all_files.IsEmpty()) {
151  // now add all runfiles corresponding to runs in number lists
152  for (auto& run : full_list) {
153  if (runs_all_files.Contains(run.run()))
154  Add(run);
155  }
156  }
157 }
158 
159 
160 
170 
172 {
173  //Get string containing list.
174  //
175  //If maxlen>0, and if length of resulting string is longer than maxlen,
176  //we truncate the list to show only the beginning and the end of the list,
177  //with "..." in between, i.e. "6000-...-8910". Note that the minimum size of
178  //the resulting string is 5 i.e. "6...0".
179  //
180  //Returns empty string if list is empty.
181 
182  auto tmp = GetList();
183  if (maxlen) {
184  maxlen = TMath::Max(maxlen, 5);
185  if (tmp.Length() > maxlen) {
186  Int_t len_left = maxlen - 3; // 3 for "..."
187  Int_t len_start = len_left / 2;
188  Int_t len_end = len_left - len_start;
189  TString tmp2 = tmp(0, len_start);
190  tmp2 += "...";
191  tmp2 += tmp2(tmp2.Length() - len_end, tmp2.Length() - 1);
192  tmp = tmp2;
193  }
194  }
195  return tmp;
196 }
197 
198 
199 
203 
205 {
206  //keep the AND logic operation result between 'list' and this list
207  //i.e. keep only run_index_t which appear in both lists
208 
209  auto tmp = *this;
210  Clear();
211  for (auto& t : tmp) {
212  if (list.Contains(t)) Add(t);
213  }
214 }
215 
216 
217 
220 
222 {
223  // Returns just the list of run numbers
224  KVNumberList l;
225  for (auto& r : *this) l.Add(r.run());
226  return l;
227 }
228 
229 
int Int_t
ROOT::R::TRInterface & r
constexpr Bool_t kTRUE
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:86
Bool_t Contains(Int_t val) const
returns kTRUE if the value 'val' is contained in the ranges defined by the number list
void Add(Int_t)
Add value 'n' to the list.
Bool_t IsEmpty() const
Definition: KVNumberList.h:176
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
Ssiz_t Length() const
List of runfiles specified by run number and file index ,.
TString AsString(Int_t maxlen=0) const
void SetListSelection(const TString &slist, const run_index_list &full_list)
void Remove(const run_index_t &r)
void Inter(const run_index_list &)
void Add(const run_index_t &r)
TString GetList(bool no_commas=true) const
void SetList(const TString &slist)
KVNumberList GetRunNumberList() const
Returns just the list of run numbers.
bool Contains(const run_index_t &r) const
Specifies a runfile according to run number and file index ,.
Definition: run_index.h:31
const Int_t n
Add
Double_t Max(Double_t a, Double_t b)
TLine l
ClassImp(TPyArg)