diff --git a/Event/CMakeLists.txt b/Event/CMakeLists.txt index 1d1685895f6cf3248944b8e04bd6266dea9f3120..ebed641c1659879bf1c69bb256d9f80899c3b0d6 100644 --- a/Event/CMakeLists.txt +++ b/Event/CMakeLists.txt @@ -37,7 +37,7 @@ 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) +target_link_libraries(EventDict Event ROOT::Core) install(TARGETS EventDict DESTINATION lib) # Headers and Libraries @@ -53,6 +53,9 @@ 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) +add_executable( read tests/read.cpp ) +target_link_libraries( read EventDict ) +install(TARGETS read DESTINATION tests) +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/read.cpp b/Event/tests/read.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0daaec8ff15b3088fc302cc0991cb2a4b8f1beea --- /dev/null +++ b/Event/tests/read.cpp @@ -0,0 +1,54 @@ +#include "EventHeaderCollection.h" +#include "MCParticleCollection.h" + +#include "podio/EventStore.h" +#include "podio/ROOTReader.h" + +int main(int argc, char* argv[]) +{ + auto reader = podio::ROOTReader(); + auto store = podio::EventStore(); + + reader.openFile("test.root"); + store.setReader(&reader); + + unsigned int nEvt = reader.getEntries(); + + for (unsigned int i = 0; i < nEvt; ++i ) { + //if ( i%10 == 0 ) { + // std::cout << "processing event " << i << std::endl; + //} + + auto& hds = store.get<plcio::EventHeaderCollection>("EvtHeaders"); + if ( hds.isValid() ) { + auto header = hds[0]; + std::cout << "processing event " << header.getEventNumber() << std::endl; + } + else { + return -1; + } + + auto& mcc = store.get<plcio::MCParticleCollection>("MCParticles"); + if ( ! mcc.isValid() ) { + return -1; + } + for ( auto p : mcc ) { + std::cout << " particle " << p.getObjectID().index << " has daughters: "; + for ( auto it = p.daughters_begin(), end = p.daughters_end(); it != end; ++it ) { + std::cout << " " << it->getObjectID().index; + } + std::cout << " and parents: "; + for ( auto it = p.parents_begin(), end = p.parents_end(); it != end ; ++it ){ + std::cout << " " << it->getObjectID().index; + } + std::cout << std::endl; + } + + store.clear(); + reader.endOfEvent(); + } + + reader.closeFile(); + + return 0; +} diff --git a/Event/tests/write.cpp b/Event/tests/write.cpp index 68109a85bd4c7518820b51048bfd3658ca993b05..539c13586543df2a8e8d1762db9ecc37c2903053 100644 --- a/Event/tests/write.cpp +++ b/Event/tests/write.cpp @@ -9,7 +9,7 @@ int main(int argc, char* argv[]) { - std::cout << "start writing test" << std::endl; + //std::cout << "start writing test" << std::endl; auto store = podio::EventStore(); auto writer = podio::ROOTWriter("test.root", &store); @@ -23,13 +23,38 @@ int main(int argc, char* argv[]) const unsigned int nEvt = 100; for ( unsigned int i = 0; i < nEvt; ++i ) { - if ( i%10 == 0 ) { + //if ( i%10 == 0 ) { std::cout << "processing event " << i << std::endl; - } + //} auto header = plcio::EventHeader(i, -99, 9999, "SimDet"); ehc.push_back(header); + for ( unsigned int i = 0; i < 10; ++i ) { + mcc.create(); + } + + for ( unsigned int i = 0; i < 4; ++i ) { + auto p = mcc[i]; + for ( unsigned int j = 0; j < 4; ++j ) { + unsigned int idx = (2+j) + (i/2)*4; + p.addDaughter( mcc[idx] ); + mcc[idx].addParent( p ); + } + } + + for ( auto p : mcc ) { + std::cout << " particle " << p.getObjectID().index << " has daughters: "; + for ( auto it = p.daughters_begin(), end = p.daughters_end(); it != end; ++it ) { + std::cout << " " << it->getObjectID().index; + } + std::cout << " and parents: "; + for ( auto it = p.parents_begin(), end = p.parents_end(); it != end ; ++it ){ + std::cout << " " << it->getObjectID().index; + } + std::cout << std::endl; + } + ////////// writer.writeEvent(); store.clearCollections();