KaliVeda
Toolkit for HIC analysis
KVNumberList.cpp
1 #include "KVNumberList.h"
2 #include "KVString.h"
3 #include <TObjArray.h>
4 #include <TObjString.h>
5 #include <Riostream.h>
6 #include "KVError.h"
7 #include "TMath.h"
8 #include "TRandom.h"
9 
11 
12 //____________________________________________________________________________________________//
13 
14 
15 
18 void KVNumberList::init_numberlist()
19 {
20  //Default initialisation used by ctors
21  fMaxNLimits = 0;
22  fNLimits = 0;
23  fFirstValue = 99999999;
24  fLastValue = -99999999;
25  fNValues = 0;
26  fName = ClassName();
27  fIsParsed = kTRUE;
28 }
29 
30 
31 
32 
35 
37 {
38  //Default constructor
40 }
41 
42 
43 
44 
47 
49 {
50  //Copy constructor
52  orig.Copy(*this);
53 }
54 
55 
56 
57 
61 
62 KVNumberList::KVNumberList(const Char_t* list): fString(list)
63 {
64  //Initialise number list using string and parse it to fill limits arrays
65  //Any number will only appear once.
67  fIsParsed = kFALSE;
68 }
69 
70 
71 
74 
76 {
77  //Initialise number list using single number
78 
80  Add(x);
81 }
82 
83 
84 
88 
89 KVNumberList::KVNumberList(Int_t deb, Int_t fin, Int_t pas): fString()
90 {
91  //Initialise number list using numbers from deb to fin with a step=pas
92  //i.e. deb,deb+pas,deb+2*pas,...,fin
94  SetMinMax(deb, fin, pas);
95 }
96 
97 
98 #ifdef WITH_CPP11
99 
102 
103 KVNumberList::KVNumberList(std::initializer_list<int> L)
104 {
105  // Use an initializer list of integers to set up number list
106 
107  init_numberlist();
108  for (auto i : L) Add(i);
109 }
110 
111 #endif
112 
113 
114 
118 
120 {
121  //PRIVATE METHOD
122  //Breaks string containing list down and fills limits arrays accordingly
123 
124  if (fIsParsed) return;
125  clear();
127  fIsParsed = kTRUE;
128 }
129 
130 
131 
132 
135 
137 {
138  //Empty number list, reset it to initial state.
139  clear();
140  fString = "";
141 }
142 
143 
144 
147 
149 {
150  // private method called by ParseList()
151  fNLimits = 0;
154  fFirstValue = 99999999;
155  fLastValue = -99999999;
156  fNValues = 0;
157  fIsParsed = kTRUE;
158 }
159 
160 
161 
162 
168 
169 void KVNumberList::SetName(const char* name)
170 {
171  // Change (i.e. set) the name of the KVNumberList.
172  // WARNING: if the object is a member of a THashTable or THashList container
173  // the container must be Rehash()'ed after SetName(). For example the list
174  // of objects in the current directory is a THashList.
175  fName = name;
176 }
177 
178 
179 
180 
185 
186 void KVNumberList::ParseAndFindLimits(const TString& string, const Char_t delim)
187 {
188  //Takes a string and breaks it up into its constituent parts,
189  //which were initially separated by white space or a comma.
190  //Any part which contains "-" will be sent to AddLimits().
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++) {
194  TString tok = ((TObjString*)(*toks1)[i])->GetString();
195  KVString kvtok(tok);
196  if (tok.Contains(','))
197  ParseAndFindLimits(tok, ',');
198  else if (tok.Contains(' '))
199  ParseAndFindLimits(tok, ' ');
200  else if (tok.Contains('-')) {
201  AddLimits(tok);
202  }
203  else if (kvtok.IsDigit()) {
204  Int_t val = kvtok.Atoi();
205  AddLimits(val, val);
206  }
207  }
208 }
209 
210 
211 
212 
217 
219 {
220  //'string' should contain something like "34-59" i.e. two integers separated by a '-'.
221  //these two numbers are taken for new lower and upper limits, fNLimits is increased by one,
222  //if necessary the arrays' size is increased.
223  std::unique_ptr<TObjArray> toks1(string.Tokenize('-'));
224  Int_t n_toks = toks1->GetEntries();
225  if (n_toks != 2) return;
226  KVString lower(((TObjString*)(*toks1)[0])->GetString());
227  KVString upper(((TObjString*)(*toks1)[1])->GetString());
228  Int_t ilow = lower.Atoi();
229  Int_t iupp = upper.Atoi();
230  AddLimits(ilow, iupp);
231 }
232 
233 
234 
235 
239 
241 {
242  //The numbers contained in the range [min,max]
243  //are added to the list.
244 
245  if (++fNLimits > fMaxNLimits) {
246  fMaxNLimits += 10;
249  }
250  fLowerBounds[fNLimits - 1] = min;
251  fUpperBounds[fNLimits - 1] = max;
252  if (min < fFirstValue)
253  fFirstValue = min;
254  if (max > fLastValue)
255  fLastValue = max;
256  fNValues += (max - min + 1);
257 }
258 
259 
260 
261 
265 
267 {
268  //Print detailed break-down of list
269 
270  //remove duplicate entries, correct fList, then re-parse
271  GetList();
272  fIsParsed = kFALSE; // force re-parse
273  const_cast<KVNumberList*>(this)->ParseList();
274 
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)
282  std::cout << ",";
283  }
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)
289  std::cout << ",";
290  }
291  std::cout << std::endl;
292  std::cout << "First value = " << fFirstValue << " Last value = " <<
293  fLastValue << std::endl;
294 }
295 
296 
297 
300 
301 bool KVNumberList::operator==(const KVNumberList& other) const
302 {
303  // Equality test for number lists
304 
305  return (TString(GetList()) == TString(other.GetList()));
306 }
307 
308 
309 
312 
313 bool KVNumberList::operator!=(const KVNumberList& other) const
314 {
315  // Inequality test for number lists
316 
317  return !((*this) == other);
318 }
319 
320 
321 
330 
332 {
333  // Make a new list in which all values are divided by the factor 'div'.
334  //
335  // Note that this is integer division only!
336  //
337  // - if list is "1000-7999 16000-18999" GetDividedBy(1000) gives "1-7 16-18"
338  // - if list is "1-12" GetDividedBy(4) gives "0-3"
339  // - if list is "1-12" GetDividedBy(2) gives "0-6"
340 
341  KVString str = AsString();
342  str.Begin(", ");
343  KVString new_list;
344  while(!str.End())
345  {
346  auto tok = str.Next();
347  tok.Begin("-");
348  bool add_dash = false;
349  while(!tok.End())
350  {
351  if(add_dash) new_list +="-";
352  auto dig = tok.Next().Atoi()/div;
353  new_list += Form("%d",dig);
354  add_dash=true;
355  }
356  new_list += " ";
357  }
358  return KVNumberList(new_list);
359 }
360 
361 
362 
363 
367 
369 {
370  // Replace internal string representation of number list
371  // List will be parsed before any subsequent operations
372  fString = list;
373  fIsParsed = kFALSE;
374 }
375 
376 
377 
378 
381 
383 {
384  //returns kTRUE if the value 'val' is contained in the ranges defined by the number list
385  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
386  for (int i = 0; i < fNLimits; i++) {
387  if (val >= fLowerBounds[i] && val <= fUpperBounds[i])
388  return kTRUE;
389  }
390  return kFALSE;
391 }
392 
393 
394 
395 
398 
400 {
401  //Returns smallest number included in list
402  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
403  return fFirstValue;
404 }
405 
406 
407 
408 
411 
413 {
414  //Returns largest number included in list
415  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
416  return fLastValue;
417 }
418 
419 
420 
421 
426 
427 IntArray KVNumberList::GetArray() const
428 {
429  // Creates and fills a sorted array with all the unique
430  // values compatible with the ranges defined in the list.
431  // (Sorting is in increasing order).
432 
433  if (IsEmpty())
434  return IntArray();
435 
436  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
437 
438  IntArray temp(fNValues);
439  Int_t index = 0;
440  for (int i = 0; i < fNLimits; i++) {
441  Int_t min = fLowerBounds[i];
442  Int_t max = fUpperBounds[i];
443  for (int j = min; j <= max; j++) {
444  temp[index++] = j;
445  }
446  }
447  //now check for duplicate entries
448  //we sort the array in increasing order
449  //any duplicate entries will then be adjacent
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); //number of unique values
454 
455  if (n_uniq < fNValues) {
456  // duplicates were removed
457  // reduce the size of the vector
458  temp.resize(n_uniq);
459  // we reconstruct a string containing all unique values & reparse it
460  fString.Form("%d", (*(beg++)));
461  while (beg != end) {
462  fString += Form(" %d", (*(beg++)));
463  }
464  fNValues = n_uniq;
465  fIsParsed = kFALSE; // force re-parsing
466  const_cast<KVNumberList*>(this)->ParseList();
467  }
468  return temp;
469 }
470 
471 
472 
473 
476 
478 {
479  //Add value 'n' to the list
480  TString tmp = (fString != "" ? fString + " " : fString);
481  tmp += n;
482  SetList(tmp);
483 }
484 
485 
486 
487 
490 
492 {
493  //Remove value 'n' from the list
494  TString tmp = " " + TString(GetExpandedList()) + " ";
495  tmp.ReplaceAll(Form(" %d ", n), " ");
496  SetList(tmp);
497 }
498 
499 
500 
501 
504 
506 {
507  //Add values in 'list' to this list
508  TString tmp = (fString != "" ? fString + " " : fString);
509  tmp += list.fString;
510  SetList(tmp);
511 }
512 
513 
514 
515 
518 
520 {
521  //Remove values in 'list' from this list
522  TString tmp = " " + TString(GetExpandedList()) + " ";
523  KVNumberList tampon(list);
524  if (!tampon.IsEmpty()) {
525  tampon.Begin();
526  while (!tampon.End()) tmp.ReplaceAll(Form(" %d ", tampon.Next()), " ");
527  }
528  SetList(tmp);
529 }
530 
531 
532 
533 
536 
537 void KVNumberList::Remove(const Char_t* list)
538 {
539  //Remove values in 'list' to this list
540  KVNumberList tmp(list);
541  Remove(tmp);
542 }
543 
544 
545 
546 
549 
551 {
552  //Add n values from array arr to the list
553 
554  TString tmp = (fString != "" ? fString + " " : fString);
555  for (int i = 0; i < n; i++) {
556  tmp += arr[i];
557  tmp += " ";
558  }
559  SetList(tmp);
560 }
561 
562 
563 
566 
567 void KVNumberList::Add(const IntArray& v)
568 {
569  // Add all values in IntArray (=std::vector<int>) to the list
570 
571  TString tmp = (fString != "" ? fString + " " : fString);
572  for (IntArrayCIter it = v.begin(); it != v.end(); ++it) {
573  tmp += *it;
574  tmp += " ";
575  }
576  SetList(tmp);
577 }
578 
579 
580 
583 
585 {
586  // Return sum of this list and the other one
587 
588  KVNumberList tmp(*this);
589  tmp.Add(other);
590  return tmp;
591 }
592 
593 
594 
595 
598 
600 {
601  //Remove n values from array arr to the list
602  TString tmp = " ";
603  for (int i = 0; i < n; i++) {
604  tmp += arr[i];
605  tmp += " ";
606  }
607  Remove(tmp);
608 }
609 
610 
611 
612 
615 
617 {
618  //Set list with all values from 'min' to 'max'
619  TString tmp;
620  for (int i = min; i <= max; i += pas) {
621  tmp += i;
622  tmp += " ";
623  }
624  SetList(tmp);
625 }
626 
627 
628 
629 
633 
635 {
636  //keep the AND logic operation result between 'list' and this list
637  //i.e. keep only numbers which appear in both lists
638 
639  KVNumberList tampon(list);
640  if (tampon.IsEmpty() || IsEmpty()) {
641  SetList("");
642  }
643  else {
644  TString tmp = "";
645  tampon.Begin();
646  while (!tampon.End()) {
647  Int_t n = tampon.Next();
648  if (!Contains(n)) tmp += n;
649  tmp += " ";
650  }
651  Begin();
652  while (!End()) {
653  Int_t n = Next();
654  if (!tampon.Contains(n)) tmp += n;
655  tmp += " ";
656  }
657  Remove(tmp);
658  }
659 }
660 
661 
662 
663 
669 
671 {
672  //Get string containing list. This is most compact representation possible,
673  //i.e. all continuous ranges are represented as "minval-maxval"
674  //This string will become the new internal representation of the list.
675  //Returns empty string if list is empty.
676 
677  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
678 
679  //no numbers in list ?
680  if (!fNValues) {
681  fString = "";
682  return fString.Data();
683  }
684  //get array of all values
685  IntArray arr = GetArray();
686  IntArrayIter it = arr.begin();
687  Int_t min, max;
688  min = max = *it; //put min & max = smallest (first) value to start with
689  fString = "";
690  for (++it; it != arr.end(); ++it) {
691 
692  Int_t val = *it; // loop over values in increasing order
693 
694  if (val - * (it - 1) > 1) {
695  //cout << "end of continuous range ?" << endl;
696  if (min != max) {
697  fString += Form("%d-%d ", min, max);
698  }
699  else {
700  fString += Form("%d ", min);
701  }
702  min = max = val;
703  }
704  else {
705  //cout << "continuous range" << endl;
706  max = val;
707  }
708 
709  }
710  if (min != max) {
711  fString += Form("%d-%d", min, max);
712  }
713  else {
714  fString += Form("%d", min);
715  }
716  return fString.Data();
717 }
718 
719 
720 
721 
726 
728 {
729  // Get string containing list. Every unique value contained
730  // in the list will be represented.
731  // Returns empty string if list is empty.
732 
733  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
734 
735  static TString tmp = "";
736 
737  //no numbers in list ?
738  if (!fNValues) {
739  fString = "";
740  return fString.Data();
741  }
742  //get array of all values
743  IntArray arr = GetArray();
744  tmp = "";
745  IntArrayIter it = arr.begin();
746  for (; it != arr.end() - 1; ++it) {
747 
748  Int_t val = *it; // loop over values in increasing order
749  tmp += Form("%d ", val);
750  }
751  Int_t val = *it; //last value
752  tmp += Form("%d", val);
753  return tmp.Data();
754 }
755 
756 
757 
758 
764 
765 TString KVNumberList::GetLogical(const Char_t* observable) const
766 {
767  // Get logical expression of 'this' list in the TTree:Draw condition format
768  // observable is one of the leaf of the TTree
769  // 12-15 20 --> ( 12<=observable&&observable<=15 || observable==20 )
770  // return "" if 'this' list is empty
771 
772  if (IsEmpty()) return "";
773  GetList();
774  TString tmp = fString;
775  tmp.ReplaceAll(" ", "||");
776  std::unique_ptr<TObjArray> toks(tmp.Tokenize("||"));
777  static TString cond;
778  cond = "( ";
779  Int_t nt = toks->GetEntries();
780  for (Int_t ii = 0; ii < nt; ii += 1) {
781  TString line = ((TObjString*)(*toks)[ii])->GetString();
782  if (line.Contains("-")) {
783  line.ReplaceAll("-", Form("<=%s&&%s<=", observable, observable));
784  cond += line;
785  }
786  else {
787  cond += Form("%s==", observable) + line;
788  }
789  if (ii != nt - 1) cond += "||";
790  }
791  cond += " )";
792  return cond;
793 }
794 
795 
796 
802 
803 TString KVNumberList::GetSQL(const Char_t* column) const
804 {
805  // Get equivalent for SQL 'WHERE' clause
806  // e.g. 12-15 20 --> column BETWEEN 12 AND 15 OR column=20
807  // (column name will be correctly quoted in case it contains spaces)
808  // return "" if 'this' list is empty
809 
810  if (IsEmpty()) return "";
811  GetList();
812  TString qcol = Form("\"%s\"", column);
813  KVString tmp = fString;
814  static TString cond;
815  cond = "";
816  tmp.Begin(" ");
817  while (!tmp.End()) {
818  if (cond != "") cond += " OR ";
819  KVString tmp2 = tmp.Next();
820  if (tmp2.Contains("-")) {
821  cond += (qcol + " BETWEEN ");
822  tmp2.Begin("-");
823  cond += tmp2.Next();
824  cond += " AND ";
825  cond += tmp2.Next();
826  }
827  else {
828  cond += (qcol + "=");
829  cond += tmp2;
830  }
831  }
832  return cond;
833 }
834 
835 
836 
839 
841 {
842  // Copy content of this number list into 'o'
843 
844  ((KVNumberList&)o).Set(fString);
845 }
846 
847 
848 
849 
855 
857 {
858  // Returns total number of unique entries in list
859  // Note that this calls GetArray() just in order to remove
860  // any duplicate entries in the list and make sure fNValues
861  // is the number of unique entries.
862 
863  GetArray();//will remove any duplicates and correct fNValues
864  return fNValues;
865 }
866 
867 
868 
869 
881 
883 {
884  //Use this method to iterate over all numbers in the list
885  //Initialise first by calling Begin(), then loop until End() returns kTRUE:
886  //
887  // KVNumberList r("1-10");
888  // r.Begin();
889  // while( !r.End() ){
890  // Int_t next_val = r.Next();
891  // ...
892  // }
893  //If list is empty, End() always returns kTRUE and Next() returns -1.
894 
895  if (fValues.empty()) {
896  Warning("Next", "List is empty. -1 returned.");
897  return -1;
898  }
899  if (fIterIndex >= fEndList) {
900  Warning("Next", "Attempt to iterate beyond end of list. -1 returned.");
901  return -1;
902  }
903  Int_t val = *(fIterIndex++);
904  return val;
905 }
906 
907 
908 
909 
913 
915 {
916  // Call before using Next(). Resets iterator to beginning of list.
917  // If list is empty, End() always returns kTRUE and Next() returns -1.
918 
919  fValues = GetArray();
920  fIterIndex = fValues.begin();
921  fEndList = fValues.end();
922 }
923 
924 
925 
937 
938 IntArrayIter KVNumberList::begin() const
939 {
940  // Returns a std::iterator over all unique values in the list, ordered from smallest to largest.
941  // Allows use in range-based for loops:
942  //
943  //~~~~~~~~~{.cpp}
944  // KVNumberList pl("1-3,6");
945  // for(auto i : pl) cout << i << " ";
946  //
947  // //output:
948  // //1 2 3 6
949  //~~~~~~~~~
950 
951  fValues = GetArray();
952  fIterIndex = fValues.begin();
953  fEndList = fValues.end();
954  return fIterIndex;
955 }
956 
957 
958 
964 
965 IntArrayIter KVNumberList::end() const
966 {
967  // Returns a std::iterator to element after end of list.
968  // Allows use in range-based for loops.
969  //
970  // \sa begin()
971  return fEndList;
972 }
973 
974 
975 
976 
983 
985 {
986  // Returns value of number in list at position 'index' (index = 0, 1, .., GetNValues()-1)
987  // We check that 'index' is neither too big nor too small (otherwise we return -1).
988  // WARNING: the list is first sorted into ascending order (and any duplicate entries are
989  // removed), so the index does not necessarily correspond to the order in which numbers
990  // are added to the list.
991 
992  IntArray arr = GetArray();
993  Int_t n = -1;
994  try {
995  n = arr.at(index);
996  }
997  catch (std::exception& e) {
998  Warning(KV__ERROR(At), "Index out of bounds. -1 returned.");
999  }
1000  return n;
1001 }
1002 
1003 
1004 
1005 
1012 
1014 {
1015  // Returns value of number in list at position 'index' (index = 0, 1, .., GetNValues()-1)
1016  // We check that 'index' is neither too big nor too small (otherwise we return -1).
1017  // WARNING: the list is first sorted into ascending order (and any duplicate entries are
1018  // removed), so the index does not necessarily correspond to the order in which numbers
1019  // are added to the list.
1020 
1021  return At(index);
1022 }
1023 
1024 
1025 
1026 
1035 
1037 {
1038  //Get string containing list. This is most compact representation possible,
1039  //i.e. all continuous ranges are represented as "minval-maxval".
1040  //If maxlen>0, and if length of resulting string is longer than maxlen,
1041  //we truncate the list to show only the beginning and the end of the list,
1042  //with "..." in between, i.e. "6000-...-8910". Note that the minimum size of
1043  //the resulting string is 5 i.e. "6...0".
1044  //Returns empty string if list is empty.
1045 
1046  fTMPSTR = GetList();
1047  if (maxlen) {
1048  maxlen = TMath::Max(maxlen, 5);
1049  if (fTMPSTR.Length() > maxlen) {
1050  Int_t len_left = maxlen - 3; // 3 for "..."
1051  Int_t len_start = len_left / 2;
1052  Int_t len_end = len_left - len_start;
1053  TString tmp2 = fTMPSTR(0, len_start);
1054  tmp2 += "...";
1055  tmp2 += fTMPSTR(fTMPSTR.Length() - len_end, fTMPSTR.Length() - 1);
1056  fTMPSTR = tmp2;
1057  }
1058  }
1059  return fTMPSTR.Data();
1060 }
1061 
1062 
1063 
1068 
1070 {
1071  // Get a string containing the compact representation of the list, enclosed
1072  // by single quotes, i.e. if AsString() returns "1 3 5-7", this method will
1073  // return "'1 3 5-7'"
1074 
1075  KVString tmp = AsString();
1076  fTMPSTR = "'";
1077  fTMPSTR.Append(tmp);
1078  fTMPSTR.Append("'");
1079  return fTMPSTR.Data();
1080 }
1081 
1082 
1083 
1085 
1087 {
1088  KVString tmp = AsString();
1089  int nws = tmp.GetNValues(" ");
1090  fTMPSTR = "";
1091 
1092  if (nws == 1) fTMPSTR = tmp;
1093  else {
1094  tmp.Begin(" ");
1095  for (int ii = 0; ii < nws - 1; ii++) fTMPSTR += Form("%s%s", tmp.Next().Data(), (ii == nws - 2) ? "" : ", ");
1096  fTMPSTR += Form(" and %s", tmp.Next().Data());
1097  }
1098  fTMPSTR.ReplaceAll("-", " to ");
1099  return fTMPSTR.Data();
1100 }
1101 
1102 
1103 
1104 
1111 
1113 {
1114  // Draw number at random from list
1115  //
1116  // Warning: this method is slow as each time it is called the number list will be sorted.
1117  //
1118  // For a more efficient method, see GetRandomFast().
1119  return At(gRandom->Integer(GetEntries()));
1120 }
1121 
1122 
1123 
1133 
1135 {
1136  // Draw number at random from list
1137  //
1138  // Unlike GetRandom(), the list is not sorted every time the method is called.
1139  // Rather, this must be done once by calling PrepareRandomFast() first before calling
1140  // this method.
1141  //
1142  // Check that PrepareRandomFast() returns kTRUE: if not, the list is empty and
1143  // calling GetRandomFast() will lead to segmentation violation...
1145 }
1146 
1147 
1148 
1154 
1156 {
1157  // Call once before using GetRandomFast() in order to generate random numbers from the list.
1158  //
1159  // If this method returns kFALSE, do not use GetRandomFast() as the list is empty
1160  // (seg fault will occur).
1162  assert((IntArray::size_type)fNValues == fRandomFastArray.size());
1163  return fRandomFastArray.size() > 0;
1164 }
1165 
1166 
1167 
1168 
1181 
1183 {
1184  //Return kTRUE if the list is in fact a continuous list of number
1185  // ie "123-126" or "1,2,3,4" etc ...
1186  //Use vinf et vsup if you want to test only a sub part
1187  //of the list by default vinf=vsup=-1 and the whole list is considered
1188  //in the test
1189  // ie :
1190  // for "123-127 129" it will be returned kFALSE
1191  // for "123-127 129",-1,-1 it will be returned kFALSE
1192  // for "123-127 129",123,127 it will be returned kTRUE
1193  // for "123-127 129",-1,127 it will be returned kTRUE
1194  // for "123-127 129",127,-1 it will be returned kFALSE
1195 
1196  if ((vinf == -1) && (vsup == -1)) {
1197  Int_t total = Last() - First() + 1;
1198  return (total == GetNValues());
1199  }
1200  else {
1201  return GetSubList(vinf, vsup).IsFull();
1202  }
1203 }
1204 
1205 
1206 
1207 
1211 
1213 {
1214  //Return the complementary of the list
1215  // ie for "123-127 129" it will be returned "128"
1216 
1217  KVNumberList nl("");
1218  if (IsFull()) return nl;
1219  nl.SetMinMax(this->First(), this->Last());
1220  nl.Remove(*this);
1221  return nl;
1222 
1223 }
1224 
1225 
1226 
1234 
1236 {
1237  //Return the sublist of numbers between vinf and vsup
1238  // i.e. put in the sublist val if vinf <= val <= vsup
1239  // if vinf=-1, put no lower limit
1240  // if vsup=-1, put no upper limit
1241  // if vinf = vsup = -1, just clone the list
1242  // i.e. "123-135 145-456",130,400 it will be returned "130-135 145-400"
1243 
1244  KVNumberList nl("");
1245  if (vinf > vsup) return nl;
1246  if (vinf == -1) vinf = First();
1247  if (vsup == -1) vsup = Last();
1248  Begin();
1249  while (!End()) {
1250  Int_t val = Next();
1251  if (val >= vinf && val <= vsup) nl.Add(val);
1252  else if (val > vsup) return nl;
1253  }
1254  return nl;
1255 
1256 }
1257 
1258 
1259 
1260 
1264 
1266 {
1267  // Returns difference between 'this' and 'other'
1268  // i.e. 'this' list with any values in 'other' removed
1269  KVNumberList tmp(*this);
1270  tmp.Remove(other);
1271  return tmp;
1272 }
1273 
1274 
1275 
1276 
1278 
1280 {
1281  PrintLimits();
1282 }
1283 
1284 
1285 
1286 
1290 
1292 {
1293  //Create sublist of KVNumberList with "number" values
1294  //TList object has to be deleted after use by the user
1295  TList* list = new TList();
1296  list->SetOwner(kTRUE);
1297 
1298  KVNumberList* nl = 0;
1299  Begin();
1300  while (!End()) {
1301  Int_t vv = Next();
1302  if (!nl) {
1303  nl = new KVNumberList();
1304  list->Add(nl);
1305  }
1306  else if (nl->GetNValues() >= number) {
1307  nl = new KVNumberList();
1308  list->Add(nl);
1309  }
1310  nl->Add(vv);
1311  }
1312 
1313  return list;
1314 
1315 }
1316 
1317 
int Int_t
#define e(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
const char Option_t
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
char name[80]
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:85
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)
Int_t fNLimits
number of limits in arrays
Definition: KVNumberList.h:90
const Char_t * AsQuotedString() const
void Copy(TObject &) const override
Copy content of this number list into 'o'.
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'.
KVNumberList GetListDividedBy(Int_t) const
Bool_t fIsParsed
Definition: KVNumberList.h:103
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
Bool_t End(void) const
Definition: KVNumberList.h:199
void Remove(Int_t)
Remove value 'n' from the list.
const char * GetName() const override
Definition: KVNumberList.h:128
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
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
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
bool operator==(const KVNumberList &) const
Equality test for number lists.
void Print(Option_t *="") const override
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.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:73
void Begin(TString delim) const
Definition: KVString.cpp:565
Bool_t End() const
Definition: KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition: KVString.cpp:695
Int_t GetNValues(TString delim) const
Definition: KVString.cpp:886
void Set(Int_t n) override
void Reset()
virtual void SetOwner(Bool_t enable=kTRUE)
void Add(TObject *obj) override
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual UInt_t Integer(UInt_t imax)
Ssiz_t Length() const
Int_t Atoi() const
const char * Data() const
Bool_t IsDigit() 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)
TLine * line
RooCmdArg ClassName(const char *name)
Double_t x[n]
const Int_t n
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)
v
ClassImp(TPyArg)