Skip to content

Commit c225e1a

Browse files
committed
Optimize 'no process' request with single option
If there is a single process which delivers a given data product when requesting without specifying a process name, the code now directly returns that option rather than requiring an additional indirection.
1 parent 73a5edb commit c225e1a

File tree

3 files changed

+68
-42
lines changed

3 files changed

+68
-42
lines changed

DataFormats/Provenance/src/ProductResolverIndexHelper.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,21 @@ namespace edm {
114114
if (iToIndexAndNames == std::numeric_limits<unsigned int>::max()) {
115115
return ProductResolverIndexInvalid;
116116
}
117-
return indexAndNames_[iToIndexAndNames].index();
117+
118+
auto checkForSingleProcess = [this](unsigned int index) {
119+
//0 is for blank process name. If not zero, we have a match
120+
if (indexAndNames_[index].startInProcessNames() != 0U) {
121+
return index;
122+
}
123+
//Now check to see if only one process has this type/module/instance name
124+
auto nextIndex = index + 1;
125+
while (indexAndNames_.size() > nextIndex && indexAndNames_[nextIndex].startInProcessNames() != 0U) {
126+
++nextIndex;
127+
}
128+
return (nextIndex == index + 2) ? index + 1 : index;
129+
};
130+
131+
return indexAndNames_[checkForSingleProcess(iToIndexAndNames)].index();
118132
}
119133

120134
ProductResolverIndexHelper::Matches::Matches(ProductResolverIndexHelper const* productResolverIndexHelper,

DataFormats/Provenance/test/productResolverIndexHelper_t.cpp

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818

1919
using namespace edm;
2020

21-
22-
23-
24-
25-
2621
TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
2722
TypeID typeID_ProductID(typeid(ProductID));
2823
TypeID typeID_EventID(typeid(EventID));
@@ -31,12 +26,15 @@ TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
3126
edm::ProductResolverIndexHelper helper;
3227
helper.setFrozen("processA");
3328

34-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
35-
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
29+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
30+
ProductResolverIndexInvalid);
31+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
32+
ProductResolverIndexInvalid);
3633
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == ProductResolverIndexInvalid);
3734
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
3835

39-
edm::ProductResolverIndexHelper::Matches matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
36+
edm::ProductResolverIndexHelper::Matches matches =
37+
helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
4038
REQUIRE(matches.numberOfMatches() == 0);
4139
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
4240
REQUIRE(matches.numberOfMatches() == 0);
@@ -51,12 +49,15 @@ TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
5149
TypeID typeIDProductID(typeid(ProductID));
5250
helper.insert(typeIDProductID, "labelA", "instanceA", "processA");
5351

54-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
55-
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
52+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
53+
ProductResolverIndexInvalid);
54+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
55+
ProductResolverIndexInvalid);
5656
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == ProductResolverIndexInvalid);
5757
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
5858

59-
edm::ProductResolverIndexHelper::Matches matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
59+
edm::ProductResolverIndexHelper::Matches matches =
60+
helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID, "label_A", "instance_A");
6061
REQUIRE(matches.numberOfMatches() == 0);
6162
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
6263
REQUIRE(matches.numberOfMatches() == 0);
@@ -72,21 +73,30 @@ TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
7273
REQUIRE(indexWithProcess < 2);
7374
REQUIRE(indexEmptyProcess != indexWithProcess);
7475

75-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == indexEmptyProcess);
76-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == indexEmptyProcess);
77-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", 0) == indexEmptyProcess);
76+
//wit only one entry, all should resolve to the one with process name
77+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA") == indexWithProcess);
78+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "") == indexWithProcess);
79+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", 0) == indexWithProcess);
7880
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == indexWithProcess);
7981

