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 <vector>
12 #include <TString.h>
13 #include <TArrayI.h>
14 #include <TObject.h>
15 #include <TList.h>
16 #include "KVConfig.h"
17 
18 typedef std::vector<Int_t> IntArray;
19 typedef std::vector<Int_t>::iterator IntArrayIter;
20 typedef std::vector<Int_t>::const_iterator IntArrayCIter;
21 
85 class KVNumberList : public TObject {
86 
87  mutable TString fString;
94  mutable Int_t fNValues;
95 
96  mutable TString fTMPSTR;
97 
98  mutable IntArrayIter fIterIndex;
99  mutable IntArrayIter fEndList;
100  mutable IntArray fValues;
102 
103  mutable Bool_t fIsParsed;
104  mutable IntArray fRandomFastArray;
105 
106  void init_numberlist();
107  void clear();
108  void ParseList();
109  void AddLimits(Int_t min, Int_t max);
110  void AddLimits(TString& string);
111  void ParseAndFindLimits(const TString& string, const Char_t delim);
112 
113 public:
114 
115  KVNumberList();
116  KVNumberList(const KVNumberList&);
117  KVNumberList(const Char_t*);
119  KVNumberList(Int_t deb, Int_t fin, Int_t pas);
120 #ifdef WITH_CPP11
121  KVNumberList(std::initializer_list<int> L);
122 #endif
123  virtual ~KVNumberList()
124  {
125  }
126 
127  virtual void SetName(const char* name);
128  virtual const char* GetName() const
129  {
130  return fName.Data();
131  }
132 
133  /* LIST MODIFIERS */
134  /* Set the number list */
135  void Set(const TString& l)
136  {
137  SetList(l);
138  }
139  void Set(Int_t min, Int_t max, Int_t pas = 1)
140  {
141  SetMinMax(min, max, pas);
142  }
143  void SetList(const TString&);
144  void SetMinMax(Int_t min, Int_t max, Int_t pas = 1);
145  ROOT_COPY_ASSIGN_OP(KVNumberList)
146  void Copy(TObject&) const;
147 
148  /* Add numbers/lists to the list */
149  void Add(Int_t);
150  void Add(const KVNumberList&);
151  void Add(Int_t, Int_t*);
152  void Add(const IntArray&);
153 
154  /* Remove numbers/lists from the list */
155  void Remove(Int_t);
156  void Remove(const Char_t*);
157  void Remove(const KVNumberList&);
158  void Remove(Int_t n, Int_t* arr);
159 
160  /* Clear the list */
161  void Clear(Option_t* = "");
162 
163  /* Intersection of two sets of numbers i.e. those which are in both lists */
164  void Inter(const KVNumberList& list);
165 
166  /* LIST PROPERTIES */
167  Bool_t Contains(Int_t val) const;
168  Int_t First() const;
169  Int_t Last() const;
170  Int_t GetNValues() const;
172  {
173  return GetNValues();
174  }
175  Bool_t IsEmpty() const
176  {
177  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
178  return (fNValues == 0);
179  }
180  Bool_t IsFull(Int_t vinf = -1, Int_t vsup = -1) const;
181 
182  /* LIST MEMBER ACCESS */
183  Int_t At(Int_t index) const;
184  Int_t operator[](Int_t index) const;
185  IntArray GetArray() const;
186  const Char_t* GetList() const;
187  const Char_t* GetExpandedList() const;
188  const Char_t* AsString(Int_t maxchars = 0) const;
189  const Char_t* AsQuotedString() const;
190  const Char_t* AsHumanReadableString() const;
191 
192  Int_t GetRandom() const;
193  Int_t GetRandomFast() const;
194  Bool_t PrepareRandomFast() const;
195 
196  /* LIST ITERATORS */
197  Int_t Next(void) const;
198  void Begin(void) const;
199  Bool_t End(void) const
200  {
201  return (fIterIndex == fEndList);
202  }
203  IntArrayIter begin() const;
204  IntArrayIter end() const;
205 
206  /* LIST ARITHMETIC OPERATIONS */
207  KVNumberList operator+(const KVNumberList&) const;
208  KVNumberList operator-(const KVNumberList&) const;
210  KVNumberList GetSubList(Int_t vinf, Int_t vsup) const;
211  TList* CutInSubList(Int_t number);
212  /* MISCELLANEOUS */
213  /* Generate TTree::Draw selection string */
214  TString GetLogical(const Char_t* observable) const;
215  TString GetSQL(const Char_t* column) const;
216  /* Convert to c-string */
217  operator const char* () const
218  {
219  return GetList();
220  }
221  /* Print list properties */
222  void Print(Option_t* = "") const;
223  void PrintLimits() const;
224  /* tests for equality */
225  bool operator==(const KVNumberList&) const;
226  bool operator!=(const KVNumberList&) const;
227 
228  ClassDef(KVNumberList, 4) //Strings used to represent a set of ranges of values
229 };
230 
231 #endif
int Int_t
bool Bool_t
char Char_t
const char Option_t
#define ClassDef(name, id)
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
void Set(Int_t min, Int_t max, Int_t pas=1)
Definition: KVNumberList.h:139
TList * CutInSubList(Int_t number)
Int_t GetRandomFast() const
bool operator!=(const KVNumberList &) const
Inequality test for number lists.
void Inter(const KVNumberList &list)
void Copy(TObject &) const
Copy content of this number list into 'o'.
virtual void SetName(const char *name)
Int_t fNLimits
number of limits in arrays
Definition: KVNumberList.h:90
const Char_t * AsQuotedString() const
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'.
void Print(Option_t *="") const
Bool_t fIsParsed
Definition: KVNumberList.h:103
KVNumberList operator+(const KVNumberList &) const
Return sum of this list and the other one.
const Char_t * AsString(Int_t maxchars=0) const
Bool_t End(void) const
Definition: KVNumberList.h:199
void Remove(Int_t)
Remove value 'n' from the list.
IntArrayIter begin() const
IntArray fRandomFastArray
used by GetRandomFast()
Definition: KVNumberList.h:104
Int_t GetNValues() const
const Char_t * AsHumanReadableString() const
Int_t fFirstValue
smallest value included in list
Definition: KVNumberList.h:92
const Char_t * GetExpandedList() const
void Begin(void) const
virtual ~KVNumberList()
Definition: KVNumberList.h:123
KVNumberList operator-(const KVNumberList &) const
TString fTMPSTR
dummy string to compute AsString (non static)
Definition: KVNumberList.h:96
Bool_t IsFull(Int_t vinf=-1, Int_t vsup=-1) const
virtual const char * GetName() const
Definition: KVNumberList.h:128
TArrayI fUpperBounds
Definition: KVNumberList.h:89
TString fName
name of the list
Definition: KVNumberList.h:101
Int_t fMaxNLimits
size of arrays
Definition: KVNumberList.h:91
TString fString
Definition: KVNumberList.h:87
Int_t GetEntries() const
Definition: KVNumberList.h:171
void SetList(const TString &)
void Add(Int_t)
Add value 'n' to the list.
IntArrayIter fEndList
used by Next() & End() to iterate over list
Definition: KVNumberList.h:99
void PrintLimits() const
void AddLimits(Int_t min, Int_t max)
IntArrayIter fIterIndex
used by Next() to iterate over list
Definition: KVNumberList.h:98
IntArray fValues
used by Next() to iterate over list
Definition: KVNumberList.h:100
void Clear(Option_t *="")
Empty number list, reset it to initial state.
bool operator==(const KVNumberList &) const
Equality test for number lists.
void Set(const TString &l)
Definition: KVNumberList.h:135
void ParseAndFindLimits(const TString &string, const Char_t delim)
Int_t fLastValue
largest value included in list
Definition: KVNumberList.h:93
Bool_t IsEmpty() const
Definition: KVNumberList.h:175
Int_t GetRandom() const
IntArray GetArray() const
TArrayI fLowerBounds
Definition: KVNumberList.h:88
TString GetSQL(const Char_t *column) const
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.
void clear()
private method called by ParseList()
TString GetLogical(const Char_t *observable) const
Int_t Next(void) const
Int_t fNValues
total number of values included in ranges
Definition: KVNumberList.h:94
void init_numberlist()
Default initialisation used by ctors.
const char * Data() const
Column in an SQLite database.
double min(double x, double y)
double max(double x, double y)
TLine l