File indexing completed on 2025-01-18 10:11:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef ROO_CATEGORY
0017 #define ROO_CATEGORY
0018
0019 #include "RooAbsCategoryLValue.h"
0020 #include "RooSharedProperties.h"
0021
0022 #include <vector>
0023 #include <map>
0024 #include <string>
0025
0026 class RooCategorySharedProperties;
0027
0028 class RooCategory final : public RooAbsCategoryLValue {
0029 public:
0030
0031 RooCategory() ;
0032 RooCategory(const char *name, const char *title);
0033 RooCategory(const char* name, const char* title, const std::map<std::string, int>& allowedStates);
0034 RooCategory(const RooCategory& other, const char* name=nullptr) ;
0035 RooCategory& operator=(const RooCategory&) = delete;
0036 ~RooCategory() override;
0037 TObject* clone(const char* newname) const override { return new RooCategory(*this,newname); }
0038
0039
0040 value_type getCurrentIndex() const final {
0041 return RooCategory::evaluate();
0042 }
0043
0044 bool setIndex(Int_t index, bool printError = true) override;
0045 using RooAbsCategoryLValue::setIndex;
0046 bool setLabel(const char* label, bool printError = true) override;
0047 using RooAbsCategoryLValue::setLabel;
0048
0049
0050 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override;
0051 void writeToStream(std::ostream& os, bool compact) const override ;
0052
0053 bool defineType(const std::string& label);
0054 bool defineType(const std::string& label, Int_t index);
0055 void defineTypes(const std::map<std::string, int>& allowedStates);
0056 value_type& operator[](const std::string& stateName);
0057 std::map<std::string, RooAbsCategory::value_type>& states();
0058
0059
0060 bool defineType(const char* label) {
0061 return defineType(std::string(label));
0062 }
0063 bool defineType(const char* label, Int_t index) {
0064 return defineType(std::string(label), index);
0065 }
0066
0067
0068
0069 void clear() {
0070 clearTypes();
0071 }
0072
0073 void clearRange(const char* name, bool silent) ;
0074 void setRange(const char* rangeName, const char* stateNameList) ;
0075 void addToRange(const char* rangeName, RooAbsCategory::value_type stateIndex);
0076 void addToRange(const char* rangeName, const char* stateNameList) ;
0077
0078
0079
0080
0081
0082
0083 inline bool isFundamental() const override {
0084 return true;
0085 }
0086
0087
0088 bool isDerived() const override {
0089 return false;
0090 }
0091
0092 bool isStateInRange(const char* rangeName, RooAbsCategory::value_type stateIndex) const ;
0093 bool isStateInRange(const char* rangeName, const char* stateName) const ;
0094
0095
0096 bool inRange(const char* rangeName) const override {
0097 return isStateInRange(rangeName, RooCategory::evaluate());
0098 }
0099
0100 bool hasRange(const char* rangeName) const override {
0101 return _ranges->find(rangeName) != _ranges->end();
0102 }
0103
0104
0105
0106 protected:
0107
0108
0109
0110 value_type evaluate() const override {
0111 if (hasIndex(_currentIndex))
0112 return _currentIndex;
0113
0114 if (_insertionOrder.empty()) {
0115 return invalidCategory().second;
0116 } else {
0117 auto item = stateNames().find(_insertionOrder.front());
0118 assert(item != stateNames().end());
0119 return item->second;
0120 }
0121 }
0122
0123
0124 void recomputeShape() override { };
0125
0126 private:
0127
0128 using RangeMap_t = std::map<std::string, std::vector<value_type>>;
0129
0130
0131 std::shared_ptr<RangeMap_t> _ranges{new RangeMap_t()};
0132 RangeMap_t* _rangesPointerForIO{nullptr};
0133
0134 void installLegacySharedProp(const RooCategorySharedProperties* sp);
0135 void installSharedRange(std::unique_ptr<RangeMap_t>&& rangeMap);
0136
0137 static std::map<RooSharedProperties::UUID, std::weak_ptr<RangeMap_t>> _uuidToSharedRangeIOHelper;
0138
0139 static std::map<std::string, std::weak_ptr<RangeMap_t>> _sharedRangeIOHelper;
0140
0141 ClassDefOverride(RooCategory, 3)
0142 };
0143
0144 #endif