Skip to content

Commit

Permalink
moving data dictionary generation to rootcling
Browse files Browse the repository at this point in the history
  • Loading branch information
hegner committed Jul 21, 2023
1 parent eb55717 commit 7a706b1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 67 deletions.
38 changes: 13 additions & 25 deletions cmake/podioMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -260,58 +260,46 @@ endfunction()


#---------------------------------------------------------------------------------------------------
#---PODIO_ADD_ROOT_IO_DICT( dict_name CORE_LIB HEADERS SELECTION_XML
#---PODIO_ADD_ROOT_IO_DICT( dict_name CORE_LIB HEADERS LINKDEF
# OUTPUT_FOLDER output_directory
# )
#
# Conditionally add the ROOT dictionary to the targets if the corresponding
# selection xml has been generated by PODIO_GENERATE_DATAMODEL.
# linkdef file has been generated by PODIO_GENERATE_DATAMODEL.
#
# Arguments:
# dict_name Name of the dictionary
# CORE_LIB The core datamodel library (e.g. from PODIO_ADD_DATAMODEL_CORE_LIB)
# HEADERS The list of all header files generated by PODIO_GENERATE_DATAMODEL
# SELECTION_XML The selection.xml file genertaed by PODIO_GENERATE_DATAMODEL (either an absolute path or relative to OUTPUT_FOLDER)
# LINKDEF The LinkDef.h file genertaed by PODIO_GENERATE_DATAMODEL (either an absolute path or relative to OUTPUT_FOLDER)
#
# Parameters:
# OUTPUT_FOLDER OPTIONAL: The folder in which the output files have been placed by PODIO_GENERATE_DATAMODEL. Defaults to ${CMAKE_CURRENT_SOURCE_DIR}
#---------------------------------------------------------------------------------------------------
function(PODIO_ADD_ROOT_IO_DICT dict_name CORE_LIB HEADERS SELECTION_XML)
function(PODIO_ADD_ROOT_IO_DICT dict_name CORE_LIB HEADERS LINKDEF)
CMAKE_PARSE_ARGUMENTS(ARG "" "OUTPUT_FOLDER" "" ${ARGN})
IF(NOT ARG_OUTPUT_FOLDER)
SET(ARG_OUTPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR})
ENDIF()

IF(IS_ABSOLUTE ${SELECTION_XML})
set(selectionfile ${SELECTION_XML})
IF(IS_ABSOLUTE ${LINKDEF})
set(selectionfile ${LINKDEF})
ELSE()
set(selectionfile ${ARG_OUTPUT_FOLDER}/${SELECTION_XML})
set(selectionfile ${ARG_OUTPUT_FOLDER}/${LINKDEF})
ENDIF()

# Make sure the LinkDef file is not in the list of headers
LIST(FILTER HEADERS EXCLUDE REGEX .*LinkDef.h)

IF (NOT EXISTS ${selectionfile})
message(STATUS "Not adding the ROOT dictionaries for ${CORE_LIB}, because \'${selectionfile}\' does not exist")
RETURN()
ENDIF()

# Filter out anything I/O backend related from the generated headers as ROOT only needs
# the core headers
LIST(FILTER HEADERS EXCLUDE REGEX .*SIOBlock.h)

