#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <stdlib.h>
#include <stdio.h>
#include "TString.h"
#include "TClass.h"
#include "RooSuperCategory.h"
#include "RooStreamParser.h"
#include "RooArgSet.h"
#include "RooMultiCatIter.h"
#include "RooAbsCategoryLValue.h"
ClassImp(RooSuperCategory)
;
RooSuperCategory::RooSuperCategory(const char *name, const char *title, const RooArgSet& inputCatList) :
  RooAbsCategoryLValue(name, title), _catSet("catSet","Input category set",this,kTRUE,kTRUE)
{  
  
  
  TIterator* iter = inputCatList.createIterator() ;
  RooAbsArg* arg ;
  while ((arg=(RooAbsArg*)iter->Next())) {
    if (!arg->IsA()->InheritsFrom(RooAbsCategoryLValue::Class())) {
      cout << "RooSuperCategory::RooSuperCategory(" << GetName() << "): input category " << arg->GetName() 
	   << " is not an lvalue" << endl ;
    }
    _catSet.add(*arg) ;
  }
  delete iter ;
  _catIter = _catSet.createIterator() ;
  
  updateIndexList() ;
}
RooSuperCategory::RooSuperCategory(const RooSuperCategory& other, const char *name) :
  RooAbsCategoryLValue(other,name), _catSet("catSet",this,other._catSet)
{
  
  _catIter = _catSet.createIterator() ;
  updateIndexList() ;
  setIndex(other.getIndex()) ;
}
RooSuperCategory::~RooSuperCategory() 
{
  
  delete _catIter ;
}
TIterator* RooSuperCategory::MakeIterator() const 
{
  
  
  return new RooMultiCatIter(_catSet) ;
}
void RooSuperCategory::updateIndexList()
{
  
  clearTypes() ;
  RooMultiCatIter mcIter(_catSet) ;
  TObjString* obj ;
  Int_t i(0) ;
  while((obj = (TObjString*) mcIter.Next())) {
    
    defineTypeUnchecked(obj->String(),i++) ;
  }
  
  setValueDirty() ;
}
TString RooSuperCategory::currentLabel() const
{
  
  
  _catIter->Reset() ;
  
  TString label ;
  RooAbsCategory* cat ;
  Bool_t first(kTRUE) ;
  while((cat=(RooAbsCategory*) _catIter->Next())) {
    label.Append(first?"{":";") ;
    label.Append(cat->getLabel()) ;      
    first=kFALSE ;
  }
  label.Append("}") ;  
  return label ;
}
RooCatType
RooSuperCategory::evaluate() const
{
  
  if (isShapeDirty()) {
    const_cast<RooSuperCategory*>(this)->updateIndexList() ;
  }
  const RooCatType* ret = lookupType(currentLabel(),kTRUE) ;
  if (!ret) {
    cout << "RooSuperCat::evaluate(" << this << ") error: current state not defined: '" << currentLabel() << "'" << endl ;
    Print("v") ;
  }
  return *ret ;
}
Bool_t RooSuperCategory::setIndex(Int_t index, Bool_t ) 
{
  
  
  const RooCatType* type = lookupType(index,kTRUE) ;
  if (!type) return kTRUE ;
  return setType(type) ;
}
Bool_t RooSuperCategory::setLabel(const char* label, Bool_t ) 
{
  
  
  const RooCatType* type = lookupType(label,kTRUE) ;
  if (!type) return kTRUE ;
  return setType(type) ;
}
Bool_t RooSuperCategory::setType(const RooCatType* type, Bool_t )
{
  
  
  char buf[1024] ;
  strcpy(buf,type->GetName()) ;
  RooAbsCategoryLValue* arg ;
  Bool_t error(kFALSE) ;
  
  char* ptr=buf+1 ;
  char* token = ptr ;
  _catIter->Reset() ;
  while ((arg=(RooAbsCategoryLValue*)_catIter->Next())) {
    
    if (*ptr=='{') {
      
      Int_t nBrak(1) ;
      while(*(++ptr)) {
	if (nBrak==0) {
	  *ptr = 0 ;
	  break ;
	}
	if (*ptr=='{') {
	  nBrak++ ;
	} else if (*ptr=='}') {
	  nBrak-- ;
	}
      }	
    } else {
      
      ptr = strtok(ptr,";}") ;
      ptr += strlen(ptr) ;
    }
    error |= arg->setLabel(token) ;
    token = ++ptr ;
  }
  
  return error ;
}
void RooSuperCategory::printToStream(ostream& os, PrintOption opt, TString indent) const
{
  
  RooAbsCategory::printToStream(os,opt,indent) ;
  
  if (opt>=Verbose) {     
    os << indent << "--- RooSuperCategory ---" << endl;
    os << indent << "  Input category list:" << endl ;
    TString moreIndent(indent) ;
    moreIndent.Append("   ") ;
    _catSet.printToStream(os,Standard,moreIndent.Data()) ;
  }
}
Bool_t RooSuperCategory::readFromStream(istream& , Bool_t , Bool_t ) 
{
  
  return kTRUE ;
}
void RooSuperCategory::writeToStream(ostream& os, Bool_t compact) const
{
  
  RooAbsCategory::writeToStream(os,compact) ;
}
Bool_t RooSuperCategory::inRange(const char* rangeName) const 
{
  
  _catIter->Reset() ;
  RooAbsCategoryLValue* cat ;
  while((cat = (RooAbsCategoryLValue*)_catIter->Next())) {
    if (!cat->inRange(rangeName)) {
      return kFALSE ;
    }
  }
  return kTRUE ;
}
Bool_t RooSuperCategory::hasRange(const char* rangeName) const 
{
  _catIter->Reset() ;
  RooAbsCategoryLValue* cat ;
  while((cat = (RooAbsCategoryLValue*)_catIter->Next())) {
    if (cat->hasRange(rangeName)) return kTRUE ;
  }
  return kFALSE ;
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.