// RooMultiCategory consolidates several RooAbsCategory objects into
// a single category. The states of the multi-category consist of all the permutations
// of the input categories.
// <p>
// RooMultiCategory state are automatically defined and updated whenever an input
// category modifies its list of states
// END_HTML
#include "RooFit.h"
#include "Riostream.h"
#include "Riostream.h"
#include <stdlib.h>
#include <stdio.h>
#include "TString.h"
#include "RooMultiCategory.h"
#include "RooStreamParser.h"
#include "RooArgSet.h"
#include "RooMultiCatIter.h"
#include "RooAbsCategory.h"
#include "RooMsgService.h"
ClassImp(RooMultiCategory)
;
RooMultiCategory::RooMultiCategory(const char *name, const char *title, const RooArgSet& inputCatList2) :
RooAbsCategory(name, title), _catSet("input","Input category set",this,kTRUE,kTRUE)
{
TIterator* iter = inputCatList2.createIterator() ;
RooAbsArg* arg ;
while ((arg=(RooAbsArg*)iter->Next())) {
if (!dynamic_cast<RooAbsCategory*>(arg)) {
coutE(InputArguments) << "RooMultiCategory::RooMultiCategory(" << GetName() << "): input argument " << arg->GetName()
<< " is not a RooAbsCategory" << endl ;
}
_catSet.add(*arg) ;
}
delete iter ;
updateIndexList() ;
}
RooMultiCategory::RooMultiCategory(const RooMultiCategory& other, const char *name) :
RooAbsCategory(other,name), _catSet("input",this,other._catSet)
{
updateIndexList() ;
}
RooMultiCategory::~RooMultiCategory()
{
}
void RooMultiCategory::updateIndexList()
{
clearTypes() ;
RooMultiCatIter iter(_catSet) ;
TObjString* obj ;
while((obj=(TObjString*)iter.Next())) {
defineType(obj->String()) ;
}
setValueDirty() ;
}
TString RooMultiCategory::currentLabel() const
{
TIterator* lIter = _catSet.createIterator() ;
TString label ;
RooAbsCategory* cat ;
Bool_t first(kTRUE) ;
while((cat=(RooAbsCategory*) lIter->Next())) {
label.Append(first?"{":";") ;
label.Append(cat->getLabel()) ;
first=kFALSE ;
}
label.Append("}") ;
delete lIter ;
return label ;
}
RooCatType RooMultiCategory::evaluate() const
{
if (isShapeDirty()) const_cast<RooMultiCategory*>(this)->updateIndexList() ;
return *lookupType(currentLabel()) ;
}
void RooMultiCategory::printMultiline(ostream& os, Int_t content, Bool_t verbose, TString indent) const
{
RooAbsCategory::printMultiline(os,content,verbose,indent) ;
if (verbose) {
os << indent << "--- RooMultiCategory ---" << endl;
os << indent << " Input category list:" << endl ;
TString moreIndent(indent) ;
moreIndent.Append(" ") ;
_catSet.printStream(os,kName|kValue,kStandard,moreIndent.Data()) ;
}
}
Bool_t RooMultiCategory::readFromStream(istream& , Bool_t , Bool_t )
{
return kTRUE ;
}
void RooMultiCategory::writeToStream(ostream& os, Bool_t compact) const
{
RooAbsCategory::writeToStream(os,compact) ;
}