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 
95 
96 TString run_index_list::AsString(Int_t maxlen) const
97 {
98  //Get string containing list.
99  //
100  //If maxlen>0, and if length of resulting string is longer than maxlen,
101  //we truncate the list to show only the beginning and the end of the list,
102  //with "..." in between, i.e. "6000-...-8910". Note that the minimum size of
103  //the resulting string is 5 i.e. "6...0".
104  //
105  //Returns empty string if list is empty.
106 
107  auto tmp = GetList();
108  if (maxlen) {
109  maxlen = TMath::Max(maxlen, 5);
110  if (tmp.Length() > maxlen) {
111  Int_t len_left = maxlen - 3; // 3 for "..."
112  Int_t len_start = len_left / 2;
113  Int_t len_end = len_left - len_start;
114  TString tmp2 = tmp(0, len_start);
115  tmp2 += "...";
116  tmp2 += tmp2(tmp2.Length() - len_end, tmp2.Length() - 1);
117  tmp = tmp2;
118  }
119  }
120  return tmp;
121 }
122 
123 
124 
128 
129 void run_index_list::Inter(const run_index_list& list)
130 {
131  //keep the AND logic operation result between 'list' and this list
132  //i.e. keep only run_index_t which appear in both lists
133 
134  auto tmp = *this;
135  Clear();
136  for (auto& t : tmp) {
137  if (list.Contains(t)) Add(t);
138  }
139 }
140 
141 
142 
145 
146 KVNumberList run_index_list::GetRunNumberList() const
147 {
148  // Returns just the list of run numbers
149  KVNumberList l;
150  for (auto& r : *this) l.Add(r.run());
151  return l;
152 }
153 
154 
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:31
const Int_t n
Add
Double_t Max(Double_t a, Double_t b)
TLine l
ClassImp(TPyArg)