Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef PhysicsTools_UtilAlgos_interface_EDFilterWrapper_h
0002 #define PhysicsTools_UtilAlgos_interface_EDFilterWrapper_h
0003 
0004 /**
0005   \class    EDFilterWrapper EDFilterWrapper.h "PhysicsTools/UtilAlgos/interface/EDFilterWrapper.h"
0006   \brief    Wrapper class for a class of type BasicFilter to "convert" it into a full EDFilter
0007 
0008    This template class is a wrapper around classes of type BasicFilter as defined in the
0009    BasicFilter.h file of this package. From this class the wrapper expects the following
0010    member functions:
0011 
0012    + a constructor with a const edm::ParameterSet& as input.
0013    + a filter function with an const edm::EventBase& as input
0014 
0015    the function is called within the wrapper. The wrapper translates the common class into
0016    a basic EDFilter as shown below:
0017 
0018    #include "PhysicsTools/UtilAlgos/interface/EDFilterWrapper.h"
0019    #include "PhysicsTools/SelectorUtils/interface/PVSelector.h"
0020 
0021    typedef edm::FilterWrapper<PVSelector> PrimaryVertexFilter;
0022 
0023    #include "FWCore/Framework/interface/MakerMacros.h"
0024    DEFINE_FWK_MODULE(PrimaryVertexFilter);
0025 
0026    You can find this example in the plugins directory of this package. With this wrapper class
0027    we have the use case in mind that you keep classes, which easily can be used both within the
0028    full framework and within FWLite.
0029 
0030    NOTE: in the current implementation this wrapper class does not support use of the EventSetup.
0031    If you want to make use of this feature we recommend you to start from an EDFilter from the
0032    very beginning and just to stay within the full framework.
0033 */
0034 
0035 #include "FWCore/Framework/interface/global/EDFilter.h"
0036 #include "FWCore/ServiceRegistry/interface/Service.h"
0037 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0038 #include "FWCore/Common/interface/EventBase.h"
0039 #include "FWCore/Framework/interface/Event.h"
0040 
0041 namespace edm {
0042 
0043   template <class T>
0044   class FilterWrapper : public edm::global::EDFilter<> {
0045   public:
0046     /// default contructor
0047     FilterWrapper(const edm::ParameterSet& cfg) { filter_ = std::shared_ptr<T>(new T(cfg, consumesCollector())); }
0048     /// default destructor
0049     ~FilterWrapper() override {}
0050     /// everything which has to be done during the event loop. NOTE: We can't use the eventSetup in FWLite so ignore it
0051     bool filter(edm::StreamID, edm::Event& event, const edm::EventSetup& eventSetup) const override {
0052       edm::EventBase& eventBase = dynamic_cast<edm::EventBase&>(event);
0053       edm::EventBase const& eventBaseConst = const_cast<edm::EventBase const&>(eventBase);
0054       return (*filter_)(eventBaseConst);
0055     }
0056 
0057   protected:
0058     /// shared pointer to analysis class of type BasicAnalyzer
0059     std::shared_ptr<T> filter_;
0060   };
0061 
0062 }  // namespace edm
0063 
0064 #endif