KaliVeda
Toolkit for HIC analysis
KVNumberList.h
1 /*******************************************************************************
2 $Id: KVNumberList.h,v 1.20 2009/03/03 14:27:15 franklan Exp $
3 $Revision: 1.20 $
4 $Date: 2009/03/03 14:27:15 $
5 $Author: franklan $
6 *******************************************************************************/
7 
8 #ifndef __KVNUMBERLIST_H
9 #define __KVNUMBERLIST_H
10 
11 #include <optional>
12 #include <vector>
13 #include <TString.h>
14 #include <TArrayI.h>
15 #include <TObject.h>
16 #include <TList.h>
17 #include "KVConfig.h"
18 
19 typedef std::vector<Int_t> IntArray;
20 typedef std::vector<Int_t>::iterator IntArrayIter;
21 typedef std::vector<Int_t>::const_iterator IntArrayCIter;
22 
86 class KVNumberList : public TObject {
87 
88  mutable TString fString;
89  TArrayI fLowerBounds;
90  TArrayI fUpperBounds;
91  Int_t fNLimits;
92  Int_t fMaxNLimits;
93  Int_t fFirstValue;
94  Int_t fLastValue;
95  mutable Int_t fNValues;
96 
97  mutable TString fTMPSTR;
98 
99  mutable IntArrayIter fIterIndex;
100  mutable IntArrayIter fEndList;
101  mutable IntArray fValues;
102  TString fName;
103 
104  mutable Bool_t fIsParsed;
105  mutable IntArray fRandomFastArray;
106 
107  void init_numberlist();
108  void clear();
109  void ParseList();
110  void AddLimits(Int_t min, Int_t max);
111  void AddLimits(TString& string);
112  void ParseAndFindLimits(const TString& string, const Char_t delim);
113 
114 public:
115 
116  KVNumberList();
117  KVNumberList(const KVNumberList&);
118  KVNumberList(const Char_t*);
120  KVNumberList(Int_t deb, Int_t fin, Int_t pas);
121 #ifdef WITH_CPP11
122  KVNumberList(std::initializer_list<int> L);
123 #endif
124 
125  virtual void SetName(const char* name);
126  const char* GetName() const override
127  {
128  return fName.Data();
129  }
130 
131  /* LIST MODIFIERS */
132  /* Set the number list */
133  void Set(const TString& l)
134  {
135  SetList(l);
136  }
137  void Set(Int_t min, Int_t max, Int_t pas = 1)
138  {
139  SetMinMax(min, max, pas);
140  }
141  void SetList(const TString&);
142  void SetMinMax(Int_t min, Int_t max, Int_t pas = 1);
143  ROOT_COPY_ASSIGN_OP(KVNumberList)
144  void Copy(TObject&) const override;
145 
146  /* Add numbers/lists to the list */
147  void Add(Int_t);
148  void Add(const KVNumberList&);
149  void Add(Int_t, Int_t*);
150  void Add(const IntArray&);
151 
152  /* Remove numbers/lists from the list */
153  void Remove(Int_t);
154  void Remove(const Char_t*);
155  void Remove(const KVNumberList&);
156  void Remove(Int_t n, Int_t* arr);
157 
158  /* Clear the list */
159  void Clear(Option_t* = "") override;
160 
161  /* Intersection of two sets of numbers i.e. those which are in both lists */
162  void Inter(const KVNumberList& list);
164  {
166 
167  A.Inter(B);
168  return A;
169  }
170 
171  /* LIST PROPERTIES */
172  Bool_t Contains(Int_t val) const;
173  Int_t First() const;
174  Int_t Last() const;
175  Int_t GetNValues() const;
177  {
178  return GetNValues();
179  }
180  Bool_t IsEmpty() const
181  {
182  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
183  return (fNValues == 0);
184  }
185  Bool_t IsFull(Int_t vinf = -1, Int_t vsup = -1) const;
186  bool SubsetOf(const KVNumberList& otherlist) const;
187 
188 
189  /* LIST MEMBER ACCESS */
190  Int_t At(Int_t index) const;
191  Int_t operator[](Int_t index) const;
192  IntArray GetArray() const;
193  const Char_t* GetList() const;
194  const Char_t* GetExpandedList() const;
195  const Char_t* AsString(Int_t maxchars = 0) const;
196  const Char_t* AsQuotedString() const;
197  const Char_t* AsHumanReadableString() const;
198 
199  Int_t GetRandom() const;
200  Int_t GetRandomFast() const;
201  Bool_t PrepareRandomFast() const;
202 
203  /* LIST ITERATORS */
204  Int_t Next(void) const;
205  void Begin(void) const;
206  Bool_t End(void) const
207  {
208  return (fIterIndex == fEndList);
209  }
210  IntArrayIter begin() const;
211  IntArrayIter end() const;
212 
213  /* LIST ARITHMETIC OPERATIONS */
214  KVNumberList operator+(const KVNumberList&) const;
215  KVNumberList operator-(const KVNumberList&) const;
217  KVNumberList GetSubList(Int_t vinf, Int_t vsup) const;
218  TList* CutInSubList(Int_t number);
219  /* MISCELLANEOUS */
220  /* Generate TTree::Draw selection string */
221  TString GetLogical(const Char_t* observable) const;
222  TString GetSQL(const Char_t* column) const;
223  /* Convert to c-string */
224  operator const char* () const
225  {
226  return GetList();
227  }
228  /* Print list properties */
229  void Print(Option_t* = "") const override;
230  void PrintLimits() const;
231  /* tests for equality */
232  bool operator==(const KVNumberList&) const;
233  bool operator!=(const KVNumberList&) const;
234 
236 
237  std::optional<int> FindOffset(const KVNumberList& other);
238 
239  ClassDefOverride(KVNumberList, 4) //Strings used to represent a set of ranges of values
240 };
241 
242 #endif
int Int_t
bool Bool_t
char Char_t
const char Option_t
#define ClassDefOverride(name, id)
char name[80]
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:86
void Set(Int_t min, Int_t max, Int_t pas=1)
Definition: KVNumberList.h:137
TList * CutInSubList(Int_t number)
Int_t GetRandomFast() const
bool operator!=(const KVNumberList &) const
Inequality test for number lists.
void Inter(const KVNumberList &list)
virtual void SetName(const char *name)
const Char_t * AsQuotedString() const
void Copy(TObject &) const override
Copy content of this number list into 'o'.
const Char_t * GetList() const
IntArrayIter end() const
Bool_t Contains(Int_t val) const
returns kTRUE if the value 'val' is contained in the ranges defined by the number list
KVNumberList()
Default constructor.
Int_t First() const
Returns smallest number included in list.
void SetMinMax(Int_t min, Int_t max, Int_t pas=1)
Set list with all values from 'min' to 'max'.
KVNumberList GetListDividedBy(Int_t) const
KVNumberList operator+(const KVNumberList &) const
Return sum of this list and the other one.
void Clear(Option_t *="") override
Empty number list, reset it to initial state.
const Char_t * AsString(Int_t maxchars=0) const
Bool_t End(void) const
Definition: KVNumberList.h:206
void Remove(Int_t)
Remove value 'n' from the list.
const char * GetName() const override
Definition: KVNumberList.h:126
IntArrayIter begin() const
Int_t GetNValues() const
const Char_t * AsHumanReadableString() const
const Char_t * GetExpandedList() const
void Begin(void) const
KVNumberList operator-(const KVNumberList &) const
Bool_t IsFull(Int_t vinf=-1, Int_t vsup=-1) const
Int_t GetEntries() const
Definition: KVNumberList.h:176
void SetList(const TString &)
void Add(Int_t)
Add value 'n' to the list.
void PrintLimits() const
bool operator==(const KVNumberList &) const
Equality test for number lists.
void Set(const TString &l)
Definition: KVNumberList.h:133
void Print(Option_t *="") const override
Bool_t IsEmpty() const
Definition: KVNumberList.h:180
Int_t GetRandom() const
IntArray GetArray() const
TString GetSQL(const Char_t *column) const
std::optional< int > FindOffset(const KVNumberList &other)
Int_t At(Int_t index) const
Bool_t PrepareRandomFast() const
KVNumberList GetSubList(Int_t vinf, Int_t vsup) const
Int_t operator[](Int_t index) const
bool SubsetOf(const KVNumberList &otherlist) const
friend KVNumberList operator&&(KVNumberList A, const KVNumberList &B)
Definition: KVNumberList.h:163
KVNumberList GetComplementaryList() const
Int_t Last() const
Returns largest number included in list.
TString GetLogical(const Char_t *observable) const
Int_t Next(void) const
const char * Data() const
RooArgList L(Args_t &&... args)
double min(double x, double y)
double max(double x, double y)
TLine l