Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:28

0001 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0002 #include "DataFormats/TestObjects/interface/ThingCollection.h"
0003 #include "FWCore/Integration/test/ThingAlgorithm.h"
0004 #include "FWCore/Framework/interface/global/EDProducer.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/MakerMacros.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/EDPutToken.h"
0009 
0010 namespace edmtest {
0011   class DetSetVectorThingProducer : public edm::global::EDProducer<> {
0012   public:
0013     explicit DetSetVectorThingProducer(edm::ParameterSet const& iConfig)
0014         : detSets_(iConfig.getParameter<std::vector<int>>("detSets")),
0015           nPerDetSet_(iConfig.getParameter<int>("nThings")),
0016           alg_(iConfig.getParameter<int>("offsetDelta"),
0017                nPerDetSet_ * detSets_.size(),
0018                iConfig.getParameter<bool>("grow")),
0019           evToken_(produces<edmNew::DetSetVector<Thing>>()) {}
0020 
0021     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0022       edm::ParameterSetDescription desc;
0023       desc.add<int>("offsetDelta", 0)
0024           ->setComment(
0025               "How much extra to increment the value used when creating Things for a new container. E.g. the last "
0026               "value "
0027               "used to create Thing from the previous event is incremented by 'offsetDelta' to compute the value to "
0028               "use "
0029               "of the first Thing created in the next Event.");
0030       desc.add<std::vector<int>>("detSets", std::vector<int>{1, 2, 3})->setComment("Vector of DetSet ids");
0031       desc.add<int>("nThings", 20)->setComment("How many Things to put in each DetSet.");
0032       desc.add<bool>("grow", false)
0033           ->setComment("If true, multiply 'nThings' by the value of offset for each run of the algorithm.");
0034       descriptions.addWithDefaultLabel(desc);
0035     }
0036 
0037     void produce(edm::StreamID, edm::Event& e, edm::EventSetup const& c) const override {
0038       edmNew::DetSetVector<Thing> ret(2);
0039 
0040       ThingCollection tmp;
0041       alg_.run(tmp);
0042       assert(tmp.end() == tmp.begin() + nPerDetSet_ * detSets_.size());
0043       auto begin = tmp.begin();
0044       auto end = begin + nPerDetSet_;
0045 
0046       for (int detSetID : detSets_) {
0047         edmNew::DetSetVector<Thing>::FastFiller filler(ret, detSetID);
0048         std::copy(begin, end, std::back_inserter(filler));
0049         begin = end;
0050         std::advance(end, nPerDetSet_);
0051       }
0052 
0053       e.emplace(evToken_, std::move(ret));
0054     }
0055 
0056   private:
0057     std::vector<int> detSets_;
0058     unsigned int nPerDetSet_;
0059     ThingAlgorithm alg_;
0060     edm::EDPutTokenT<edmNew::DetSetVector<Thing>> evToken_;
0061   };
0062 
0063 }  // namespace edmtest
0064 
0065 using edmtest::DetSetVectorThingProducer;
0066 DEFINE_FWK_MODULE(DetSetVectorThingProducer);