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();
98 _inputCat(
"input", this, other._inputCat),
99 _mapArray(other._mapArray)
114 if (!inKeyRegExp || !outKey)
return true ;
118 coutE(InputArguments) <<
"RooMappedCategory::map(" <<
GetName() <<
"): ERROR expression "
119 << inKeyRegExp <<
" already mapped" << std::endl ;
134 coutE(InputArguments) <<
"RooMappedCategory::map(" <<
GetName()
135 <<
"): ERROR, unable to define category for output type " << outKey << std::endl ;
140 Entry e(inKeyRegExp, catIdx);
142 coutE(InputArguments) <<
"RooMappedCategory::map(" <<
GetName()
143 <<
"): ERROR, expression " << inKeyRegExp <<
" didn't compile" << std::endl ;
178 os <<
indent <<
"--- RooMappedCategory ---" << std::endl
179 <<
indent <<
" Maps from " ;
184 os <<
indent <<
" Mapping rules:" << std::endl;
185 for (
const auto& strAndEntry :
_mapArray) {
186 os <<
indent <<
" " << strAndEntry.first <<
" -> " << strAndEntry.second.outCat() << std::endl ;
196 coutE(InputArguments) <<
"RooMappedCategory::readFromSteam(" <<
GetName() <<
"): can't read in compact mode" << std::endl ;
208 TString errorPrefix(
"RooMappedCategory::readFromStream(");
216 bool readToken(
true) ;
220 if (readToken) token=parser.
readToken() ;
221 if (token.
IsNull()) break ;
233 if (
map(srcKey,destKey))
return true ;
260 if (iter.second.outCat() != prevOutCat) {
261 if (!first) { os <<
" " ; }
264 os << iter.second.outCat() <<
":" << iter.first ;
265 prevOutCat = iter.second.outCat();
267 os <<
"," << iter.first ;
271 if (!first) { os <<
" " ; }
293 if (iter.second.outCat() != prevOutCat) {
294 if (!first) { os <<
" " ; }
297 os << iter.second.outCat() <<
"<-" << iter.first ;
298 prevOutCat = iter.second.outCat();
300 os <<
"," << iter.first ;
304 if (!first) { os <<
" " ; }
329 if (&other==
this)
return *this ;
331 _expr = other.
_expr ;
343 return (
TString(testPattern).Index(*regexp())>=0);
352 const char *
c = exp ;
363 _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 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.
void setDefCat(value_type defCat)
std::unique_ptr< RooMappedCategoryCache > _mapcache
! transient member: cache the mapping
static constexpr value_type NoCatIdx
bool map(const char *inKeyRegExp, const char *outKeyName, Int_t outKeyNum=NoCatIdx)
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)
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 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)