Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooAbsCategoryLegacyIterator.h
Go to the documentation of this file.
1// Author: Stephan Hageboeck, CERN 3 Feb 2020
2
3/*****************************************************************************
4 * RooFit
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2019, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17#ifndef ROOABSCATEGORYLEGACYITERATOR_H_
18#define ROOABSCATEGORYLEGACYITERATOR_H_
19
20#include "TIterator.h"
21#include "RooAbsCategory.h"
22#include <map>
23#include <vector>
24#include <string>
25
27
28/// \deprecated Legacy class to iterate through legacy RooAbsCategory states.
29/// Use RooAbsCategory::begin(), RooAbsCategory::end() or range-based for loops instead.
30/// \ingroup Roofitlegacy
32 public:
33 RooAbsCategoryLegacyIterator(const std::map<std::string, RooAbsCategory::value_type>& stateNames) :
34 _origStateNames(&stateNames), index(-1) {
35 populate();
36 }
37
38 virtual const TCollection *GetCollection() const override { return nullptr; }
39
40 TObject* Next() override {
41 ++index;
42 return this->operator*();
43 }
44
45 void Reset() override { populate(); index = -1; }
46
47 TObject* operator*() const override {
48 if (! (0 <= index && index < (int)_origStateNames->size()) )
49 return nullptr;
50
51 return const_cast<RooCatType*>(&_legacyStates[index]);
52 }
53
55
56 TIterator& operator=(const TIterator&) override {
57 throw std::logic_error("Assigning from another iterator is not supported for the RooAbsCategoryLegacyIterator.");
58 }
59
60 private:
61 void populate() {
62 _legacyStates.clear();
63
64 for (const auto& item : *_origStateNames) {
65 _legacyStates.emplace_back(item.first.c_str(), item.second);
66 }
67 std::sort(_legacyStates.begin(), _legacyStates.end(), [](const RooCatType& left, const RooCatType& right){
68 return left.getVal() < right.getVal();
69 });
70 }
71
72 const std::map<std::string, RooAbsCategory::value_type>* _origStateNames;
73 std::vector<RooCatType> _legacyStates;
74 int index;
75};
76
77
78#endif /* ROOABSCATEGORYLEGACYITERATOR_H_ */
TObject * operator*() const override
Return current object or nullptr.
RooAbsCategoryLegacyIterator(const std::map< std::string, RooAbsCategory::value_type > &stateNames)
const std::map< std::string, RooAbsCategory::value_type > * _origStateNames
TIterator & operator=(const TIterator &) override
RooAbsCategoryLegacyIterator & operator=(const RooAbsCategoryLegacyIterator &)=default
virtual const TCollection * GetCollection() const override
RooCatType is an auxilary class for RooAbsCategory and defines a a single category state.
Collection abstract base class.
Definition TCollection.h:65
Iterator abstract base class.
Definition TIterator.h:30
Mother of all ROOT objects.
Definition TObject.h:41