Skip to content

Commit

Permalink
Adding the functionality to include analysis specific c++ code to CROWN
Browse files Browse the repository at this point in the history
  • Loading branch information
a-monsch committed Dec 10, 2024
1 parent e3d9f70 commit ca1396f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cmake/ConfigureCrownlib.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# build a shared lib from all CROWN functions
include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${CMAKE_SOURCE_DIR}/include)

include_directories(${CMAKE_SOURCE_DIR}/analysis_configurations/*/cpp_addons/src)
include_directories(${CMAKE_SOURCE_DIR}/analysis_configurations/*/cpp_addons/include)

file(GLOB SOURCES_1 ${CMAKE_SOURCE_DIR}/src/*.cxx)
file(GLOB SOURCES_2 ${CMAKE_SOURCE_DIR}/src/utility/*.cxx
${CMAKE_SOURCE_DIR}/src/RecoilCorrections/*.cxx
${CMAKE_SOURCE_DIR}/src/SVFit/*.cxx)
set(SOURCES ${SOURCES_1} ${SOURCES_2})

file(GLOB SOURCES_3 ${CMAKE_SOURCE_DIR}/analysis_configurations/*/cpp_addons/src/*.cxx)

set(SOURCES ${SOURCES_1} ${SOURCES_2} ${SOURCES_3})

if(BUILD_CROWNLIB_ONLY)
message(STATUS "Building only the CROWNLIB library")
Expand Down
2 changes: 2 additions & 0 deletions code_generation/analysis_template.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "include/triggers.hxx"
#include "include/fakefactors.hxx"

// {INCLUDE_ANALYSISADDONS}

// {INCLUDES}

int main(int argc, char *argv[]) {
Expand Down
3 changes: 3 additions & 0 deletions code_generation/analysis_template_friends.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "include/topreco.hxx"
#include "include/triggers.hxx"
#include "include/tripleselection.hxx"

// {INCLUDE_ANALYSISADDONS}

// {INCLUDES}

int validate_rootfile(std::string file, std::string &basetree) {
Expand Down
11 changes: 11 additions & 0 deletions code_generation/code_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ def load_template(self, template_path: str) -> str:
template = template_file.read()
return template

def addon_includes(self):
path = f"analysis_configurations/{self.analysis_name}/cpp_addons/include"
if os.path.exists(path) and os.path.isdir(path) and os.listdir(path):
log.info(f"Adding addons from {path}: {' '.join(os.listdir(path))}")
paths = "\n".join(f'#include "{os.path.join(path, item)}"' for item in os.listdir(path))
return paths
else:
log.info(f"No addons found in {path}")
return ""

def write_code(self, calls: str, includes: str, run_commands: str) -> None:
"""
Write the code of the main executable to the output folder
Expand All @@ -350,6 +360,7 @@ def write_code(self, calls: str, includes: str, run_commands: str) -> None:
" // {ZERO_EVENTS_FALLBACK}", self.zero_events_fallback()
)
.replace(" // {CODE_GENERATION}", calls)
.replace("// {INCLUDE_ANALYSISADDONS}", self.addon_includes())
.replace("// {INCLUDES}", includes)
.replace(" // {RUN_COMMANDS}", run_commands)
.replace("// {MULTITHREADING}", threadcall)
Expand Down
3 changes: 3 additions & 0 deletions code_generation/subset_template.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "include/topreco.hxx"
#include "include/triggers.hxx"
#include "include/fakefactors.hxx"

// {INCLUDE_ANALYSISADDONS}

ROOT::RDF::RNode {subsetname} (ROOT::RDF::RNode df0, OnnxSessionManager &onnxSessionManager, correctionManager::CorrectionManager &correctionManager) {

// { commands }
Expand Down

0 comments on commit ca1396f

Please sign in to comment.