From 17c5c4c15aa996253d8605e2c3ae28d2c30b162d Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Tue, 16 Nov 2021 16:06:14 +0100 Subject: [PATCH 1/2] Add an EmptyEventCreator data source for testing and examples --- source/include/marlin/EmptyEventCreator.h | 38 +++++++++++++++++++++ source/src/EmptyEventCreator.cc | 40 +++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 source/include/marlin/EmptyEventCreator.h create mode 100644 source/src/EmptyEventCreator.cc diff --git a/source/include/marlin/EmptyEventCreator.h b/source/include/marlin/EmptyEventCreator.h new file mode 100644 index 0000000..fd9f3ad --- /dev/null +++ b/source/include/marlin/EmptyEventCreator.h @@ -0,0 +1,38 @@ +#ifndef EmptyEventCreator_h +#define EmptyEventCreator_h 1 + +#include "marlin/DataSourceProcessor.h" + +namespace marlin { + +/** Creates empty LCIO Events that can then be populated by other processors. + * Useful for testing purposes and examples, where having a dedicated input + * just for "getting the event loop going" is not always practical. This needs + * to be the first active processor and additionally requires that there are no + * LCIO input collections present (i.e. make sure to not set the + * LCIOInputFiles parameter). + * + *

Input

+ * None + * + *

