ROOT  6.06/09
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 "TObjArray.h"
20 #include "RooAbsCategory.h"
21 #include "RooCategoryProxy.h"
22 #include "RooCatType.h"
23 #include "TRegexp.h"
24 #include <map>
25 #include <string>
26 
28 
30 public:
31  // Constructors etc.
32  enum CatIdx { NoCatIdx=-99999 } ;
33  inline RooMappedCategory() : _defCat(0), _mapcache(0) { }
34  RooMappedCategory(const char *name, const char *title, RooAbsCategory& inputCat, const char* defCatName="NotMapped", Int_t defCatIdx=NoCatIdx);
35  RooMappedCategory(const RooMappedCategory& other, const char *name=0) ;
36  virtual TObject* clone(const char* newname) const { return new RooMappedCategory(*this,newname); }
37  virtual ~RooMappedCategory();
38 
39  // Mapping function
40  Bool_t map(const char* inKeyRegExp, const char* outKeyName, Int_t outKeyNum=NoCatIdx) ;
41 
42  // Printing interface (human readable)
43  void printMultiline(std::ostream& os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const ;
44  void printMetaArgs(std::ostream& os) const ;
45 
46  // I/O streaming interface (machine readable)
47  virtual Bool_t readFromStream(std::istream& is, Bool_t compact, Bool_t verbose=kFALSE) ;
48  virtual void writeToStream(std::ostream& os, Bool_t compact) const ;
49 
50 
51  class Entry {
52  public:
53  inline Entry() : _regexp(0), _cat() {}
54  virtual ~Entry() { delete _regexp ; } ;
55  Entry(const char* exp, const RooCatType* cat) : _expr(exp), _regexp(new TRegexp(mangle(exp),kTRUE)), _cat(*cat) {}
56  Entry(const Entry& other) : _expr(other._expr), _regexp(new TRegexp(mangle(other._expr.Data()),kTRUE)), _cat(other._cat) {}
57  inline Bool_t ok() { return (_regexp->Status()==TRegexp::kOK) ; }
58  Bool_t match(const char* testPattern) const { return (TString(testPattern).Index(*_regexp)>=0) ; }
59  inline const RooCatType& outCat() const { return _cat ; }
60  Entry& operator=(const Entry& other);
61 
62  protected:
63 
64  TString mangle(const char* exp) const ;
65 
69 
70  ClassDef(Entry,1) // Map cat entry definition
71  };
72 
73 protected:
74 
75  RooCatType* _defCat ; // 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  virtual RooCatType evaluate() const ;
82 
83  friend class RooMappedCategoryCache;
84 
85  ClassDef(RooMappedCategory,1) // Index variable, derived from another index using pattern-matching based mapping
86 };
87 
88 #endif
RooMappedCategoryCache(const RooAbsCache &other, RooAbsArg *owner=0)
RooMappedCategoryCache * _mapcache
const RooMappedCategoryCache * getOrCreateCache() const
RooCatType * _defCat
Entry(const char *exp, const RooCatType *cat)
Regular expression class.
Definition: TRegexp.h:35
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
virtual void writeToStream(std::ostream &os, Bool_t compact) const
Write object contents to ostream.
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Entry & operator=(const Entry &other)
TString mangle(const char *exp) const
Mangle name : escape regexp character '+'.
friend class RooMappedCategoryCache
Bool_t match(const char *testPattern) const
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual RooCatType evaluate() const
transient member: cache the mapping
std::vector< std::vector< double > > Data
void printMultiline(std::ostream &os, Int_t content, Bool_t verbose=kFALSE, TString indent="") const
Print info about this object to the specified stream.
Bool_t map(const char *inKeyRegExp, const char *outKeyName, Int_t outKeyNum=NoCatIdx)
bool verbose
Entry(const Entry &other)
static void indent(ostringstream &buf, int indent_level)
RooCmdArg Index(RooCategory &icat)
std::map< std::string, RooMappedCategory::Entry > _mapArray
void printMetaArgs(std::ostream &os) const
Customized printing of arguments of a RooMappedCategory to more intuitively reflect the contents of t...
virtual Bool_t readFromStream(std::istream &is, Bool_t compact, Bool_t verbose=kFALSE)
Read object contents from stream (dummy for now)
#define name(a, b)
Definition: linkTestLib0.cpp:5
const RooCatType & outCat() const
RooCategoryProxy _inputCat
Mother of all ROOT objects.
Definition: TObject.h:58
virtual TObject * clone(const char *newname) const
EStatVal Status()
Check status of regexp.
Definition: TRegexp.cxx:230
double exp(double)
const Bool_t kTRUE
Definition: Rtypes.h:91