KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVNumberList.h
Go to the documentation of this file.
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 
83 class KVNumberList : public TObject {
84 
85  mutable TString fString;
92  mutable Int_t fNValues;
93 
94  mutable TString fTMPSTR;
95 
98  mutable IntArray fValues;
100 
101  mutable Bool_t fIsParsed;
103 
104  void init_numberlist();
105  void clear();
106  void ParseList();
107  void AddLimits(Int_t min, Int_t max);
108  void AddLimits(TString& string);
109  void ParseAndFindLimits(const TString& string, const Char_t delim);
110 
111 public:
112 
113  KVNumberList();
114  KVNumberList(const KVNumberList&);
115  KVNumberList(const Char_t*);
117  KVNumberList(Int_t deb, Int_t fin, Int_t pas);
118 #ifdef WITH_CPP11
119  KVNumberList(std::initializer_list<int> L);
120 #endif
121  virtual ~KVNumberList()
122  {
123  }
124 
125  virtual void SetName(const char* name);
126  virtual const char* GetName() const
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;
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* = "");
160 
161  /* Intersection of two sets of numbers i.e. those which are in both lists */
162  void Inter(const KVNumberList& list);
163 
164  /* LIST PROPERTIES */
165  Bool_t Contains(Int_t val) const;
166  Int_t First() const;
167  Int_t Last() const;
168  Int_t GetNValues() const;
170  {
171  return GetNValues();
172  }
173  Bool_t IsEmpty() const
174  {
175  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
176  return (fNValues == 0);
177  }
178  Bool_t IsFull(Int_t vinf = -1, Int_t vsup = -1) const;
179 
180  /* LIST MEMBER ACCESS */
181  Int_t At(Int_t index) const;
182  Int_t operator[](Int_t index) const;
183  IntArray GetArray() const;
184  const Char_t* GetList() const;
185  const Char_t* GetExpandedList() const;
186  const Char_t* AsString(Int_t maxchars = 0) const;
187  const Char_t* AsQuotedString() const;
188  const Char_t* AsHumanReadableString() const;
189 
190  Int_t GetRandom() const;
191  Int_t GetRandomFast() const;
192  Bool_t PrepareRandomFast() const;
193 
194  /* LIST ITERATORS */
195  Int_t Next(void) const;
196  void Begin(void) const;
197  Bool_t End(void) const
198  {
199  return (fIterIndex == fEndList);
200  }
201  IntArrayIter begin() const;
202  IntArrayIter end() const;
203 
204  /* LIST ARITHMETIC OPERATIONS */
205  KVNumberList operator+(const KVNumberList&) const;
206  KVNumberList operator-(const KVNumberList&) const;
208  KVNumberList GetSubList(Int_t vinf, Int_t vsup) const;
209  TList* CutInSubList(Int_t number);
210  /* MISCELLANEOUS */
211  /* Generate TTree::Draw selection string */
212  TString GetLogical(const Char_t* observable) const;
213  TString GetSQL(const Char_t* column) const;
214  /* Convert to c-string */
215  operator const char* () const
216  {
217  return GetList();
218  }
219  /* Print list properties */
220  void Print(Option_t* = "") const;
221  void PrintLimits() const;
222  /* tests for equality */
223  bool operator==(const KVNumberList&) const;
224  bool operator!=(const KVNumberList&) const;
225 
226  ClassDef(KVNumberList, 4) //Strings used to represent a set of ranges of values
227 };
228 
229 #endif
int Int_t
std::vector< Int_t >::iterator IntArrayIter
Definition: KVNumberList.h:19
std::vector< Int_t >::const_iterator IntArrayCIter
Definition: KVNumberList.h:20
std::vector< Int_t > IntArray
Definition: KVNumberList.h:18
char Char_t
bool Bool_t
const char Option_t
#define ClassDef(name, id)
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:83
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)
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:88
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:101
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:197
void Remove(Int_t)
Remove value 'n' from the list.
IntArrayIter begin() const
IntArray fRandomFastArray
used by GetRandomFast()
Definition: KVNumberList.h:102
Int_t GetNValues() const
const Char_t * AsHumanReadableString() const
Int_t fFirstValue
smallest value included in list
Definition: KVNumberList.h:90
const Char_t * GetExpandedList() const
void Begin(void) const
virtual ~KVNumberList()
Definition: KVNumberList.h:121
KVNumberList operator-(const KVNumberList &) const
TString fTMPSTR
dummy string to compute AsString (non static)
Definition: KVNumberList.h:94
Bool_t IsFull(Int_t vinf=-1, Int_t vsup=-1) const
virtual const char * GetName() const
Definition: KVNumberList.h:126
TArrayI fUpperBounds
Definition: KVNumberList.h:87
TString fName
name of the list
Definition: KVNumberList.h:99
Int_t fMaxNLimits
size of arrays
Definition: KVNumberList.h:89
TString fString
Definition: KVNumberList.h:85
Int_t GetEntries() const
Definition: KVNumberList.h:169
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:97
void PrintLimits() const
void AddLimits(Int_t min, Int_t max)
IntArrayIter fIterIndex
used by Next() to iterate over list
Definition: KVNumberList.h:96
IntArray fValues
used by Next() to iterate over list
Definition: KVNumberList.h:98
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:133
void ParseAndFindLimits(const TString &string, const Char_t delim)
Int_t fLastValue
largest value included in list
Definition: KVNumberList.h:91
Bool_t IsEmpty() const
Definition: KVNumberList.h:173
Int_t GetRandom() const
IntArray GetArray() const
TArrayI fLowerBounds
Definition: KVNumberList.h:86
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:92
void init_numberlist()
Default initialisation used by ctors.
const char * Data() const
auto * l