Skip to content
Snippets Groups Projects
Commit 86112aed authored by zoujh@ihep.ac.cn's avatar zoujh@ihep.ac.cn
Browse files

add reading test for plcio

parent fcd6ddd1
No related branches found
No related tags found
No related merge requests found
......@@ -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)
#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;
}
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment