ROOT logo
/*****************************************************************************
 * Project: RooFit                                                           *
 * Package: RooFitCore                                                       *
 * @(#)root/roofitcore:$Id: RooAbsCategoryLValue.cxx 28259 2009-04-16 16:21:16Z wouter $
 * Authors:                                                                  *
 *   WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu       *
 *   DK, David Kirkby,    UC Irvine,         dkirkby@uci.edu                 *
 *                                                                           *
 * Copyright (c) 2000-2005, Regents of the University of California          *
 *                          and Stanford University. All rights reserved.    *
 *                                                                           *
 * Redistribution and use in source and binary forms,                        *
 * with or without modification, are permitted according to the terms        *
 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)             *
 *****************************************************************************/

//////////////////////////////////////////////////////////////////////////////
// 
// BEGIN_HTML
// RooAbsCategoryLValue is the common abstract base class for objects that represent a
// discrete value that may appear on the left hand side of an equation ('lvalue')
//
// Each implementation must provide setIndex()/setLabel() members to allow direct modification 
// of the value. RooAbsCategoryLValue may be derived, but its functional relation
// to other RooAbsArgs must be invertible
// END_HTML
//
//

#include "RooFit.h"

#include "Riostream.h"
#include "Riostream.h"
#include <stdlib.h>
#include <string.h>
#include "TTree.h"
#include "TString.h"
#include "TH1.h"
#include "RooAbsCategoryLValue.h"
#include "RooArgSet.h"
#include "RooStreamParser.h"
#include "RooRandom.h"
#include "RooMsgService.h"

ClassImp(RooAbsCategoryLValue) 
;


//_____________________________________________________________________________
RooAbsCategoryLValue::RooAbsCategoryLValue(const char *name, const char *title) : 
  RooAbsCategory(name,title)
{
  // Constructor

  setValueDirty() ;  
  setShapeDirty() ;  
}



//_____________________________________________________________________________
RooAbsCategoryLValue::RooAbsCategoryLValue(const RooAbsCategoryLValue& other, const char* name) :
  RooAbsCategory(other, name), RooAbsLValue(other)
{
  // Copy constructor
}



//_____________________________________________________________________________
RooAbsCategoryLValue::~RooAbsCategoryLValue()
{
  // Destructor
}



//_____________________________________________________________________________
RooAbsArg& RooAbsCategoryLValue::operator=(Int_t index) 
{
  // Assignment operator from integer index number

  setIndex(index,kTRUE) ;
  return *this ;
}



//_____________________________________________________________________________
RooAbsArg& RooAbsCategoryLValue::operator=(const char *label) 
{
  // Assignment operator from string pointer

  setLabel(label) ;
  return *this ;
}



//_____________________________________________________________________________
RooAbsArg& RooAbsCategoryLValue::operator=(const RooAbsCategory& other) 
{
  // Assignment from another RooAbsCategory

  if (&other==this) return *this ;

  const RooCatType* type = lookupType(other.getLabel(),kTRUE) ;
  if (!type) return *this ;

  _value = *type ;
  setValueDirty() ;
  return *this ;
}



//_____________________________________________________________________________
Bool_t RooAbsCategoryLValue::setOrdinal(UInt_t n, const char* rangeName) 
{
  // Set our state to our n'th defined type and return kTRUE.
  // Return kFALSE if n is out of range.

  const RooCatType *newValue= getOrdinal(n,rangeName);
  if(newValue) {
    return setIndex(newValue->getVal());
  }
  else {
    return kFALSE;
  }
}



//_____________________________________________________________________________
void RooAbsCategoryLValue::copyCache(const RooAbsArg* source, Bool_t /*valueOnly*/) 
{
  // Copy the cached value from given source and raise dirty flag.
  // It is the callers responsability to ensure that the sources
  // cache is clean(valid) before this function is called, e.g. by
  // calling syncCache() on the source.

  RooAbsCategory::copyCache(source) ;
  if (isValid(_value)) {
    setIndex(_value.getVal()) ; // force back-propagation
  }
}



//_____________________________________________________________________________
Bool_t RooAbsCategoryLValue::readFromStream(istream&, Bool_t, Bool_t) 
{
  // Read object contents from given stream (dummy implementation)

  return kTRUE ;
}



