Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:17

0001 #ifndef FWCore_TFWLiteSelector_TFWLiteSelector_h
0002 #define FWCore_TFWLiteSelector_TFWLiteSelector_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     TFWLiteSelector
0006 // Class  :     TFWLiteSelector
0007 //
0008 /**\class TFWLiteSelector TFWLiteSelector.h FWCore/TFWLiteSelector/interface/TFWLiteSelector.h
0009 
0010  Description: A 'safe' form of a TSelector which uses a Worker helper class to do the processing
0011 
0012  Usage:
0013     This is a safe form of a TSelector which separates the processing (which could happen on many 
0014     computers when using PROOF) from the handling of the final result (which only happens on the
0015     original computer which is running the ROOT job).
0016 
0017     The processing is handled by a worker class.  This class is expected to have the following methods
0018     1) a constructor which takes a 'const TList*' and a 'TList&' as its arguments.  The 'const TList*' holds
0019        objects The 'TList&' is used to hold all the
0020        'TObject' items (e.g. histograms) you want to access for the final result (e.g. the sum of all 
0021        histograms created by the many Workers running on different computers).  You should create the
0022        items in the constructor, hold onto them as member data in the Worker and 'Add' them to the TList.
0023        In addition, the 'TList&' can hold items sent to the workers from the TFWLiteSelector. 
0024     2) a method called 'process(const edm::Event&)'
0025        this is called for each Event
0026     3) a destructor which does what ever you want to have done after all the Events have finished
0027 
0028     You should inherit from TFWLiteSelector<...> where the template argument should be the worker you want
0029     to use.  You need to implement the following methods
0030     1) 'begin(const TList*& itemsForProcessing)'
0031       this is called before processing has started and before any workers get created.  If you want to pass data to
0032       your workers, you can create a new TList and assign it to 'itemsForProcessing' and then add the objects you 
0033       want passed into that list. 
0034       NOTE: you are responsible for deleting the created TList and for deleting all items held by the TList. The easiest
0035       way to do this is to add a 'std::unique_ptr<TList>' member data to your Selector and then call 'SetOwner()' on the TList.
0036     2) 'terminate(TList&)'
0037        this is called after all processing has finished.  The TList& contains all the accumulated information
0038        from all the workers.
0039 */
0040 //
0041 // Original Author:  Chris Jones
0042 //         Created:  Fri Jun 30 21:04:46 CDT 2006
0043 //
0044 
0045 // system include files
0046 #include <memory>
0047 
0048 class TList;
0049 
0050 // user include files
0051 
0052 #include "FWCore/TFWLiteSelector/interface/TFWLiteSelectorBasic.h"
0053 #include "FWCore/Utilities/interface/propagate_const.h"
0054 
0055 // forward declarations
0056 template <class TWorker>
0057 class TFWLiteSelector : public TFWLiteSelectorBasic {
0058 public:
0059   TFWLiteSelector() : worker_() {}
0060   ~TFWLiteSelector() override {}
0061 
0062   // ---------- const member functions ---------------------
0063 
0064   // ---------- static member functions --------------------
0065 
0066   // ---------- member functions ---------------------------
0067 
0068 private:
0069   TFWLiteSelector(const TFWLiteSelector&);  // stop default
0070 
0071   const TFWLiteSelector& operator=(const TFWLiteSelector&);  // stop default
0072 
0073   void preProcessing(const TList* in, TList& out) override { worker_ = std::make_shared<TWorker>(in, out); }
0074   void process(const edm::Event& iEvent) override { worker_->process(iEvent); }
0075   void postProcessing(TList& out) override { worker_->postProcess(out); }
0076 
0077   // ---------- member data --------------------------------
0078   edm::propagate_const<std::shared_ptr<TWorker>> worker_;
0079   ClassDefOverride(TFWLiteSelector, 2)
0080 };
0081 
0082 #endif