![]() |
![]() |
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/ParameterSet/interface/ParameterSet.h" 00018 #include "FWCore/Framework/interface/LooperFactory.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 // { 00060 // // do actual copying here; 00061 // } 00062 00063 IterateNTimesLooper::~IterateNTimesLooper() { 00064 } 00065 00066 // 00067 // assignment operators 00068 // 00069 // IterateNTimesLooper const& IterateNTimesLooper::operator=(IterateNTimesLooper const& rhs) { 00070 // //An exception safe implementation is 00071 // IterateNTimesLooper temp(rhs); 00072 // swap(rhs); 00073 // 00074 // return *this; 00075 // } 00076 00077 // 00078 // member functions 00079 // 00080 void 00081 IterateNTimesLooper::startingNewLoop(unsigned int iIteration) { 00082 times_ = iIteration; 00083 if (iIteration >= max_) { 00084 shouldStop_ = true; 00085 } 00086 } 00087 00088 EDLooper::Status 00089 IterateNTimesLooper::duringLoop(Event const& event, EventSetup const& eventSetup) { 00090 return shouldStop_ ? kStop : kContinue; 00091 } 00092 00093 EDLooper::Status 00094 IterateNTimesLooper::endOfLoop(EventSetup const& es, unsigned int iCounter) { 00095 ++times_; 00096 return (times_ < max_) ? kContinue : kStop; 00097 } 00098 } 00099 00100 using edm::IterateNTimesLooper; 00101 DEFINE_FWK_LOOPER(IterateNTimesLooper);