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

Add an EmptyEventCreator data source for testing and examples #44

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions source/include/marlin/EmptyEventCreator.h
Original file line number Diff line number Diff line change
@@ -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).
*
* <h4>Input</h4>
* None
*
* <h4>Output</4>
* 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
40 changes: 40 additions & 0 deletions source/src/EmptyEventCreator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "marlin/EmptyEventCreator.h"

#include "marlin/ProcessorMgr.h"

#include "IMPL/LCEventImpl.h"
#include "IMPL/LCRunHeaderImpl.h"

#include <memory>

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<LCEventImpl>();
evt->setRunNumber(0);
evt->setEventNumber(m_eventNumber++);

ProcessorMgr::instance()->processEvent(evt.get());
}
}

} // namespace marlin
28 changes: 28 additions & 0 deletions test/marlintest/include/TestEmptyEventCreator.h
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions test/marlintest/src/TestEmptyEventCreator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "TestEmptyEventCreator.h"

#include <string>
#include <vector>

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 &params = evt->getParameters();

std::vector<std::string> 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++;
}
14 changes: 14 additions & 0 deletions test/testmarlin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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." )
#---------------------------------------------------------------------------------------
22 changes: 22 additions & 0 deletions test/testmarlin/empty_event_creator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<marlin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ilcsoft.desy.de/marlin/marlin.xsd">

<execute>
<processor name="EmptyEventCreator"/>
<processor name="MyTestEmptyEventCreator"/>
</execute>

<global>
<parameter name="MaxRecordNumber" value="10"/>
</global>

<processor name="EmptyEventCreator" type="EmptyEventCreator"/>

<processor name="MyTestEmptyEventCreator" type="TestEmptyEventCreator">
<!--Processor to test whether the EmptyEventCreator data source works as expected-->
<!--verbosity level of this processor ("DEBUG0-4,MESSAGE0-4,WARNING0-4,ERROR0-4,SILENT")-->
<!--parameter name="Verbosity" type="string">DEBUG </parameter-->
</processor>

</marlin>