Logo ROOT  
Reference Guide
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
25
26/// \deprecated Legacy class to iterate through legacy RooAbsCategory states.
27/// Use RooAbsCategory::begin(), RooAbsCategory::end() or range-based for loops instead.
28/// \ingroup Roofitlegacy
30 public:
31 RooAbsCategoryLegacyIterator(const std::map<std::string, RooAbsCategory::value_type>& stateNames) :
32 _origStateNames(&stateNames), index(-1) {
33 populate();
34 }
35
36 virtual const TCollection *GetCollection() const override { return nullptr; }
37
38 TObject* Next() override {
39 ++index;
40 return this->operator*();
41 }
42
43 void Reset() override { populate(); index = -1; }
44
45 TObject* operator*() const override {
46 if (! (0 <= index && index < (int)_origStateNames->size()) )
47 return nullptr;
48
49 return const_cast<RooCatType*>(&_legacyStates[index]);
50 }
51
53
54 TIterator& operator=(const TIterator&) override {
55 throw std::logic_error("Assigning from another iterator is not supported for the RooAbsCategoryLegacyIterator.");
56 }
57
58 private:
59 void populate() {
60 _legacyStates.clear();
61
62 for (const auto& item : *_origStateNames) {
63 _legacyStates.emplace_back(item.first.c_str(), item.second);
64 }
65 std::sort(_legacyStates.begin(), _legacyStates.end(), [](const RooCatType& left, const RooCatType& right){
66 return left.getVal() < right.getVal();
67 });
68 }
69
70 const std::map<std::string, RooAbsCategory::value_type>* _origStateNames;
71 std::vector<RooCatType> _legacyStates;
72 int index;
73};
74
75
76#endif /* ROOABSCATEGORYLEGACYITERATOR_H_ */
TObject * operator*() const override
Return current object or nullptr.
RooAbsCategoryLegacyIterator(const std::map< std::string, RooAbsCategory::value_type > &stateNames)
std::vector< RooCatType > _legacyStates
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:63
Iterator abstract base class.
Definition: TIterator.h:30
Mother of all ROOT objects.
Definition: TObject.h:37