Skip to content

Commit 60b81a3

Browse files
committed
Implement an integration test for post_insert()
1 parent 9920497 commit 60b81a3

File tree

8 files changed

+171
-2
lines changed

8 files changed

+171
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef DataFormats_TestObjects_interface_ThingWithDoNotSort_h
2+
#define DataFormats_TestObjects_interface_ThingWithDoNotSort_h
3+
4+
#include <stdexcept>
5+
#include <cstdint>
6+
7+
#include "DataFormats/Common/interface/traits.h"
8+
#include "FWCore/Utilities/interface/Exception.h"
9+
#include "FWCore/Utilities/interface/typedefs.h"
10+
11+
namespace edmtest {
12+
13+
class ThingWithDoNotSort : public edm::DoNotSortUponInsertion {
14+
public:
15+
ThingWithDoNotSort() : value_{0} {};
16+
explicit ThingWithDoNotSort(cms_int32_t v) : value_{v} {}
17+
18+
void post_insert() {
19+
throw cms::Exception("LogicError")
20+
<< "post_insert() called for ThingWithDoNotSort that inherits from edm::DoNotSortUponInsertion";
21+
}
22+
23+
int32_t value() const { return value_; }
24+
25+
private:
26+
cms_int32_t value_;
27+
};
28+
29+
} // namespace edmtest
30+
31+
#endif // DataFormats_TestObjects_interface_ThingWithDoNotSort_h
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef DataFormats_TestObjects_interface_ThingWithPostInsert_h
2+
#define DataFormats_TestObjects_interface_ThingWithPostInsert_h
3+
4+
#include <cstdint>
5+
6+
#include "FWCore/Utilities/interface/typedefs.h"
7+
8+
namespace edmtest {
9+
10+
class ThingWithPostInsert {
11+
public:
12+
ThingWithPostInsert() : value_{0}, valid_{false} {};
13+
explicit ThingWithPostInsert(cms_int32_t v) : value_{v}, valid_{false} {}
14+
15+
void post_insert() { valid_ = true; }
16+
17+
int32_t value() const { return value_; }
18+
19+
bool valid() const { return valid_; }
20+
21+
private:
22+
cms_int32_t value_;
23+
bool valid_;
24+
};
25+
26+
} // namespace edmtest
27+
28+
#endif // DataFormats_TestObjects_interface_ThingWithPostInsert_h

DataFormats/TestObjects/src/classes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "DataFormats/TestObjects/interface/Thing.h"
1919
#include "DataFormats/TestObjects/interface/ThingWithMerge.h"
2020
#include "DataFormats/TestObjects/interface/ThingWithIsEqual.h"
21+
#include "DataFormats/TestObjects/interface/ThingWithPostInsert.h"
22+
#include "DataFormats/TestObjects/interface/ThingWithDoNotSort.h"
2123
#include "DataFormats/TestObjects/interface/TrackOfThings.h"
2224
#include "DataFormats/TestObjects/interface/TrackOfDSVThings.h"
2325

DataFormats/TestObjects/src/classes_def.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@
146146
<class name="edm::Wrapper<std::vector<edmtest::Thing> >"/>
147147
<class name="edm::Wrapper<std::vector<edmtest::OtherThing> >"/>
148148

149+
<class name="edmtest::ThingWithPostInsert" ClassVersion="3">
150+
<version ClassVersion="3" checksum="2193684721"/>
151+
</class>
152+
<class name="edm::Wrapper<edmtest::ThingWithPostInsert>"/>
153+
154+
<class name="edmtest::ThingWithDoNotSort" ClassVersion="3">
155+
<version ClassVersion="3" checksum="1286605803"/>
156+
</class>
157+
<class name="edm::Wrapper<edmtest::ThingWithDoNotSort>"/>
158+
149159
<class name="edmNew::DetSetVector<edmtest::Thing>"/>
150160
<class name="edm::Ref<edmNew::DetSetVector<edmtest::Thing>, edmtest::Thing, edmNew::DetSetVector<edmtest::Thing>::FindForDetSetVector>"/>
151161
<class name="edm::RefVector<edmNew::DetSetVector<edmtest::Thing>, edmtest::Thing, edmNew::DetSetVector<edmtest::Thing>::FindForDetSetVector>"/>

FWCore/Integration/plugins/BuildFile.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
<use name="FWCore/Utilities"/>
88
</library>
99

