CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/Modules/src/IterateNTimesLooper.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Modules
00004 // Class  :     IterateNTimesLooper
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Tue Jul 11 11:16:14 EDT 2006
00011 //
00012 
00013 // system include files
00014 
00015 // user include files
00016 #include "FWCore/Framework/interface/EDLooper.h"
00017 #include "FWCore/Framework/interface/LooperFactory.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 
00020 namespace edm {
00021 
00022   class IterateNTimesLooper : public EDLooper {
00023 
00024     public:
00025       IterateNTimesLooper(ParameterSet const&);
00026       virtual ~IterateNTimesLooper();
00027 
00028       // ---------- const member functions ---------------------
00029 
00030       // ---------- static member functions --------------------
00031 
00032       // ---------- member functions ---------------------------
00033       virtual void startingNewLoop(unsigned int);
00034       virtual Status duringLoop(Event const&, EventSetup const&);
00035       virtual Status endOfLoop(EventSetup const&, unsigned int);
00036 
00037     private:
00038       IterateNTimesLooper(IterateNTimesLooper const&); // stop default
00039 
00040       IterateNTimesLooper const& operator=(IterateNTimesLooper const&); // stop default
00041 
00042       // ---------- member data --------------------------------
00043       unsigned int max_;
00044       unsigned int times_;
00045       bool shouldStop_;
00046   };
00047 
00048   //
00049   //
00050   // constructors and destructor
00051   //
00052   IterateNTimesLooper::IterateNTimesLooper(ParameterSet const& iConfig) :
00053     max_(iConfig.getParameter<unsigned int>("nTimes")),
00054     times_(0),
00055     shouldStop_(false) {
00056   }
00057 
00058   // IterateNTimesLooper::IterateNTimesLooper(IterateNTimesLooper const& rhs) {
00059   //    // do actual copying here;
00060   // }
00061 
00062   IterateNTimesLooper::~IterateNTimesLooper() {
00063   }
00064 
00065   //
00066   // assignment operators
00067   //
00068   // IterateNTimesLooper const& IterateNTimesLooper::operator=(IterateNTimesLooper const& rhs) {
00069   //   //An exception safe implementation is
00070   //   IterateNTimesLooper temp(rhs);
00071   //   swap(rhs);
00072   //
00073   //   return *this;
00074   // }
00075 
00076   //
00077   // member functions
00078   //
00079   void
00080   IterateNTimesLooper::startingNewLoop(unsigned int iIteration) {
00081     times_ = iIteration;
00082     if(iIteration >= max_) {
00083       shouldStop_ = true;
00084     }
00085   }
00086 
00087   EDLooper::Status
00088   IterateNTimesLooper::duringLoop(Event const&, EventSetup const&) {
00089     return shouldStop_ ? kStop : kContinue;
00090   }
00091 
00092   EDLooper::Status
00093   IterateNTimesLooper::endOfLoop(EventSetup const&, unsigned int /*iCounter*/) {
00094     ++times_;
00095     return (times_ < max_) ? kContinue : kStop;
00096   }
00097 }
00098 
00099 using edm::IterateNTimesLooper;
00100 DEFINE_FWK_LOOPER(IterateNTimesLooper);