Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PodioExample #352

Merged
merged 10 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ccpp-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Other examples
run: |
export LD_LIBRARY_PATH=/app/podio/install/lib:$LD_LIBRARY_PATH
ctest --test-dir build --output-on-failure -R "jana-example-dst-tests|jana-example-tutorial-tests|jana-example-eventgroup-tests|jana-example-unit-tests"
ctest --test-dir build --output-on-failure -R "jana-example-dst-tests|jana-example-tutorial-tests|jana-example-eventgroup-tests|jana-example-unit-tests|jana-example-podio-tests"



Expand Down
3 changes: 3 additions & 0 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ add_subdirectory(EventGroupExample)
add_subdirectory(SubeventExample)
add_subdirectory(SubeventCUDAExample)
add_subdirectory(UnitTestingExample)
add_subdirectory(PodioDatamodel)
add_subdirectory(PodioFileReader)
add_subdirectory(PodioFileWriter)
add_subdirectory(PodioExample)
add_subdirectory(TimesliceExample)
add_subdirectory(RootDatamodelExample)
Expand Down
35 changes: 35 additions & 0 deletions src/examples/PodioDatamodel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

if (USE_PODIO)

PODIO_GENERATE_DATAMODEL(PodioDatamodel datamodel.yaml headers sources
IO_BACKEND_HANDLERS ROOT
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)

PODIO_ADD_DATAMODEL_CORE_LIB(PodioDatamodel "${headers}" "${sources}"
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR})

PODIO_ADD_ROOT_IO_DICT(PodioDatamodelDict PodioDatamodel "${headers}"
${CMAKE_CURRENT_BINARY_DIR}/src/selection.xml)

install(TARGETS PodioDatamodel
EXPORT jana2_targets
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/JANA/examples/PodioDatamodel
)

install(TARGETS PodioDatamodelDict
EXPORT jana2_targets
DESTINATION lib
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PodioDatamodelDictDict.rootmap DESTINATION lib)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libPodioDatamodelDict_rdict.pcm DESTINATION lib)

else()
message(STATUS "Skipping examples/PodioDatamodel because USE_PODIO=Off")

endif()



11 changes: 11 additions & 0 deletions src/examples/PodioDatamodel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

PodioDatamodel
==============

This example shows how to define and integrate a PODIO data model within a JANA project.
The entire data model is defined within a single YAML file. The generated files can be found
in the build directory. The headers are installed to `$CMAKE_INSTALL_PREFIX/include/examples/PodioDatamodel`
and the shared library is installed to `$CMAKE_INSTALL_PREFIX/lib`.

This data model is used by `PodioExample`, `TimesliceExample`, and more.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
# A more complete example is provided by podio under tests/datalayout.yaml

schema_version: 1
options :
# should getters / setters be prefixed with get / set?
Expand Down Expand Up @@ -29,12 +27,12 @@ datatypes :
Description : "Example Hit"
Author : "B. Hegner"
Members:
- unsigned long long cellID // cellID
- double x // x-coordinate
- double y // y-coordinate
- double z // z-coordinate
- double energy // measured energy deposit
- uint64_t time // ticks since start of timeframe
- uint64_t cellID // cellID
- double x // x-coordinate
- double y // y-coordinate
- double z // z-coordinate
- double energy // measured energy deposit
- uint64_t time // ticks since start of timeframe

ExampleCluster :
Description : "Cluster"
Expand Down
33 changes: 2 additions & 31 deletions src/examples/PodioExample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,21 @@
set(PodioExample_SOURCES
PodioExample.cc
PodioExampleProcessor.cc
PodioExampleSource.cc
ExampleClusterFactory.cc
ExampleMultifactory.cc
)

if (USE_PODIO)

PODIO_GENERATE_DATAMODEL(PodioExampleDatamodel layout.yaml headers sources
IO_BACKEND_HANDLERS ROOT
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR}
)

PODIO_ADD_DATAMODEL_CORE_LIB(PodioExampleDatamodel "${headers}" "${sources}"
OUTPUT_FOLDER ${CMAKE_CURRENT_BINARY_DIR})

PODIO_ADD_ROOT_IO_DICT(PodioExampleDatamodelDict PodioExampleDatamodel "${headers}"
${CMAKE_CURRENT_BINARY_DIR}/src/selection.xml)

find_package(podio REQUIRED)
add_executable(PodioExample ${PodioExample_SOURCES})
target_link_libraries(PodioExample
jana2 PodioExampleDatamodel PodioExampleDatamodelDict podio::podioRootIO)
PUBLIC jana2 PodioDatamodel PodioDatamodelDict podio::podioRootIO)

set_target_properties(PodioExample PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)

install(TARGETS PodioExample DESTINATION bin)

install(TARGETS PodioExampleDatamodel
EXPORT jana2_targets
LIBRARY DESTINATION lib/JANA/plugins
PUBLIC_HEADER DESTINATION include/JANA/plugins/PodioExampleDatamodel
)

