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);
382 KVError::Warning(
this,
"FindOffset(const KVNumberList&)",
"Lists must have same size/length");
385 std::optional<int>
offset;
390 offset = other[i] - (*this)[i];
419 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
420 for (
int i = 0; i < fNLimits; i++) {
421 if (val >= fLowerBounds[i] && val <= fUpperBounds[i])
436 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
449 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
470 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
472 IntArray temp(fNValues);
474 for (
int i = 0; i < fNLimits; i++) {
477 for (
int j =
min; j <=
max; j++) {
484 IntArrayIter beg = temp.begin();
485 std::sort(beg, temp.end());
486 IntArrayIter
end = std::unique(beg, temp.end());
487 Int_t n_uniq = std::distance(beg,
end);
489 if (n_uniq < fNValues) {
494 fString.
Form(
"%d", (*(beg++)));
496 fString +=
Form(
" %d", (*(beg++)));
514 TString tmp = (fString !=
"" ? fString +
" " : fString);
542 TString tmp = (fString !=
"" ? fString +
" " : fString);
588 TString tmp = (fString !=
"" ? fString +
" " : fString);
589 for (
int i = 0; i <
n; i++) {
605 TString tmp = (fString !=
"" ? fString +
" " : fString);
606 for (IntArrayCIter it =
v.begin(); it !=
v.end(); ++it) {
637 for (
int i = 0; i <
n; i++) {
654 for (
int i =
min; i <=
max; i += pas) {
680 while (!tampon.
End()) {
711 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
716 return fString.
Data();
720 IntArrayIter it = arr.begin();
724 for (++it; it != arr.end(); ++it) {
728 if (val - * (it - 1) > 1) {
750 return fString.
Data();
767 if (!fIsParsed)
const_cast<KVNumberList*
>(
this)->ParseList();
774 return fString.
Data();
779 IntArrayIter it = arr.begin();
780 for (; it != arr.end() - 1; ++it) {
783 tmp +=
Form(
"%d ", val);
786 tmp +=
Form(
"%d", val);
810 std::unique_ptr<TObjArray> toks(tmp.
Tokenize(
"||"));
813 Int_t nt = toks->GetEntries();
814 for (
Int_t ii = 0; ii < nt; ii += 1) {
816 if (
line.Contains(
"-")) {
817 line.ReplaceAll(
"-",
Form(
"<=%s&&%s<=", observable, observable));
821 cond +=
Form(
"%s==", observable) +
line;
823 if (ii != nt - 1) cond +=
"||";
852 if (cond !=
"") cond +=
" OR ";
855 cond += (qcol +
" BETWEEN ");
862 cond += (qcol +
"=");
929 if (fValues.empty()) {
933 if (fIterIndex >= fEndList) {
934 KVError::Warning(
this,
"Next",
"Attempt to iterate beyond end of list. -1 returned.");
937 Int_t val = *(fIterIndex++);
954 fIterIndex = fValues.begin();
955 fEndList = fValues.end();
986 fIterIndex = fValues.begin();
987 fEndList = fValues.end();
1031 catch (std::exception&
e) {
1083 if (fTMPSTR.
Length() > maxlen) {
1084 Int_t len_left = maxlen - 3;
1085 Int_t len_start = len_left / 2;
1086 Int_t len_end = len_left - len_start;
1087 TString tmp2 = fTMPSTR(0, len_start);
1089 tmp2 += fTMPSTR(fTMPSTR.
Length() - len_end, fTMPSTR.
Length() - 1);
1093 return fTMPSTR.
Data();
1113 return fTMPSTR.
Data();
1126 if (nws == 1) fTMPSTR = tmp;
1129 for (
int ii = 0; ii < nws - 1; ii++) fTMPSTR +=
Form(
"%s%s", tmp.
Next().
Data(), (ii == nws - 2) ?
"" :
", ");
1133 return fTMPSTR.
Data();
1196 assert((IntArray::size_type)fNValues == fRandomFastArray.size());
1197 return fRandomFastArray.size() > 0;
1230 if ((vinf == -1) && (vsup == -1)) {
1279 if (vinf > vsup)
return nl;
1280 if (vinf == -1) vinf =
First();
1281 if (vsup == -1) vsup =
Last();
1285 if (val >= vinf && val <= vsup) nl.
Add(val);
1286 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 Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
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
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
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)