add_library(${dict_name} SHARED)
target_link_libraries(${dict_name} PUBLIC
${CORE_LIB}
podio::podio
ROOT::Core
)
target_include_directories(${dict_name} PUBLIC
$<BUILD_INTERFACE:${ARG_OUTPUT_FOLDER}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
ROOT_GENERATE_DICTIONARY(${dict_name} ${HEADERS} LINKDEF ${selectionfile}
MODULE ${CORE_LIB}
)
PODIO_GENERATE_DICTIONARY(${dict_name} ${HEADERS} SELECTION ${selectionfile}
OPTIONS --library ${CMAKE_SHARED_LIBRARY_PREFIX}${dict_name}${CMAKE_SHARED_LIBRARY_SUFFIX}
)
set_target_properties(${dict_name}-dictgen PROPERTIES EXCLUDE_FROM_ALL TRUE)
add_dependencies(${dict_name} ${CORE_LIB})

endfunction()

#---------------------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def process(self):
self._write_edm_def_file()

if 'ROOT' in self.io_handlers:
self._create_selection_xml()
self._create_ROOT_dictionary_selection()

self._write_cmake_lists_file()
self.process_schema_evolution()
Expand Down Expand Up @@ -482,13 +482,13 @@ def _needs_include(self, classname) -> IncludeFrom:

return IncludeFrom.NOWHERE

def _create_selection_xml(self):
def _create_ROOT_dictionary_selection(self):
"""Create the selection xml that is necessary for ROOT I/O"""
data = {'components': [DataType(c) for c in self.datamodel.components],
'datatypes': [DataType(d) for d in self.datamodel.datatypes],
'old_schema_components': [DataType(d) for d in
self.old_datamodels_datatypes | self.old_datamodels_components]}
self._write_file('selection.xml', self._eval_template('selection.xml.jinja2', data))
self._write_file('LinkDef.h', self._eval_template('DictLinkDef.h.jinja2', data))

def _build_include(self, member):
"""Return the include statment for the passed member."""
Expand Down
18 changes: 16 additions & 2 deletions python/templates/DictLinkDef.h.jinja2
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{% macro class_selection(class, prefix='', postfix='') %}
{%- if class.namespace %}
#pragma link C++ class {{ class.namespace }}::{{ class.bare_type }}{{ postfix }}+;
{%- else %}
#pragma link C++ class {{ class.bare_type }}{{ postfix }}+;
{%- endif %}
{% endmacro %}
// See: https://root.cern.ch/selecting-dictionary-entries-linkdefh
#ifdef __CINT__

Expand All @@ -7,7 +14,14 @@
#pragma link C++ nestedclasses;

{% for class in components %}
#pragma link C++ class {{ class }}
{{ class_selection(class) }}
{% endfor %}

#endif
{% for class in datatypes %}
{{ class_selection(class) }}
{{ class_selection(class, postfix='Data') }}
{{ class_selection(class, postfix='Collection') }}
{% endfor %}

#endif

34 changes: 0 additions & 34 deletions python/templates/selection.xml.jinja2

This file was deleted.

39 changes: 39 additions & 0 deletions src/DictLinkDef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifdef __CLING__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;

#pragma link C++ class podio::GenericParameters+;
#pragma link C++ class podio::GenericParameters::MapType<int>+;
#pragma link C++ class podio::GenericParameters::MapType<float>+;
#pragma link C++ class podio::GenericParameters::MapType<double>+;
#pragma link C++ class podio::GenericParameters::MapType<std::string>+;
#pragma link C++ class podio::GenericParameters+;
#pragma link C++ class std::map<int,podio::GenericParameters>+;
#pragma link C++ class std::vector<std::tuple<int, std::string, bool, unsigned int>>+;
#pragma link C++ class std::vector<std::tuple<int, std::string, bool, unsigned>>+;
#pragma link C++ class std::vector<std::tuple<int, std::string, bool>>+;
#pragma link C++ class std::vector<std::tuple<std::string, std::string>>+;
#pragma link C++ class std::vector<std::tuple<uint32_t, std::string, bool, unsigned int>>+;
#pragma link C++ class std::vector<std::tuple<uint32_t, std::string, bool, unsigned>>+;
#pragma link C++ class std::vector<std::tuple<uint32_t, std::string, bool>>+;
#pragma link C++ class podio::CollectionBase+;
#pragma link C++ class podio::CollectionIDTable+;
#pragma link C++ class podio::version::Version+;
#pragma link C++ class podio::ObjectID+;
#pragma link C++ class vector<podio::ObjectID>+;
#pragma link C++ class podio::UserDataCollection<float>+;
#pragma link C++ class podio::UserDataCollection<double>+;
#pragma link C++ class podio::UserDataCollection<int8_t>+;
#pragma link C++ class podio::UserDataCollection<int16_t>+;
#pragma link C++ class podio::UserDataCollection<int32_t>+;
#pragma link C++ class podio::UserDataCollection<int64_t>+;
#pragma link C++ class podio::UserDataCollection<uint8_t>+;
#pragma link C++ class podio::UserDataCollection<uint16_t>+;
#pragma link C++ class podio::UserDataCollection<uint32_t>+;
#pragma link C++ class podio::UserDataCollection<uint64_t>+;

#endif

2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (nlohmann_json_FOUND)
target_link_libraries(TestDataModel PUBLIC nlohmann_json::nlohmann_json)
endif()

PODIO_ADD_ROOT_IO_DICT(TestDataModelDict TestDataModel "${headers}" src/selection.xml)
PODIO_ADD_ROOT_IO_DICT(TestDataModelDict TestDataModel "${headers}" datamodel/LinkDef.h)
PODIO_ADD_SIO_IO_BLOCKS(TestDataModel "${headers}" "${sources}")

# Build the extension data model and link it against the upstream model
Expand Down
4 changes: 2 additions & 2 deletions tests/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(root_dependent_tests
read_frame_legacy_root.cpp
read_frame_root_multiple.cpp
)
set(root_libs TestDataModelDict ExtensionDataModelDict podio::podioRootIO)
set(root_libs podio::podioRootIO)
foreach( sourcefile ${root_dependent_tests} )
CREATE_PODIO_TEST(${sourcefile} "${root_libs}")
endforeach()
Expand All @@ -37,7 +37,7 @@ set_property(TEST check_benchmark_outputs PROPERTY DEPENDS read_timed write_time
if (DEFINED CACHE{PODIO_TEST_INPUT_DATA_DIR})
message(STATUS "Using test inputs stored in: " ${PODIO_TEST_INPUT_DATA_DIR})
add_executable(read-legacy-files-root read-legacy-files-root.cpp)
target_link_libraries(read-legacy-files-root PRIVATE TestDataModel TestDataModelDict podio::podioRootIO)
target_link_libraries(read-legacy-files-root PRIVATE TestDataModel podio::podioRootIO)

# Add a legacy test case based on a base executable and a version for which an
# input file exists
Expand Down

0 comments on commit 7a706b1

Please sign in to comment.