56 mutable std::map<Int_t, RooAbsCategory::value_type>
_map;
64 for (
const auto& inCat : *parent.
_inputCat) {
65 const std::string& inKey = inCat.first;
68 for (
const auto& strAndEntry : parent.
_mapArray) {
69 if (strAndEntry.second.match(inKey.c_str())) {
71 _map[inCat.second] = strAndEntry.second.outCat();
97 RooAbsCategory(other,
name), _inputCat(
"input",this,other._inputCat), _mapArray(other._mapArray),
121 if (!inKeyRegExp || !outKey)
return true ;
125 coutE(InputArguments) <<
"RooMappedCategory::map(" <<
GetName() <<
"): ERROR expression "
126 << inKeyRegExp <<
" already mapped" << std::endl ;
141 coutE(InputArguments) <<
"RooMappedCategory::map(" <<
GetName()
142 <<
"): ERROR, unable to define category for output type " << outKey << std::endl ;
147 Entry e(inKeyRegExp, catIdx);
149 coutE(InputArguments) <<
"RooMappedCategory::map(" <<
GetName()
150 <<
"): ERROR, expression " << inKeyRegExp <<
" didn't compile" << std::endl ;
185 os <<
indent <<
"--- RooMappedCategory ---" << std::endl
186 <<
indent <<
" Maps from " ;
191 os <<
indent <<
" Mapping rules:" << std::endl;
192 for (
const auto& strAndEntry :
_mapArray) {
193 os <<
indent <<
" " << strAndEntry.first <<
" -> " << strAndEntry.second.outCat() << std::endl ;
203 coutE(InputArguments) <<
"RooMappedCategory::readFromSteam(" <<
GetName() <<
"): can't read in compact mode" << std::endl ;
215 TString token,errorPrefix(
"RooMappedCategory::readFromStream(") ;
222 bool readToken(
true) ;
226 if (readToken) token=parser.
readToken() ;
227 if (token.
IsNull()) break ;
239 if (
map(srcKey,destKey))
return true ;
266 if (iter.second.outCat() != prevOutCat) {
267 if (!
first) { os <<
" " ; }
270 os << iter.second.outCat() <<
":" << iter.first ;
271 prevOutCat = iter.second.outCat();
273 os <<
"," << iter.first ;
277 if (!
first) { os <<
" " ; }
299 if (iter.second.outCat() != prevOutCat) {
300 if (!
first) { os <<
" " ; }
303 os << iter.second.outCat() <<
"<-" << iter.first ;
304 prevOutCat = iter.second.outCat();
306 os <<
"," << iter.first ;
310 if (!
first) { os <<
" " ; }
328 _expr(exp), _regexp(nullptr), _catIdx(cat) {}
330 _expr(other._expr), _regexp(nullptr), _catIdx(other._catIdx) {}
338 if (&other==
this)
return *this ;
340 _expr = other.
_expr ;
352 return (
TString(testPattern).Index(*regexp())>=0);
361 const char *
c = exp ;
372 _regexp =
new TRegexp(mangle(_expr),
true);
static void indent(ostringstream &buf, int indent_level)
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Abstract base class for data members of RooAbsArgs that cache other (composite) RooAbsArg expressions...
RooAbsArg * _owner
Pointer to owning RooAbsArg.
A space to attach TBranches.
virtual value_type getCurrentIndex() const
Return index number of current state.
virtual const char * getCurrentLabel() const
Return label string of current state.
const std::string & lookupName(value_type index) const
Get the name corresponding to the given index.
virtual const std::map< std::string, RooAbsCategory::value_type >::value_type & defineState(const std::string &label)
Define a new state with given label.
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Print info about this object to the specified stream.
static const decltype(_stateNames) ::value_type & invalidCategory()
A category state to signify an invalid category.
value_type lookupIndex(const std::string &stateName) const
Find the index number corresponding to the state name.
void clearTypes()
Delete all currently defined states.
Abstract container object that can hold multiple RooAbsArg objects.
RooAbsCategory::value_type lookup(Int_t idx) const
bool redirectServersHook(const RooAbsCollection &, bool, bool, bool) override
Interface for server redirect calls.
void wireCache() override
RooMappedCategoryCache(const RooAbsCache &, RooAbsArg *owner)
RooMappedCategoryCache(RooAbsArg *owner)
std::map< Int_t, RooAbsCategory::value_type > _map
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.
friend class RooMappedCategoryCache
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.
~RooMappedCategory() override
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)
virtual void printStream(std::ostream &os, Int_t contents, StyleOption style, TString indent="") const
Print description of object on ostream, printing contents set by contents integer,...
void setPunctuation(const TString &punct)
Change list of characters interpreted as punctuation.
bool expectToken(const TString &expected, bool zapOnError=false)
Read the next token and return true if it is identical to the given 'expected' token.
TString readToken()
Read one token separated by any of the know punctuation characters This function recognizes and handl...
const T & arg() const
Return reference to object held in proxy.
const char * GetName() const override
Returns name of object.
Regular expression class.
int CompareTo(const char *cs, ECaseCompare cmp=kExact) const
Compare a string to char *cs2.
const char * Data() const
TString & Append(const char *cs)