Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:17

0001 // -*- C++ -*-
0002 //
0003 // Package:    NTuplingDevice
0004 // Class:      NTuplingDevice
0005 //
0006 /**\class NTuplingDevice NTuplingDevice.cc Workspace/NTuplingDevice/src/NTuplingDevice.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Jean-Roch Vlimant
0015 //         Created:  Sun May 11 21:12:46 CEST 2008
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include "PhysicsTools/UtilAlgos/interface/NTupler.h"
0032 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0033 
0034 //
0035 // class decleration
0036 //
0037 
0038 class NTuplingDevice : public edm::one::EDProducer<edm::one::SharedResources> {
0039 public:
0040   explicit NTuplingDevice(const edm::ParameterSet&);
0041   ~NTuplingDevice() override;
0042 
0043 private:
0044   void produce(edm::Event&, const edm::EventSetup&) override;
0045 
0046   // ----------member data ---------------------------
0047   std::unique_ptr<NTupler> ntupler_;
0048 };
0049 
0050 //
0051 // constants, enums and typedefs
0052 //
0053 
0054 //
0055 // static data member definitions
0056 //
0057 
0058 //
0059 // constructors and destructor
0060 //
0061 NTuplingDevice::NTuplingDevice(const edm::ParameterSet& iConfig) {
0062   usesResource(TFileService::kSharedResource);
0063   //this Ntupler can work with the InputTagDistributor, but should not be configured as such.
0064   edm::ParameterSet ntPset = iConfig.getParameter<edm::ParameterSet>("Ntupler");
0065   std::string ntuplerName = ntPset.getParameter<std::string>("ComponentName");
0066   ntupler_ = NTuplerFactory::get()->create(ntuplerName, ntPset);
0067 
0068   //register the leaves from the ntupler
0069   ntupler_->registerleaves(producesCollector());
0070 
0071   //put a dummy product if the ntupler does not output on edm
0072   produces<double>("dummy");
0073 }
0074 
0075 NTuplingDevice::~NTuplingDevice() {}
0076 
0077 // ------------ method called to produce the data  ------------
0078 void NTuplingDevice::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0079   ntupler_->fill(iEvent);
0080   iEvent.put(std::make_unique<double>(0.), "dummy");
0081 }
0082 
0083 //define this as a plug-in
0084 DEFINE_FWK_MODULE(NTuplingDevice);