Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef PhysicsTools_UtilAlgos_interface_EDAnalyzerWrapper_h
0002 #define PhysicsTools_UtilAlgos_interface_EDAnalyzerWrapper_h
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0008 
0009 /**
0010    \class    EDAnalyzerWrapper EDAnalyzerWrapper.h "PhysicsTools/UtilAlgos/interface/EDAnalyzerWrapper.h"
0011    \brief    Wrapper class around a class of type BasicAnalyzer to "convert" it into a full EDAnalyzer
0012 
0013    This template class is a wrapper round classes of type BasicAnalyzer as defined in in the
0014    BasicAnalyzer.h file of this package. From this class the wrapper expects the following
0015    member functions:
0016 
0017    + a contructor with a const edm::ParameterSet& and a TFileDirectory& as input.
0018    + a beginJob function
0019    + a endJob function
0020    + a analyze function with an const edm::EventBase& as input
0021 
0022    these functions are called within the wrapper. The wrapper translates the common class into
0023    a basic EDAnalyzer as shown below:
0024 
0025    #include "PhysicsTools/PatExamples/interface/BasicMuonAnalyzer.h"
0026    #include "PhysicsTools/UtilAlgos/interface/EDAnalyzerWrapper.h"
0027 
0028    typedef edm::AnalyzerWrapper<BasicMuonAnalyzer> WrappedEDAnalyzer;
0029 
0030    #include "FWCore/Framework/interface/MakerMacros.h"
0031    DEFINE_FWK_MODULE(WrappedEDAnalyzer);
0032 
0033    With this wrapper class we have the use case in mind that you keep classes, which easily can
0034    be used both within the full framework and within FWLite.
0035 
0036    NOTE: in the current implementation this wrapper class does not support use of the EventSetup.
0037    If you want to make use of this feature we recommend you to start from an EDAnalyzer from the
0038    very beginning and just to stay within the full framework.
0039 */
0040 
0041 namespace edm {
0042 
0043   template <class T>
0044   class AnalyzerWrapper : public one::EDAnalyzer<one::SharedResources> {
0045   public:
0046     /// default contructor
0047     AnalyzerWrapper(const edm::ParameterSet& cfg);
0048     /// default destructor
0049     ~AnalyzerWrapper() override{};
0050     /// everything which has to be done before the event loop
0051     void beginJob() override { analyzer_->beginJob(); }
0052     /// everything which has to be done during the event loop. NOTE: We can't use the eventSetup in FWLite so ignore it
0053     void analyze(edm::Event const& event, const edm::EventSetup& eventSetup) override { analyzer_->analyze(event); }
0054     /// everything which has to be done after the event loop
0055     void endJob() override { analyzer_->endJob(); }
0056 
0057   protected:
0058     /// shared pointer to analysis class of type BasicAnalyzer
0059     std::shared_ptr<T> analyzer_;
0060   };
0061 
0062   /// default contructor
0063   template <class T>
0064   AnalyzerWrapper<T>::AnalyzerWrapper(const edm::ParameterSet& cfg) {
0065     usesResource(TFileService::kSharedResource);
0066     // defined TFileService
0067     edm::Service<TFileService> fileService;
0068     // create analysis class of type BasicAnalyzer
0069     analyzer_ = std::shared_ptr<T>(new T(cfg, fileService->tFileDirectory(), consumesCollector()));
0070   }
0071 
0072 }  // namespace edm
0073 
0074 #endif