CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/FWCore/Modules/src/NavigateEventsLooper.cc

Go to the documentation of this file.
00001 
00020 #include "FWCore/Framework/interface/EDLooperBase.h"
00021 #include "FWCore/Framework/interface/LooperFactory.h"
00022 #include "FWCore/Framework/interface/ProcessingController.h"
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 
00025 #include <iostream>
00026 
00027 namespace edm {
00028 
00029   class NavigateEventsLooper : public EDLooperBase {
00030 
00031   public:
00032     NavigateEventsLooper(ParameterSet const& pset);
00033     virtual ~NavigateEventsLooper();
00034 
00035     virtual void startingNewLoop(unsigned int iIteration);
00036     virtual Status duringLoop(Event const& ev, EventSetup const& es, ProcessingController& pc);
00037     virtual Status endOfLoop(EventSetup const& es, unsigned int iCounter);
00038 
00039   private:
00040     NavigateEventsLooper(NavigateEventsLooper const&); // stop default
00041     NavigateEventsLooper const& operator=(NavigateEventsLooper const&); // stop default
00042 
00043     int maxLoops_;
00044     int countLoops_;
00045     bool shouldStopLoop_;
00046     bool shouldStopProcess_;
00047   };
00048 
00049   NavigateEventsLooper::NavigateEventsLooper(ParameterSet const& pset) :
00050     maxLoops_(pset.getUntrackedParameter<int>("maxLoops", -1)),
00051     countLoops_(0),
00052     shouldStopLoop_(false),
00053     shouldStopProcess_(false) {
00054   }
00055 
00056   NavigateEventsLooper::~NavigateEventsLooper() {
00057   }
00058 
00059   void
00060   NavigateEventsLooper::startingNewLoop(unsigned int /*iIteration*/) {
00061   }
00062 
00063   EDLooperBase::Status
00064   NavigateEventsLooper::duringLoop(Event const&, EventSetup const&, ProcessingController& pc) {
00065 
00066     if(!pc.lastOperationSucceeded()) {
00067       std::cout << "Event could not be found. Nothing done. Try again.\n";
00068     }
00069 
00070     std::cout << "\nWhat should we do next?\n";
00071 
00072     if(pc.forwardState() == ProcessingController::kEventsAheadInFile) {
00073       std::cout << "(0) process the next event\n";
00074     } else if(pc.forwardState() == ProcessingController::kNextFileExists) {
00075       std::cout << "(0) process the next event if it exists (at last event in the open file. there are more files)\n";
00076     } else if(pc.forwardState() == ProcessingController::kAtLastEvent) {
00077       std::cout << "(0) will stop the loop because this is the last event\n";
00078     } else if(pc.forwardState() == ProcessingController::kUnknownForward) {
00079       std::cout << "(0) process the next event (if it exists)\n";
00080     }
00081 
00082     if(pc.canRandomAccess()) {
00083       if(pc.reverseState() == ProcessingController::kEventsBackwardsInFile) {
00084         std::cout << "(1) process the previous event\n";
00085       } else if(pc.reverseState() == ProcessingController::kPreviousFileExists) {
00086         std::cout << "(1) process the previous event if there are any (at first event in the open file. there are previous files)\n";
00087       } else if(pc.reverseState() == ProcessingController::kAtFirstEvent) {
00088         std::cout << "(1) will stop the loop because this is the first event\n";
00089       }
00090 
00091       std::cout << "(2) process a specific event\n";
00092     }
00093 
00094     std::cout << "(3) stop loop\n";
00095     std::cout << "(4) stop process" << std::endl;
00096     int x;
00097 
00098     bool inputFailed = false;
00099     do {
00100       inputFailed = false;
00101       if(!(std::cin >> x) || x < 0 || x > 4) {
00102         inputFailed = true;
00103         std::cin.clear();
00104         std::cin.ignore(10000, '\n');
00105         std::cout << "Please enter numeric characters only. The value must be in the range 0 to 4 (inclusive). Please try again." << std::endl;
00106       }
00107       if(!pc.canRandomAccess() && (x == 1 || x == 2)) {
00108         inputFailed = true;
00109         std::cout << "The source cannot do random access. 1 and 2 are illegal values. Please try again." << std::endl;
00110       }
00111     } while(inputFailed);
00112 
00113     shouldStopLoop_ = false;
00114     shouldStopProcess_ = false;
00115     if(x == 0) {
00116       pc.setTransitionToNextEvent();
00117     } else if(x == 1) {
00118       pc.setTransitionToPreviousEvent();
00119     } else if(x == 2) {
00120       std::cout << "Which run?" << std::endl;
00121       do {
00122         inputFailed = false;
00123         if(!(std::cin >> x)) {
00124           inputFailed = true;
00125           std::cin.clear();
00126           std::cin.ignore(10000, '\n');
00127           std::cout << "Please enter numeric characters only. Please try again." << std::endl;
00128         }
00129       } while(inputFailed);
00130       RunNumber_t run = x;
00131       std::cout << "Which luminosity block?" << std::endl;
00132       do {
00133         inputFailed = false;
00134         if(!(std::cin >> x)) {
00135           inputFailed = true;
00136           std::cin.clear();
00137           std::cin.ignore(10000, '\n');
00138           std::cout << "Please enter numeric characters only. Please try again." << std::endl;
00139         }
00140       } while(inputFailed);
00141       LuminosityBlockNumber_t lumi = x;
00142       std::cout << "Which event?" << std::endl;
00143       do {
00144         inputFailed = false;
00145         if(!(std::cin >> x)) {
00146           inputFailed = true;
00147           std::cin.clear();
00148           std::cin.ignore(10000, '\n');
00149           std::cout << "Please enter numeric characters only. Please try again." << std::endl;
00150         }
00151       } while(inputFailed);
00152       EventNumber_t ev = x;
00153       pc.setTransitionToEvent(EventID(run, lumi, ev));
00154     } else if(x == 3) {
00155       pc.setTransitionToNextEvent();
00156       shouldStopLoop_ = true;
00157     } else if(x == 4) {
00158       pc.setTransitionToNextEvent();
00159       shouldStopLoop_ = true;
00160       shouldStopProcess_ = true;
00161     }
00162     return shouldStopLoop_ ? kStop : kContinue;
00163   }
00164 
00165   EDLooperBase::Status
00166   NavigateEventsLooper::endOfLoop(EventSetup const&, unsigned int /*iCounter*/) {
00167     std::cout << "Ending loop" << std::endl;
00168     if(shouldStopProcess_) return kStop;
00169     ++countLoops_;
00170     return(maxLoops_ < 0 || countLoops_ < maxLoops_) ? kContinue : kStop;
00171   }
00172 }
00173 
00174 using edm::NavigateEventsLooper;
00175 DEFINE_FWK_LOOPER(NavigateEventsLooper);