10-
<library file="ThingProducer.cc,ThingAlgorithm.cc,TrackOfThingsProducer.cc,ThinningTestAnalyzer.cc,ThinnedRefFromTestAnalyzer.cc,DetSetVectorThingProducer.cc,TrackOfDSVThingsProducer.cc,ThinningDSVThingProducer.cc,SlimmingDSVThingProducer.cc,ThinningDSVTestAnalyzer.cc,ThingSource.cc,ThingExtSource.cc,ThingWithMergeProducer.cc,TestGetterOfProducts.cc,PutOrMergeTestSource.cc,TestGetByLabelAnalyzer.cc,ThingAnalyzer.cc,TestOutputWithGetterOfProducts.cc,TestOutputWithGetterOfProductsGlobal.cc,TestOutputWithGetterOfProductsLimited.cc"
11-
name="FWCoreIntegrationTestWithThing">
10+
<library file="DetSetVectorThingProducer.cc,PostInsertProducer.cc,PutOrMergeTestSource.cc,SlimmingDSVThingProducer.cc,TestGetByLabelAnalyzer.cc,TestGetterOfProducts.cc,TestOutputWithGetterOfProducts.cc,TestOutputWithGetterOfProductsGlobal.cc,TestOutputWithGetterOfProductsLimited.cc,ThingAlgorithm.cc,ThingAnalyzer.cc,ThingExtSource.cc,ThingProducer.cc,ThingSource.cc,ThingWithMergeProducer.cc,ThinnedRefFromTestAnalyzer.cc,ThinningDSVTestAnalyzer.cc,ThinningDSVThingProducer.cc,ThinningTestAnalyzer.cc,TrackOfDSVThingsProducer.cc,TrackOfThingsProducer.cc" name="FWCoreIntegrationTestWithThing">
1211
<flags EDM_PLUGIN="1"/>
1312
<use name="FWCore/Framework"/>
1413
<use name="FWCore/Sources"/>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "DataFormats/TestObjects/interface/ThingWithDoNotSort.h"
2+
#include "DataFormats/TestObjects/interface/ThingWithPostInsert.h"
3+
#include "FWCore/Framework/interface/Event.h"
4+
#include "FWCore/Framework/interface/global/EDProducer.h"
5+
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
6+
#include "FWCore/ParameterSet/interface/ParameterSet.h"
7+
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
8+
#include "FWCore/Utilities/interface/EDPutToken.h"
9+
10+
namespace edmtest {
11+
12+
class PostInsertProducer : public edm::global::EDProducer<> {
13+
public:
14+
explicit PostInsertProducer(edm::ParameterSet const& ps);
15+
16+
void produce(edm::StreamID sid, edm::Event& event, edm::EventSetup const& es) const override;
17+
18+
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
19+
20+
private:
21+
edm::EDPutTokenT<ThingWithPostInsert> putTokenPostInsert_;
22+
edm::EDPutTokenT<ThingWithDoNotSort> putTokenDoNotSort_;
23+
edm::EDPutTokenT<ThingWithPostInsert> emplaceTokenPostInsert_;
24+
edm::EDPutTokenT<ThingWithDoNotSort> emplaceTokenDoNotSort_;
25+
};
26+
27+
PostInsertProducer::PostInsertProducer(edm::ParameterSet const& iConfig)
28+
: putTokenPostInsert_{produces<ThingWithPostInsert>("put")},
29+
putTokenDoNotSort_{produces<ThingWithDoNotSort>("put")},
30+
emplaceTokenPostInsert_{produces<ThingWithPostInsert>("emplace")},
31+
emplaceTokenDoNotSort_{produces<ThingWithDoNotSort>("emplace")} {}
32+
33+
// Functions that gets called by framework every event
34+
void PostInsertProducer::produce(edm::StreamID sid, edm::Event& event, edm::EventSetup const& es) const {
35+
{
36+
// Check that event.put() calls ThingWithPostInsert::post_insert().
37+
auto product = std::make_unique<ThingWithPostInsert>(42);
38+
assert(not product->valid());
39+
assert(product->value() == 42);
40+
auto handle = event.put(putTokenPostInsert_, std::move(product));
41+
assert(handle->valid());
42+
assert(handle->value() == 42);
43+
}
44+
45+
{
46+
// Check that event.put *does not* call ThingWithDoNotSort::post_insert(),
47+
// which would throw an exception.
48+
auto product = std::make_unique<ThingWithDoNotSort>(42);
49+
assert(product->value() == 42);
50+
auto handle = event.put(putTokenDoNotSort_, std::move(product));
51+
assert(handle->value() == 42);
52+
}
53+
54+
{
55+
// Check that event.emplace() calls ThingWithPostInsert::post_insert().
56+
ThingWithPostInsert product{42};
57+
assert(not product.valid());
58+
assert(product.value() == 42);
59+
auto handle = event.emplace(emplaceTokenPostInsert_, product);
60+
assert(handle->valid());
61+
assert(handle->value() == 42);
62+
}
63+
64+
{
65+
// Check that event.emplace *does not* call ThingWithDoNotSort::post_insert(),
66+
// which would throw an exception.
67+
ThingWithDoNotSort product{42};
68+
assert(product.value() == 42);
69+
auto handle = event.emplace(emplaceTokenDoNotSort_, product);
70+
assert(handle->value() == 42);
71+
}
72+
}
73+
74+
void PostInsertProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
75+
edm::ParameterSetDescription desc;
76+
descriptions.addWithDefaultLabel(desc);
77+
}
78+
79+
} // namespace edmtest
80+
81+
#include "FWCore/Framework/interface/MakerMacros.h"
82+
using edmtest::PostInsertProducer;
83+
DEFINE_FWK_MODULE(PostInsertProducer);

FWCore/Integration/test/BuildFile.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<test name="TestIntegrationExistingDictionary" command="run_TestExistingDictionary.sh"/>
4343
<test name="TestIntegrationEmptyRootFile" command="run_TestEmptyRootFile.sh"/>
4444
<test name="TestStdProducts" command="cmsRun ${LOCALTOP}/src/FWCore/Integration/test/testStdProducts_cfg.py"/>
45+
<test name="TestPostInsertProducer" command="cmsRun ${LOCALTOP}/src/FWCore/Integration/test/testPostInsertProducer_cfg.py"/>
4546

4647
<bin file="ProcessConfiguration_t.cpp,ProcessHistory_t.cpp" name="TestIntegrationDataFormatsProvenance">
4748
<use name="FWCore/ParameterSet"/>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import FWCore.ParameterSet.Config as cms
2+
3+
process = cms.Process("TEST")
4+
5+
process.options.numberOfThreads = 4
6+
process.options.numberOfStreams = 4
7+
8+
process.source = cms.Source("EmptySource")
9+
process.maxEvents.input = 10
10+
11+
process.prod = cms.EDProducer("PostInsertProducer")
12+
13+
process.path = cms.Path(
14+
process.prod
15+
)

0 commit comments

Comments
 (0)