1 #include "KVNumberList.h"
18 void KVNumberList::init_numberlist()
23 fFirstValue = 99999999;
24 fLastValue = -99999999;
108 for (
auto i :
L)
Add(i);
119 void KVNumberList::ParseList()
124 if (fIsParsed)
return;
126 ParseAndFindLimits(fString,
' ');
148 void KVNumberList::clear()
152 fLowerBounds.
Reset();
153 fUpperBounds.
Reset();
154 fFirstValue = 99999999;
155 fLastValue = -99999999;
186 void KVNumberList::ParseAndFindLimits(
const TString&
string,
const Char_t delim)
191 std::unique_ptr<TObjArray> toks1(
string.Tokenize(delim));
192 Int_t n_toks = toks1->GetEntries();
193 for (
int i = 0; i < n_toks; i++) {
197 ParseAndFindLimits(tok,
',');
199 ParseAndFindLimits(tok,
' ');
203 else if (kvtok.IsDigit()) {
204 Int_t val = kvtok.Atoi();
218 void KVNumberList::AddLimits(
TString&
string)
223 std::unique_ptr<TObjArray> toks1(
string.Tokenize(
'-'));
224 Int_t n_toks = toks1->GetEntries();
225 if (n_toks != 2)
return;
228 Int_t ilow = lower.Atoi();
229 Int_t iupp = upper.Atoi();
230 AddLimits(ilow, iupp);
240 void KVNumberList::AddLimits(
Int_t min,
Int_t max)
245 if (++fNLimits > fMaxNLimits) {
247 fLowerBounds.
Set(fMaxNLimits);
248 fUpperBounds.
Set(fMaxNLimits);
250 fLowerBounds[fNLimits - 1] =
min;
251 fUpperBounds[fNLimits - 1] =
max;
252 if (min < fFirstValue)
254 if (max > fLastValue)
256 fNValues += (
max -
min + 1);
275 std::cout <<
"KVNumberList::" <<
GetName() << std::endl;
276 std::cout <<
"There are " << fNLimits <<
" limits in the string : " <<
277 fString.
Data() << std::endl;
278 std::cout <<
"MIN = ";
279 for (
int i = 0; i < fNLimits; i++) {
280 std::cout <<
Form(
"%5d", fLowerBounds[i]);
281 if (i < fNLimits - 1)
284 std::cout << std::endl;
285 std::cout <<
"MAX = ";
286 for (
int i = 0; i < fNLimits; i++) {
287 std::cout <<
Form(
"%5d", fUpperBounds[i]);
288 if (i < fNLimits - 1)
291 std::cout << std::endl;
292 std::cout <<
"First value = " << fFirstValue <<
" Last value = " <<
293 fLastValue << std::endl;
317 return !((*this) == other);
346 auto tok = str.
Next();
348 bool add_dash =
false;
351 if(add_dash) new_list +=
"-";
352 auto dig = tok.Next().
Atoi()/div;
353 new_list +=
Form(
"%d",dig);
385 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
386 for (
int i = 0; i < fNLimits; i++) {
387 if (val >= fLowerBounds[i] && val <= fUpperBounds[i])
402 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
415 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
436 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
438 IntArray temp(fNValues);
440 for (
int i = 0; i < fNLimits; i++) {
443 for (
int j =
min; j <=
max; j++) {
450 IntArrayIter beg = temp.begin();
451 std::sort(beg, temp.end());
452 IntArrayIter
end = std::unique(beg, temp.end());
453 Int_t n_uniq = std::distance(beg,
end);
455 if (n_uniq < fNValues) {
460 fString.
Form(
"%d", (*(beg++)));
462 fString +=
Form(
" %d", (*(beg++)));
480 TString tmp = (fString !=
"" ? fString +
" " : fString);
508 TString tmp = (fString !=
"" ? fString +
" " : fString);
554 TString tmp = (fString !=
"" ? fString +
" " : fString);
555 for (
int i = 0; i <
n; i++) {
571 TString tmp = (fString !=
"" ? fString +
" " : fString);
572 for (IntArrayCIter it =
v.begin(); it !=
v.end(); ++it) {
603 for (
int i = 0; i <
n; i++) {
620 for (
int i =
min; i <=
max; i += pas) {
646 while (!tampon.
End()) {
677 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
682 return fString.
Data();
686 IntArrayIter it = arr.begin();
690 for (++it; it != arr.end(); ++it) {
694 if (val - * (it - 1) > 1) {
716 return fString.
Data();
733 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
740 return fString.
Data();
745 IntArrayIter it = arr.begin();
746 for (; it != arr.end() - 1; ++it) {
749 tmp +=
Form(
"%d ", val);
752 tmp +=
Form(
"%d", val);
776 std::unique_ptr<TObjArray> toks(tmp.
Tokenize(
"||"));
779 Int_t nt = toks->GetEntries();
780 for (
Int_t ii = 0; ii < nt; ii += 1) {
782 if (
line.Contains(
"-")) {
783 line.ReplaceAll(
"-",
Form(
"<=%s&&%s<=", observable, observable));
787 cond +=
Form(
"%s==", observable) +
line;
789 if (ii != nt - 1) cond +=
"||";
818 if (cond !=
"") cond +=
" OR ";
821 cond += (qcol +
" BETWEEN ");
828 cond += (qcol +
"=");
895 if (fValues.empty()) {
899 if (fIterIndex >= fEndList) {
900 KVError::Warning(
this,
"Next",
"Attempt to iterate beyond end of list. -1 returned.");
903 Int_t val = *(fIterIndex++);
920 fIterIndex = fValues.begin();
921 fEndList = fValues.end();
952 fIterIndex = fValues.begin();
953 fEndList = fValues.end();
997 catch (std::exception&
e) {
1049 if (fTMPSTR.
Length() > maxlen) {
1050 Int_t len_left = maxlen - 3;
1051 Int_t len_start = len_left / 2;
1052 Int_t len_end = len_left - len_start;
1053 TString tmp2 = fTMPSTR(0, len_start);
1055 tmp2 += fTMPSTR(fTMPSTR.
Length() - len_end, fTMPSTR.
Length() - 1);
1059 return fTMPSTR.
Data();
1079 return fTMPSTR.
Data();
1092 if (nws == 1) fTMPSTR = tmp;
1095 for (
int ii = 0; ii < nws - 1; ii++) fTMPSTR +=
Form(
"%s%s", tmp.
Next().
Data(), (ii == nws - 2) ?
"" :
", ");
1099 return fTMPSTR.
Data();
1162 assert((IntArray::size_type)fNValues == fRandomFastArray.size());
1163 return fRandomFastArray.size() > 0;
1196 if ((vinf == -1) && (vsup == -1)) {
1245 if (vinf > vsup)
return nl;
1246 if (vinf == -1) vinf =
First();
1247 if (vsup == -1) vsup =
Last();
1251 if (val >= vinf && val <= vsup) nl.
Add(val);
1252 else if (val > vsup)
return nl;
winID h TVirtualViewer3D vv
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Strings used to represent a set of ranges of values.
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
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
void Remove(Int_t)
Remove value 'n' from the list.
const char * GetName() const override
IntArrayIter begin() const
const Char_t * AsHumanReadableString() const
const Char_t * GetExpandedList() const
KVNumberList operator-(const KVNumberList &) const
Bool_t IsFull(Int_t vinf=-1, Int_t vsup=-1) const
void SetList(const TString &)
void Add(Int_t)
Add value 'n' to the list.
bool operator==(const KVNumberList &) const
Equality test for number lists.
void Print(Option_t *="") const override
IntArray GetArray() const
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.
TString GetLogical(const Char_t *observable) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
Int_t GetNValues(TString delim) const
void Set(Int_t n) override
virtual void SetOwner(Bool_t enable=kTRUE)
void Add(TObject *obj) override
virtual const char * ClassName() const
virtual UInt_t Integer(UInt_t imax)
const char * Data() const
TObjArray * Tokenize(const TString &delim) const
TString & Append(char c, Ssiz_t rep=1)
void Form(const char *fmt,...)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
void Warning(UserClass p, const char *location, const char *va_(fmt),...)
RooArgList L(Args_t &&... args)
double min(double x, double y)
double max(double x, double y)
Double_t Max(Double_t a, Double_t b)