install(TARGETS PodioExampleDatamodelDict
EXPORT jana2_targets
DESTINATION lib/JANA/plugins)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/PodioExampleDatamodelDictDict.rootmap DESTINATION lib/JANA/plugins)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libPodioExampleDatamodelDict_rdict.pcm DESTINATION lib/JANA/plugins)

add_test(NAME jana-example-podio-tests
COMMAND PodioExample)

set_tests_properties(jana-example-podio-tests PROPERTIES DISABLED TRUE)
add_test(NAME jana-example-podio-tests COMMAND PodioExample)

else()
message(STATUS "Skipping examples/PodioExample because USE_PODIO=Off")
Expand Down
72 changes: 0 additions & 72 deletions src/examples/PodioExample/DatamodelGlue.h

This file was deleted.

4 changes: 2 additions & 2 deletions src/examples/PodioExample/ExampleClusterFactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


#include "ExampleClusterFactory.h"
#include "PodioExampleDatamodel/ExampleHit.h"
#include "PodioDatamodel/ExampleClusterCollection.h"
#include "PodioDatamodel/ExampleHitCollection.h"
#include <JANA/JEvent.h>

ExampleClusterFactory::ExampleClusterFactory() {
Expand Down Expand Up @@ -54,4 +55,3 @@ void ExampleClusterFactory::Process(const std::shared_ptr<const JEvent> &event)
}


// TODO: Expose collections as refs, not ptrs?
3 changes: 1 addition & 2 deletions src/examples/PodioExample/ExampleClusterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#define JANA2_EXAMPLECLUSTERFACTORY_H

#include <JANA/Podio/JFactoryPodioT.h>
#include "PodioExampleDatamodel/ExampleCluster.h"
#include "DatamodelGlue.h"
#include "PodioDatamodel/ExampleCluster.h"

class ExampleClusterFactory : public JFactoryPodioT<ExampleCluster> {
public:
Expand Down
3 changes: 2 additions & 1 deletion src/examples/PodioExample/ExampleMultifactory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

#include "ExampleMultifactory.h"
#include <JANA/JEvent.h>
#include "DatamodelGlue.h"
#include <PodioDatamodel/ExampleHitCollection.h>
#include <PodioDatamodel/ExampleClusterCollection.h>

ExampleMultifactory::ExampleMultifactory() {

Expand Down
14 changes: 8 additions & 6 deletions src/examples/PodioExample/PodioExample.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
// Subject to the terms in the LICENSE file found in the top-level directory.
#include <podio/CollectionBase.h>
#include <podio/Frame.h>
#include "PodioExampleDatamodel/MutableExampleHit.h"
#include "PodioExampleDatamodel/ExampleHitCollection.h"

#include "PodioDatamodel/EventInfoCollection.h"
#include "PodioDatamodel/ExampleHitCollection.h"
#include <podio/ROOTFrameWriter.h>
#include <podio/ROOTFrameReader.h>

#include <JANA/JApplication.h>
#include <JANA/JFactoryGenerator.h>
#include <JANA/Podio/JEventProcessorPodio.h>

#include "PodioExampleSource.h"
#include "PodioExampleProcessor.h"
#include "ExampleClusterFactory.h"
#include "ExampleMultifactory.h"
Expand Down Expand Up @@ -79,10 +78,13 @@ int main() {

JApplication app;
app.Add(new PodioExampleProcessor);
app.Add(new JEventProcessorPodio);
app.Add(new JFactoryGeneratorT<ExampleClusterFactory>());
app.Add(new JFactoryGeneratorT<ExampleMultifactory>());
app.Add(new PodioExampleSource("hits.root"));
app.Add("hits.root");
app.AddPlugin("PodioFileReader");
app.AddPlugin("PodioFileWriter");
app.SetParameterValue("podio:output_file", "podio_output.root");
app.SetParameterValue("podio:output_collections", "hits_filtered,clusters_from_hits_filtered,clusters_filtered");
app.Run();

verify_clusters_file();
Expand Down
2 changes: 2 additions & 0 deletions src/examples/PodioExample/PodioExampleProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@


#include "PodioExampleProcessor.h"
#include <PodioDatamodel/ExampleHitCollection.h>
#include <PodioDatamodel/ExampleClusterCollection.h>

/*
struct PrintingVisitor {
Expand Down
1 change: 0 additions & 1 deletion src/examples/PodioExample/PodioExampleProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#define JANA2_PODIOEXAMPLEPROCESSOR_H

#include <JANA/JEventProcessor.h>
#include "DatamodelGlue.h"

class PodioExampleProcessor : public JEventProcessor {
public:
Expand Down
19 changes: 0 additions & 19 deletions src/examples/PodioExample/PodioExampleSource.cc

This file was deleted.

21 changes: 0 additions & 21 deletions src/examples/PodioExample/PodioExampleSource.h

This file was deleted.

15 changes: 15 additions & 0 deletions src/examples/PodioFileReader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

if (USE_PODIO)

add_jana_plugin(PodioFileReader)

target_link_libraries(PodioFileReader
PUBLIC PodioDatamodel PodioDatamodelDict podio::podioRootIO)

else()
message(STATUS "Skipping examples/PodioFileReader because USE_PODIO=Off")

endif()



Loading
Loading