Go to the documentation of this file.00001
00020 #include "FWCore/Framework/interface/EDLooperBase.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/Framework/interface/LooperFactory.h"
00023 #include "FWCore/Framework/interface/ProcessingController.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&);
00041 NavigateEventsLooper const& operator=(NavigateEventsLooper const&);
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& ev, EventSetup const& es, 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 }
00075 else if (pc.forwardState() == ProcessingController::kNextFileExists) {
00076 std::cout << "(0) process the next event if it exists (at last event in the open file. there are more files)\n";
00077 }
00078 else if (pc.forwardState() == ProcessingController::kAtLastEvent) {
00079 std::cout << "(0) will stop the loop because this is the last event\n";
00080 }
00081 else if (pc.forwardState() == ProcessingController::kUnknownForward) {
00082 std::cout << "(0) process the next event (if it exists)\n";
00083 }
00084
00085 if (pc.canRandomAccess()) {
00086 if (pc.reverseState() == ProcessingController::kEventsBackwardsInFile) {
00087 std::cout << "(1) process the previous event\n";
00088 }
00089 else if (pc.reverseState() == ProcessingController::kPreviousFileExists) {
00090 std::cout << "(1) process the previous event if there are any (at first event in the open file. there are previous files)\n";
00091 }
00092 else if (pc.reverseState() == ProcessingController::kAtFirstEvent) {
00093 std::cout << "(1) will stop the loop because this is the first event\n";
00094 }
00095
00096 std::cout << "(2) process a specific event\n";
00097 }
00098
00099 std::cout << "(3) stop loop\n";
00100 std::cout << "(4) stop process" << std::endl;
00101 int x;
00102
00103 bool inputFailed = false;
00104 do {
00105 inputFailed = false;
00106 if (!(std::cin >> x) || x < 0 || x > 4) {
00107 inputFailed = true;
00108 std::cin.clear();
00109 std::cin.ignore(10000,'\n');
00110 std::cout << "Please enter numeric characters only. The value must be in the range 0 to 4 (inclusive). Please try again." << std::endl;
00111 }
00112 if (!pc.canRandomAccess() && (x == 1 || x == 2)) {
00113 inputFailed = true;
00114 std::cout << "The source cannot do random access. 1 and 2 are illegal values. Please try again." << std::endl;
00115 }
00116 } while (inputFailed);
00117
00118 shouldStopLoop_ = false;
00119 shouldStopProcess_ = false;
00120 if (x == 0) {
00121 pc.setTransitionToNextEvent();
00122 }
00123 else if (x == 1) {
00124 pc.setTransitionToPreviousEvent();
00125 }
00126 else if (x == 2) {
00127 std::cout << "Which run?" << std::endl;
00128 do {
00129 inputFailed = false;
00130 if (!(std::cin >> x)) {
00131 inputFailed = true;
00132 std::cin.clear();
00133 std::cin.ignore(10000,'\n');
00134 std::cout << "Please enter numeric characters only. Please try again." << std::endl;
00135 }
00136 } while (inputFailed);
00137 RunNumber_t run = x;
00138 std::cout << "Which luminosity block?" << std::endl;
00139 do {
00140 inputFailed = false;
00141 if (!(std::cin >> x)) {
00142 inputFailed = true;
00143 std::cin.clear();
00144 std::cin.ignore(10000,'\n');
00145 std::cout << "Please enter numeric characters only. Please try again." << std::endl;
00146 }
00147 } while (inputFailed);
00148 LuminosityBlockNumber_t lumi = x;
00149 std::cout << "Which event?" << std::endl;
00150 do {
00151 inputFailed = false;
00152 if (!(std::cin >> x)) {
00153 inputFailed = true;
00154 std::cin.clear();
00155 std::cin.ignore(10000,'\n');
00156 std::cout << "Please enter numeric characters only. Please try again." << std::endl;
00157 }
00158 } while (inputFailed);
00159 EventNumber_t ev = x;
00160 pc.setTransitionToEvent(EventID(run, lumi, ev));
00161 }
00162 else if (x == 3) {
00163 pc.setTransitionToNextEvent();
00164 shouldStopLoop_ = true;
00165 }
00166 else if (x == 4) {
00167 pc.setTransitionToNextEvent();
00168 shouldStopLoop_ = true;
00169 shouldStopProcess_ = true;
00170 }
00171 return shouldStopLoop_ ? kStop : kContinue;
00172 }
00173
00174 EDLooperBase::Status
00175 NavigateEventsLooper::endOfLoop(EventSetup const& es, unsigned int iCounter) {
00176 std::cout << "Ending loop" << std::endl;
00177 if (shouldStopProcess_) return kStop;
00178 ++countLoops_;
00179 return (maxLoops_ < 0 || countLoops_ < maxLoops_) ? kContinue : kStop;
00180 }
00181 }
00182
00183 using edm::NavigateEventsLooper;
00184 DEFINE_FWK_LOOPER(NavigateEventsLooper);