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