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