diff --git a/Event/CMakeLists.txt b/Event/CMakeLists.txt index bb764a76068a9638433cf1f5846633c302b4e9bb..1d1685895f6cf3248944b8e04bd6266dea9f3120 100644 --- a/Event/CMakeLists.txt +++ b/Event/CMakeLists.txt @@ -30,13 +30,15 @@ file(GLOB headers Event/*.h) include_directories(Event) # Dictionary and Modules +add_library(Event SHARED ${sources} ${headers}) +target_link_libraries(Event podio) +install(TARGETS Event DESTINATION lib) + REFLEX_GENERATE_DICTIONARY(Event ${headers} SELECTION src/selection.xml) add_library(EventDict SHARED Event.cxx) add_dependencies(EventDict Event-dictgen) -target_link_libraries(EventDict Event ROOT::Core) - -add_library(Event SHARED ${sources} ${headers}) -target_link_libraries(Event podio ROOT::RIO ROOT::Tree) +target_link_libraries(EventDict Event) +install(TARGETS EventDict DESTINATION lib) # Headers and Libraries gaudi_install_headers(Event) @@ -44,6 +46,13 @@ gaudi_install_headers(Event) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/EventDict.rootmap DESTINATION lib) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Event_rdict.pcm DESTINATION lib) -# Unit tests -#gaudi_add_test(HelloAlg -# FRAMEWORK options/helloalg.py) +# tests +add_executable( write tests/write.cpp ) +target_link_libraries( write EventDict ) +install(TARGETS write DESTINATION tests) +add_test(NAME write COMMAND write) +set_property(TEST write PROPERTY ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:$ENV{LD_LIBRARY_PATH}) + +#add_test(NAME read COMMAND read) +#set_property(TEST read PROPERTY ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:$ENV{LD_LIBRARY_PATH}) +#set_property(TEST read PROPERTY DEPENDS write) diff --git a/Event/tests/write.cpp b/Event/tests/write.cpp new file mode 100644 index 0000000000000000000000000000000000000000..68109a85bd4c7518820b51048bfd3658ca993b05 --- /dev/null +++ b/Event/tests/write.cpp @@ -0,0 +1,41 @@ +#include "EventHeaderCollection.h" +#include "MCParticleCollection.h" + +#include "podio/EventStore.h" +#include "podio/ROOTWriter.h" + +#include <vector> +#include <iostream> + +int main(int argc, char* argv[]) +{ + std::cout << "start writing test" << std::endl; + + auto store = podio::EventStore(); + auto writer = podio::ROOTWriter("test.root", &store); + + auto& ehc = store.create<plcio::EventHeaderCollection>("EvtHeaders"); + auto& mcc = store.create<plcio::MCParticleCollection>("MCParticles"); + + writer.registerForWrite("EvtHeaders"); + writer.registerForWrite("MCParticles"); + + const unsigned int nEvt = 100; + + for ( unsigned int i = 0; i < nEvt; ++i ) { + if ( i%10 == 0 ) { + std::cout << "processing event " << i << std::endl; + } + + auto header = plcio::EventHeader(i, -99, 9999, "SimDet"); + ehc.push_back(header); + + ////////// + writer.writeEvent(); + store.clearCollections(); + } + + writer.finish(); + + return 0; +}