CMS 3D CMS Logo

ThinningProducer.h
Go to the documentation of this file.
1 #ifndef FWCore_Framework_ThinningProducer_h
2 #define FWCore_Framework_ThinningProducer_h
3 
9 
22 
23 #include <memory>
24 
25 namespace edm {
26 
27  class EventSetup;
28 
29  template <typename Collection, typename Selector>
31  public:
32  explicit ThinningProducer(ParameterSet const& pset);
33  ~ThinningProducer() override;
34 
35  static void fillDescriptions(ConfigurationDescriptions& descriptions);
36 
37  void produce(Event& event, EventSetup const& eventSetup) override;
38 
39  void registerThinnedAssociations(ProductRegistry const& productRegistry,
40  ThinnedAssociationsHelper& thinnedAssociationsHelper) override;
41 
42  private:
48  };
49 
50  template <typename Collection, typename Selector>
52  : selector_(new Selector(pset, consumesCollector())) {
53  inputTag_ = pset.getParameter<InputTag>("inputTag");
54  inputToken_ = consumes<Collection>(inputTag_);
55 
56  outputToken_ = produces<Collection>();
57  thinnedOutToken_ = produces<ThinnedAssociation>();
58  }
59 
60  template <typename Collection, typename Selector>
62 
63  template <typename Collection, typename Selector>
66  desc.setComment("Produces thinned collections and associations to them");
67  desc.add<edm::InputTag>("inputTag");
68  Selector::fillDescription(desc);
69  descriptions.addDefault(desc);
70  }
71 
72  template <typename Collection, typename Selector>
74  auto inputCollection = event.getHandle(inputToken_);
75 
76  edm::Event const& constEvent = event;
77  selector_->preChoose(inputCollection, constEvent, eventSetup);
78 
79  Collection thinnedCollection;
80  ThinnedAssociation thinnedAssociation;
81 
82  unsigned int iIndex = 0;
83  for (auto iter = inputCollection->begin(), iterEnd = inputCollection->end(); iter != iterEnd; ++iter, ++iIndex) {
84  if (selector_->choose(iIndex, *iter)) {
85  thinnedCollection.push_back(*iter);
86  thinnedAssociation.push_back(iIndex);
87  }
88  }
89  OrphanHandle<Collection> orphanHandle = event.emplace(outputToken_, std::move(thinnedCollection));
90 
91  thinnedAssociation.setParentCollectionID(inputCollection.id());
92  thinnedAssociation.setThinnedCollectionID(orphanHandle.id());
93  event.emplace(thinnedOutToken_, std::move(thinnedAssociation));
94  }
95 
96  template <typename Collection, typename Selector>
98  ProductRegistry const& productRegistry, ThinnedAssociationsHelper& thinnedAssociationsHelper) {
99  BranchID associationID;
100  BranchID thinnedCollectionID;
101 
102  // If the InputTag does not specify the process name, it is
103  // possible that there will be more than one match found below.
104  // For a particular event only one match is correct and the
105  // others will be false. It even possible for some events one
106  // match is correct and for others another is correct. This is
107  // a side effect of the lookup mechanisms when the process name
108  // is not specified.
109  // When using the registry this generates one would have to
110  // check the ProductIDs in ThinnedAssociation product to get
111  // the correct association. This ambiguity will probably be
112  // rare and possibly never occur in practice.
113  std::vector<BranchID> parentCollectionIDs;
114 
115  ProductRegistry::ProductList const& productList = productRegistry.productList();
116  for (auto const& product : productList) {
117  BranchDescription const& desc = product.second;
118  if (desc.unwrappedType().typeInfo() == typeid(Collection)) {
119  if (desc.produced() && desc.moduleLabel() == moduleDescription().moduleLabel() &&
120  desc.productInstanceName().empty()) {
121  thinnedCollectionID = desc.branchID();
122  }
123  if (desc.moduleLabel() == inputTag_.label() && desc.productInstanceName() == inputTag_.instance()) {
124  if (inputTag_.willSkipCurrentProcess()) {
125  if (!desc.produced()) {
126  parentCollectionIDs.push_back(desc.branchID());
127  }
128  } else if (inputTag_.process().empty() || inputTag_.process() == desc.processName()) {
129  if (desc.produced()) {
130  parentCollectionIDs.push_back(desc.originalBranchID());
131  } else {
132  parentCollectionIDs.push_back(desc.branchID());
133  }
134  }
135  }
136  }
137  if (desc.produced() && desc.unwrappedType().typeInfo() == typeid(ThinnedAssociation) &&
138  desc.moduleLabel() == moduleDescription().moduleLabel() && desc.productInstanceName().empty()) {
139  associationID = desc.branchID();
140  }
141  }
142  if (parentCollectionIDs.empty()) {
143  // This could happen if the input collection was dropped. Go ahead and add
144  // an entry and let the exception be thrown only if the module is run (when
145  // it cannot find the product).
146  thinnedAssociationsHelper.addAssociation(BranchID(), associationID, thinnedCollectionID);
147  } else {
148  for (auto const& parentCollectionID : parentCollectionIDs) {
149  thinnedAssociationsHelper.addAssociation(parentCollectionID, associationID, thinnedCollectionID);
150  }
151  }
152  }
153 } // namespace edm
154 #endif
ConfigurationDescriptions.h
ThinnedAssociationsHelper.h
Handle.h
Selector
Functor that operates on <T>
Definition: Selector.h:22
edm::BranchDescription::productInstanceName
std::string const & productInstanceName() const
Definition: BranchDescription.h:81
edm::ParameterSetDescription::add
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Definition: ParameterSetDescription.h:95
propagate_const.h
edm::BranchDescription::unwrappedType
TypeWithDict const & unwrappedType() const
Definition: BranchDescription.h:94
edm::EDGetTokenT< Collection >
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::EDPutTokenT< Collection >
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edm::ThinnedAssociation
Definition: ThinnedAssociation.h:14
EDProducer.h
edm::ThinningProducer
Definition: ThinningProducer.h:30
edm::ThinningProducer::outputToken_
edm::EDPutTokenT< Collection > outputToken_
Definition: ThinningProducer.h:46
ProductRegistry.h
edm::ThinningProducer::selector_
edm::propagate_const< std::unique_ptr< Selector > > selector_
Definition: ThinningProducer.h:43
edm::ThinnedAssociation::setThinnedCollectionID
void setThinnedCollectionID(ProductID const &v)
Definition: ThinnedAssociation.h:25
edm::ThinningProducer::ThinningProducer
ThinningProducer(ParameterSet const &pset)
Definition: ThinningProducer.h:51
edm::ProductRegistry
Definition: ProductRegistry.h:34
edm::ThinningProducer::inputToken_
edm::EDGetTokenT< Collection > inputToken_
Definition: ThinningProducer.h:44
edm::propagate_const
Definition: propagate_const.h:32
PDWG_EXOHSCP_cff.inputCollection
inputCollection
Definition: PDWG_EXOHSCP_cff.py:56
edm::BranchDescription::processName
std::string const & processName() const
Definition: BranchDescription.h:73
OrphanHandle.h
edm::BranchID
Definition: BranchID.h:14
edm::BranchDescription::originalBranchID
BranchID const & originalBranchID() const
Definition: BranchDescription.h:77
edm::ThinningProducer::registerThinnedAssociations
void registerThinnedAssociations(ProductRegistry const &productRegistry, ThinnedAssociationsHelper &thinnedAssociationsHelper) override
Definition: ThinningProducer.h:97
ParameterSetDescription.h
EDGetToken.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::ThinnedAssociationsHelper
Definition: ThinnedAssociationsHelper.h:35
edm::ProductRegistry::ProductList
std::map< BranchKey, BranchDescription > ProductList
Definition: ProductRegistry.h:36
edm::ThinnedAssociation::setParentCollectionID
void setParentCollectionID(ProductID const &v)
Definition: ThinnedAssociation.h:24
edm::ParameterSet
Definition: ParameterSet.h:36
edm::ParameterSetDescription::setComment
void setComment(std::string const &value)
Definition: ParameterSetDescription.cc:33
Event.h
edm::TypeWithDict::typeInfo
std::type_info const & typeInfo() const
Definition: TypeWithDict.cc:357
edm::ThinningProducer::thinnedOutToken_
edm::EDPutTokenT< ThinnedAssociation > thinnedOutToken_
Definition: ThinningProducer.h:47
edm::ThinningProducer::produce
void produce(Event &event, EventSetup const &eventSetup) override
Definition: ThinningProducer.h:73
edm::ThinningProducer::inputTag_
edm::InputTag inputTag_
Definition: ThinningProducer.h:45
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
edm::BranchDescription::produced
bool produced() const
Definition: BranchDescription.h:82
InputTag.h
edm::OrphanHandleBase::id
ProductID id() const
Definition: OrphanHandleBase.cc:6
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::ProductRegistry::productList
ProductList const & productList() const
Definition: ProductRegistry.h:73
edm::OrphanHandle
Definition: EDProductfwd.h:39
edm::BranchDescription::moduleLabel
std::string const & moduleLabel() const
Definition: BranchDescription.h:72
edm::ThinningProducer::~ThinningProducer
~ThinningProducer() override
Definition: ThinningProducer.h:61
edm::ThinnedAssociation::push_back
void push_back(unsigned int index)
Definition: ThinnedAssociation.h:26
ThinnedAssociation.h
edm::BranchDescription
Definition: BranchDescription.h:32
EventSetup
ParameterSet.h
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
edm::BranchDescription::branchID
BranchID const & branchID() const
Definition: BranchDescription.h:74
event
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of "!*" before the partial wildcard feature was incorporated). The per-event "cost" of each negative criterion with multiple relevant triggers is about the same as ! *was in the past
edm::InputTag
Definition: InputTag.h:15
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
edm::ThinnedAssociationsHelper::addAssociation
void addAssociation(BranchID const &, BranchID const &, BranchID const &)
Definition: ThinnedAssociationsHelper.cc:56
edm::ThinningProducer::fillDescriptions
static void fillDescriptions(ConfigurationDescriptions &descriptions)
Definition: ThinningProducer.h:64