Skip to content

Commit

Permalink
[RF] Dispatching via interpreter for RooFit code generation
Browse files Browse the repository at this point in the history
Use dispatching via interpreter for code generation, so that the code
generation methods can be defined in any place (also user frameworks).

This also includes a priority mechanism for easy overriding.
  • Loading branch information
guitargeek committed Nov 18, 2024
1 parent 969e975 commit cfdeddf
Show file tree
Hide file tree
Showing 98 changed files with 1,472 additions and 1,087 deletions.
1 change: 1 addition & 0 deletions roofit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
set(roofit_legacy_eval_backend ON CACHE BOOL "" FORCE)

add_subdirectory(batchcompute)
add_subdirectory(codegen)
if (roofit_multiprocess)
add_subdirectory(roofitZMQ)
add_subdirectory(multiprocess)
Expand Down
23 changes: 23 additions & 0 deletions roofit/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.
# All rights reserved.
#
# For the licensing terms see $ROOTSYS/LICENSE.
# For the list of contributors see $ROOTSYS/README/CREDITS.

############################################################################
# CMakeLists.txt file for building ROOT rootfit/histfactory package
# @author Pere Mato, CERN
############################################################################

ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCodegen
HEADERS
RooFit/CodegenImpl.h
SOURCES
src/CodegenImpl.cxx
DICTIONARY_OPTIONS
"-writeEmptyRootPCM"
DEPENDENCIES
RooFit
RooFitCore
HistFactory
)
7 changes: 7 additions & 0 deletions roofit/codegen/LinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifdef __CLING__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#endif
155 changes: 155 additions & 0 deletions roofit/codegen/inc/RooFit/CodegenImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Project: RooFit
* Authors:
* Jonas Rembser, CERN 2024
*
* Copyright (c) 2024, CERN
*
* 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)
*/

#ifndef RooFit_Detail_CodegenImpl_h
#define RooFit_Detail_CodegenImpl_h

#include <RooFit/CodegenContext.h>

#include <type_traits>

class ParamHistFunc;
class PiecewiseInterpolation;
class RooAbsArg;
class RooAbsReal;
class RooAddPdf;
class RooAddition;
class RooBernstein;
class RooBifurGauss;
class RooCBShape;
class RooChebychev;
class RooConstVar;
class RooConstraintSum;
class RooEffProd;
class RooEfficiency;
class RooExponential;
class RooExtendPdf;
class RooFormulaVar;
class RooGamma;
class RooGaussian;
class RooGenericPdf;
class RooHistFunc;
class RooHistPdf;
class RooLandau;
class RooLognormal;
class RooMultiVarGaussian;
class RooParamHistFunc;
class RooPoisson;
class RooPolyVar;
class RooPolynomial;
class RooProduct;
class RooRatio;
class RooRealIntegral;
class RooRealSumFunc;
class RooRealSumPdf;
class RooRealVar;
class RooRecursiveFraction;
class RooUniform;

namespace RooStats {
namespace HistFactory {
class FlexibleInterpVar;
}
} // namespace RooStats

