Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:33:06

0001 // -*- C++ -*-
0002 //
0003 // Package:     Modules
0004 // Class  :     IterateNTimesLooper
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Jul 11 11:16:14 EDT 2006
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "FWCore/Framework/interface/EDLooper.h"
0017 #include "FWCore/Framework/interface/LooperFactory.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 
0020 namespace edm {
0021 
0022   class IterateNTimesLooper : public EDLooper {
0023   public:
0024     IterateNTimesLooper(ParameterSet const&);
0025     IterateNTimesLooper(IterateNTimesLooper const&) = delete;                   // stop default
0026     IterateNTimesLooper const& operator=(IterateNTimesLooper const&) = delete;  // stop default
0027     ~IterateNTimesLooper() override;
0028 
0029     // ---------- const member functions ---------------------
0030 
0031     // ---------- static member functions --------------------
0032 
0033     // ---------- member functions ---------------------------
0034     void startingNewLoop(unsigned int) override;
0035     Status duringLoop(Event const&, EventSetup const&) override;
0036     Status endOfLoop(EventSetup const&, unsigned int) override;
0037 
0038   private:
0039     // ---------- member data --------------------------------
0040     unsigned int max_;
0041     unsigned int times_;
0042     bool shouldStop_;
0043   };
0044 
0045   //
0046   //
0047   // constructors and destructor
0048   //
0049   IterateNTimesLooper::IterateNTimesLooper(ParameterSet const& iConfig)
0050       : max_(iConfig.getParameter<unsigned int>("nTimes")), times_(0), shouldStop_(false) {}
0051 
0052   // IterateNTimesLooper::IterateNTimesLooper(IterateNTimesLooper const& rhs) {
0053   //    // do actual copying here;
0054   // }
0055 
0056   IterateNTimesLooper::~IterateNTimesLooper() {}
0057 
0058   //
0059   // assignment operators
0060   //
0061   // IterateNTimesLooper const& IterateNTimesLooper::operator=(IterateNTimesLooper const& rhs) {
0062   //   //An exception safe implementation is
0063   //   IterateNTimesLooper temp(rhs);
0064   //   swap(rhs);
0065   //
0066   //   return *this;
0067   // }
0068 
0069   //
0070   // member functions
0071   //
0072   void IterateNTimesLooper::startingNewLoop(unsigned int iIteration) {
0073     times_ = iIteration;
0074     if (iIteration >= max_) {
0075       shouldStop_ = true;
0076     }
0077   }
0078 
0079   EDLooper::Status IterateNTimesLooper::duringLoop(Event const&, EventSetup const&) {
0080     return shouldStop_ ? kStop : kContinue;
0081   }
0082 
0083   EDLooper::Status IterateNTimesLooper::endOfLoop(EventSetup const&, unsigned int /*iCounter*/) {
0084     ++times_;
0085     return (times_ < max_) ? kContinue : kStop;
0086   }
0087 }  // namespace edm
0088 
0089 using edm::IterateNTimesLooper;
0090 DEFINE_FWK_LOOPER(IterateNTimesLooper);