//_____________________________________________________________________________
void RooAbsCategoryLValue::writeToStream(ostream&, Bool_t) const
{
  // Write object contents to given stream (dummy implementation)
}



//_____________________________________________________________________________
void RooAbsCategoryLValue::randomize(const char* rangeName) 
{
  // Randomize current value
  
  UInt_t ordinal= RooRandom::integer(numTypes(rangeName));
  setOrdinal(ordinal,rangeName);
}



//_____________________________________________________________________________
void RooAbsCategoryLValue::setBin(Int_t ibin, const char* rangeName) 
{
  // Set category to i-th fit bin, which is the i-th registered state.

  // Check validity of ibin
  if (ibin<0 || ibin>=numBins(rangeName)) {
    coutE(InputArguments) << "RooAbsCategoryLValue::setBin(" << GetName() << ") ERROR: bin index " << ibin
			  << " is out of range (0," << numBins(rangeName)-1 << ")" << endl ;
    return ;
  }

  // Retrieve state corresponding to bin
  const RooCatType* type = getOrdinal(ibin,rangeName) ;

  // Set value to requested state
  setIndex(type->getVal()) ;
}



//_____________________________________________________________________________
Int_t RooAbsCategoryLValue::getBin(const char* /*rangeName*/) const 
{
  // Get index of plot bin for current value this category.

  //Synchronize _value
  getIndex() ; 

  // Lookup ordinal index number 
  return _types.IndexOf(_types.FindObject(_value.GetName())) ;
}