Output + * an empty LCEvent + * + * @author: T. Madlener, DESY + */ +class EmptyEventCreator : public DataSourceProcessor { +public: + EmptyEventCreator(); + + marlin::Processor* newProcessor() override { return new EmptyEventCreator; } + + void readDataSource(int numEvents) override; + void init() override; + +private: + int m_eventNumber{0}; +}; + +} + +#endif diff --git a/source/src/EmptyEventCreator.cc b/source/src/EmptyEventCreator.cc new file mode 100644 index 0000000..f4405a2 --- /dev/null +++ b/source/src/EmptyEventCreator.cc @@ -0,0 +1,40 @@ +#include "marlin/EmptyEventCreator.h" + +#include "marlin/ProcessorMgr.h" + +#include "IMPL/LCEventImpl.h" +#include "IMPL/LCRunHeaderImpl.h" + +#include + +namespace marlin { +EmptyEventCreator anEmptyEventCreator; + +EmptyEventCreator::EmptyEventCreator() : DataSourceProcessor("EmptyEventCreator") { + _description = "Creates empty events that can be filled by other processors"; +} + +void EmptyEventCreator::init() { + printParameters(); // Do we need to do anything at all? +} + +void EmptyEventCreator::readDataSource(int numEvents) { + while (m_eventNumber < numEvents) { + if (isFirstEvent()) { + auto* runHeader = new LCRunHeaderImpl; // who cleans this up? + runHeader->setDescription("Empty events produced to be filled later"); + runHeader->setRunNumber(0); + + ProcessorMgr::instance()->processRunHeader(runHeader); + _isFirstEvent = false; + } + + auto evt = std::make_unique(); + evt->setRunNumber(0); + evt->setEventNumber(m_eventNumber++); + + ProcessorMgr::instance()->processEvent(evt.get()); + } +} + +} // namespace marlin From f139b3e69bd56a6384bb80babd3f22f7ccfd0535 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 19 Sep 2022 14:24:43 +0200 Subject: [PATCH 2/2] Add basic tests for the EmptyEventCreator source --- .../include/TestEmptyEventCreator.h | 28 +++++++++ test/marlintest/src/TestEmptyEventCreator.cc | 59 +++++++++++++++++++ test/testmarlin/CMakeLists.txt | 14 +++++ test/testmarlin/empty_event_creator.xml | 22 +++++++ 4 files changed, 123 insertions(+) create mode 100644 test/marlintest/include/TestEmptyEventCreator.h create mode 100644 test/marlintest/src/TestEmptyEventCreator.cc create mode 100644 test/testmarlin/empty_event_creator.xml diff --git a/test/marlintest/include/TestEmptyEventCreator.h b/test/marlintest/include/TestEmptyEventCreator.h new file mode 100644 index 0000000..5850cd3 --- /dev/null +++ b/test/marlintest/include/TestEmptyEventCreator.h @@ -0,0 +1,28 @@ +#ifndef TestEmptyEventCreator_h +#define TestEmptyEventCreator_h 1 + +#include "marlin/Processor.h" + +#include "lcio.h" + +/** Test processor to check that the EmptyEventCreator data source produces the + * expected empty events + */ +class TestEmptyEventCreator : public marlin::Processor { + +public: + TestEmptyEventCreator *newProcessor() override { + return new TestEmptyEventCreator; + } + + TestEmptyEventCreator(); + + void processRunHeader(lcio::LCRunHeader *run) override; + + void processEvent(lcio::LCEvent *evt) override; + +private: + int m_expectedEvt{0}; +}; + +#endif diff --git a/test/marlintest/src/TestEmptyEventCreator.cc b/test/marlintest/src/TestEmptyEventCreator.cc new file mode 100644 index 0000000..17d4cf0 --- /dev/null +++ b/test/marlintest/src/TestEmptyEventCreator.cc @@ -0,0 +1,59 @@ +#include "TestEmptyEventCreator.h" + +#include +#include + +TestEmptyEventCreator aTestEmptyEventCreator; + +TestEmptyEventCreator::TestEmptyEventCreator() + : marlin::Processor("TestEmptyEventCreator") { + _description = "Processor to test whether the EmptyEventCreator data source " + "works as expected"; +} + +void TestEmptyEventCreator::processRunHeader(lcio::LCRunHeader *run) { + if (run->getRunNumber() != 0) { + throw lcio::Exception("Run number from EmptyEventCreator is not 0 (" + + std::to_string(run->getRunNumber()) + ")"); + } +} + +void TestEmptyEventCreator::processEvent(lcio::LCEvent *evt) { + if (evt->getEventNumber() != m_expectedEvt) { + throw lcio::Exception( + "Event number from EmptyEventCreator is not as expected (expected: " + + std::to_string(m_expectedEvt) + + ", actual: " + std::to_string(evt->getEventNumber()) + ")"); + } + + if (!evt->getCollectionNames()->empty()) { + throw lcio::Exception( + "EmptyEventCreator should create empty events, but LCEvent contains " + + std::to_string(evt->getCollectionNames()->size()) + " collections"); + } + + const auto ¶ms = evt->getParameters(); + + std::vector keys; + params.getIntKeys(keys); + if (!keys.empty()) { + throw lcio::Exception( + "EmptyEventCreator should create empty events, but has int parameters"); + } + keys.clear(); + + params.getFloatKeys(keys); + if (!keys.empty()) { + throw lcio::Exception("EmptyEventCreator should create empty events, but " + "has float parameters"); + } + keys.clear(); + + params.getStringKeys(keys); + if (!keys.empty()) { + throw lcio::Exception("EmptyEventCreator should create empty events, but " + "has string parameters"); + } + + m_expectedEvt++; +} diff --git a/test/testmarlin/CMakeLists.txt b/test/testmarlin/CMakeLists.txt index ee859f6..b677e04 100644 --- a/test/testmarlin/CMakeLists.txt +++ b/test/testmarlin/CMakeLists.txt @@ -81,3 +81,17 @@ SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSI SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSION "ONLY {}") SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSION "TRAILING {Content, first}") SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSION "EXPLICIT {Hello, It, Is, Me}") + +#--------------------------------------------------------------------------------------- +SET( MARLIN_STEERING_FILE empty_event_creator.xml ) +SET( MARLIN_INPUT_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/${MARLIN_STEERING_FILE} + ${CMAKE_CURRENT_SOURCE_DIR}/gear_simjob.xml + ${CMAKE_CURRENT_SOURCE_DIR}/simjob.slcio +) + +CONFIGURE_FILE( runmarlin.cmake.in empty_event_creator.cmake @ONLY ) +ADD_TEST( t_empty_event_creator "${CMAKE_COMMAND}" -P empty_event_creator.cmake ) + +SET_TESTS_PROPERTIES( t_empty_event_creator PROPERTIES FAIL_REGULAR_EXPRESSION "Marlin will have to be terminated, sorry." ) +#--------------------------------------------------------------------------------------- diff --git a/test/testmarlin/empty_event_creator.xml b/test/testmarlin/empty_event_creator.xml new file mode 100644 index 0000000..c9825d1 --- /dev/null +++ b/test/testmarlin/empty_event_creator.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + +