12 #include "DataFormats/TestObjects/interface/Thing.h" 13 #include "DataFormats/TestObjects/interface/ThingCollection.h" 14 #include "DataFormats/TestObjects/interface/TrackOfThings.h" 35 template <
typename RefT>
37 std::string_view refName,
38 int const expectedValue,
39 int const eventOffset)
const;
41 template <
typename RefT>
43 std::string_view refName,
44 int const expectedValue,
45 int const eventOffset,
51 int const eventOffset)
const;
102 int const slimmedValueFactor =
pset.getParameter<
int>(
"slimmedValueFactor");
114 desc.add<
bool>(
"parentWasDropped",
false);
115 desc.add<
bool>(
"thinnedWasDropped",
false);
116 desc.add<
bool>(
"thinnedIsAlias",
false);
117 desc.add<
bool>(
"refToParentIsAvailable",
true)
119 "If Ref-to-parent is generally available. With thinnedRefFrom it may happen that the Ref-to-parent is not " 120 "available, but the Ref-to-thinned is. In such case this parameter should be set to 'False', and the " 121 "'expectedValues' should be set to correspond the values via Ref-to-thinned.");
122 std::vector<int> defaultV;
123 std::vector<unsigned int> defaultVU;
124 desc.add<std::vector<int>>(
"expectedParentContent", defaultV);
125 desc.add<std::vector<int>>(
"expectedThinnedContent", defaultV);
126 desc.add<std::vector<unsigned int>>(
"expectedIndexesIntoParent", defaultVU);
127 desc.add<
bool>(
"associationShouldBeDropped",
false);
128 desc.add<std::vector<int>>(
"expectedValues");
129 desc.add<
int>(
"parentSlimmedCount", 0);
130 desc.add<
int>(
"thinnedSlimmedCount", 0);
131 desc.add<
int>(
"refSlimmedCount", 0);
132 desc.add<
int>(
"slimmedValueFactor", 10);
143 if (associationCollection->parentCollectionID() != parentCollection.id()) {
144 throw cms::Exception(
"TestFailure") <<
"analyze parent ProductID is not correct";
149 if (associationCollection->thinnedCollectionID() != thinnedCollection.id()) {
150 throw cms::Exception(
"TestFailure") <<
"analyze thinned ProductID is not correct";
154 int const eventOffset =
static_cast<int>(
event.eventAuxiliary().event() * 100 + 100);
156 std::vector<int>::const_iterator expectedValue =
expectedValues_.begin();
164 thinnedCollection.id());
175 thinnedCollection.id());
194 if (parentCollection.isValid()) {
195 throw cms::Exception(
"TestFailure") <<
"parent collection present, should have been dropped";
199 throw cms::Exception(
"TestFailure") <<
"parent collection has unexpected size, got " << parentCollection->size()
202 for (
auto const& thing : *parentCollection) {
207 if (thing.a != expected) {
209 <<
"parent collection has unexpected content, got " << thing.a <<
" expected " << expected;
215 return parentCollection;
227 if (thinnedCollection.isValid()) {
228 throw cms::Exception(
"TestFailure") <<
"thinned collection present, should have been dropped";
232 unsigned expectedIndex = 0;
235 <<
"thinned collection has unexpected size, got " << thinnedCollection->size() <<
" expected " 238 for (
auto const& thing : *thinnedCollection) {
239 const int expected = (
expectedThinnedContent_.at(expectedIndex) +
event.eventAuxiliary().event() * 100 + 100) *
241 if (thing.a != expected) {
243 <<
"thinned collection has unexpected content, got " << thing.a <<
" expected " << expected;
248 return std::tuple(thinnedCollection, thinnedRefProd);
254 throw cms::Exception(
"TestFailure") <<
"association collection should have been dropped but was not";
257 unsigned int expectedIndex = 0;
259 throw cms::Exception(
"TestFailure") <<
"association collection has unexpected size";
261 for (
auto const&
association : associationCollection->indexesIntoParent()) {
264 <<
"association collection has unexpected content, for index " << expectedIndex <<
" got " <<
association 270 return associationCollection;
281 template <
typename RefT>
283 std::string_view refName,
284 int const expectedValue,
285 int const eventOffset)
const {
287 if (ref.isAvailable()) {
289 << refName <<
" is available when it should not be, refers to " << ref.id() <<
" key " << ref.key();
292 if (!ref.isAvailable()) {
293 throw cms::Exception(
"TestFailure") << refName <<
" is not available when it should be";
297 if (ref->a != expected) {
299 <<
"Unexpected values from " << refName <<
", got " << ref->a <<
" expected " << expected;
301 if (ref->a != expected) {
303 <<
"Unexpected values from " << refName <<
" (2nd try), got " << ref->a <<
" expected " << expected;
308 template <
typename RefT>
310 std::string_view refName,
311 int const expectedValue,
312 int const eventOffset,
314 if (expectedValue == -1) {
315 if (refToThinned.isNonnull()) {
316 throw cms::Exception(
"TestFailure") <<
"thinnedRefFrom(" << refName <<
") is non-null when it should be null";
318 if (refToThinned.isAvailable()) {
319 throw cms::Exception(
"TestFailure") <<
"thinnedRefFrom(" << refName <<
") is available when it should not be";
322 if (refToThinned.isNull()) {
323 throw cms::Exception(
"TestFailure") <<
"thinnedRefFrom(" << refName <<
") is null when it should not be";
325 if (refToThinned.id() != thinnedCollectionID) {
326 throw cms::Exception(
"TestFailure") <<
"thinnedRefFrom(" << refName <<
").id() " << refToThinned.id()
327 <<
" differs from expectation " << thinnedCollectionID;
329 if (not refToThinned.isAvailable()) {
330 throw cms::Exception(
"TestFailure") <<
"thinnedRefFrom(" << refName <<
") is not available when it should be";
335 if (refToThinned->a != expected) {
336 throw cms::Exception(
"TestFailure") <<
"Unexpected values from thinnedRefFrom(" << refName <<
"), got " 337 << refToThinned->a <<
" expected " << expected;
339 if (refToThinned->a != expected) {
340 throw cms::Exception(
"TestFailure") <<
"Unexpected values from thinnedRefFrom(" << refName <<
") (2nd try) " 341 << refToThinned->a <<
" expected " << expected;
349 int const eventOffset)
const {
352 bool allPresent =
true;
354 if (iExpectedValue != -1) {
359 if (refToThinned->a != expected) {
360 throw cms::Exception(
"TestFailure") <<
"unexpected values from thinnedRefFrom(refVector1), got " 361 << refToThinned->a <<
" expected " << expected;
366 if (
track.refVector1[
k]->a != expected) {
368 <<
"unexpected values from refVector1, got " <<
track.refVector1[
k]->a <<
" expected " << expected;
370 if (
track.ptrVector1[
k]->a != expected) {
371 throw cms::Exception(
"TestFailure") <<
"unexpected values from ptrVector1";
373 if (
track.refToBaseVector1[
k]->a != expected) {
374 throw cms::Exception(
"TestFailure") <<
"unexpected values from refToBaseVector1";
384 if (!
track.refVector1.isAvailable()) {
385 throw cms::Exception(
"TestFailure") <<
"unexpected value (false) from refVector::isAvailable";
387 if (!
track.ptrVector1.isAvailable()) {
388 throw cms::Exception(
"TestFailure") <<
"unexpected value (false) from ptrVector::isAvailable";
390 if (!
track.refToBaseVector1.isAvailable()) {
391 throw cms::Exception(
"TestFailure") <<
"unexpected value (false) from refToBaseVector::isAvailable";
394 if (
track.refVector1.isAvailable()) {
395 throw cms::Exception(
"TestFailure") <<
"unexpected value (true) from refVector::isAvailable";
397 if (
track.ptrVector1.isAvailable()) {
398 throw cms::Exception(
"TestFailure") <<
"unexpected value (true) from ptrVector::isAvailable";
400 if (
track.refToBaseVector1.isAvailable()) {
401 throw cms::Exception(
"TestFailure") <<
"unexpected value (true) from refToBaseVector::isAvailable";
408 if (
track.refVector1[
k]->a != expected) {
410 <<
"unexpected values from refVector1, got " <<
track.refVector1[
k]->a <<
" expected " << expected;
412 if (
track.ptrVector1[
k]->a != expected) {
413 throw cms::Exception(
"TestFailure") <<
"unexpected values from ptrVector1";
415 if (
track.refToBaseVector1[
k]->a != expected) {
416 throw cms::Exception(
"TestFailure") <<
"unexpected values from refToBaseVector1";
int thinnedSlimmedValueFactor_
int refSlimmedValueFactor_
bool associationShouldBeDropped_
void analyze(edm::StreamID, edm::Event const &e, edm::EventSetup const &c) const override
ret
prodAgent to be discontinued
edm::EDGetTokenT< ThingCollection > thinnedToken_
std::vector< int > expectedThinnedContent_
edm::Handle< TrackOfThingsCollection > getTrackCollection(edm::Event const &event) const
edm::EDGetTokenT< TrackOfThingsCollection > trackToken_
std::vector< int > expectedParentContent_
edm::EDGetTokenT< ThingCollection > parentToken_
void addDefault(ParameterSetDescription const &psetDescription)
std::tuple< layerClusterToCaloParticle, caloParticleToLayerCluster > association
std::vector< int > expectedValues_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
bool refToParentIsAvailable_
void incrementExpectedValue(std::vector< int >::const_iterator &iter) const
void testVectors(TrackOfThings const &track, edm::RefProd< ThingCollection > const &thinnedRefProd, edm::EDProductGetter const &productGetter, int const eventOffset) const
edm::Handle< ThingCollection > getParent(edm::Event const &event) const
#define DEFINE_FWK_MODULE(type)
edm::Handle< edm::ThinnedAssociation > getAssociation(edm::Event const &event) const
int parentSlimmedValueFactor_
Ref< C, T, F > thinnedRefFrom(Ref< C, T, F > const &parent, RefProd< C > const &thinned, edm::EDProductGetter const &prodGetter)
Return a Ref to thinned collection corresponding to an element of the Ref to parent collection...
std::vector< unsigned int > expectedIndexesIntoParent_
void testRefToThinned(RefT const &ref, std::string_view refName, int const expectedValue, int const eventOffset, edm::ProductID const thinnedCollectionID) const
void testRefToParent(RefT const &ref, std::string_view refName, int const expectedValue, int const eventOffset) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< edm::ThinnedAssociation > associationToken_
ThinningTestAnalyzer(edm::ParameterSet const &pset)
EDProductGetter const * productGetter(std::atomic< void const *> const &iCache)
std::tuple< edm::Handle< ThingCollection >, edm::RefProd< ThingCollection > > getThinned(edm::Event const &event) const