KaliVeda
Toolkit for HIC analysis
|
Strings used to represent a set of ranges of values.
Handles lists of positive numbers such as "15-17 1-12 14"
or "345,356-390"
. Strings with this format can be handled and analysed by this class. They can also be iterated over. Note that the numbers in the initializing string do not have to be in ascending order, or indeed unique. The resulting KVNumberList will contain only the unique values in ascending order.
Create a new list with one of the constructors:
Change an existing list:
Get first and last values of ranges in list (i.e. largest and smallest included values)
Get a vector filled with all values corresponding to ranges defined in list:
val[0]
is same value as a.First()
. val[n-1]
is same value as a.Last()
.
Use AsString() or GetList() method to obtain list in its most compact form, using the "1-20, 51, 52-56" format.
IsEmpty() returns kTRUE if the list is empty ;-p
Initialise first by calling Begin(), then loop until End() returns kTRUE:
If list is empty, End() always returns kTRUE and Next() returns -1.
Methods begin() and end() return a std:iterator for the underlying std::vector<int>. This means (from C++11 onwards), range-based for loops can be used:
Definition at line 85 of file KVNumberList.h.
#include <KVNumberList.h>
Public Member Functions | |
KVNumberList () | |
Default constructor. | |
KVNumberList (const Char_t *) | |
KVNumberList (const KVNumberList &) | |
Copy constructor. | |
KVNumberList (Int_t deb, Int_t fin, Int_t pas) | |
KVNumberList (Int_t) | |
Initialise number list using single number. | |
KVNumberList (std::initializer_list< int > L) | |
Use an initializer list of integers to set up number list. | |
virtual | ~KVNumberList () |
void | Add (const IntArray &) |
Add all values in IntArray (=std::vector<int>) to the list. | |
void | Add (const KVNumberList &) |
Add values in 'list' to this list. | |
void | Add (Int_t) |
Add value 'n' to the list. | |
void | Add (Int_t, Int_t *) |
Add n values from array arr to the list. | |
const Char_t * | AsHumanReadableString () const |
const Char_t * | AsQuotedString () const |
const Char_t * | AsString (Int_t maxchars=0) const |
Int_t | At (Int_t index) const |
IntArrayIter | begin () const |
void | Begin (void) const |
void | Clear (Option_t *="") |
Empty number list, reset it to initial state. | |
Bool_t | Contains (Int_t val) const |
returns kTRUE if the value 'val' is contained in the ranges defined by the number list | |
void | Copy (TObject &) const |
Copy content of this number list into 'o'. | |
TList * | CutInSubList (Int_t number) |
IntArrayIter | end () const |
Bool_t | End (void) const |
Int_t | First () const |
Returns smallest number included in list. | |
IntArray | GetArray () const |
KVNumberList | GetComplementaryList () const |
Int_t | GetEntries () const |
const Char_t * | GetExpandedList () const |
const Char_t * | GetList () const |
TString | GetLogical (const Char_t *observable) const |
virtual const char * | GetName () const |
Int_t | GetNValues () const |
Int_t | GetRandom () const |
Int_t | GetRandomFast () const |
TString | GetSQL (const Char_t *column) const |
KVNumberList | GetSubList (Int_t vinf, Int_t vsup) const |
void | Inter (const KVNumberList &list) |
Bool_t | IsEmpty () const |
Bool_t | IsFull (Int_t vinf=-1, Int_t vsup=-1) const |
Int_t | Last () const |
Returns largest number included in list. | |
Int_t | Next (void) const |
operator const char * () const | |
bool | operator!= (const KVNumberList &) const |
Inequality test for number lists. | |
KVNumberList | operator+ (const KVNumberList &) const |
Return sum of this list and the other one. | |
KVNumberList | operator- (const KVNumberList &) const |
bool | operator== (const KVNumberList &) const |
Equality test for number lists. | |
Int_t | operator[] (Int_t index) const |
Bool_t | PrepareRandomFast () const |
void | Print (Option_t *="") const |
void | PrintLimits () const |
void | Remove (const Char_t *) |
Remove values in 'list' to this list. | |
void | Remove (const KVNumberList &) |
Remove values in 'list' from this list. | |
void | Remove (Int_t n, Int_t *arr) |
Remove n values from array arr to the list. | |
void | Remove (Int_t) |
Remove value 'n' from the list. | |
void | Set (const TString &l) |
void | Set (Int_t min, Int_t max, Int_t pas=1) |
void | SetList (const TString &) |
void | SetMinMax (Int_t min, Int_t max, Int_t pas=1) |
Set list with all values from 'min' to 'max'. | |
virtual void | SetName (const char *name) |
Public Member Functions inherited from TObject | |
TObject () | |
TObject (const TObject &object) | |
virtual | ~TObject () |
void | AbstractMethod (const char *method) const |
virtual void | AppendPad (Option_t *option="") |
virtual void | Browse (TBrowser *b) |
ULong_t | CheckedHash () |
virtual const char * | ClassName () const |
virtual TObject * | Clone (const char *newname="") const |
virtual Int_t | Compare (const TObject *obj) const |
virtual void | Delete (Option_t *option="") |
virtual Int_t | DistancetoPrimitive (Int_t px, Int_t py) |
virtual void | Draw (Option_t *option="") |
virtual void | DrawClass () const |
virtual TObject * | DrawClone (Option_t *option="") const |
virtual void | Dump () const |
virtual void | Error (const char *method, const char *msgfmt,...) const |
virtual void | Execute (const char *method, const char *params, Int_t *error=nullptr) |
virtual void | Execute (TMethod *method, TObjArray *params, Int_t *error=nullptr) |
virtual void | ExecuteEvent (Int_t event, Int_t px, Int_t py) |
virtual void | Fatal (const char *method, const char *msgfmt,...) const |
virtual TObject * | FindObject (const char *name) const |
virtual TObject * | FindObject (const TObject *obj) const |
virtual Option_t * | GetDrawOption () const |
virtual const char * | GetIconName () const |
virtual char * | GetObjectInfo (Int_t px, Int_t py) const |
virtual Option_t * | GetOption () const |
virtual const char * | GetTitle () const |
virtual UInt_t | GetUniqueID () const |
virtual Bool_t | HandleTimer (TTimer *timer) |
virtual ULong_t | Hash () const |
Bool_t | HasInconsistentHash () const |
virtual void | Info (const char *method, const char *msgfmt,...) const |
virtual Bool_t | InheritsFrom (const char *classname) const |
virtual Bool_t | InheritsFrom (const TClass *cl) const |
virtual void | Inspect () const |
void | InvertBit (UInt_t f) |
virtual TClass * | IsA () const |
Bool_t | IsDestructed () const |
virtual Bool_t | IsEqual (const TObject *obj) const |
virtual Bool_t | IsFolder () const |
R__ALWAYS_INLINE Bool_t | IsOnHeap () const |
virtual Bool_t | IsSortable () const |
R__ALWAYS_INLINE Bool_t | IsZombie () const |
virtual void | ls (Option_t *option="") const |
void | MayNotUse (const char *method) const |
virtual Bool_t | Notify () |
void | Obsolete (const char *method, const char *asOfVers, const char *removedFromVers) const |
void | operator delete (void *ptr) |
void | operator delete (void *ptr, void *vp) |
void | operator delete[] (void *ptr) |
void | operator delete[] (void *ptr, void *vp) |
void * | operator new (size_t sz) |
void * | operator new (size_t sz, void *vp) |
void * | operator new[] (size_t sz) |
void * | operator new[] (size_t sz, void *vp) |
TObject & | operator= (const TObject &rhs) |
virtual void | Paint (Option_t *option="") |
virtual void | Pop () |
virtual Int_t | Read (const char *name) |
virtual void | RecursiveRemove (TObject *obj) |
void | ResetBit (UInt_t f) |
virtual void | SaveAs (const char *filename="", Option_t *option="") const |
virtual void | SavePrimitive (std::ostream &out, Option_t *option="") |
void | SetBit (UInt_t f) |
void | SetBit (UInt_t f, Bool_t set) |
virtual void | SetDrawOption (Option_t *option="") |
virtual void | SetUniqueID (UInt_t uid) |
virtual void | Streamer (TBuffer &) |
void | StreamerNVirtual (TBuffer &ClassDef_StreamerNVirtual_b) |
virtual void | SysError (const char *method, const char *msgfmt,...) const |
R__ALWAYS_INLINE Bool_t | TestBit (UInt_t f) const |
Int_t | TestBits (UInt_t f) const |
virtual void | UseCurrentStyle () |
virtual void | Warning (const char *method, const char *msgfmt,...) const |
virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) |
virtual Int_t | Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) const |
Private Member Functions | |
void | AddLimits (Int_t min, Int_t max) |
void | AddLimits (TString &string) |
void | clear () |
private method called by ParseList() | |
void | init_numberlist () |
Default initialisation used by ctors. | |
void | ParseAndFindLimits (const TString &string, const Char_t delim) |
void | ParseList () |
Private Attributes | |
IntArrayIter | fEndList |
used by Next() & End() to iterate over list | |
Int_t | fFirstValue |
smallest value included in list | |
Bool_t | fIsParsed |
IntArrayIter | fIterIndex |
used by Next() to iterate over list | |
Int_t | fLastValue |
largest value included in list | |
TArrayI | fLowerBounds |
Int_t | fMaxNLimits |
size of arrays | |
TString | fName |
name of the list | |
Int_t | fNLimits |
number of limits in arrays | |
Int_t | fNValues |
total number of values included in ranges | |
IntArray | fRandomFastArray |
used by GetRandomFast() | |
TString | fString |
TString | fTMPSTR |
dummy string to compute AsString (non static) | |
TArrayI | fUpperBounds |
IntArray | fValues |
used by Next() to iterate over list | |
Additional Inherited Members | |
Public Types inherited from TObject | |
enum | EDeprecatedStatusBits |
enum | EStatusBits |
Static Public Member Functions inherited from TObject | |
static TClass * | Class () |
static const char * | Class_Name () |
static constexpr Version_t | Class_Version () |
static const char * | DeclFileName () |
static Longptr_t | GetDtorOnly () |
static Bool_t | GetObjectStat () |
static void | SetDtorOnly (void *obj) |
static void | SetObjectStat (Bool_t stat) |
Public Attributes inherited from TObject | |
kBitMask | |
kCanDelete | |
kCannotPick | |
kHasUUID | |
kInconsistent | |
kInvalidObject | |
kIsOnHeap | |
kIsReferenced | |
kMustCleanup | |
kNoContextMenu | |
kNotDeleted | |
kObjInCanvas | |
kOverwrite | |
kSingleKey | |
kWriteDelete | |
kZombie | |
Protected Member Functions inherited from TObject | |
virtual void | DoError (int level, const char *location, const char *fmt, va_list va) const |
void | MakeZombie () |
Protected Attributes inherited from TObject | |
kOnlyPrepStep | |
KVNumberList::KVNumberList | ( | ) |
Default constructor.
Definition at line 36 of file KVNumberList.cpp.
KVNumberList::KVNumberList | ( | const KVNumberList & | orig | ) |
Copy constructor.
Definition at line 48 of file KVNumberList.cpp.
KVNumberList::KVNumberList | ( | const Char_t * | list | ) |
Initialise number list using string and parse it to fill limits arrays Any number will only appear once.
Definition at line 62 of file KVNumberList.cpp.
KVNumberList::KVNumberList | ( | Int_t | x | ) |
Initialise number list using single number.
Definition at line 75 of file KVNumberList.cpp.
Initialise number list using numbers from deb to fin with a step=pas i.e. deb,deb+pas,deb+2*pas,...,fin
Definition at line 89 of file KVNumberList.cpp.
KVNumberList::KVNumberList | ( | std::initializer_list< int > | L | ) |
Use an initializer list of integers to set up number list.
Definition at line 103 of file KVNumberList.cpp.
|
inlinevirtual |
Definition at line 123 of file KVNumberList.h.
void KVNumberList::Add | ( | const IntArray & | v | ) |
Add all values in IntArray (=std::vector<int>) to the list.
Definition at line 526 of file KVNumberList.cpp.
void KVNumberList::Add | ( | const KVNumberList & | list | ) |
Add values in 'list' to this list.
Definition at line 464 of file KVNumberList.cpp.
Add value 'n' to the list.
Definition at line 436 of file KVNumberList.cpp.
Add n values from array arr to the list.
Definition at line 509 of file KVNumberList.cpp.
The numbers contained in the range [min,max] are added to the list.
Definition at line 240 of file KVNumberList.cpp.
'string' should contain something like "34-59" i.e. two integers separated by a '-'. these two numbers are taken for new lower and upper limits, fNLimits is increased by one, if necessary the arrays' size is increased.
Definition at line 218 of file KVNumberList.cpp.
const Char_t * KVNumberList::AsHumanReadableString | ( | ) | const |
Definition at line 1045 of file KVNumberList.cpp.
const Char_t * KVNumberList::AsQuotedString | ( | ) | const |
Get a string containing the compact representation of the list, enclosed by single quotes, i.e. if AsString() returns "1 3 5-7", this method will return "'1 3 5-7'"
Definition at line 1028 of file KVNumberList.cpp.
Get string containing list. This is most compact representation possible, i.e. all continuous ranges are represented as "minval-maxval". If maxlen>0, and if length of resulting string is longer than maxlen, we truncate the list to show only the beginning and the end of the list, with "..." in between, i.e. "6000-...-8910". Note that the minimum size of the resulting string is 5 i.e. "6...0". Returns empty string if list is empty.
Definition at line 995 of file KVNumberList.cpp.
Returns value of number in list at position 'index' (index = 0, 1, .., GetNValues()-1) We check that 'index' is neither too big nor too small (otherwise we return -1). WARNING: the list is first sorted into ascending order (and any duplicate entries are removed), so the index does not necessarily correspond to the order in which numbers are added to the list.
Definition at line 943 of file KVNumberList.cpp.
IntArrayIter KVNumberList::begin | ( | ) | const |
Returns a std::iterator over all unique values in the list, ordered from smallest to largest. Allows use in range-based for loops:
Definition at line 897 of file KVNumberList.cpp.
Call before using Next(). Resets iterator to beginning of list. If list is empty, End() always returns kTRUE and Next() returns -1.
Definition at line 873 of file KVNumberList.cpp.
|
private |
private method called by ParseList()
Definition at line 148 of file KVNumberList.cpp.
Empty number list, reset it to initial state.
Reimplemented from TObject.
Definition at line 136 of file KVNumberList.cpp.
returns kTRUE if the value 'val' is contained in the ranges defined by the number list
Definition at line 341 of file KVNumberList.cpp.
Copy content of this number list into 'o'.
Reimplemented from TObject.
Definition at line 799 of file KVNumberList.cpp.
Create sublist of KVNumberList with "number" values TList object has to be deleted after use by the user
Definition at line 1250 of file KVNumberList.cpp.
IntArrayIter KVNumberList::end | ( | ) | const |
Returns a std::iterator to element after end of list. Allows use in range-based for loops.
Definition at line 924 of file KVNumberList.cpp.
Definition at line 199 of file KVNumberList.h.
Int_t KVNumberList::First | ( | ) | const |
Returns smallest number included in list.
Definition at line 358 of file KVNumberList.cpp.
IntArray KVNumberList::GetArray | ( | ) | const |
Creates and fills a sorted array with all the unique values compatible with the ranges defined in the list. (Sorting is in increasing order).
Definition at line 386 of file KVNumberList.cpp.
KVNumberList KVNumberList::GetComplementaryList | ( | ) | const |
Return the complementary of the list ie for "123-127 129" it will be returned "128"
Definition at line 1171 of file KVNumberList.cpp.
|
inline |
Definition at line 171 of file KVNumberList.h.
const Char_t * KVNumberList::GetExpandedList | ( | ) | const |
Get string containing list. Every unique value contained in the list will be represented. Returns empty string if list is empty.
Definition at line 686 of file KVNumberList.cpp.
const Char_t * KVNumberList::GetList | ( | ) | const |
Get string containing list. This is most compact representation possible, i.e. all continuous ranges are represented as "minval-maxval" This string will become the new internal representation of the list. Returns empty string if list is empty.
Definition at line 629 of file KVNumberList.cpp.
Get logical expression of 'this' list in the TTree:Draw condition format observable is one of the leaf of the TTree 12-15 20 --> ( 12<=observable&&observable<=15 || observable==20 ) return "" if 'this' list is empty
Definition at line 724 of file KVNumberList.cpp.
|
inlinevirtual |
Reimplemented from TObject.
Definition at line 128 of file KVNumberList.h.
Int_t KVNumberList::GetNValues | ( | ) | const |
Returns total number of unique entries in list Note that this calls GetArray() just in order to remove any duplicate entries in the list and make sure fNValues is the number of unique entries.
Definition at line 815 of file KVNumberList.cpp.
Int_t KVNumberList::GetRandom | ( | ) | const |
Draw number at random from list
Warning: this method is slow as each time it is called the number list will be sorted.
For a more efficient method, see GetRandomFast().
Definition at line 1071 of file KVNumberList.cpp.
Int_t KVNumberList::GetRandomFast | ( | ) | const |
Draw number at random from list
Unlike GetRandom(), the list is not sorted every time the method is called. Rather, this must be done once by calling PrepareRandomFast() first before calling this method.
Check that PrepareRandomFast() returns kTRUE: if not, the list is empty and calling GetRandomFast() will lead to segmentation violation...
Definition at line 1093 of file KVNumberList.cpp.
Get equivalent for SQL 'WHERE' clause e.g. 12-15 20 --> column BETWEEN 12 AND 15 OR column=20 (column name will be correctly quoted in case it contains spaces) return "" if 'this' list is empty
Definition at line 762 of file KVNumberList.cpp.
KVNumberList KVNumberList::GetSubList | ( | Int_t | vinf, |
Int_t | vsup | ||
) | const |
Return the sublist of numbers between vinf and vsup i.e. put in the sublist val if vinf <= val <= vsup if vinf=-1, put no lower limit if vsup=-1, put no upper limit if vinf = vsup = -1, just clone the list i.e. "123-135 145-456",130,400 it will be returned "130-135 145-400"
Definition at line 1194 of file KVNumberList.cpp.
|
private |
Default initialisation used by ctors.
Definition at line 18 of file KVNumberList.cpp.
void KVNumberList::Inter | ( | const KVNumberList & | list | ) |
keep the AND logic operation result between 'list' and this list i.e. keep only numbers which appear in both lists
Definition at line 593 of file KVNumberList.cpp.
|
inline |
Definition at line 175 of file KVNumberList.h.
Return kTRUE if the list is in fact a continuous list of number ie "123-126" or "1,2,3,4" etc ... Use vinf et vsup if you want to test only a sub part of the list by default vinf=vsup=-1 and the whole list is considered in the test ie : for "123-127 129" it will be returned kFALSE for "123-127 129",-1,-1 it will be returned kFALSE for "123-127 129",123,127 it will be returned kTRUE for "123-127 129",-1,127 it will be returned kTRUE for "123-127 129",127,-1 it will be returned kFALSE
Definition at line 1141 of file KVNumberList.cpp.
Int_t KVNumberList::Last | ( | ) | const |
Returns largest number included in list.
Definition at line 371 of file KVNumberList.cpp.
Use this method to iterate over all numbers in the list Initialise first by calling Begin(), then loop until End() returns kTRUE:
KVNumberList r("1-10"); r.Begin(); while( !r.End() ){ Int_t next_val = r.Next(); ... } If list is empty, End() always returns kTRUE and Next() returns -1.
Definition at line 841 of file KVNumberList.cpp.
|
inline |
Definition at line 217 of file KVNumberList.h.
bool KVNumberList::operator!= | ( | const KVNumberList & | other | ) | const |
Inequality test for number lists.
Definition at line 313 of file KVNumberList.cpp.
KVNumberList KVNumberList::operator+ | ( | const KVNumberList & | other | ) | const |
Return sum of this list and the other one.
Definition at line 543 of file KVNumberList.cpp.
KVNumberList KVNumberList::operator- | ( | const KVNumberList & | other | ) | const |
Returns difference between 'this' and 'other' i.e. 'this' list with any values in 'other' removed
Definition at line 1224 of file KVNumberList.cpp.
bool KVNumberList::operator== | ( | const KVNumberList & | other | ) | const |
Equality test for number lists.
Definition at line 301 of file KVNumberList.cpp.
Returns value of number in list at position 'index' (index = 0, 1, .., GetNValues()-1) We check that 'index' is neither too big nor too small (otherwise we return -1). WARNING: the list is first sorted into ascending order (and any duplicate entries are removed), so the index does not necessarily correspond to the order in which numbers are added to the list.
Definition at line 972 of file KVNumberList.cpp.
Takes a string and breaks it up into its constituent parts, which were initially separated by white space or a comma. Any part which contains "-" will be sent to AddLimits().
Definition at line 186 of file KVNumberList.cpp.
|
private |
PRIVATE METHOD Breaks string containing list down and fills limits arrays accordingly
Definition at line 119 of file KVNumberList.cpp.
Bool_t KVNumberList::PrepareRandomFast | ( | ) | const |
Call once before using GetRandomFast() in order to generate random numbers from the list.
If this method returns kFALSE, do not use GetRandomFast() as the list is empty (seg fault will occur).
Definition at line 1114 of file KVNumberList.cpp.
Reimplemented from TObject.
Definition at line 1238 of file KVNumberList.cpp.
void KVNumberList::PrintLimits | ( | ) | const |
Print detailed break-down of list remove duplicate entries, correct fList, then re-parse
Definition at line 266 of file KVNumberList.cpp.
Remove values in 'list' to this list.
Definition at line 496 of file KVNumberList.cpp.
void KVNumberList::Remove | ( | const KVNumberList & | list | ) |
Remove values in 'list' from this list.
Definition at line 478 of file KVNumberList.cpp.
Remove n values from array arr to the list.
Definition at line 558 of file KVNumberList.cpp.
Remove value 'n' from the list.
Definition at line 450 of file KVNumberList.cpp.
Definition at line 135 of file KVNumberList.h.
Definition at line 139 of file KVNumberList.h.
Replace internal string representation of number list List will be parsed before any subsequent operations
Definition at line 327 of file KVNumberList.cpp.
Set list with all values from 'min' to 'max'.
Definition at line 575 of file KVNumberList.cpp.
|
virtual |
Change (i.e. set) the name of the KVNumberList. WARNING: if the object is a member of a THashTable or THashList container the container must be Rehash()'ed after SetName(). For example the list of objects in the current directory is a THashList.
Definition at line 169 of file KVNumberList.cpp.
|
mutableprivate |
used by Next() & End() to iterate over list
Definition at line 99 of file KVNumberList.h.
|
private |
smallest value included in list
Definition at line 92 of file KVNumberList.h.
|
mutableprivate |
Definition at line 103 of file KVNumberList.h.
|
mutableprivate |
used by Next() to iterate over list
Definition at line 98 of file KVNumberList.h.
|
private |
largest value included in list
Definition at line 93 of file KVNumberList.h.
|
private |
Definition at line 88 of file KVNumberList.h.
|
private |
size of arrays
Definition at line 91 of file KVNumberList.h.
|
private |
name of the list
Definition at line 101 of file KVNumberList.h.
|
private |
number of limits in arrays
Definition at line 90 of file KVNumberList.h.
|
mutableprivate |
total number of values included in ranges
Definition at line 94 of file KVNumberList.h.
|
mutableprivate |
used by GetRandomFast()
Definition at line 104 of file KVNumberList.h.
|
mutableprivate |
Definition at line 87 of file KVNumberList.h.
|
mutableprivate |
dummy string to compute AsString (non static)
Definition at line 96 of file KVNumberList.h.
|
private |
Definition at line 89 of file KVNumberList.h.
|
mutableprivate |
used by Next() to iterate over list
Definition at line 100 of file KVNumberList.h.