//_____________________________________________________________________________
Int_t RooAbsCategoryLValue::numBins(const char* rangeName) const 
{
  // Returm the number of fit bins ( = number of types )

  return numTypes(rangeName) ;
}
 RooAbsCategoryLValue.cxx:1
 RooAbsCategoryLValue.cxx:2
 RooAbsCategoryLValue.cxx:3
 RooAbsCategoryLValue.cxx:4
 RooAbsCategoryLValue.cxx:5
 RooAbsCategoryLValue.cxx:6
 RooAbsCategoryLValue.cxx:7
 RooAbsCategoryLValue.cxx:8
 RooAbsCategoryLValue.cxx:9
 RooAbsCategoryLValue.cxx:10
 RooAbsCategoryLValue.cxx:11
 RooAbsCategoryLValue.cxx:12
 RooAbsCategoryLValue.cxx:13
 RooAbsCategoryLValue.cxx:14
 RooAbsCategoryLValue.cxx:15
 RooAbsCategoryLValue.cxx:16
 RooAbsCategoryLValue.cxx:17
 RooAbsCategoryLValue.cxx:18
 RooAbsCategoryLValue.cxx:19
 RooAbsCategoryLValue.cxx:20
 RooAbsCategoryLValue.cxx:21
 RooAbsCategoryLValue.cxx:22
 RooAbsCategoryLValue.cxx:23
 RooAbsCategoryLValue.cxx:24
 RooAbsCategoryLValue.cxx:25
 RooAbsCategoryLValue.cxx:26
 RooAbsCategoryLValue.cxx:27
 RooAbsCategoryLValue.cxx:28
 RooAbsCategoryLValue.cxx:29
 RooAbsCategoryLValue.cxx:30
 RooAbsCategoryLValue.cxx:31
 RooAbsCategoryLValue.cxx:32
 RooAbsCategoryLValue.cxx:33
 RooAbsCategoryLValue.cxx:34
 RooAbsCategoryLValue.cxx:35
 RooAbsCategoryLValue.cxx:36
 RooAbsCategoryLValue.cxx:37
 RooAbsCategoryLValue.cxx:38
 RooAbsCategoryLValue.cxx:39
 RooAbsCategoryLValue.cxx:40
 RooAbsCategoryLValue.cxx:41
 RooAbsCategoryLValue.cxx:42
 RooAbsCategoryLValue.cxx:43
 RooAbsCategoryLValue.cxx:44
 RooAbsCategoryLValue.cxx:45
 RooAbsCategoryLValue.cxx:46
 RooAbsCategoryLValue.cxx:47
 RooAbsCategoryLValue.cxx:48
 RooAbsCategoryLValue.cxx:49
 RooAbsCategoryLValue.cxx:50
 RooAbsCategoryLValue.cxx:51
 RooAbsCategoryLValue.cxx:52
 RooAbsCategoryLValue.cxx:53
 RooAbsCategoryLValue.cxx:54
 RooAbsCategoryLValue.cxx:55
 RooAbsCategoryLValue.cxx:56
 RooAbsCategoryLValue.cxx:57
 RooAbsCategoryLValue.cxx:58
 RooAbsCategoryLValue.cxx:59
 RooAbsCategoryLValue.cxx:60
 RooAbsCategoryLValue.cxx:61
 RooAbsCategoryLValue.cxx:62
 RooAbsCategoryLValue.cxx:63
 RooAbsCategoryLValue.cxx:64
 RooAbsCategoryLValue.cxx:65
 RooAbsCategoryLValue.cxx:66
 RooAbsCategoryLValue.cxx:67
 RooAbsCategoryLValue.cxx:68
 RooAbsCategoryLValue.cxx:69
 RooAbsCategoryLValue.cxx:70
 RooAbsCategoryLValue.cxx:71
 RooAbsCategoryLValue.cxx:72
 RooAbsCategoryLValue.cxx:73
 RooAbsCategoryLValue.cxx:74
 RooAbsCategoryLValue.cxx:75
 RooAbsCategoryLValue.cxx:76
 RooAbsCategoryLValue.cxx:77
 RooAbsCategoryLValue.cxx:78
 RooAbsCategoryLValue.cxx:79
 RooAbsCategoryLValue.cxx:80
 RooAbsCategoryLValue.cxx:81
 RooAbsCategoryLValue.cxx:82
 RooAbsCategoryLValue.cxx:83
 RooAbsCategoryLValue.cxx:84
 RooAbsCategoryLValue.cxx:85
 RooAbsCategoryLValue.cxx:86
 RooAbsCategoryLValue.cxx:87
 RooAbsCategoryLValue.cxx:88
 RooAbsCategoryLValue.cxx:89
 RooAbsCategoryLValue.cxx:90
 RooAbsCategoryLValue.cxx:91
 RooAbsCategoryLValue.cxx:92
 RooAbsCategoryLValue.cxx:93
 RooAbsCategoryLValue.cxx:94
 RooAbsCategoryLValue.cxx:95
 RooAbsCategoryLValue.cxx:96
 RooAbsCategoryLValue.cxx:97
 RooAbsCategoryLValue.cxx:98
 RooAbsCategoryLValue.cxx:99
 RooAbsCategoryLValue.cxx:100
 RooAbsCategoryLValue.cxx:101
 RooAbsCategoryLValue.cxx:102
 RooAbsCategoryLValue.cxx:103
 RooAbsCategoryLValue.cxx:104
 RooAbsCategoryLValue.cxx:105
 RooAbsCategoryLValue.cxx:106
 RooAbsCategoryLValue.cxx:107
 RooAbsCategoryLValue.cxx:108
 RooAbsCategoryLValue.cxx:109
 RooAbsCategoryLValue.cxx:110
 RooAbsCategoryLValue.cxx:111
 RooAbsCategoryLValue.cxx:112
 RooAbsCategoryLValue.cxx:113
 RooAbsCategoryLValue.cxx:114
 RooAbsCategoryLValue.cxx:115
 RooAbsCategoryLValue.cxx:116
 RooAbsCategoryLValue.cxx:117
 RooAbsCategoryLValue.cxx:118
 RooAbsCategoryLValue.cxx:119
 RooAbsCategoryLValue.cxx:120
 RooAbsCategoryLValue.cxx:121
 RooAbsCategoryLValue.cxx:122
 RooAbsCategoryLValue.cxx:123
 RooAbsCategoryLValue.cxx:124
 RooAbsCategoryLValue.cxx:125
 RooAbsCategoryLValue.cxx:126
 RooAbsCategoryLValue.cxx:127
 RooAbsCategoryLValue.cxx:128
 RooAbsCategoryLValue.cxx:129
 RooAbsCategoryLValue.cxx:130
 RooAbsCategoryLValue.cxx:131
 RooAbsCategoryLValue.cxx:132
 RooAbsCategoryLValue.cxx:133
 RooAbsCategoryLValue.cxx:134
 RooAbsCategoryLValue.cxx:135
 RooAbsCategoryLValue.cxx:136
 RooAbsCategoryLValue.cxx:137
 RooAbsCategoryLValue.cxx:138
 RooAbsCategoryLValue.cxx:139
 RooAbsCategoryLValue.cxx:140
 RooAbsCategoryLValue.cxx:141
 RooAbsCategoryLValue.cxx:142
 RooAbsCategoryLValue.cxx:143
 RooAbsCategoryLValue.cxx:144
 RooAbsCategoryLValue.cxx:145
 RooAbsCategoryLValue.cxx:146
 RooAbsCategoryLValue.cxx:147
 RooAbsCategoryLValue.cxx:148
 RooAbsCategoryLValue.cxx:149
 RooAbsCategoryLValue.cxx:150
 RooAbsCategoryLValue.cxx:151
 RooAbsCategoryLValue.cxx:152
 RooAbsCategoryLValue.cxx:153
 RooAbsCategoryLValue.cxx:154
 RooAbsCategoryLValue.cxx:155
 RooAbsCategoryLValue.cxx:156
 RooAbsCategoryLValue.cxx:157
 RooAbsCategoryLValue.cxx:158
 RooAbsCategoryLValue.cxx:159
 RooAbsCategoryLValue.cxx:160
 RooAbsCategoryLValue.cxx:161
 RooAbsCategoryLValue.cxx:162
 RooAbsCategoryLValue.cxx:163
 RooAbsCategoryLValue.cxx:164
 RooAbsCategoryLValue.cxx:165
 RooAbsCategoryLValue.cxx:166
 RooAbsCategoryLValue.cxx:167
 RooAbsCategoryLValue.cxx:168
 RooAbsCategoryLValue.cxx:169
 RooAbsCategoryLValue.cxx:170
 RooAbsCategoryLValue.cxx:171
 RooAbsCategoryLValue.cxx:172
 RooAbsCategoryLValue.cxx:173
 RooAbsCategoryLValue.cxx:174
 RooAbsCategoryLValue.cxx:175
 RooAbsCategoryLValue.cxx:176
 RooAbsCategoryLValue.cxx:177
 RooAbsCategoryLValue.cxx:178
 RooAbsCategoryLValue.cxx:179
 RooAbsCategoryLValue.cxx:180
 RooAbsCategoryLValue.cxx:181
 RooAbsCategoryLValue.cxx:182
 RooAbsCategoryLValue.cxx:183
 RooAbsCategoryLValue.cxx:184
 RooAbsCategoryLValue.cxx:185
 RooAbsCategoryLValue.cxx:186
 RooAbsCategoryLValue.cxx:187
 RooAbsCategoryLValue.cxx:188
 RooAbsCategoryLValue.cxx:189
 RooAbsCategoryLValue.cxx:190
 RooAbsCategoryLValue.cxx:191
 RooAbsCategoryLValue.cxx:192
 RooAbsCategoryLValue.cxx:193
 RooAbsCategoryLValue.cxx:194
 RooAbsCategoryLValue.cxx:195
 RooAbsCategoryLValue.cxx:196
 RooAbsCategoryLValue.cxx:197
 RooAbsCategoryLValue.cxx:198
 RooAbsCategoryLValue.cxx:199
 RooAbsCategoryLValue.cxx:200
 RooAbsCategoryLValue.cxx:201
 RooAbsCategoryLValue.cxx:202
 RooAbsCategoryLValue.cxx:203
 RooAbsCategoryLValue.cxx:204
 RooAbsCategoryLValue.cxx:205
 RooAbsCategoryLValue.cxx:206
 RooAbsCategoryLValue.cxx:207
 RooAbsCategoryLValue.cxx:208
 RooAbsCategoryLValue.cxx:209
 RooAbsCategoryLValue.cxx:210
 RooAbsCategoryLValue.cxx:211
 RooAbsCategoryLValue.cxx:212
 RooAbsCategoryLValue.cxx:213
 RooAbsCategoryLValue.cxx:214
 RooAbsCategoryLValue.cxx:215
 RooAbsCategoryLValue.cxx:216
 RooAbsCategoryLValue.cxx:217
 RooAbsCategoryLValue.cxx:218
 RooAbsCategoryLValue.cxx:219
 RooAbsCategoryLValue.cxx:220