namespace RooFit {

namespace Detail {
class RooFixedProdPdf;
class RooNLLVarNew;
class RooNormalizedPdf;
} // namespace Detail

class CodegenContext;

void codegenImpl(Detail::RooFixedProdPdf &arg, CodegenContext &ctx);
void codegenImpl(Detail::RooNLLVarNew &arg, CodegenContext &ctx);
void codegenImpl(Detail::RooNormalizedPdf &arg, CodegenContext &ctx);
void codegenImpl(ParamHistFunc &arg, CodegenContext &ctx);
void codegenImpl(PiecewiseInterpolation &arg, CodegenContext &ctx);
void codegenImpl(RooAbsArg &arg, RooFit::CodegenContext &ctx);
void codegenImpl(RooAddPdf &arg, CodegenContext &ctx);
void codegenImpl(RooAddition &arg, CodegenContext &ctx);
void codegenImpl(RooBernstein &arg, CodegenContext &ctx);
void codegenImpl(RooBifurGauss &arg, CodegenContext &ctx);
void codegenImpl(RooCBShape &arg, CodegenContext &ctx);
void codegenImpl(RooChebychev &arg, CodegenContext &ctx);
void codegenImpl(RooConstVar &arg, CodegenContext &ctx);
void codegenImpl(RooConstraintSum &arg, CodegenContext &ctx);
void codegenImpl(RooEffProd &arg, CodegenContext &ctx);
void codegenImpl(RooEfficiency &arg, CodegenContext &ctx);
void codegenImpl(RooExponential &arg, CodegenContext &ctx);
void codegenImpl(RooExtendPdf &arg, CodegenContext &ctx);
void codegenImpl(RooFormulaVar &arg, CodegenContext &ctx);
void codegenImpl(RooGamma &arg, CodegenContext &ctx);
void codegenImpl(RooGaussian &arg, CodegenContext &ctx);
void codegenImpl(RooGenericPdf &arg, CodegenContext &ctx);
void codegenImpl(RooHistFunc &arg, CodegenContext &ctx);
void codegenImpl(RooHistPdf &arg, CodegenContext &ctx);
void codegenImpl(RooLandau &arg, CodegenContext &ctx);
void codegenImpl(RooLognormal &arg, CodegenContext &ctx);
void codegenImpl(RooMultiVarGaussian &arg, CodegenContext &ctx);
void codegenImpl(RooParamHistFunc &arg, CodegenContext &ctx);
void codegenImpl(RooPoisson &arg, CodegenContext &ctx);
void codegenImpl(RooPolyVar &arg, CodegenContext &ctx);
void codegenImpl(RooPolynomial &arg, CodegenContext &ctx);
void codegenImpl(RooProduct &arg, CodegenContext &ctx);
void codegenImpl(RooRatio &arg, CodegenContext &ctx);
void codegenImpl(RooRealIntegral &arg, CodegenContext &ctx);
void codegenImpl(RooRealSumFunc &arg, CodegenContext &ctx);
void codegenImpl(RooRealSumPdf &arg, CodegenContext &ctx);
void codegenImpl(RooRealVar &arg, CodegenContext &ctx);
void codegenImpl(RooRecursiveFraction &arg, CodegenContext &ctx);
void codegenImpl(RooStats::HistFactory::FlexibleInterpVar &arg, CodegenContext &ctx);
void codegenImpl(RooUniform &arg, CodegenContext &ctx);

std::string codegenIntegralImpl(RooAbsReal &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooBernstein &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooBifurGauss &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooCBShape &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooChebychev &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooEfficiency &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooExponential &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooGamma &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooGaussian &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooHistFunc &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooHistPdf &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooLandau &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooLognormal &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooMultiVarGaussian &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooPoisson &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooPolyVar &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooPolynomial &arg, int code, const char *rangeName, CodegenContext &ctx);
std::string codegenIntegralImpl(RooUniform &arg, int code, const char *rangeName, CodegenContext &ctx);

template <class Arg_t, int P>
std::string codegenIntegralImpl(Arg_t &arg, int code, const char *rangeName, CodegenContext &ctx, Prio<P> p)
{
if constexpr (std::is_same<Prio<P>, PrioLowest>::value) {
return codegenIntegralImpl(arg, code, rangeName, ctx);
} else {
return codegenIntegralImpl(arg, code, rangeName, ctx, p.next());
}
}

template <class Arg_t>
struct CodegenIntegralImplCaller {

static auto call(RooAbsReal &arg, int code, const char *rangeName, RooFit::CodegenContext &ctx)
{
return codegenIntegralImpl(static_cast<Arg_t &>(arg), code, rangeName, ctx, PrioHighest{});
}
};

} // namespace RooFit

#endif
Loading

0 comments on commit cfdeddf

Please sign in to comment.