Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-26 22:39:10

0001 /*_________________________________________________________________
0002 class:   AlcaPCCIntegrator.cc
0003 
0004 
0005 
0006 authors: Sam Higginbotham (shigginb@cern.ch), Chris Palmer (capalmer@cern.ch), Attila Radl (attila.radl@cern.ch) 
0007 
0008 ________________________________________________________________**/
0009 
0010 // C++ standard
0011 #include <string>
0012 // CMS
0013 #include "DataFormats/Luminosity/interface/PixelClusterCounts.h"
0014 #include "DataFormats/Luminosity/interface/PixelClusterCountsInEvent.h"
0015 #include "FWCore/Framework/interface/ConsumesCollector.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/Frameworkfwd.h"
0019 #include "FWCore/Framework/interface/LuminosityBlock.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/Framework/interface/global/EDProducer.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 //The class
0026 class AlcaPCCIntegrator : public edm::global::EDProducer<edm::LuminosityBlockSummaryCache<reco::PixelClusterCounts>,
0027                                                          edm::StreamCache<reco::PixelClusterCounts>,
0028                                                          edm::EndLuminosityBlockProducer,
0029                                                          edm::Accumulator> {
0030 public:
0031   explicit AlcaPCCIntegrator(const edm::ParameterSet&);
0032   ~AlcaPCCIntegrator() override = default;
0033 
0034   std::unique_ptr<reco::PixelClusterCounts> beginStream(edm::StreamID) const override;
0035   std::shared_ptr<reco::PixelClusterCounts> globalBeginLuminosityBlockSummary(edm::LuminosityBlock const&,
0036                                                                               edm::EventSetup const&) const override;
0037   void accumulate(edm::StreamID iID, const edm::Event& iEvent, const edm::EventSetup&) const override;
0038   void streamEndLuminosityBlockSummary(edm::StreamID,
0039                                        edm::LuminosityBlock const&,
0040                                        edm::EventSetup const&,
0041                                        reco::PixelClusterCounts*) const override;
0042   void globalEndLuminosityBlockSummary(edm::LuminosityBlock const&,
0043                                        edm::EventSetup const&,
0044                                        reco::PixelClusterCounts* iCounts) const override;
0045   void globalEndLuminosityBlockProduce(edm::LuminosityBlock& iLumi,
0046                                        edm::EventSetup const&,
0047                                        reco::PixelClusterCounts const* iCounts) const override;
0048 
0049 private:
0050   const edm::EDPutTokenT<reco::PixelClusterCounts> lumiPutToken_;
0051   const edm::EDGetTokenT<reco::PixelClusterCountsInEvent> pccToken_;
0052 };
0053 
0054 AlcaPCCIntegrator::AlcaPCCIntegrator(const edm::ParameterSet& iConfig)
0055     : lumiPutToken_(produces<reco::PixelClusterCounts, edm::Transition::EndLuminosityBlock>(
0056           iConfig.getParameter<edm::ParameterSet>("AlcaPCCIntegratorParameters").getParameter<std::string>("ProdInst"))),
0057       pccToken_(consumes<reco::PixelClusterCountsInEvent>(
0058           iConfig.getParameter<edm::ParameterSet>("AlcaPCCIntegratorParameters")
0059               .getParameter<edm::InputTag>("inputPccLabel"))) {}
0060 
0061 std::unique_ptr<reco::PixelClusterCounts> AlcaPCCIntegrator::beginStream(edm::StreamID StreamID) const {
0062   return std::make_unique<reco::PixelClusterCounts>();
0063 }
0064 
0065 std::shared_ptr<reco::PixelClusterCounts> AlcaPCCIntegrator::globalBeginLuminosityBlockSummary(
0066     edm::LuminosityBlock const&, edm::EventSetup const&) const {
0067   return std::make_shared<reco::PixelClusterCounts>();
0068 }
0069 
0070 void AlcaPCCIntegrator::globalEndLuminosityBlockSummary(edm::LuminosityBlock const&,
0071                                                         edm::EventSetup const&,
0072                                                         reco::PixelClusterCounts*) const {}
0073 
0074 void AlcaPCCIntegrator::accumulate(edm::StreamID iID, const edm::Event& iEvent, const edm::EventSetup&) const {
0075   edm::Handle<reco::PixelClusterCountsInEvent> pccHandle;
0076   iEvent.getByToken(pccToken_, pccHandle);
0077 
0078   if (!pccHandle.isValid()) {
0079     // do not resolve a not existing product!
0080     return;
0081   }
0082 
0083   const reco::PixelClusterCountsInEvent inputPcc = *pccHandle;
0084   unsigned int bx = iEvent.bunchCrossing();
0085   // add the BXID of the event to the stream cache
0086   streamCache(iID)->eventCounter(bx);
0087   // add the PCCs from the event to the stream cache
0088   streamCache(iID)->add(inputPcc);
0089 }
0090 
0091 void AlcaPCCIntegrator::streamEndLuminosityBlockSummary(edm::StreamID iID,
0092                                                         edm::LuminosityBlock const&,
0093                                                         edm::EventSetup const&,
0094                                                         reco::PixelClusterCounts* iCounts) const {
0095   iCounts->merge(*streamCache(iID));
0096   // now clear in order to be ready for the next LuminosityBlock
0097   streamCache(iID)->reset();
0098 }
0099 
0100 void AlcaPCCIntegrator::globalEndLuminosityBlockProduce(edm::LuminosityBlock& iLumi,
0101                                                         edm::EventSetup const&,
0102                                                         reco::PixelClusterCounts const* iCounts) const {
0103   // save the PCC object
0104   iLumi.emplace(lumiPutToken_, *iCounts);
0105 }
0106 DEFINE_FWK_MODULE(AlcaPCCIntegrator);