80-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instance", "processA") == ProductResolverIndexInvalid);
81-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceAX", "processA") == ProductResolverIndexInvalid);
82-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "label", "instanceA", "processA") == ProductResolverIndexInvalid);
83-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelAX", "instanceA", "processA") == ProductResolverIndexInvalid);
84-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "process") == ProductResolverIndexInvalid);
85-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processAX") == ProductResolverIndexInvalid);
86-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_EventID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
82+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instance", "processA") ==
83+
ProductResolverIndexInvalid);
84+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceAX", "processA") ==
85+
ProductResolverIndexInvalid);
86+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "label", "instanceA", "processA") ==
87+
ProductResolverIndexInvalid);
88+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelAX", "instanceA", "processA") ==
89+
ProductResolverIndexInvalid);
90+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "process") ==
91+
ProductResolverIndexInvalid);
92+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_ProductID, "labelA", "instanceA", "processAX") ==
93+
ProductResolverIndexInvalid);
94+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_EventID, "labelA", "instanceA", "processA") ==
95+
ProductResolverIndexInvalid);
8796

8897
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA") == ProductResolverIndexInvalid);
89-
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") == ProductResolverIndexInvalid);
98+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_ProductID, "labelA", "instanceA", "processA") ==
99+
ProductResolverIndexInvalid);
90100

91101
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_ProductID);
92102
REQUIRE(matches.numberOfMatches() == 2);
@@ -125,19 +135,19 @@ TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
125135
TypeID typeIDSetInt(typeid(std::set<int>));
126136
TypeID typeIDVSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
127137

128-
helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC"); // 0, 1, 2
129-
helper.insert(typeIDVectorInt, "label", "instance", "process"); // 3, 4, 5
130-
helper.insert(typeIDEventID, "labelB", "instanceB", "processB"); // 6, 7
131-
helper.insert(typeIDEventID, "label", "instanceB", "processB"); // 8, 9
132-
helper.insert(typeIDEventID, "labelX", "instanceB", "processB"); // 10, 11
133-
helper.insert(typeIDEventID, "labelB", "instance", "processB"); // 12, 13
134-
helper.insert(typeIDEventID, "labelB", "instanceX", "processB"); // 14, 15
135-
helper.insert(typeIDEventID, "labelB", "instanceB", "processB1"); // 16, 5
136-
helper.insert(typeIDEventID, "labelB", "instanceB", "processB3"); // 17, 5
137-
helper.insert(typeIDEventID, "labelB", "instanceB", "processB2"); // 18, 5
138-
helper.insert(typeIDProductID, "label", "instance", "process"); // 19, 20
139-
helper.insert(typeIDEventID, "label", "instance", "process"); // 21, 22
140-
helper.insert(typeIDProductID, "labelA", "instanceA", "processA"); // 23, 24
138+
helper.insert(typeIDVectorInt, "labelC", "instanceC", "processC"); // 0, 1, 2
139+
helper.insert(typeIDVectorInt, "label", "instance", "process"); // 3, 4, 5
140+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB"); // 6, 7
141+
helper.insert(typeIDEventID, "label", "instanceB", "processB"); // 8, 9
142+
helper.insert(typeIDEventID, "labelX", "instanceB", "processB"); // 10, 11
143+
helper.insert(typeIDEventID, "labelB", "instance", "processB"); // 12, 13
144+
helper.insert(typeIDEventID, "labelB", "instanceX", "processB"); // 14, 15
145+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB1"); // 16, 5
146+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB3"); // 17, 5
147+
helper.insert(typeIDEventID, "labelB", "instanceB", "processB2"); // 18, 5
148+
helper.insert(typeIDProductID, "label", "instance", "process"); // 19, 20
149+
helper.insert(typeIDEventID, "label", "instance", "process"); // 21, 22
150+
helper.insert(typeIDProductID, "labelA", "instanceA", "processA"); // 23, 24
141151
REQUIRE_THROWS_AS(helper.insert(typeIDProductID, "labelA", "instanceA", "processA"), cms::Exception); // duplicate
142152

