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  virtual ~KVNumberList()
125  {
126  }
127 
128  virtual void SetName(const char* name);
129  const char* GetName() const override
130  {
131  return fName.Data();
132  }
133 
134  /* LIST MODIFIERS */
135  /* Set the number list */
136  void Set(const TString& l)
137  {
138  SetList(l);
139  }
140  void Set(Int_t min, Int_t max, Int_t pas = 1)
141  {
142  SetMinMax(min, max, pas);
143  }
144  void SetList(const TString&);
145  void SetMinMax(Int_t min, Int_t max, Int_t pas = 1);
146  ROOT_COPY_ASSIGN_OP(KVNumberList)
147  void Copy(TObject&) const override;
148 
149  /* Add numbers/lists to the list */
150  void Add(Int_t);
151  void Add(const KVNumberList&);
152  void Add(Int_t, Int_t*);
153  void Add(const IntArray&);
154 
155  /* Remove numbers/lists from the list */
156  void Remove(Int_t);
157  void Remove(const Char_t*);
158  void Remove(const KVNumberList&);
159  void Remove(Int_t n, Int_t* arr);
160 
161  /* Clear the list */
162  void Clear(Option_t* = "") override;
163 
164  /* Intersection of two sets of numbers i.e. those which are in both lists */
165  void Inter(const KVNumberList& list);
166 
167  /* LIST PROPERTIES */
168  Bool_t Contains(Int_t val) const;
169  Int_t First() const;
170  Int_t Last() const;
171  Int_t GetNValues() const;
173  {
174  return GetNValues();
175  }
176  Bool_t IsEmpty() const
177  {
178  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
179  return (fNValues == 0);
180  }
181  Bool_t IsFull(Int_t vinf = -1, Int_t vsup = -1) const;
182 
183  /* LIST MEMBER ACCESS */
184  Int_t At(Int_t index) const;
185  Int_t operator[](Int_t index) const;
186  IntArray GetArray() const;
187  const Char_t* GetList() const;
188  const Char_t* GetExpandedList() const;
189  const Char_t* AsString(Int_t maxchars = 0) const;
190  const Char_t* AsQuotedString() const;
191  const Char_t* AsHumanReadableString() const;
192 
193  Int_t GetRandom() const;
194  Int_t GetRandomFast() const;
195  Bool_t PrepareRandomFast() const;
196 
197  /* LIST ITERATORS */
198  Int_t Next(void) const;
199  void Begin(void) const;
200  Bool_t End(void) const
201  {
202  return (fIterIndex == fEndList);
203  }
204  IntArrayIter begin() const;
205  IntArrayIter end() const;
206 
207  /* LIST ARITHMETIC OPERATIONS */
208  KVNumberList operator+(const KVNumberList&) const;
209  KVNumberList operator-(const KVNumberList&) const;
211  KVNumberList GetSubList(Int_t vinf, Int_t vsup) const;
212  TList* CutInSubList(Int_t number);
213  /* MISCELLANEOUS */
214  /* Generate TTree::Draw selection string */
215  TString GetLogical(const Char_t* observable) const;
216  TString GetSQL(const Char_t* column) const;
217  /* Convert to c-string */
218  operator const char* () const
219  {
220  return GetList();
221  }
222  /* Print list properties */
223  void Print(Option_t* = "") const override;
224  void PrintLimits() const;
225  /* tests for equality */
226  bool operator==(const KVNumberList&) const;
227  bool operator!=(const KVNumberList&) const;
228 
230 
231  std::optional<int> FindOffset(const KVNumberList& other);
232 
233  ClassDefOverride(KVNumberList, 4) //Strings used to represent a set of ranges of values
234 };
235 
236 #endif
int Int_t
bool Bool_t
char Char_t
const char Option_t
#define ClassDefOverride(name, id)
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:140
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:200
void Remove(Int_t)
Remove value 'n' from the list.
const char * GetName() const override
Definition: KVNumberList.h:129
IntArrayIter begin() const
Int_t GetNValues() const
const Char_t * AsHumanReadableString() const
const Char_t * GetExpandedList() const
void Begin(void) const
virtual ~KVNumberList()
Definition: KVNumberList.h:124
KVNumberList operator-(const KVNumberList &) const
Bool_t IsFull(Int_t vinf=-1, Int_t vsup=-1) const
Int_t GetEntries() const
Definition: KVNumberList.h:172
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:136
void Print(Option_t *="") const override
Bool_t IsEmpty() const
Definition: KVNumberList.h:176
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
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