#include "RooFit.h"
#include "Riostream.h"
#include "TMethodCall.h"
#include <stdlib.h>
#include <stdio.h>
#include "TString.h"
#include "Api.h"
#include "RooGenCategory.h"
#include "RooStreamParser.h"
#include "RooMapCatEntry.h"
#include "RooErrorHandler.h"
ClassImp(RooGenCategory)
RooGenCategory::RooGenCategory(const char *name, const char *title, void *userFunc, RooArgSet& catList) :
RooAbsCategory(name, title),
_superCat("superCat","Super Category",catList),
_superCatProxy("superCatProxy","Super Category Proxy",this,_superCat),
_map(0)
{
_userFuncName = G__p2f2funcname(userFunc);
if(_userFuncName.IsNull()) {
cout << GetName() << ": cannot find dictionary info for (void*)"
<< (void*)userFunc << endl;
return;
}
initialize() ;
}
RooGenCategory::RooGenCategory(const RooGenCategory& other, const char *name) :
RooAbsCategory(other,name), _superCat(other._superCat),
_superCatProxy("superCatProxy","Super Category Proxy",this,_superCat),
_map(0), _userFuncName(other._userFuncName)
{
removeServer((RooAbsArg&)other._superCat) ;
initialize() ;
}
void RooGenCategory::initialize()
{
addServer(_superCat,kTRUE,kTRUE) ;
_userFunc= new TMethodCall();
_userFunc->InitWithPrototype(_userFuncName.Data(),"RooArgSet*");
updateIndexList() ;
}
RooGenCategory::~RooGenCategory()
{
if (_serverList.FindObject(&_superCat)) {
removeServer(_superCat) ;
}
if (_map) delete[] _map ;
}
TString RooGenCategory::evalUserFunc(RooArgSet *vars)
{
assert(0 != _userFunc);
Long_t result;
_userArgs[0]= (Long_t)vars ;
_userFunc->SetParamPtrs(_userArgs);
_userFunc->Execute(result);
const char *text= (const char *)result;
return TString(text);
}
void RooGenCategory::updateIndexList()
{
if (_map) delete[] _map ;
_map = new Int_t[_superCatProxy.arg().numTypes()] ;
clearTypes() ;
RooArgSet* tmp=(RooArgSet*) RooArgSet(_superCatProxy.arg()).snapshot(kTRUE) ;
if (!tmp) {
cout << "RooGenCategory::updateIndexList(" << GetName() << ") Couldn't deep-clone super category, abort," << endl ;
RooErrorHandler::softAbort() ;
}
RooSuperCategory* superClone = (RooSuperCategory*) tmp->find(_superCatProxy.arg().GetName()) ;
TIterator* sIter = superClone->typeIterator() ;
RooArgSet *catList = superClone->getParameters((const RooArgSet*)0) ;
RooCatType* type ;
while ((type=(RooCatType*)sIter->Next())) {
superClone->setIndex(type->getVal()) ;
TString typeName = evalUserFunc(catList) ;
const RooCatType* type = lookupType(typeName,kFALSE) ;
if (!type) type = defineType(typeName) ;
_map[superClone->getIndex()] = type->getVal() ;
}
delete tmp ;
delete catList ;
}
RooCatType
RooGenCategory::evaluate() const
{
if (isShapeDirty()) {
const_cast<RooGenCategory*>(this)->updateIndexList() ;
}
const RooCatType* ret = lookupType(_map[(Int_t)_superCatProxy]) ;
if (!ret) {
cout << "RooGenCategory::evaluate(" << GetName() << ") ERROR: cannot lookup super index " << (Int_t) _superCatProxy << endl ;
assert(0) ;
}
return *ret ;
}
void RooGenCategory::printToStream(ostream& os, PrintOption opt, TString indent) const
{
RooAbsCategory::printToStream(os,opt,indent);
if (opt>=Verbose) {
os << indent << "--- RooGenCategory ---" << endl;
os << indent << " Input category list:" << endl ;
TString moreIndent(indent) ;
indent.Append(" ") ;
((RooSuperCategory&)_superCatProxy.arg()).inputCatList().printToStream(os,OneLine) ;
os << indent << " User mapping function is 'const char* " << _userFuncName << "(RooArgSet*)'" << endl ;
}
}
Bool_t RooGenCategory::readFromStream(istream& , Bool_t compact, Bool_t )
{
if (compact) {
cout << "RooGenCategory::readFromSteam(" << GetName() << "): can't read in compact mode" << endl ;
return kTRUE ;
} else {
return kFALSE ;
}
}
void RooGenCategory::writeToStream(ostream& os, Bool_t compact) const
{
if (compact) {
os << getLabel() ;
} else {
}
}
ROOT page - Class index - Class Hierarchy - Top of the page
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.