CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/FWCore/Framework/src/Path.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Framework/src/Path.h"
00003 #include "FWCore/Framework/interface/Actions.h"
00004 #include "FWCore/Framework/src/EarlyDeleteHelper.h"
00005 #include "FWCore/Utilities/interface/Algorithms.h"
00006 #include "FWCore/MessageLogger/interface/ExceptionMessages.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 #include <algorithm>
00010 #include "boost/bind.hpp"
00011 
00012 namespace edm {
00013   Path::Path(int bitpos, std::string const& path_name,
00014              WorkersInPath const& workers,
00015              TrigResPtr trptr,
00016              ActionTable const& actions,
00017              boost::shared_ptr<ActivityRegistry> areg,
00018              bool isEndPath):
00019     stopwatch_(),
00020     timesRun_(),
00021     timesPassed_(),
00022     timesFailed_(),
00023     timesExcept_(),
00024     state_(hlt::Ready),
00025     bitpos_(bitpos),
00026     name_(path_name),
00027     trptr_(trptr),
00028     actReg_(areg),
00029     act_table_(&actions),
00030     workers_(workers),
00031     isEndPath_(isEndPath) {
00032   }
00033   
00034   bool
00035   Path::handleWorkerFailure(cms::Exception & e,
00036                             int nwrwue,
00037                             bool isEvent,
00038                             bool begin,
00039                             BranchType branchType,
00040                             CurrentProcessingContext const& cpc,
00041                             std::string const& id) {
00042 
00043     exceptionContext(e, isEvent, begin, branchType, cpc, id);
00044 
00045     bool should_continue = true;
00046 
00047     // there is no support as of yet for specific paths having
00048     // different exception behavior
00049     
00050     // If not processing an event, always rethrow.
00051     actions::ActionCodes action = (isEvent ? act_table_->find(e.category()) : actions::Rethrow);
00052     switch(action) {
00053       case actions::FailPath: {
00054           should_continue = false;
00055           edm::printCmsExceptionWarning("FailPath", e);
00056           break;
00057       }
00058       default: {
00059           if (isEvent) ++timesExcept_;
00060           state_ = hlt::Exception;
00061           recordStatus(nwrwue, isEvent);
00062           if (action == actions::Rethrow) {
00063             std::string pNF = Exception::codeToString(errors::ProductNotFound);
00064             if (e.category() == pNF) {
00065               std::ostringstream ost;
00066               ost <<  "If you wish to continue processing events after a " << pNF << " exception,\n" <<
00067               "add \"SkipEvent = cms.untracked.vstring('ProductNotFound')\" to the \"options\" PSet in the configuration.\n";
00068               e.addAdditionalInfo(ost.str());
00069             }
00070           }
00071           throw;
00072       }
00073     }
00074 
00075     return should_continue;
00076   }
00077 
00078   void
00079   Path::exceptionContext(cms::Exception & ex,
00080                          bool isEvent,
00081                          bool begin,
00082                          BranchType branchType,
00083                          CurrentProcessingContext const& cpc,
00084                          std::string const& id) {
00085     std::ostringstream ost;
00086     if (isEvent) {
00087       ost << "Calling event method";
00088     }
00089     else if (begin && branchType == InRun) {
00090       ost << "Calling beginRun";
00091     }
00092     else if (begin && branchType == InLumi) {
00093       ost << "Calling beginLuminosityBlock";
00094     }
00095     else if (!begin && branchType == InLumi) {
00096       ost << "Calling endLuminosityBlock";
00097     }
00098     else if (!begin && branchType == InRun) {
00099       ost << "Calling endRun";
00100     }
00101     else {
00102       // It should be impossible to get here ...
00103       ost << "Calling unknown function";
00104     }
00105     if (cpc.moduleDescription()) {
00106       ost << " for module " << cpc.moduleDescription()->moduleName() << "/'" << cpc.moduleDescription()->moduleLabel() << "'";
00107     }
00108     ex.addContext(ost.str());
00109     ost.str("");
00110     ost << "Running path '";
00111     if (cpc.pathName()) {
00112       ost << *cpc.pathName() << "'";
00113     }
00114     else {
00115       ost << "unknown'";
00116     }
00117     ex.addContext(ost.str());
00118     ost.str("");
00119     ost << "Processing ";
00120     ost << id;
00121     ex.addContext(ost.str());
00122   }
00123 
00124   void
00125   Path::recordStatus(int nwrwue, bool isEvent) {
00126     if(isEvent) {
00127       (*trptr_)[bitpos_]=HLTPathStatus(state_, nwrwue);    
00128     }
00129   }
00130 
00131   void
00132   Path::updateCounters(bool success, bool isEvent) {
00133     if (success) {
00134       if (isEvent) ++timesPassed_;
00135       state_ = hlt::Pass;
00136     } else {
00137       if(isEvent) ++timesFailed_;
00138       state_ = hlt::Fail;
00139     }
00140   }
00141 
00142   void
00143   Path::clearCounters() {
00144     timesRun_ = timesPassed_ = timesFailed_ = timesExcept_ = 0;
00145     for_all(workers_, boost::bind(&WorkerInPath::clearCounters, _1));
00146   }
00147 
00148   void
00149   Path::useStopwatch() {
00150     stopwatch_.reset(new RunStopwatch::StopwatchPointer::element_type);
00151     for(WorkersInPath::iterator it=workers_.begin(), itEnd = workers_.end();
00152         it != itEnd;
00153         ++it) {
00154       it->useStopwatch();
00155     }
00156   }
00157 
00158   void 
00159   Path::setEarlyDeleteHelpers(std::map<const Worker*,EarlyDeleteHelper*> const& iWorkerToDeleter) {
00160     //we use a temp so we can overset the size but then when moving to earlyDeleteHelpers we only
00161     // have to use the space necessary
00162     std::vector<EarlyDeleteHelper*> temp;
00163     temp.reserve(iWorkerToDeleter.size());
00164     for(unsigned int index=0; index !=size();++index) {
00165       auto found = iWorkerToDeleter.find(getWorker(index));
00166       if(found != iWorkerToDeleter.end()) {
00167         temp.push_back(found->second);
00168         found->second->addedToPath();
00169       }
00170     }
00171     std::vector<EarlyDeleteHelper*> tempCorrectSize(temp.begin(),temp.end());
00172     earlyDeleteHelpers_.swap(tempCorrectSize);
00173   }
00174 
00175   void
00176   Path::handleEarlyFinish(EventPrincipal& iEvent) {
00177     for(auto helper: earlyDeleteHelpers_) {
00178       helper->pathFinished(iEvent);
00179     }
00180   }
00181 
00182 }