Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/RooMappedCategory.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooMappedCategory.h,v 1.22 2007/05/11 09:11:30 verkerke Exp $
0005  * Authors:                                                                  *
0006  *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
0007  *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
0008  *                                                                           *
0009  * Copyright (c) 2000-2005, Regents of the University of California          *
0010  *                          and Stanford University. All rights reserved.    *
0011  *                                                                           *
0012  * Redistribution and use in source and binary forms,                        *
0013  * with or without modification, are permitted according to the terms        *
0014  * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
0015  *****************************************************************************/
0016 #ifndef ROO_MAPPED_CATEGORY
0017 #define ROO_MAPPED_CATEGORY
0018 
0019 #include "RooAbsCategory.h"
0020 #include "RooCategoryProxy.h"
0021 #include <map>
0022 #include <string>
0023 
0024 class TRegexp;
0025 class RooMappedCategoryCache;
0026 
0027 class RooMappedCategory : public RooAbsCategory {
0028 public:
0029   static constexpr value_type NoCatIdx = std::numeric_limits<value_type>::min();
0030   // Constructors etc.
0031 
0032   RooMappedCategory();
0033   RooMappedCategory(const char *name, const char *title, RooAbsCategory& inputCat, const char* defCatName="NotMapped", Int_t defCatIdx=NoCatIdx);
0034   RooMappedCategory(const RooMappedCategory& other, const char *name=nullptr) ;
0035   TObject* clone(const char* newname) const override { return new RooMappedCategory(*this,newname); }
0036   ~RooMappedCategory() override;
0037 
0038   // Mapping function
0039   bool map(const char* inKeyRegExp, const char* outKeyName, Int_t outKeyNum=NoCatIdx) ;
0040 
0041   // Printing interface (human readable)
0042   void printMultiline(std::ostream& os, Int_t content, bool verbose=false, TString indent="") const override ;
0043   void printMetaArgs(std::ostream& os) const override ;
0044 
0045   // I/O streaming interface (machine readable)
0046   bool readFromStream(std::istream& is, bool compact, bool verbose=false) override ;
0047   void writeToStream(std::ostream& os, bool compact) const override ;
0048 
0049 
0050   class Entry {
0051   public:
0052     inline Entry() : _catIdx() {}
0053     virtual ~Entry();
0054     Entry(const char* exp, RooAbsCategory::value_type cat);
0055     Entry(const Entry& other);
0056     bool ok();
0057     bool match(const char* testPattern) const;
0058     Entry& operator=(const Entry& other);
0059     RooAbsCategory::value_type outCat() const { return _catIdx; }
0060     const TRegexp* regexp() const;
0061 
0062   protected:
0063 
0064     TString mangle(const char* exp) const ;
0065 
0066     TString _expr ;
0067     mutable TRegexp* _regexp{nullptr}; ///<!
0068     RooAbsCategory::value_type _catIdx;
0069 
0070     ClassDef(Entry, 2) // Map cat entry definition
0071   };
0072 
0073 protected:
0074 
0075   value_type _defCat{NoCatIdx}; ///< Default (unmapped) output type
0076   RooCategoryProxy _inputCat ;  ///< Input category
0077   std::map<std::string,RooMappedCategory::Entry> _mapArray ;  ///< List of mapping rules
0078   mutable std::unique_ptr<RooMappedCategoryCache> _mapcache; ///<! transient member: cache the mapping
0079 
0080   value_type evaluate() const override ;
0081   const RooMappedCategoryCache* getOrCreateCache() const;
0082 
0083   /// When the input category changes states, the cached state mappings are invalidated
0084   void recomputeShape() override;
0085 
0086   friend class RooMappedCategoryCache;
0087 
0088 private:
0089   inline void setDefCat(value_type defCat) { _defCat = defCat; }
0090 
0091   ClassDefOverride(RooMappedCategory, 2) // Index variable, derived from another index using pattern-matching based mapping
0092 };
0093 
0094 #endif