CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/CommonTools/UtilAlgos/plugins/StopAfterNEvents.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/EDFilter.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 
00004 class StopAfterNEvents : public edm::EDFilter {
00005 public:
00006   StopAfterNEvents( const edm::ParameterSet & );
00007   ~StopAfterNEvents();
00008 private:
00009   bool filter( edm::Event &, edm::EventSetup const& );
00010   const int nMax_;
00011   int n_;
00012   const bool verbose_;
00013 };
00014 
00015 #include <iostream>
00016 
00017 using namespace std;
00018 using namespace edm;
00019 
00020 StopAfterNEvents::StopAfterNEvents( const ParameterSet & pset ) :
00021   nMax_( pset.getParameter<int>( "maxEvents" ) ), n_( 0 ),
00022   verbose_( pset.getUntrackedParameter<bool>( "verbose", false ) ) {
00023 }
00024 
00025 StopAfterNEvents::~StopAfterNEvents() {
00026 }
00027 
00028 bool StopAfterNEvents::filter( Event &, EventSetup const& ) {
00029   if ( n_ < 0 ) return true;
00030   n_ ++ ;
00031   bool ret = n_ <= nMax_;
00032   if ( verbose_ )
00033     cout << ">>> filtering event" << n_ << "/" << nMax_ 
00034               << "(" <<  ( ret ? "true" : "false" ) << ")" << endl;
00035   return ret;
00036 }
00037 
00038 #include "FWCore/Framework/interface/MakerMacros.h"
00039 
00040 DEFINE_FWK_MODULE( StopAfterNEvents );