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

Issue508 performance tests #509

Merged
merged 20 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
14 changes: 12 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,21 @@ if (env.CHANGE_ID) {
checkout scm
unstash 'event-formation-unit-centos7.tar.gz'
sh "tar xzvf event-formation-unit-centos7.tar.gz"
sh "ls -R"
sh """
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:./event-formation-unit/lib/
python3 -u ./integrationtest/integrationtest.py
python3 -u ./test/integrationtest.py
"""
} // stage
} // node
node('inttest'){
stage('Performance Test'){
checkout scm
unstash 'event-formation-unit-centos7.tar.gz'
sh "tar xzvf event-formation-unit-centos7.tar.gz"
sh """
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:./event-formation-unit/lib/
python3 -u ./test/performancetest.py
"""
}
}
} // if
30 changes: 19 additions & 11 deletions src/common/reduction/EventBuilder2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// #define TRC_LEVEL TRC_L_INF



EventBuilder2D::EventBuilder2D() { matcher.set_minimum_time_gap(timegap); }

void EventBuilder2D::insert(Hit hit) {
Expand All @@ -33,29 +32,38 @@ void EventBuilder2D::insert(Hit hit) {
}
}

void EventBuilder2D::flush() {
void EventBuilder2D::flush(bool full_flush) {
matcher.matched_events.clear();

sort_chronologically(HitsX);
ClustersX.cluster(HitsX);
ClustersX.flush();
ClustererX.cluster(HitsX);

sort_chronologically(HitsY);
ClustersY.cluster(HitsY);
ClustersY.flush();
ClustererY.cluster(HitsY);

if(full_flush){
flushClusterers();
}

matcher.insert(PlaneX, ClustersX.clusters);
matcher.insert(PlaneY, ClustersY.clusters);
matcher.match(true);
matcher.insert(PlaneX, ClustererX.clusters);
matcher.insert(PlaneY, ClustererY.clusters);
matcher.match(full_flush);

auto &e = matcher.matched_events;
Events.insert(Events.end(), e.begin(), e.end());

clear();
clearHits();
}

void EventBuilder2D::clear() {
void EventBuilder2D::clearHits() {
HitsX.clear();
HitsY.clear();
}

void EventBuilder2D::flushClusterers() {
ClustererX.flush();
ClustererY.flush();
}



8 changes: 5 additions & 3 deletions src/common/reduction/EventBuilder2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ class EventBuilder2D {
// \todo pass by rvalue?
void insert(Hit hit);

void flush();
void flush(bool full_flush = false);

void clear();
void clearHits();

void flushClusterers();

void setTimeBox(uint32_t TimeBoxValue) { TimeBoxSize = TimeBoxValue; }

HitVector HitsX, HitsY;

// \todo parametrize
GapClusterer ClustersX{timegap, coordgap}, ClustersY{timegap, coordgap};
GapClusterer ClustererX{timegap, coordgap}, ClustererY{timegap, coordgap};

// \todo parametrize
GapMatcher matcher{latency, PlaneX, PlaneY};
Expand Down
1 change: 1 addition & 0 deletions src/common/reduction/HitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ template <typename T, typename Alloc = std::allocator<T>> class MyVector {
Vec.clear();
reserve(MinReserveCount);
}

void resize(size_type sz) { Vec.resize(sz); }
void resize(size_type sz, const value_type &c) { Vec.resize(sz, c); }
};
Expand Down
5 changes: 5 additions & 0 deletions src/common/reduction/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ set(ChronoMergerTest_SRC
ChronoMergerTest.cpp
)
create_test_executable(ChronoMergerTest)

set(HitVectorBenchmark_SRC
HitVectorBenchmark.cpp
)
create_benchmark_executable(HitVectorBenchmark)
16 changes: 16 additions & 0 deletions src/common/reduction/test/HitVectorBenchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <benchmark/benchmark.h>
#include <common/reduction/HitVector.h>


static void BM_pushback_hits(benchmark::State &state){
HitVector hits;
for (auto _ : state){
Hit hit;
hit.coordinate = 50;
hit.weight = 50;
hit.time = 50;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

hits.push_back(hit);
}
}
BENCHMARK(BM_pushback_hits);
BENCHMARK_MAIN();
2 changes: 1 addition & 1 deletion src/modules/cspec/CSPECBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CSPECBase::CSPECBase(BaseSettings const &settings,
Stats.create("readouts.tof_neg", Counters.TimeStats.TofNegative);
Stats.create("readouts.prevtof_count", Counters.TimeStats.PrevTofCount);
Stats.create("readouts.prevtof_neg", Counters.TimeStats.PrevTofNegative);
Stats.create("readouts.tof_toolarge", Counters.TOFErrors);
Stats.create("readouts.tof_toolarge", Counters.TOFErrors); //move this to events.tof_toolarge
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or discard at readouts stage



// Clustering stats
Expand Down
73 changes: 65 additions & 8 deletions src/modules/cspec/test/CSPECInstrumentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@ std::vector<uint8_t> GoodEvent {

};


std::vector<uint8_t> SplitEventA {
// First readout - plane Y - Grids
0x00, 0x01, 0x14, 0x00, // Data Header - Ring 0, FEN 1
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x01, 0x00, 0x00, 0x00, // Time LO 1 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3C, // GEO 0, TDC 0, VMM 1, CH 60

};

std::vector<uint8_t> SplitEventB {
// Second readout - plane Y - Grids
0x00, 0x01, 0x14, 0x00, // Data Header - Ring 0, FEN 1
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x02, 0x00, 0x00, 0x00, // Time LO 2 tick
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x02, 0x3D, // GEO 0, TDC 0, VMM 1, CH 61

// Third readout - plane X & Z - Wires
0x00, 0x01, 0x14, 0x00, // Data Header, Ring 0, FEN 1
0x00, 0x00, 0x00, 0x00, // Time HI 0 s
0x05, 0x00, 0x00, 0x00, // Time LO 5 ticks
0x00, 0x00, 0x00, 0x01, // ADC 0x100
0x00, 0x00, 0x00, 0x3C, // GEO 0, TDC 0, VMM 0, CH 60

};

std::vector<uint8_t> BadEventMultipleWires {
// First readout - plane Y - Grids
0x00, 0x01, 0x14, 0x00, // Data Header - Ring 0, FEN 1
Expand Down Expand Up @@ -441,7 +469,7 @@ TEST_F(CSPECInstrumentTest, GoodEvent) {
ASSERT_EQ(counters.VMMStats.Readouts, 3);

for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 1);
Expand All @@ -465,7 +493,7 @@ TEST_F(CSPECInstrumentTest, BadMappingError) {
ASSERT_EQ(counters.VMMStats.Readouts, 2);

for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
Expand Down Expand Up @@ -511,7 +539,7 @@ TEST_F(CSPECInstrumentTest, NoEventGridOnly) {
ASSERT_EQ(counters.VMMStats.Readouts, 2);

for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
Expand All @@ -536,7 +564,7 @@ TEST_F(CSPECInstrumentTest, NoEventWireOnly) {
ASSERT_EQ(counters.VMMStats.Readouts, 2);

for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
Expand Down Expand Up @@ -576,7 +604,7 @@ TEST_F(CSPECInstrumentTest, BadEventLargeGridSpan) {
ASSERT_EQ(counters.VMMStats.Readouts, 5);

for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}
ASSERT_EQ(counters.Events, 0);
Expand All @@ -593,7 +621,7 @@ TEST_F(CSPECInstrumentTest, NegativeTOF) {

cspec->processReadouts();
for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}

Expand All @@ -611,7 +639,7 @@ TEST_F(CSPECInstrumentTest, HighTOFError) {

cspec->processReadouts();
for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}

Expand All @@ -629,7 +657,7 @@ TEST_F(CSPECInstrumentTest, BadEventLargeTimeSpan) {

cspec->processReadouts();
for (auto &builder : cspec->builders) {
builder.flush();
builder.flush(true);
cspec->generateEvents(builder.Events);
}

Expand All @@ -639,6 +667,35 @@ TEST_F(CSPECInstrumentTest, BadEventLargeTimeSpan) {
ASSERT_EQ(counters.ClustersNoCoincidence, 1);
}

TEST_F(CSPECInstrumentTest, EventCrossPackets) {
makeHeader(cspec->ESSReadoutParser.Packet, SplitEventA);

auto Res = cspec->VMMParser.parse(cspec->ESSReadoutParser.Packet);
counters.VMMStats = cspec->VMMParser.Stats;

cspec->processReadouts();
for (auto &builder : cspec->builders) {
builder.flush();
cspec->generateEvents(builder.Events);
}
ASSERT_EQ(Res, 1);

makeHeader(cspec->ESSReadoutParser.Packet, SplitEventB);

Res = cspec->VMMParser.parse(cspec->ESSReadoutParser.Packet);
counters.VMMStats = cspec->VMMParser.Stats;

cspec->processReadouts();
for (auto &builder : cspec->builders) {
builder.flush(true);
cspec->generateEvents(builder.Events);
}

ASSERT_EQ(Res, 2);
ASSERT_EQ(counters.VMMStats.Readouts, 3);
ASSERT_EQ(counters.Events, 1);
}

int main(int argc, char **argv) {
saveBuffer(ConfigFile, (void *)ConfigStr.c_str(), ConfigStr.size());
saveBuffer(BadConfigFile, (void *)BadConfigStr.c_str(), BadConfigStr.size());
Expand Down
3 changes: 2 additions & 1 deletion src/modules/freia/FreiaInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ void FreiaInstrument::processReadouts(void) {

void FreiaInstrument::generateEvents(std::vector<Event> &Events) {
ESSReadout::ESSTime &TimeRef = ESSReadoutParser.Packet.Time;

XTRACE(EVENT, DEB, "Number of events: %u", Events.size());
for (const auto &e : Events) {
if (e.empty()) {
XTRACE(EVENT, DEB, "Empty event");
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/freia/test/FreiaInstrumentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ TEST_F(FreiaInstrumentTest, EventTOFError) {

freia->processReadouts();
for (auto &builder : freia->builders) {
builder.flush();
builder.flush(true);
freia->generateEvents(builder.Events);
}
ASSERT_EQ(Res, 2);
Expand Down
File renamed without changes.
Loading