Logo ROOT  
Reference Guide
RooMappedCategory.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Project: RooFit *
3 * Package: RooFitCore *
4 * File: $Id: RooMappedCategory.h,v 1.22 2007/05/11 09:11:30 verkerke Exp $
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-2005, 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#ifndef ROO_MAPPED_CATEGORY
17#define ROO_MAPPED_CATEGORY
18
19#include "RooAbsCategory.h"
20#include "RooCategoryProxy.h"
21#include <map>
22#include <string>
23
24class TRegexp;
26
28public:
29 static constexpr value_type NoCatIdx = std::numeric_limits<value_type>::min();
30 // Constructors etc.
31
32 inline RooMappedCategory() : _defCat(0), _mapcache(nullptr) { }
33 RooMappedCategory(const char *name, const char *title, RooAbsCategory& inputCat, const char* defCatName="NotMapped", Int_t defCatIdx=NoCatIdx);
34 RooMappedCategory(const RooMappedCategory& other, const char *name=nullptr) ;
35 TObject* clone(const char* newname) const override { return new RooMappedCategory(*this,newname); }
36 ~RooMappedCategory() override;
37
38 // Mapping function
39 bool map(const char* inKeyRegExp, const char* outKeyName, Int_t outKeyNum=NoCatIdx) ;
40
41 // Printing interface (human readable)
42 void printMultiline(std::ostream& os, Int_t content, bool verbose=false, TString indent="") const override ;
43 void printMetaArgs(std::ostream& os) const override ;
44
45 // I/O streaming interface (machine readable)
46 bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
47 void writeToStream(std::ostream& os, bool compact) const override ;
48
49
50 class Entry {
51 public:
52 inline Entry() : _regexp(nullptr), _catIdx() {}
53 virtual ~Entry();
54 Entry(const char* exp, RooAbsCategory::value_type cat);
55 Entry(const Entry& other);
56 bool ok();
57 bool match(const char* testPattern) const;
58 Entry& operator=(const Entry& other);
60 const TRegexp* regexp() const;
61
62 protected:
63
64 TString mangle(const char* exp) const ;
65
67 mutable TRegexp* _regexp{nullptr}; ///<!
69
70 ClassDef(Entry, 2) // Map cat entry definition
71 };
72
73protected:
74
75 value_type _defCat{NoCatIdx}; ///< Default (unmapped) output type
76 RooCategoryProxy _inputCat ; ///< Input category
77 std::map<std::string,RooMappedCategory::Entry> _mapArray ; ///< List of mapping rules
78 mutable RooMappedCategoryCache* _mapcache; ///<! transient member: cache the mapping
79
80 value_type evaluate() const override ;
82
83 /// When the input category changes states, the cached state mappings are invalidated
84 void recomputeShape() override;
85
87
88 ClassDefOverride(RooMappedCategory, 2) // Index variable, derived from another index using pattern-matching based mapping
89};
90
91#endif
#define ClassDef(name, id)
Definition: Rtypes.h:335
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
static void indent(ostringstream &buf, int indent_level)
char name[80]
Definition: TGX11.cxx:110
A space to attach TBranches.
RooAbsCategory::value_type outCat() const
Entry & operator=(const Entry &other)
const TRegexp * regexp() const
TString mangle(const char *exp) const
Mangle name : escape regexp character '+'.
RooAbsCategory::value_type _catIdx
bool match(const char *testPattern) const
RooMappedCategory provides a category-to-category mapping defined by pattern matching on their state ...
value_type _defCat
Default (unmapped) output type.
void writeToStream(std::ostream &os, bool compact) const override
Write object contents to ostream.
const RooMappedCategoryCache * getOrCreateCache() const
RooCategoryProxy _inputCat
Input category.
void printMetaArgs(std::ostream &os) const override
Customized printing of arguments of a RooMappedCategory to more intuitively reflect the contents of t...
std::map< std::string, RooMappedCategory::Entry > _mapArray
List of mapping rules.
void recomputeShape() override
When the input category changes states, the cached state mappings are invalidated.
TObject * clone(const char *newname) const override
static constexpr value_type NoCatIdx
bool map(const char *inKeyRegExp, const char *outKeyName, Int_t outKeyNum=NoCatIdx)
RooMappedCategoryCache * _mapcache
! transient member: cache the mapping
void printMultiline(std::ostream &os, Int_t content, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
value_type evaluate() const override
Evaluate the category state and return.
bool readFromStream(std::istream &is, bool compact, bool verbose=false) override
Read object contents from stream (dummy for now)
Mother of all ROOT objects.
Definition: TObject.h:41
Regular expression class.
Definition: TRegexp.h:31
Basic string class.
Definition: TString.h:136
RVec< PromoteType< T > > exp(const RVec< T > &v)
Definition: RVec.hxx:1783