Skip to content

Commit f139b3e

Browse files
committed
Add basic tests for the EmptyEventCreator source
1 parent 17c5c4c commit f139b3e

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef TestEmptyEventCreator_h
2+
#define TestEmptyEventCreator_h 1
3+
4+
#include "marlin/Processor.h"
5+
6+
#include "lcio.h"
7+
8+
/** Test processor to check that the EmptyEventCreator data source produces the
9+
* expected empty events
10+
*/
11+
class TestEmptyEventCreator : public marlin::Processor {
12+
13+
public:
14+
TestEmptyEventCreator *newProcessor() override {
15+
return new TestEmptyEventCreator;
16+
}
17+
18+
TestEmptyEventCreator();
19+
20+
void processRunHeader(lcio::LCRunHeader *run) override;
21+
22+
void processEvent(lcio::LCEvent *evt) override;
23+
24+
private:
25+
int m_expectedEvt{0};
26+
};
27+
28+
#endif
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "TestEmptyEventCreator.h"
2+
3+
#include <string>
4+
#include <vector>
5+
6+
TestEmptyEventCreator aTestEmptyEventCreator;
7+
8+
TestEmptyEventCreator::TestEmptyEventCreator()
9+
: marlin::Processor("TestEmptyEventCreator") {
10+
_description = "Processor to test whether the EmptyEventCreator data source "
11+
"works as expected";
12+
}
13+
14+
void TestEmptyEventCreator::processRunHeader(lcio::LCRunHeader *run) {
15+
if (run->getRunNumber() != 0) {
16+
throw lcio::Exception("Run number from EmptyEventCreator is not 0 (" +
17+
std::to_string(run->getRunNumber()) + ")");
18+
}
19+
}
20+
21+
void TestEmptyEventCreator::processEvent(lcio::LCEvent *evt) {
22+
if (evt->getEventNumber() != m_expectedEvt) {
23+
throw lcio::Exception(
24+
"Event number from EmptyEventCreator is not as expected (expected: " +
25+
std::to_string(m_expectedEvt) +
26+
", actual: " + std::to_string(evt->getEventNumber()) + ")");
27+
}
28+
29+
if (!evt->getCollectionNames()->empty()) {
30+
throw lcio::Exception(
31+
"EmptyEventCreator should create empty events, but LCEvent contains " +
32+
std::to_string(evt->getCollectionNames()->size()) + " collections");
33+
}
34+
35+
const auto &params = evt->getParameters();
36+
37+
std::vector<std::string> keys;
38+
params.getIntKeys(keys);
39+
if (!keys.empty()) {
40+
throw lcio::Exception(
41+
"EmptyEventCreator should create empty events, but has int parameters");
42+
}
43+
keys.clear();
44+
45+
params.getFloatKeys(keys);
46+
if (!keys.empty()) {
47+
throw lcio::Exception("EmptyEventCreator should create empty events, but "
48+
"has float parameters");
49+
}
50+
keys.clear();
51+
52+
params.getStringKeys(keys);
53+
if (!keys.empty()) {
54+
throw lcio::Exception("EmptyEventCreator should create empty events, but "
55+
"has string parameters");
56+
}
57+
58+
m_expectedEvt++;
59+
}

test/testmarlin/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,17 @@ SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSI
8181
SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSION "ONLY {}")
8282
SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSION "TRAILING {Content, first}")
8383
SET_TESTS_PROPERTIES( t_parse_steering_comments PROPERTIES PASS_REGULAR_EXPRESSION "EXPLICIT {Hello, It, Is, Me}")
84+
85+
#---------------------------------------------------------------------------------------
86+
SET( MARLIN_STEERING_FILE empty_event_creator.xml )
87+
SET( MARLIN_INPUT_FILES
88+
${CMAKE_CURRENT_SOURCE_DIR}/${MARLIN_STEERING_FILE}
89+
${CMAKE_CURRENT_SOURCE_DIR}/gear_simjob.xml
90+
${CMAKE_CURRENT_SOURCE_DIR}/simjob.slcio
91+
)
92+
93+
CONFIGURE_FILE( runmarlin.cmake.in empty_event_creator.cmake @ONLY )
94+
ADD_TEST( t_empty_event_creator "${CMAKE_COMMAND}" -P empty_event_creator.cmake )
95+
96+
SET_TESTS_PROPERTIES( t_empty_event_creator PROPERTIES FAIL_REGULAR_EXPRESSION "Marlin will have to be terminated, sorry." )
97+
#---------------------------------------------------------------------------------------
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<marlin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ilcsoft.desy.de/marlin/marlin.xsd">
4+
5+
<execute>
6+
<processor name="EmptyEventCreator"/>
7+
<processor name="MyTestEmptyEventCreator"/>
8+
</execute>
9+
10+
<global>
11+
<parameter name="MaxRecordNumber" value="10"/>
12+
</global>
13+
14+
<processor name="EmptyEventCreator" type="EmptyEventCreator"/>
15+
16+
<processor name="MyTestEmptyEventCreator" type="TestEmptyEventCreator">
17+
<!--Processor to test whether the EmptyEventCreator data source works as expected-->
18+
<!--verbosity level of this processor ("DEBUG0-4,MESSAGE0-4,WARNING0-4,ERROR0-4,SILENT")-->
19+
<!--parameter name="Verbosity" type="string">DEBUG </parameter-->
20+
</processor>
21+
22+
</marlin>

0 commit comments

Comments
 (0)