143153
helper.insert(typeIDSetInt, "labelC", "instanceC", "processC"); // 25, 26
@@ -149,7 +159,7 @@ TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
149159
TypeID typeID_int(typeid(int));
150160
REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC", "processC") == ProductResolverIndexAmbiguous);
151161
REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC", "processQ") == ProductResolverIndexInvalid);
152-
REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC") == 2);
162+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_int, "labelC", "instanceC") == ProductResolverIndexAmbiguous);
153163
edm::ProductResolverIndexHelper::Matches matches = helper.relatedIndexes(ELEMENT_TYPE, typeID_int);
154164
REQUIRE(matches.numberOfMatches() == 4);
155165
REQUIRE(matches.index(0) == 5);
@@ -159,22 +169,22 @@ TEST_CASE("ProductResolverIndexHelper", "[ProductResolverIndexHelper]") {
159169

160170
TypeID typeID_vint(typeid(std::vector<int>));
161171
REQUIRE(helper.index(PRODUCT_TYPE, typeID_vint, "labelC", "instanceC", "processC") == 0);
162-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_vint, "labelC", "instanceC") == 1);
172+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_vint, "labelC", "instanceC") == 0); //only one with no process
163173

164174
TypeID typeID_sint(typeid(std::set<int>));
165175
REQUIRE(helper.index(PRODUCT_TYPE, typeID_sint, "labelC", "instanceC", "processC") == 25);
166-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_sint, "labelC", "instanceC") == 26);
176+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_sint, "labelC", "instanceC") == 25); //only one with no process
167177

168178
TypeID typeID_Simple(typeid(edmtest::Simple));
169-
REQUIRE(helper.index(ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC") == 30);
179+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC") == 27); //only one with no process
170180
REQUIRE(helper.index(ELEMENT_TYPE, typeID_Simple, "labelC", "instanceC", "processC") == 27);
171181

172182
TypeID typeID_SimpleDerived(typeid(edmtest::SimpleDerived));
173-
REQUIRE(helper.index(ELEMENT_TYPE, typeID_SimpleDerived, "labelC", "instanceC") == 29);
183+
REQUIRE(helper.index(ELEMENT_TYPE, typeID_SimpleDerived, "labelC", "instanceC") == 27); //only one with no process
174184
REQUIRE(helper.index(ELEMENT_TYPE, typeID_SimpleDerived, "labelC", "instanceC", "processC") == 27);
175185

176186
TypeID typeID_VSimpleDerived(typeid(std::vector<edmtest::SimpleDerived>));
177-
REQUIRE(helper.index(PRODUCT_TYPE, typeID_VSimpleDerived, "labelC", "instanceC") == 28);
187+
REQUIRE(helper.index(PRODUCT_TYPE, typeID_VSimpleDerived, "labelC", "instanceC") == 27); //only one with no process
178188
REQUIRE(helper.index(PRODUCT_TYPE, typeID_VSimpleDerived, "labelC", "instanceC", "processC") == 27);
179189

180190
matches = helper.relatedIndexes(PRODUCT_TYPE, typeID_EventID, "labelB", "instanceB");

FWCore/Framework/src/ProductResolvers.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ namespace edm {
11941194
bool skipCurrentProcess,
11951195
SharedResourcesAcquirer* sra,
11961196
ModuleCallingContext const* mcc) const {
1197+
assert(false);
11971198
//NOTE: Have to lookup the other ProductResolver each time rather than cache
11981199
// it's pointer since it appears the pointer can change at some later stage
11991200
return principal.getProductResolverByIndex(realResolverIndex_)
@@ -1206,6 +1207,7 @@ namespace edm {
12061207
ServiceToken const& token,
12071208
SharedResourcesAcquirer* sra,
12081209
ModuleCallingContext const* mcc) const noexcept {
1210+
assert(false);
12091211
principal.getProductResolverByIndex(realResolverIndex_)
12101212
->prefetchAsync(waitTask, principal, skipCurrentProcess, token, sra, mcc);
12111213
}

0 commit comments

Comments
 (0)