Skip to content

Commit e6a6d0e

Browse files
committed
fix SiStripLatency when empty
1 parent eaefa4c commit e6a6d0e

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

CondFormats/SiStripObjects/src/SiStripLatency.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ std::pair<uint16_t, uint16_t> SiStripLatency::latencyAndMode(const uint32_t detI
7777
}
7878

7979
uint16_t SiStripLatency::singleLatency() const {
80+
if (latencies_.empty()) {
81+
return 255;
82+
}
8083
if (latencies_.size() == 1) {
8184
return latencies_[0].latency;
8285
}
@@ -94,6 +97,9 @@ uint16_t SiStripLatency::singleLatency() const {
9497
}
9598

9699
uint16_t SiStripLatency::singleMode() const {
100+
if (latencies_.empty()) {
101+
return 0;
102+
}
97103
if (latencies_.size() == 1) {
98104
return latencies_[0].mode;
99105
}

CondFormats/SiStripObjects/test/BuildFile.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<bin file="testSerializationSiStripObjects.cpp">
1010
</bin>
1111

12-
<bin file="test_catch2_*.cpp" name="test_catch2_SiStripBadStrip_Phase2">
12+
<bin file="test_catch2_main.cpp,test_catch2_SiStripBadStripForPhase2.cpp" name="test_catch2_SiStripBadStrip_Phase2">
13+
<use name="catch2"/>
14+
</bin>
15+
16+
<bin file="test_catch2_main.cpp,test_catch2_SiStripLatency.cpp" name="test_catch2_SiStripLatency">
1317
<use name="catch2"/>
1418
</bin>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <sstream>
2+
#include "catch.hpp"
3+
#include <iostream>
4+
#include <iomanip> // std::setw
5+
6+
// Include the headers for SiStripLatency and TrackerTopology
7+
#include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
8+
#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
9+
#include "FWCore/Utilities/interface/Exception.h"
10+
11+
// Test case to check the SiStripLatency::printSummary and printDebug
12+
TEST_CASE("SiStripLatency basic test", "[SiStripLatency]") {
13+
// Step 1: Create an empty SiStripLatency object
14+
SiStripLatency latency;
15+
16+
// Step 2: Create a mock or dummy TrackerTopology object
17+
TrackerTopology* trackerTopo = nullptr; // Assuming null for now (replace with actual initialization if needed)
18+
19+
// Step 3: Create a stringstream to capture the output
20+
std::stringstream ssSummary;
21+
std::stringstream ssDebug;
22+
23+
// Step 4: Call printSummary and printDebug on the SiStripLatency object
24+
try {
25+
latency.printSummary(ssSummary, trackerTopo);
26+
latency.printDebug(ssDebug, trackerTopo);
27+
} catch (const cms::Exception& e) {
28+
FAIL("Exception caught during printSummary or printDebug: " << e.what());
29+
}
30+
31+
// Step 5: Optional - Check the output
32+
REQUIRE(!ssSummary.str().empty()); // Ensure the summary output is not empty
33+
REQUIRE(!ssDebug.str().empty()); // Ensure the debug output is not empty
34+
35+
// Print outputs for manual inspection
36+
std::cout << "Summary Output:\n" << ssSummary.str() << std::endl;
37+
std::cout << "Debug Output:\n" << ssDebug.str() << std::endl;
38+
}

0 commit comments

Comments
 (0)