KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVNumberList.cpp
Go to the documentation of this file.
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 
322 
326 
328 {
329  // Replace internal string representation of number list
330  // List will be parsed before any subsequent operations
331  fString = list;
332  fIsParsed = kFALSE;
333 }
334 
335 
336 
337 
340 
342 {
343  //returns kTRUE if the value 'val' is contained in the ranges defined by the number list
344  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
345  for (int i = 0; i < fNLimits; i++) {
346  if (val >= fLowerBounds[i] && val <= fUpperBounds[i])
347  return kTRUE;
348  }
349  return kFALSE;
350 }
351 
352 
353 
354 
357 
359 {
360  //Returns smallest number included in list
361  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
362  return fFirstValue;
363 }
364 
365 
366 
367 
370 
372 {
373  //Returns largest number included in list
374  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
375  return fLastValue;
376 }
377 
378 
379 
380 
385 
387 {
388  // Creates and fills a sorted array with all the unique
389  // values compatible with the ranges defined in the list.
390  // (Sorting is in increasing order).
391 
392  if (IsEmpty())
393  return IntArray();
394 
395  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
396 
397  IntArray temp(fNValues);
398  Int_t index = 0;
399  for (int i = 0; i < fNLimits; i++) {
400  Int_t min = fLowerBounds[i];
401  Int_t max = fUpperBounds[i];
402  for (int j = min; j <= max; j++) {
403  temp[index++] = j;
404  }
405  }
406  //now check for duplicate entries
407  //we sort the array in increasing order
408  //any duplicate entries will then be adjacent
409  IntArrayIter beg = temp.begin();
410  std::sort(beg, temp.end());
411  IntArrayIter end = std::unique(beg, temp.end());
412  Int_t n_uniq = std::distance(beg, end); //number of unique values
413 
414  if (n_uniq < fNValues) {
415  // duplicates were removed
416  // reduce the size of the vector
417  temp.resize(n_uniq);
418  // we reconstruct a string containing all unique values & reparse it
419  fString.Form("%d", (*(beg++)));
420  while (beg != end) {
421  fString += Form(" %d", (*(beg++)));
422  }
423  fNValues = n_uniq;
424  fIsParsed = kFALSE; // force re-parsing
425  const_cast<KVNumberList*>(this)->ParseList();
426  }
427  return temp;
428 }
429 
430 
431 
432 
435 
437 {
438  //Add value 'n' to the list
439  TString tmp = (fString != "" ? fString + " " : fString);
440  tmp += n;
441  SetList(tmp);
442 }
443 
444 
445 
446 
449 
451 {
452  //Remove value 'n' from the list
453  TString tmp = " " + TString(GetExpandedList()) + " ";
454  tmp.ReplaceAll(Form(" %d ", n), " ");
455  SetList(tmp);
456 }
457 
458 
459 
460 
463 
465 {
466  //Add values in 'list' to this list
467  TString tmp = (fString != "" ? fString + " " : fString);
468  tmp += list.fString;
469  SetList(tmp);
470 }
471 
472 
473 
474 
477 
479 {
480  //Remove values in 'list' from this list
481  TString tmp = " " + TString(GetExpandedList()) + " ";
482  KVNumberList tampon(list);
483  if (!tampon.IsEmpty()) {
484  tampon.Begin();
485  while (!tampon.End()) tmp.ReplaceAll(Form(" %d ", tampon.Next()), " ");
486  }
487  SetList(tmp);
488 }
489 
490 
491 
492 
495 
496 void KVNumberList::Remove(const Char_t* list)
497 {
498  //Remove values in 'list' to this list
499  KVNumberList tmp(list);
500  Remove(tmp);
501 }
502 
503 
504 
505 
508 
510 {
511  //Add n values from array arr to the list
512 
513  TString tmp = (fString != "" ? fString + " " : fString);
514  for (int i = 0; i < n; i++) {
515  tmp += arr[i];
516  tmp += " ";
517  }
518  SetList(tmp);
519 }
520 
521 
522 
525 
527 {
528  // Add all values in IntArray (=std::vector<int>) to the list
529 
530  TString tmp = (fString != "" ? fString + " " : fString);
531  for (IntArrayCIter it = v.begin(); it != v.end(); ++it) {
532  tmp += *it;
533  tmp += " ";
534  }
535  SetList(tmp);
536 }
537 
538 
539 
542 
544 {
545  // Return sum of this list and the other one
546 
547  KVNumberList tmp(*this);
548  tmp.Add(other);
549  return tmp;
550 }
551 
552 
553 
554 
557 
559 {
560  //Remove n values from array arr to the list
561  TString tmp = " ";
562  for (int i = 0; i < n; i++) {
563  tmp += arr[i];
564  tmp += " ";
565  }
566  Remove(tmp);
567 }
568 
569 
570 
571 
574 
576 {
577  //Set list with all values from 'min' to 'max'
578  TString tmp;
579  for (int i = min; i <= max; i += pas) {
580  tmp += i;
581  tmp += " ";
582  }
583  SetList(tmp);
584 }
585 
586 
587 
588 
592 
594 {
595  //keep the AND logic operation result between 'list' and this list
596  //i.e. keep only numbers which appear in both lists
597 
598  KVNumberList tampon(list);
599  if (tampon.IsEmpty() || IsEmpty()) {
600  SetList("");
601  }
602  else {
603  TString tmp = "";
604  tampon.Begin();
605  while (!tampon.End()) {
606  Int_t n = tampon.Next();
607  if (!Contains(n)) tmp += n;
608  tmp += " ";
609  }
610  Begin();
611  while (!End()) {
612  Int_t n = Next();
613  if (!tampon.Contains(n)) tmp += n;
614  tmp += " ";
615  }
616  Remove(tmp);
617  }
618 }
619 
620 
621 
622 
628 
630 {
631  //Get string containing list. This is most compact representation possible,
632  //i.e. all continuous ranges are represented as "minval-maxval"
633  //This string will become the new internal representation of the list.
634  //Returns empty string if list is empty.
635 
636  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
637 
638  //no numbers in list ?
639  if (!fNValues) {
640  fString = "";
641  return fString.Data();
642  }
643  //get array of all values
644  IntArray arr = GetArray();
645  IntArrayIter it = arr.begin();
646  Int_t min, max;
647  min = max = *it; //put min & max = smallest (first) value to start with
648  fString = "";
649  for (++it; it != arr.end(); ++it) {
650 
651  Int_t val = *it; // loop over values in increasing order
652 
653  if (val - * (it - 1) > 1) {
654  //cout << "end of continuous range ?" << endl;
655  if (min != max) {
656  fString += Form("%d-%d ", min, max);
657  }
658  else {
659  fString += Form("%d ", min);
660  }
661  min = max = val;
662  }
663  else {
664  //cout << "continuous range" << endl;
665  max = val;
666  }
667 
668  }
669  if (min != max) {
670  fString += Form("%d-%d", min, max);
671  }
672  else {
673  fString += Form("%d", min);
674  }
675  return fString.Data();
676 }
677 
678 
679 
680 
685 
687 {
688  // Get string containing list. Every unique value contained
689  // in the list will be represented.
690  // Returns empty string if list is empty.
691 
692  if (!fIsParsed) const_cast<KVNumberList*>(this)->ParseList();
693 
694  static TString tmp = "";
695 
696  //no numbers in list ?
697  if (!fNValues) {
698  fString = "";
699  return fString.Data();
700  }
701  //get array of all values
702  IntArray arr = GetArray();
703  tmp = "";
704  IntArrayIter it = arr.begin();
705  for (; it != arr.end() - 1; ++it) {
706 
707  Int_t val = *it; // loop over values in increasing order
708  tmp += Form("%d ", val);
709  }
710  Int_t val = *it; //last value
711  tmp += Form("%d", val);
712  return tmp.Data();
713 }
714 
715 
716 
717 
723 
724 TString KVNumberList::GetLogical(const Char_t* observable) const
725 {
726  // Get logical expression of 'this' list in the TTree:Draw condition format
727  // observable is one of the leaf of the TTree
728  // 12-15 20 --> ( 12<=observable&&observable<=15 || observable==20 )
729  // return "" if 'this' list is empty
730 
731  if (IsEmpty()) return "";
732  GetList();
733  TString tmp = fString;
734  tmp.ReplaceAll(" ", "||");
735  std::unique_ptr<TObjArray> toks(tmp.Tokenize("||"));
736  static TString cond;
737  cond = "( ";
738  Int_t nt = toks->GetEntries();
739  for (Int_t ii = 0; ii < nt; ii += 1) {
740  TString line = ((TObjString*)(*toks)[ii])->GetString();
741  if (line.Contains("-")) {
742  line.ReplaceAll("-", Form("<=%s&&%s<=", observable, observable));
743  cond += line;
744  }
745  else {
746  cond += Form("%s==", observable) + line;
747  }
748  if (ii != nt - 1) cond += "||";
749  }
750  cond += " )";
751  return cond;
752 }
753 
754 
755 
761 
762 TString KVNumberList::GetSQL(const Char_t* column) const
763 {
764  // Get equivalent for SQL 'WHERE' clause
765  // e.g. 12-15 20 --> column BETWEEN 12 AND 15 OR column=20
766  // (column name will be correctly quoted in case it contains spaces)
767  // return "" if 'this' list is empty
768 
769  if (IsEmpty()) return "";
770  GetList();
771  TString qcol = Form("\"%s\"", column);
772  KVString tmp = fString;
773  static TString cond;
774  cond = "";
775  tmp.Begin(" ");
776  while (!tmp.End()) {
777  if (cond != "") cond += " OR ";
778  KVString tmp2 = tmp.Next();
779  if (tmp2.Contains("-")) {
780  cond += (qcol + " BETWEEN ");
781  tmp2.Begin("-");
782  cond += tmp2.Next();
783  cond += " AND ";
784  cond += tmp2.Next();
785  }
786  else {
787  cond += (qcol + "=");
788  cond += tmp2;
789  }
790  }
791  return cond;
792 }
793 
794 
795 
798 
800 {
801  // Copy content of this number list into 'o'
802 
803  ((KVNumberList&)o).Set(fString);
804 }
805 
806 
807 
808 
814 
816 {
817  // Returns total number of unique entries in list
818  // Note that this calls GetArray() just in order to remove
819  // any duplicate entries in the list and make sure fNValues
820  // is the number of unique entries.
821 
822  GetArray();//will remove any duplicates and correct fNValues
823  return fNValues;
824 }
825 
826 
827 
828 
840 
842 {
843  //Use this method to iterate over all numbers in the list
844  //Initialise first by calling Begin(), then loop until End() returns kTRUE:
845  //
846  // KVNumberList r("1-10");
847  // r.Begin();
848  // while( !r.End() ){
849  // Int_t next_val = r.Next();
850  // ...
851  // }
852  //If list is empty, End() always returns kTRUE and Next() returns -1.
853 
854  if (fValues.empty()) {
855  Warning("Next", "List is empty. -1 returned.");
856  return -1;
857  }
858  if (fIterIndex >= fEndList) {
859  Warning("Next", "Attempt to iterate beyond end of list. -1 returned.");
860  return -1;
861  }
862  Int_t val = *(fIterIndex++);
863  return val;
864 }
865 
866 
867 
868 
872 
874 {
875  // Call before using Next(). Resets iterator to beginning of list.
876  // If list is empty, End() always returns kTRUE and Next() returns -1.
877 
878  fValues = GetArray();
879  fIterIndex = fValues.begin();
880  fEndList = fValues.end();
881 }
882 
883 
884 
896 
898 {
899  // Returns a std::iterator over all unique values in the list, ordered from smallest to largest.
900  // Allows use in range-based for loops:
901  //
902  //~~~~~~~~~{.cpp}
903  // KVNumberList pl("1-3,6");
904  // for(auto i : pl) cout << i << " ";
905  //
906  // //output:
907  // //1 2 3 6
908  //~~~~~~~~~
909 
910  fValues = GetArray();
911  fIterIndex = fValues.begin();
912  fEndList = fValues.end();
913  return fIterIndex;
914 }
915 
916 
917 
923 
925 {
926  // Returns a std::iterator to element after end of list.
927  // Allows use in range-based for loops.
928  //
929  // \sa begin()
930  return fEndList;
931 }
932 
933 
934 
935 
942 
944 {
945  // Returns value of number in list at position 'index' (index = 0, 1, .., GetNValues()-1)
946  // We check that 'index' is neither too big nor too small (otherwise we return -1).
947  // WARNING: the list is first sorted into ascending order (and any duplicate entries are
948  // removed), so the index does not necessarily correspond to the order in which numbers
949  // are added to the list.
950 
951  IntArray arr = GetArray();
952  Int_t n = -1;
953  try {
954  n = arr.at(index);
955  }
956  catch (std::exception& e) {
957  Warning(KV__ERROR(At), "Index out of bounds. -1 returned.");
958  }
959  return n;
960 }
961 
962 
963 
964 
971 
973 {
974  // Returns value of number in list at position 'index' (index = 0, 1, .., GetNValues()-1)
975  // We check that 'index' is neither too big nor too small (otherwise we return -1).
976  // WARNING: the list is first sorted into ascending order (and any duplicate entries are
977  // removed), so the index does not necessarily correspond to the order in which numbers
978  // are added to the list.
979 
980  return At(index);
981 }
982 
983 
984 
985 
994 
995 const Char_t* KVNumberList::AsString(Int_t maxlen) const
996 {
997  //Get string containing list. This is most compact representation possible,
998  //i.e. all continuous ranges are represented as "minval-maxval".
999  //If maxlen>0, and if length of resulting string is longer than maxlen,
1000  //we truncate the list to show only the beginning and the end of the list,
1001  //with "..." in between, i.e. "6000-...-8910". Note that the minimum size of
1002  //the resulting string is 5 i.e. "6...0".
1003  //Returns empty string if list is empty.
1004 
1005  fTMPSTR = GetList();
1006  if (maxlen) {
1007  maxlen = TMath::Max(maxlen, 5);
1008  if (fTMPSTR.Length() > maxlen) {
1009  Int_t len_left = maxlen - 3; // 3 for "..."
1010  Int_t len_start = len_left / 2;
1011  Int_t len_end = len_left - len_start;
1012  TString tmp2 = fTMPSTR(0, len_start);
1013  tmp2 += "...";
1014  tmp2 += fTMPSTR(fTMPSTR.Length() - len_end, fTMPSTR.Length() - 1);
1015  fTMPSTR = tmp2;
1016  }
1017  }
1018  return fTMPSTR.Data();
1019 }
1020 
1021 
1022 
1027 
1029 {
1030  // Get a string containing the compact representation of the list, enclosed
1031  // by single quotes, i.e. if AsString() returns "1 3 5-7", this method will
1032  // return "'1 3 5-7'"
1033 
1034  KVString tmp = AsString();
1035  fTMPSTR = "'";
1036  fTMPSTR.Append(tmp);
1037  fTMPSTR.Append("'");
1038  return fTMPSTR.Data();
1039 }
1040 
1041 
1042 
1044 
1046 {
1047  KVString tmp = AsString();
1048  int nws = tmp.GetNValues(" ");
1049  fTMPSTR = "";
1050 
1051  if (nws == 1) fTMPSTR = tmp;
1052  else {
1053  tmp.Begin(" ");
1054  for (int ii = 0; ii < nws - 1; ii++) fTMPSTR += Form("%s%s", tmp.Next().Data(), (ii == nws - 2) ? "" : ", ");
1055  fTMPSTR += Form(" and %s", tmp.Next().Data());
1056  }
1057  fTMPSTR.ReplaceAll("-", " to ");
1058  return fTMPSTR.Data();
1059 }
1060 
1061 
1062 
1063 
1070 
1072 {
1073  // Draw number at random from list
1074  //
1075  // Warning: this method is slow as each time it is called the number list will be sorted.
1076  //
1077  // For a more efficient method, see GetRandomFast().
1078  return At(gRandom->Integer(GetEntries()));
1079 }
1080 
1081 
1082 
1092 
1094 {
1095  // Draw number at random from list
1096  //
1097  // Unlike GetRandom(), the list is not sorted every time the method is called.
1098  // Rather, this must be done once by calling PrepareRandomFast() first before calling
1099  // this method.
1100  //
1101  // Check that PrepareRandomFast() returns kTRUE: if not, the list is empty and
1102  // calling GetRandomFast() will lead to segmentation violation...
1104 }
1105 
1106 
1107 
1113 
1115 {
1116  // Call once before using GetRandomFast() in order to generate random numbers from the list.
1117  //
1118  // If this method returns kFALSE, do not use GetRandomFast() as the list is empty
1119  // (seg fault will occur).
1121  assert((IntArray::size_type)fNValues == fRandomFastArray.size());
1122  return fRandomFastArray.size() > 0;
1123 }
1124 
1125 
1126 
1127 
1140 
1142 {
1143  //Return kTRUE if the list is in fact a continuous list of number
1144  // ie "123-126" or "1,2,3,4" etc ...
1145  //Use vinf et vsup if you want to test only a sub part
1146  //of the list by default vinf=vsup=-1 and the whole list is considered
1147  //in the test
1148  // ie :
1149  // for "123-127 129" it will be returned kFALSE
1150  // for "123-127 129",-1,-1 it will be returned kFALSE
1151  // for "123-127 129",123,127 it will be returned kTRUE
1152  // for "123-127 129",-1,127 it will be returned kTRUE
1153  // for "123-127 129",127,-1 it will be returned kFALSE
1154 
1155  if ((vinf == -1) && (vsup == -1)) {
1156  Int_t total = Last() - First() + 1;
1157  return (total == GetNValues());
1158  }
1159  else {
1160  return GetSubList(vinf, vsup).IsFull();
1161  }
1162 }
1163 
1164 
1165 
1166 
1170 
1172 {
1173  //Return the complementary of the list
1174  // ie for "123-127 129" it will be returned "128"
1175 
1176  KVNumberList nl("");
1177  if (IsFull()) return nl;
1178  nl.SetMinMax(this->First(), this->Last());
1179  nl.Remove(*this);
1180  return nl;
1181 
1182 }
1183 
1184 
1185 
1193 
1195 {
1196  //Return the sublist of numbers between vinf and vsup
1197  // i.e. put in the sublist val if vinf <= val <= vsup
1198  // if vinf=-1, put no lower limit
1199  // if vsup=-1, put no upper limit
1200  // if vinf = vsup = -1, just clone the list
1201  // i.e. "123-135 145-456",130,400 it will be returned "130-135 145-400"
1202 
1203  KVNumberList nl("");
1204  if (vinf > vsup) return nl;
1205  if (vinf == -1) vinf = First();
1206  if (vsup == -1) vsup = Last();
1207  Begin();
1208  while (!End()) {
1209  Int_t val = Next();
1210  if (val >= vinf && val <= vsup) nl.Add(val);
1211  else if (val > vsup) return nl;
1212  }
1213  return nl;
1214 
1215 }
1216 
1217 
1218 
1219 
1223 
1225 {
1226  // Returns difference between 'this' and 'other'
1227  // i.e. 'this' list with any values in 'other' removed
1228  KVNumberList tmp(*this);
1229  tmp.Remove(other);
1230  return tmp;
1231 }
1232 
1233 
1234 
1235 
1237 
1239 {
1240  PrintLimits();
1241 }
1242 
1243 
1244 
1245 
1249 
1251 {
1252  //Create sublist of KVNumberList with "number" values
1253  //TList object has to be deleted after use by the user
1254  TList* list = new TList();
1255  list->SetOwner(kTRUE);
1256 
1257  KVNumberList* nl = 0;
1258  Begin();
1259  while (!End()) {
1260  Int_t vv = Next();
1261  if (!nl) {
1262  nl = new KVNumberList();
1263  list->Add(nl);
1264  }
1265  else if (nl->GetNValues() >= number) {
1266  nl = new KVNumberList();
1267  list->Add(nl);
1268  }
1269  nl->Add(vv);
1270  }
1271 
1272  return list;
1273 
1274 }
1275 
1276 
int Int_t
Defines macros for standard error messages.
#define KV__ERROR(method)
Definition: KVError.h:30
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
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define e(i)
char Char_t
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
const char Option_t
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Strings used to represent a set of ranges of values.
Definition: KVNumberList.h:83
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
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 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.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
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)
void Reset()
virtual void SetOwner(Bool_t enable=kTRUE)
virtual void Add(TObject *obj)
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
Bool_t IsDigit() const
TObjArray * Tokenize(const TString &delim) const
TString & Append(char c, Ssiz_t rep=1)
const char * Data() const
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_t Max(Double_t a, Double_t b)
v