CMS 3D CMS Logo

OtherThingProducer.cc
Go to the documentation of this file.
1 #include <string>
2 
3 #include "DataFormats/TestObjects/interface/OtherThingCollection.h"
8 
9 #include "OtherThingAlgorithm.h"
13 
14 namespace edmtest {
16  public:
17  explicit OtherThingProducer(edm::ParameterSet const& ps);
18 
19  ~OtherThingProducer() override;
20 
21  void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override;
22 
23  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
24 
25  private:
29  bool useRefs_;
31  };
32 
33  OtherThingProducer::OtherThingProducer(edm::ParameterSet const& pset) : alg_(), refsAreTransient_(false) {
34  putToken_ = produces<OtherThingCollection>("testUserTag");
35  useRefs_ = pset.getUntrackedParameter<bool>("useRefs");
36  if (useRefs_) {
37  thingToken_ = consumes<ThingCollection>(pset.getParameter<edm::InputTag>("thingTag"));
38  }
39  refsAreTransient_ = pset.getUntrackedParameter<bool>("transient");
40  }
41 
42  // Virtual destructor needed.
44 
45  // Functions that gets called by framework every event
47  // Step A: Get Inputs
48 
49  // Step B: Create empty output
50  auto result = std::make_unique<OtherThingCollection>(); //Empty
51 
52  // Step C: Get data for algorithm
53  edm::Handle<ThingCollection> parentHandle;
54  if (useRefs_) {
55  bool succeeded = e.getByToken(thingToken_, parentHandle);
57  assert(parentHandle.isValid());
58  }
59 
60  // Step D: Invoke the algorithm, passing in inputs (NONE) and getting back outputs.
61  alg_.run(parentHandle, *result, useRefs_, refsAreTransient_);
62 
63  // Step E: Put outputs into event
64  e.put(putToken_, std::move(result));
65  }
66 
69  desc.add<edm::InputTag>("thingTag", edm::InputTag("Thing"))->setComment("Where to get the ThingCollection");
70  desc.addUntracked<bool>("useRefs", true)
71  ->setComment("Actually get the ThingCollection and build edm::Refs to the contained items.");
72  desc.addUntracked<bool>("transient", false)
73  ->setComment("If true, then the Refs constructed by the ThingCollection can not be persisted");
74  descriptions.add("otherThingProd", desc);
75  }
76 
77 } // namespace edmtest
OtherThingProducer(edm::ParameterSet const &ps)
void run(edm::Handle< ThingCollection > const &iThingHandle, OtherThingCollection &otherThingCollection, bool useRefs=true, bool refsAreTransient=false) const
assert(be >=bs)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::StreamID, edm::Event &e, edm::EventSetup const &c) const override
def move(src, dest)
Definition: eostools.py:511