Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:27

0001 /*****************************************************************************
0002  * Project: RooFit                                                           *
0003  * Package: RooFitCore                                                       *
0004  *    File: $Id: RooCatType.h,v 1.20 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_CAT_TYPE
0017 #define ROO_CAT_TYPE
0018 
0019 #include "TObject.h"
0020 #include "RooPrintable.h"
0021 #include "strlcpy.h"
0022 
0023 class RooCatType : public TObject, public RooPrintable {
0024 public:
0025   inline RooCatType()
0026   {
0027      _label[0] = 0;
0028   }
0029 
0030   /// Constructor with state name and index value.
0031   inline RooCatType(const char *name, Int_t value) : _value(value)
0032   {
0033      SetName(name);
0034   }
0035   /// Copy constructor.
0036   inline RooCatType(const RooCatType& other) :
0037     TObject(other), RooPrintable(other), _value(other._value) {
0038     strlcpy(_label,other._label,256) ;
0039   }
0040 
0041   TObject* Clone(const char*) const override { return new RooCatType(*this); }
0042 
0043   const Text_t* GetName() const override {
0044     // Return state name
0045     return _label[0] ? _label : nullptr ;
0046   }
0047   void SetName(const Text_t* name) ;
0048 
0049   inline RooCatType& operator=(const RooCatType& other) {
0050     // Assignment operator from other RooCatType
0051     if (&other==this) return *this ;
0052     SetName(other.GetName()) ;
0053     _value = other._value ;
0054     return *this ;
0055   }
0056 
0057   inline void assignFast(const RooCatType& other) {
0058     // Fast assignment operator from other RooCatType
0059     _label[0] = 0 ;
0060     _value = other._value ;
0061   }
0062 
0063   inline bool operator==(const RooCatType& other) const {
0064     // Equality operator with other RooCatType
0065     return (_value==other._value) ;
0066   }
0067 
0068   inline bool operator==(Int_t index) const {
0069     // Return true if index value matches integer
0070     return (_value==index) ;
0071   }
0072 
0073   bool operator==(const char* label) const {
0074     // Return true if state name matchins string
0075     return label && !strcmp(_label,label) ;
0076   }
0077 
0078   inline Int_t getVal() const {
0079     // Return index value
0080     return _value ;
0081   }
0082   void setVal(Int_t newValue) {
0083     // Set index value
0084   _value = newValue ;
0085   }
0086 
0087   void printName(std::ostream& os) const override ;
0088   void printTitle(std::ostream& os) const override ;
0089   void printClassName(std::ostream& os) const override ;
0090   void printValue(std::ostream& os) const override ;
0091 
0092   inline void Print(Option_t *options= nullptr) const override {
0093     // Printing interface
0094     printStream(defaultPrintStream(),defaultPrintContents(options),defaultPrintStyle(options));
0095   }
0096 
0097 protected:
0098 
0099   friend class RooAbsCategoryLValue ;
0100   friend class RooAbsCategory ;
0101   Int_t _value = 0;  ///< Index value
0102   char _label[256] ; ///< State name
0103 
0104   ClassDefOverride(RooCatType,1) // Category state, (name,index) pair
0105 } R__SUGGEST_ALTERNATIVE("Instead of RooCatType, directly use the category number returned by RooAbsCategory::getIndex().\n"
0106     "Convert it into a name using RooAbsCategory::lookupName(index).");
0107 
0108 
0109 #endif
0110