00001
00002 #include "FWCore/Framework/src/EPStates.h"
00003 #include "FWCore/Framework/interface/IEventProcessor.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005
00006 #include <exception>
00007 #include <sstream>
00008 #include <string>
00009 #include <cassert>
00010
00011 namespace statemachine {
00012 namespace {
00013 int const INVALID_RUN_NUMBER = 0;
00014 int const INVALID_LUMI = 0;
00015 Run const INVALID_RUN(edm::ProcessHistoryID(), INVALID_RUN_NUMBER);
00016 HandleLumis::LumiID const InvalidLumiID = HandleLumis::LumiID(edm::ProcessHistoryID(), INVALID_RUN_NUMBER, INVALID_LUMI);
00017 }
00018
00019 Run::Run(edm::ProcessHistoryID const& phid, int runNumber) :
00020 processHistoryID_(phid),
00021 runNumber_(runNumber) {
00022 }
00023
00024 Lumi::Lumi(int id) : id_(id) {}
00025
00026 Machine::Machine(edm::IEventProcessor* ep,
00027 FileMode fileMode,
00028 EmptyRunLumiMode emptyRunLumiMode) :
00029 ep_(ep),
00030 fileMode_(fileMode),
00031 emptyRunLumiMode_(emptyRunLumiMode) {
00032 }
00033
00034 edm::IEventProcessor& Machine::ep() const { return *ep_; }
00035 FileMode Machine::fileMode() const { return fileMode_; }
00036 EmptyRunLumiMode Machine::emptyRunLumiMode() const { return emptyRunLumiMode_; }
00037
00038 void Machine::startingNewLoop(File const& file) {
00039 ep_->startingNewLoop();
00040 }
00041
00042 void Machine::startingNewLoop(Stop const& stop) {
00043 if (ep_->alreadyHandlingException()) return;
00044 ep_->startingNewLoop();
00045 }
00046
00047 void Machine::rewindAndPrepareForNextLoop(Restart const& restart) {
00048 ep_->prepareForNextLoop();
00049 ep_->rewindInput();
00050 }
00051
00052 Starting::Starting(my_context ctx) : my_base(ctx) { }
00053
00054 Starting::~Starting() { }
00055
00056 HandleFiles::HandleFiles(my_context ctx) :
00057 my_base(ctx),
00058 ep_(context<Machine>().ep()),
00059 exitCalled_(false) { }
00060
00061 void HandleFiles::exit() {
00062 if (ep_.alreadyHandlingException()) return;
00063 exitCalled_ = true;
00064 closeFiles();
00065 }
00066
00067 HandleFiles::~HandleFiles() {
00068 if (!exitCalled_) {
00069 try {
00070 closeFiles();
00071 }
00072 catch (...) {
00073 std::ostringstream message;
00074 message << "------------------------------------------------------------\n"
00075 << "Another exception was caught while trying to clean up after the primary fatal exception.\n"
00076 << " We give up trying to clean up at this point.\n";
00077 std::string msg(message.str());
00078 ep_.setExceptionMessageFiles(msg);
00079 }
00080 }
00081 }
00082
00083 void HandleFiles::closeFiles() {
00084 ep_.respondToCloseInputFile();
00085 ep_.closeInputFile();
00086 ep_.respondToCloseOutputFiles();
00087 ep_.closeOutputFiles();
00088 }
00089
00090 void HandleFiles::goToNewInputFile() {
00091 ep_.respondToCloseInputFile();
00092 ep_.closeInputFile();
00093
00094 ep_.readFile();
00095 ep_.respondToOpenInputFile();
00096 }
00097
00098 bool HandleFiles::shouldWeCloseOutput() {
00099 if (context<Machine>().fileMode() == NOMERGE) return true;
00100 return ep_.shouldWeCloseOutput();
00101 }
00102
00103 EndingLoop::EndingLoop(my_context ctx) :
00104 my_base(ctx),
00105 ep_(context<Machine>().ep())
00106 {
00107 if (ep_.alreadyHandlingException() || ep_.endOfLoop()) post_event(Stop());
00108 else post_event(Restart());
00109 }
00110
00111 EndingLoop::~EndingLoop() { }
00112
00113 sc::result EndingLoop::react(Stop const&)
00114 {
00115 return terminate();
00116 }
00117
00118 Error::Error(my_context ctx) :
00119 my_base(ctx),
00120 ep_(context<Machine>().ep())
00121 {
00122 post_event(Stop());
00123 ep_.doErrorStuff();
00124 }
00125
00126 Error::~Error() { }
00127
00128 class HandleNewInputFile1;
00129 class NewInputAndOutputFiles;
00130
00131 FirstFile::FirstFile(my_context ctx) :
00132 my_base(ctx),
00133 ep_(context<Machine>().ep())
00134 {
00135 openFiles();
00136 }
00137
00138 FirstFile::~FirstFile() { }
00139
00140 sc::result FirstFile::react(File const& file)
00141 {
00142 if (context<HandleFiles>().shouldWeCloseOutput()) {
00143 return transit<NewInputAndOutputFiles>();
00144 }
00145 else {
00146 return transit<HandleNewInputFile1>();
00147 }
00148 }
00149
00150 void FirstFile::openFiles() {
00151 ep_.readFile();
00152 ep_.respondToOpenInputFile();
00153
00154 ep_.openOutputFiles();
00155 ep_.respondToOpenOutputFiles();
00156 }
00157
00158 HandleNewInputFile1::HandleNewInputFile1(my_context ctx) :
00159 my_base(ctx)
00160 {
00161 context<HandleFiles>().goToNewInputFile();
00162 }
00163
00164 HandleNewInputFile1::~HandleNewInputFile1() { }
00165
00166 sc::result HandleNewInputFile1::react(File const& file)
00167 {
00168 if (context<HandleFiles>().shouldWeCloseOutput()) {
00169 return transit<NewInputAndOutputFiles>();
00170 }
00171 else {
00172 return transit<HandleNewInputFile1>();
00173 }
00174 }
00175
00176 NewInputAndOutputFiles::NewInputAndOutputFiles(my_context ctx) :
00177 my_base(ctx),
00178 ep_(context<Machine>().ep())
00179 {
00180 goToNewInputAndOutputFiles();
00181 }
00182
00183 NewInputAndOutputFiles::~NewInputAndOutputFiles() { }
00184
00185 sc::result NewInputAndOutputFiles::react(File const& file)
00186 {
00187 if (context<HandleFiles>().shouldWeCloseOutput()) {
00188 return transit<NewInputAndOutputFiles>();
00189 }
00190 else {
00191 return transit<HandleNewInputFile1>();
00192 }
00193 }
00194
00195 void NewInputAndOutputFiles::goToNewInputAndOutputFiles() {
00196 ep_.respondToCloseInputFile();
00197 ep_.closeInputFile();
00198
00199 ep_.respondToCloseOutputFiles();
00200 ep_.closeOutputFiles();
00201
00202 ep_.readFile();
00203 ep_.respondToOpenInputFile();
00204
00205 ep_.openOutputFiles();
00206 ep_.respondToOpenOutputFiles();
00207 }
00208
00209 HandleRuns::HandleRuns(my_context ctx) :
00210 my_base(ctx),
00211 ep_(context<Machine>().ep()),
00212 exitCalled_(false),
00213 beginRunCalled_(false),
00214 currentRun_(INVALID_RUN),
00215 runException_(false) { }
00216
00217 void HandleRuns::exit() {
00218 if (ep_.alreadyHandlingException()) return;
00219 exitCalled_ = true;
00220 finalizeRun();
00221 }
00222
00223 HandleRuns::~HandleRuns() {
00224 if (!exitCalled_) {
00225 try {
00226 finalizeRun();
00227 }
00228 catch (cms::Exception& e) {
00229 std::ostringstream message;
00230 message << "------------------------------------------------------------\n"
00231 << "Another exception was caught while trying to clean up runs after\n"
00232 << "the primary exception. We give up trying to clean up runs at\n"
00233 << "this point. The description of this additional exception follows:\n"
00234 << "cms::Exception\n"
00235 << e.explainSelf();
00236 std::string msg(message.str());
00237 ep_.setExceptionMessageRuns(msg);
00238 }
00239 catch (std::bad_alloc& e) {
00240 std::ostringstream message;
00241 message << "------------------------------------------------------------\n"
00242 << "Another exception was caught while trying to clean up runs\n"
00243 << "after the primary exception. We give up trying to clean up runs\n"
00244 << "at this point. This additional exception was a\n"
00245 << "std::bad_alloc exception thrown inside HandleRuns::finalizeRun.\n"
00246 << "The job has probably exhausted the virtual memory available\n"
00247 << "to the process.\n";
00248 std::string msg(message.str());
00249 ep_.setExceptionMessageRuns(msg);
00250 }
00251 catch (std::exception& e) {
00252 std::ostringstream message;
00253 message << "------------------------------------------------------------\n"
00254 << "Another exception was caught while trying to clean up runs after\n"
00255 << "the primary exception. We give up trying to clean up runs at\n"
00256 << "this point. This additional exception was a\n"
00257 << "standard library exception thrown inside HandleRuns::finalizeRun\n"
00258 << e.what() << "\n";
00259 std::string msg(message.str());
00260 ep_.setExceptionMessageRuns(msg);
00261 }
00262 catch (...) {
00263 std::ostringstream message;
00264 message << "------------------------------------------------------------\n"
00265 << "Another exception was caught while trying to clean up runs after\n"
00266 << "the primary exception. We give up trying to clean up runs at\n"
00267 << "this point. This additional exception was of unknown type and\n"
00268 << "thrown inside HandleRuns::finalizeRun\n";
00269 std::string msg(message.str());
00270 ep_.setExceptionMessageRuns(msg);
00271 }
00272 }
00273 }
00274
00275 bool HandleRuns::beginRunCalled() const { return beginRunCalled_; }
00276 Run const& HandleRuns::currentRun() const { return currentRun_; }
00277 bool HandleRuns::runException() const { return runException_; }
00278
00279 void HandleRuns::setupCurrentRun() {
00280
00281 runException_ = true;
00282 currentRun_ = ep_.readAndCacheRun();
00283 runException_ = false;
00284
00285 if (context<Machine>().emptyRunLumiMode() != doNotHandleEmptyRunsAndLumis) {
00286 beginRun(currentRun());
00287 }
00288 }
00289
00290 void HandleRuns::beginRun(Run const& run) {
00291 beginRunCalled_ = true;
00292
00293 runException_ = true;
00294 ep_.beginRun(run);
00295 runException_ = false;
00296 }
00297
00298 void HandleRuns::endRun(Run const& run) {
00299 beginRunCalled_ = false;
00300
00301 runException_ = true;
00302 ep_.endRun(run);
00303 runException_ = false;
00304 }
00305
00306 void HandleRuns::finalizeRun(Run const&) {
00307 finalizeRun();
00308 }
00309
00310 void HandleRuns::finalizeRun() {
00311
00312 if (runException_) return;
00313 runException_ = true;
00314
00315 if (beginRunCalled_) endRun(currentRun());
00316 ep_.writeRun(currentRun_);
00317 ep_.deleteRunFromCache(currentRun_);
00318 currentRun_ = INVALID_RUN;
00319 runException_ = false;
00320 }
00321
00322 void HandleRuns::beginRunIfNotDoneAlready() {
00323 if (!beginRunCalled_) beginRun(currentRun());
00324 }
00325
00326 NewRun::NewRun(my_context ctx) :
00327 my_base(ctx)
00328 {
00329 assert(context<HandleRuns>().currentRun() == INVALID_RUN);
00330 context<HandleRuns>().setupCurrentRun();
00331
00332
00333
00334
00335 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00336 }
00337
00338 NewRun::~NewRun() { }
00339
00340 sc::result NewRun::react(Run const& run)
00341 {
00342 if (run == context<HandleRuns>().currentRun()) {
00343 return transit<ContinueRun1>();
00344 }
00345 context<HandleRuns>().finalizeRun();
00346 return transit<NewRun>();
00347 }
00348
00349 sc::result NewRun::react(File const& file)
00350 {
00351 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00352 return transit<HandleNewInputFile2>();
00353 }
00354 return forward_event();
00355 }
00356
00357 HandleNewInputFile2::HandleNewInputFile2(my_context ctx) :
00358 my_base(ctx)
00359 {
00360 context<HandleFiles>().goToNewInputFile();
00361 checkInvariant();
00362 }
00363
00364 HandleNewInputFile2::~HandleNewInputFile2() {
00365 checkInvariant();
00366 }
00367
00368 bool HandleNewInputFile2::checkInvariant() {
00369 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00370 return true;
00371 }
00372
00373 sc::result HandleNewInputFile2::react(Run const& run)
00374 {
00375 checkInvariant();
00376
00377 if (context<HandleRuns>().currentRun() != run) {
00378 return transit<NewRun, HandleRuns, Run>(&HandleRuns::finalizeRun, run);
00379 }
00380 else {
00381 return transit<ContinueRun1>();
00382 }
00383 }
00384
00385 sc::result HandleNewInputFile2::react(File const& file)
00386 {
00387 checkInvariant();
00388 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00389 return transit<HandleNewInputFile2>();
00390 }
00391 return forward_event();
00392 }
00393
00394 ContinueRun1::ContinueRun1(my_context ctx) :
00395 my_base(ctx),
00396 ep_(context<Machine>().ep())
00397 {
00398 ep_.readAndCacheRun();
00399 checkInvariant();
00400 }
00401
00402 ContinueRun1::~ContinueRun1() {
00403 checkInvariant();
00404 }
00405
00406 bool ContinueRun1::checkInvariant() {
00407 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00408 return true;
00409 }
00410
00411 sc::result ContinueRun1::react(Run const& run)
00412 {
00413 checkInvariant();
00414 if (context<HandleRuns>().currentRun() != run) {
00415 return transit<NewRun, HandleRuns, Run>(&HandleRuns::finalizeRun, run);
00416 }
00417 else {
00418 return transit<ContinueRun1>();
00419 }
00420 }
00421
00422 sc::result ContinueRun1::react(File const& file)
00423 {
00424 checkInvariant();
00425 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00426 return transit<HandleNewInputFile2>();
00427 }
00428 return forward_event();
00429 }
00430
00431 HandleLumis::LumiID::LumiID(edm::ProcessHistoryID const& phid, int run, int lumi) :
00432 processHistoryID_(phid),
00433 run_(run),
00434 lumi_(lumi) {
00435 }
00436
00437 HandleLumis::HandleLumis(my_context ctx) :
00438 my_base(ctx),
00439 ep_(context<Machine>().ep()),
00440 exitCalled_(false),
00441 currentLumiEmpty_(true),
00442 currentLumi_(InvalidLumiID),
00443 lumiException_(false)
00444 {
00445 checkInvariant();
00446 }
00447
00448 void HandleLumis::exit() {
00449 if (ep_.alreadyHandlingException()) return;
00450 exitCalled_ = true;
00451 checkInvariant();
00452 if (!lumiException_ && !context<HandleRuns>().runException()) {
00453 finalizeLumi();
00454 }
00455 }
00456
00457 HandleLumis::~HandleLumis() {
00458 if (!exitCalled_) {
00459 try {
00460 checkInvariant();
00461 if (!lumiException_ && !context<HandleRuns>().runException()) {
00462 finalizeLumi();
00463 }
00464 }
00465 catch (cms::Exception& e) {
00466 std::ostringstream message;
00467 message << "------------------------------------------------------------\n"
00468 << "Another exception was caught while trying to clean up lumis after\n"
00469 << "the primary exception. We give up trying to clean up lumis at\n"
00470 << "this point. The description of this additional exception follows:\n"
00471 << "cms::Exception\n"
00472 << e.explainSelf();
00473 std::string msg(message.str());
00474 ep_.setExceptionMessageLumis(msg);
00475 }
00476 catch (std::bad_alloc& e) {
00477 std::ostringstream message;
00478 message << "------------------------------------------------------------\n"
00479 << "Another exception was caught while trying to clean up lumis\n"
00480 << "after the primary exception. We give up trying to clean up lumis\n"
00481 << "at this point. This additional exception was a\n"
00482 << "std::bad_alloc exception thrown inside HandleLumis::finalizeLumi.\n"
00483 << "The job has probably exhausted the virtual memory available\n"
00484 << "to the process.\n";
00485 std::string msg(message.str());
00486 ep_.setExceptionMessageLumis(msg);
00487 }
00488 catch (std::exception& e) {
00489 std::ostringstream message;
00490 message << "------------------------------------------------------------\n"
00491 << "Another exception was caught while trying to clean up lumis after\n"
00492 << "the primary exception. We give up trying to clean up lumis at\n"
00493 << "this point. This additional exception was a\n"
00494 << "standard library exception thrown inside HandleLumis::finalizeLumi\n"
00495 << e.what() << "\n";
00496 std::string msg(message.str());
00497 ep_.setExceptionMessageLumis(msg);
00498 }
00499 catch (...) {
00500 std::ostringstream message;
00501 message << "------------------------------------------------------------\n"
00502 << "Another exception was caught while trying to clean up lumis after\n"
00503 << "the primary exception. We give up trying to clean up lumis at\n"
00504 << "this point. This additional exception was of unknown type and\n"
00505 << "thrown inside HandleLumis::finalizeLumi\n";
00506 std::string msg(message.str());
00507 ep_.setExceptionMessageLumis(msg);
00508 }
00509 }
00510 }
00511
00512 bool HandleLumis::checkInvariant() {
00513 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00514 return true;
00515 }
00516
00517 HandleLumis::LumiID const& HandleLumis::currentLumi() const { return currentLumi_; }
00518
00519 bool HandleLumis::currentLumiEmpty() const { return currentLumiEmpty_; }
00520
00521 void HandleLumis::setupCurrentLumi() {
00522
00523 Run const& run = context<HandleRuns>().currentRun();
00524 assert (run != INVALID_RUN);
00525 lumiException_ = true;
00526 currentLumi_ = HandleLumis::LumiID(run.processHistoryID(), run.runNumber(), ep_.readAndCacheLumi());
00527
00528 if (context<Machine>().emptyRunLumiMode() == handleEmptyRunsAndLumis) {
00529 assert(context<HandleRuns>().beginRunCalled());
00530 ep_.beginLumi(currentLumi().processHistoryID(), currentLumi().run(), currentLumi().lumi());
00531 }
00532
00533 lumiException_ = false;
00534
00535 currentLumiEmpty_ = true;
00536 }
00537
00538 void HandleLumis::finalizeLumi() {
00539
00540 lumiException_ = true;
00541
00542 if (!currentLumiEmpty_ ||
00543 context<Machine>().emptyRunLumiMode() == handleEmptyRunsAndLumis) {
00544 ep_.endLumi(currentLumi().processHistoryID(), currentLumi().run(), currentLumi().lumi());
00545 }
00546
00547 ep_.writeLumi(currentLumi().processHistoryID(), currentLumi().run(), currentLumi().lumi());
00548 ep_.deleteLumiFromCache(currentLumi().processHistoryID(), currentLumi().run(), currentLumi().lumi());
00549 currentLumi_ = InvalidLumiID;
00550
00551 lumiException_ = false;
00552 }
00553
00554 void HandleLumis::markLumiNonEmpty() {
00555 if (currentLumiEmpty_) {
00556
00557 if (context<Machine>().emptyRunLumiMode() != handleEmptyRunsAndLumis) {
00558 lumiException_ = true;
00559 ep_.beginLumi(currentLumi().processHistoryID(), currentLumi().run(), currentLumi().lumi());
00560 lumiException_ = false;
00561 }
00562 currentLumiEmpty_ = false;
00563 }
00564 }
00565
00566 FirstLumi::FirstLumi(my_context ctx) :
00567 my_base(ctx)
00568 {
00569 context<HandleLumis>().setupCurrentLumi();
00570 checkInvariant();
00571 }
00572
00573 FirstLumi::~FirstLumi() {
00574 checkInvariant();
00575 }
00576
00577 bool FirstLumi::checkInvariant() {
00578 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00579 assert(context<HandleLumis>().currentLumi().processHistoryID() == context<HandleRuns>().currentRun().processHistoryID());
00580 assert(context<HandleLumis>().currentLumi().run() == context<HandleRuns>().currentRun().runNumber());
00581 assert(context<HandleLumis>().currentLumi().lumi() != INVALID_LUMI);
00582 assert(context<HandleLumis>().currentLumiEmpty() == true);
00583 return true;
00584 }
00585
00586 sc::result FirstLumi::react(Lumi const& lumi)
00587 {
00588 if (lumi.id() == context<HandleLumis>().currentLumi().lumi()) {
00589 return transit<ContinueLumi>();
00590 }
00591 return transit<AnotherLumi>();
00592 }
00593
00594 sc::result FirstLumi::react(File const& file)
00595 {
00596 checkInvariant();
00597 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00598 return transit<HandleNewInputFile3>();
00599 }
00600 return forward_event();
00601 }
00602
00603 AnotherLumi::AnotherLumi(my_context ctx) :
00604 my_base(ctx)
00605 {
00606 context<HandleLumis>().finalizeLumi();
00607 context<HandleLumis>().setupCurrentLumi();
00608 checkInvariant();
00609 }
00610
00611 AnotherLumi::~AnotherLumi() {
00612 checkInvariant();
00613 }
00614
00615 bool AnotherLumi::checkInvariant() {
00616 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00617 assert(context<HandleLumis>().currentLumi().processHistoryID() == context<HandleRuns>().currentRun().processHistoryID());
00618 assert(context<HandleLumis>().currentLumi().run() == context<HandleRuns>().currentRun().runNumber());
00619 assert(context<HandleLumis>().currentLumi().lumi() != INVALID_LUMI);
00620 assert(context<HandleLumis>().currentLumiEmpty() == true);
00621 return true;
00622 }
00623
00624 sc::result AnotherLumi::react(Lumi const& lumi)
00625 {
00626 if (lumi.id() == context<HandleLumis>().currentLumi().lumi()) {
00627 return transit<ContinueLumi>();
00628 }
00629 return transit<AnotherLumi>();
00630 }
00631
00632 sc::result AnotherLumi::react(File const& file)
00633 {
00634 checkInvariant();
00635 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00636 return transit<HandleNewInputFile3>();
00637 }
00638 return forward_event();
00639 }
00640
00641 HandleEvent::HandleEvent(my_context ctx) :
00642 my_base(ctx),
00643 ep_(context<Machine>().ep())
00644 {
00645 readAndProcessEvent();
00646 checkInvariant();
00647 }
00648
00649 HandleEvent::~HandleEvent() {
00650 checkInvariant();
00651 }
00652
00653 bool HandleEvent::checkInvariant() {
00654 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00655 assert(context<HandleRuns>().beginRunCalled());
00656 assert(context<HandleLumis>().currentLumi().processHistoryID() == context<HandleRuns>().currentRun().processHistoryID());
00657 assert(context<HandleLumis>().currentLumi().run() == context<HandleRuns>().currentRun().runNumber());
00658 assert(context<HandleLumis>().currentLumi().lumi() != INVALID_LUMI);
00659 assert(context<HandleLumis>().currentLumiEmpty() == false);
00660 return true;
00661 }
00662
00663 sc::result HandleEvent::react(File const& file)
00664 {
00665 checkInvariant();
00666 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00667 return transit<HandleNewInputFile3>();
00668 }
00669 return forward_event();
00670 }
00671
00672 void HandleEvent::readAndProcessEvent() {
00673 markNonEmpty();
00674 ep_.readAndProcessEvent();
00675 if (ep_.shouldWeStop()) post_event(Stop());
00676 }
00677
00678 void HandleEvent::markNonEmpty() {
00679 context<HandleRuns>().beginRunIfNotDoneAlready();
00680 context<HandleLumis>().markLumiNonEmpty();
00681 }
00682
00683
00684 HandleNewInputFile3::HandleNewInputFile3(my_context ctx) :
00685 my_base(ctx)
00686 {
00687 context<HandleFiles>().goToNewInputFile();
00688 checkInvariant();
00689 }
00690
00691 HandleNewInputFile3::~HandleNewInputFile3() {
00692 checkInvariant();
00693 }
00694
00695 bool HandleNewInputFile3::checkInvariant() {
00696 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00697 assert(context<HandleLumis>().currentLumi().processHistoryID() == context<HandleRuns>().currentRun().processHistoryID());
00698 assert(context<HandleLumis>().currentLumi().run() == context<HandleRuns>().currentRun().runNumber());
00699 assert(context<HandleLumis>().currentLumi().lumi() != INVALID_LUMI);
00700 return true;
00701 }
00702
00703 sc::result HandleNewInputFile3::react(Run const& run)
00704 {
00705 checkInvariant();
00706
00707 if (context<HandleRuns>().currentRun() == run) {
00708 return transit<ContinueRun2>();
00709 }
00710 return forward_event();
00711 }
00712
00713 sc::result HandleNewInputFile3::react(File const& file)
00714 {
00715 checkInvariant();
00716 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00717 return transit<HandleNewInputFile3>();
00718 }
00719 return forward_event();
00720 }
00721
00722 ContinueRun2::ContinueRun2(my_context ctx) :
00723 my_base(ctx),
00724 ep_(context<Machine>().ep())
00725 {
00726 ep_.readAndCacheRun();
00727 checkInvariant();
00728 }
00729
00730 ContinueRun2::~ContinueRun2() {
00731 checkInvariant();
00732 }
00733
00734 bool ContinueRun2::checkInvariant() {
00735 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00736 assert(context<HandleLumis>().currentLumi().processHistoryID() == context<HandleRuns>().currentRun().processHistoryID());
00737 assert(context<HandleLumis>().currentLumi().run() == context<HandleRuns>().currentRun().runNumber());
00738 assert(context<HandleLumis>().currentLumi().lumi() != INVALID_LUMI);
00739 return true;
00740 }
00741
00742 sc::result ContinueRun2::react(Run const& run)
00743 {
00744 checkInvariant();
00745 if (context<HandleRuns>().currentRun() != run) {
00746 return forward_event();
00747 }
00748 else {
00749 return transit<ContinueRun2>();
00750 }
00751 }
00752
00753 sc::result ContinueRun2::react(Lumi const& lumi)
00754 {
00755 checkInvariant();
00756
00757 if (context<HandleLumis>().currentLumi().lumi() != lumi.id()) {
00758 return transit<AnotherLumi>();
00759 }
00760 else {
00761 return transit<ContinueLumi>();
00762 }
00763 }
00764
00765 sc::result ContinueRun2::react(File const& file)
00766 {
00767 checkInvariant();
00768 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00769 return transit<HandleNewInputFile3>();
00770 }
00771 return forward_event();
00772 }
00773
00774 ContinueLumi::ContinueLumi(my_context ctx) :
00775 my_base(ctx),
00776 ep_(context<Machine>().ep())
00777 {
00778 ep_.readAndCacheLumi();
00779 checkInvariant();
00780 }
00781
00782 ContinueLumi::~ContinueLumi() {
00783 checkInvariant();
00784 }
00785
00786 bool ContinueLumi::checkInvariant() {
00787 assert(context<HandleRuns>().currentRun() != INVALID_RUN);
00788 assert(context<HandleLumis>().currentLumi().processHistoryID() == context<HandleRuns>().currentRun().processHistoryID());
00789 assert(context<HandleLumis>().currentLumi().run() == context<HandleRuns>().currentRun().runNumber());
00790 assert(context<HandleLumis>().currentLumi().lumi() != INVALID_LUMI);
00791 return true;
00792 }
00793
00794 sc::result ContinueLumi::react(Lumi const& lumi)
00795 {
00796 checkInvariant();
00797 if (context<HandleLumis>().currentLumi().lumi() != lumi.id()) {
00798 return transit<AnotherLumi>();
00799 }
00800 else {
00801 return transit<ContinueLumi>();
00802 }
00803 }
00804
00805 sc::result ContinueLumi::react(File const& file)
00806 {
00807 checkInvariant();
00808 if (!context<HandleFiles>().shouldWeCloseOutput()) {
00809 return transit<HandleNewInputFile3>();
00810 }
00811 return forward_event();
00812 }
00813 }