CMS 3D CMS Logo

Schedule.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Framework/interface/Schedule.h"
00003 #include "FWCore/Utilities/interface/GetPassID.h"
00004 #include "FWCore/Utilities/interface/GetReleaseVersion.h"
00005 #include "FWCore/Framework/interface/EDFilter.h"
00006 #include "FWCore/Framework/interface/EDProducer.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/TriggerNamesService.h"
00009 #include "FWCore/Framework/interface/TriggerReport.h"
00010 #include "FWCore/Framework/interface/OutputModuleDescription.h"
00011 #include "FWCore/Framework/src/OutputWorker.h"
00012 #include "FWCore/Framework/src/WorkerT.h"
00013 #include "FWCore/Framework/src/WorkerInPath.h"
00014 #include "FWCore/Framework/src/WorkerRegistry.h"
00015 #include "DataFormats/Provenance/interface/ModuleDescription.h"
00016 #include "DataFormats/Provenance/interface/PassID.h"
00017 #include "DataFormats/Provenance/interface/ProductRegistry.h"
00018 #include "DataFormats/Provenance/interface/ReleaseVersion.h"
00019 #include "FWCore/Framework/src/TriggerResultInserter.h"
00020 
00021 #include "boost/bind.hpp"
00022 #include "boost/ref.hpp"
00023 
00024 #include <algorithm>
00025 #include <cstdlib>
00026 #include <iomanip>
00027 #include <list>
00028 
00029 namespace edm {
00030   namespace {
00031 
00032     // Function template to transform each element in the input range to
00033     // a value placed into the output range. The supplied function
00034     // should take a const_reference to the 'input', and write to a
00035     // reference to the 'output'.
00036     template <class InputIterator, class ForwardIterator, class Func>
00037     void
00038     transform_into(InputIterator begin, InputIterator end,
00039                    ForwardIterator out, Func func) {
00040       for (; begin != end; ++begin, ++out) func(*begin, *out);
00041     }
00042     
00043     // Function template that takes a sequence 'from', a sequence
00044     // 'to', and a callable object 'func'. It and applies
00045     // transform_into to fill the 'to' sequence with the values
00046     // calcuated by the callable object, taking care to fill the
00047     // outupt only if all calls succeed.
00048     template <class FROM, class TO, class FUNC>
00049     void
00050     fill_summary(FROM const& from, TO& to, FUNC func) {
00051       TO temp(from.size());
00052       transform_into(from.begin(), from.end(), temp.begin(), func);
00053       to.swap(temp);
00054     }
00055 
00056     // -----------------------------
00057 
00058     // Here we make the trigger results inserter directly.  This should
00059     // probably be a utility in the WorkerRegistry or elsewhere.
00060 
00061     Schedule::WorkerPtr 
00062     makeInserter(ParameterSet const& proc_pset,
00063                  ParameterSet const& trig_pset,
00064                  std::string const& proc_name,
00065                  ProductRegistry& preg,
00066                  ActionTable& actions,
00067                  boost::shared_ptr<ActivityRegistry> areg,
00068                  Schedule::TrigResPtr trptr) {
00069 
00070       WorkerParams work_args(proc_pset,trig_pset,preg,actions,proc_name);
00071       ModuleDescription md;
00072       md.parameterSetID_ = trig_pset.id();
00073       md.moduleName_ = "TriggerResultInserter";
00074       md.moduleLabel_ = "TriggerResults";
00075       md.processConfiguration_ = ProcessConfiguration(proc_name, proc_pset.id(), getReleaseVersion(), getPassID());
00076 
00077       areg->preModuleConstructionSignal_(md);
00078       std::auto_ptr<EDProducer> producer(new TriggerResultInserter(trig_pset,trptr));
00079       areg->postModuleConstructionSignal_(md);
00080 
00081       Schedule::WorkerPtr ptr(new WorkerT<EDProducer>(producer, md, work_args));
00082       ptr->setActivityRegistry(areg);
00083       return ptr;
00084     }
00085 
00086   }
00087 
00088   // -----------------------------
00089 
00090   typedef std::vector<std::string> vstring;
00091 
00092   // -----------------------------
00093 
00094   Schedule::Schedule(ParameterSet const& proc_pset,
00095                      edm::service::TriggerNamesService& tns,
00096                      WorkerRegistry& wreg,
00097                      ProductRegistry& preg,
00098                      ActionTable& actions,
00099                      boost::shared_ptr<ActivityRegistry> areg):
00100     pset_(proc_pset),
00101     worker_reg_(&wreg),
00102     prod_reg_(&preg),
00103     act_table_(&actions),
00104     processName_(tns.getProcessName()),
00105     actReg_(areg),
00106     state_(Ready),
00107     trig_name_list_(tns.getTrigPaths()),
00108     end_path_name_list_(tns.getEndPaths()),
00109     results_        (new HLTGlobalStatus(trig_name_list_.size())),
00110     endpath_results_(), // delay!
00111     results_inserter_(),
00112     all_workers_(),
00113     all_output_workers_(),
00114     trig_paths_(),
00115     end_paths_(),
00116     wantSummary_(tns.wantSummary()),
00117     total_events_(),
00118     total_passed_(),
00119     stopwatch_(new RunStopwatch::StopwatchPointer::element_type),
00120     unscheduled_(new UnscheduledCallProducer),
00121     demandBranches_(),
00122     endpathsAreActive_(true)
00123   {
00124     ParameterSet opts(pset_.getUntrackedParameter<ParameterSet>("options", ParameterSet()));
00125     bool hasPath = false;
00126 
00127     int trig_bitpos = 0;
00128     for (vstring::const_iterator i = trig_name_list_.begin(),
00129            e = trig_name_list_.end();
00130          i != e;
00131          ++i) {
00132       fillTrigPath(trig_bitpos,*i, results_);
00133       ++trig_bitpos;
00134       hasPath = true;
00135     }
00136 
00137     if (hasPath) {
00138       // the results inserter stands alone
00139       results_inserter_ = makeInserter(pset_, tns.getTriggerPSet(), 
00140                                        processName_,
00141                                        preg, actions, actReg_, results_);
00142       addToAllWorkers(results_inserter_.get());
00143     }
00144 
00145     TrigResPtr epptr(new HLTGlobalStatus(end_path_name_list_.size()));
00146     endpath_results_ = epptr;
00147 
00148     // fill normal endpaths
00149     vstring::iterator eib(end_path_name_list_.begin()),eie(end_path_name_list_.end());
00150     for(int bitpos = 0; eib != eie; ++eib, ++bitpos) {
00151       fillEndPath(bitpos, *eib);
00152     }
00153 
00154     //See if all modules were used
00155     std::set<std::string> usedWorkerLabels;
00156     for(AllWorkers::iterator itWorker=workersBegin();
00157         itWorker != workersEnd();
00158         ++itWorker) {
00159       usedWorkerLabels.insert((*itWorker)->description().moduleLabel_);
00160     }
00161     std::vector<std::string> modulesInConfig(proc_pset.getParameter<std::vector<std::string> >("@all_modules"));
00162     std::set<std::string> modulesInConfigSet(modulesInConfig.begin(),modulesInConfig.end());
00163     std::vector<std::string> unusedLabels;
00164     set_difference(modulesInConfigSet.begin(),modulesInConfigSet.end(),
00165                    usedWorkerLabels.begin(),usedWorkerLabels.end(),
00166                    back_inserter(unusedLabels));
00167     //does the configuration say we should allow on demand?
00168     bool allowUnscheduled = opts.getUntrackedParameter<bool>("allowUnscheduled", false);
00169     std::set<std::string> unscheduledLabels;
00170     if(!unusedLabels.empty()) {
00171       //Need to
00172       // 1) create worker
00173       // 2) if it is a WorkerT<EDProducer>, add it to our list
00174       // 3) hand list to our delayed reader
00175       std::vector<std::string>  shouldBeUsedLabels;
00176         
00177       for(std::vector<std::string>::iterator itLabel = unusedLabels.begin(), itLabelEnd = unusedLabels.end();
00178           itLabel != itLabelEnd;
00179           ++itLabel) {
00180         if (allowUnscheduled) {
00181           //Need to hold onto the parameters long enough to make the call to getWorker
00182           ParameterSet workersParams(proc_pset.getParameter<ParameterSet>(*itLabel));
00183           WorkerParams params(proc_pset, workersParams,
00184                               *prod_reg_, *act_table_,
00185                               processName_, getReleaseVersion(), getPassID());
00186           Worker* newWorker(wreg.getWorker(params));
00187           if (dynamic_cast<WorkerT<EDProducer>*>(newWorker) ||
00188               dynamic_cast<WorkerT<EDFilter>*>(newWorker) ) {
00189             unscheduledLabels.insert(*itLabel);
00190             unscheduled_->addWorker(newWorker);
00191             //add to list so it gets reset each new event
00192             addToAllWorkers(newWorker);
00193           } else {
00194             //not a producer so should be marked as not used
00195             shouldBeUsedLabels.push_back(*itLabel);
00196           }
00197         } else {
00198           //everthing is marked are unused so no 'on demand' allowed
00199           shouldBeUsedLabels.push_back(*itLabel);
00200         }
00201       }
00202       if(!shouldBeUsedLabels.empty()) {
00203         std::ostringstream unusedStream;
00204         unusedStream << "'"<< shouldBeUsedLabels.front() <<"'";
00205         for(std::vector<std::string>::iterator itLabel = shouldBeUsedLabels.begin() + 1,
00206               itLabelEnd = shouldBeUsedLabels.end();
00207             itLabel != itLabelEnd;
00208             ++itLabel) {
00209           unusedStream <<",'" << *itLabel<<"'";
00210         }
00211         LogInfo("path")
00212           << "The following module labels are not assigned to any path:\n"
00213           <<unusedStream.str()
00214           <<"\n";
00215       }
00216     }
00217 
00218     // All the workers should be in all_workers_ by this point. Thus
00219     // we can now fill all_output_workers_.  We provide a little
00220     // sanity-check to make sure no code modifications alter the
00221     // number of workers at a later date... Much better would be to
00222     // refactor this huge constructor into a series of well-named
00223     // private functions.
00224     size_t all_workers_count = all_workers_.size();
00225     for (AllWorkers::iterator i = all_workers_.begin(), e = all_workers_.end();
00226          i != e;
00227          ++i)   {
00228       OutputWorker* ow = dynamic_cast<OutputWorker*>(*i);
00229       if (ow) all_output_workers_.push_back(ow);
00230     }
00231 
00232     // Now that the output workers are filled in, set any output limits.
00233     limitOutput();
00234 
00235     prod_reg_->setFrozen();
00236 
00237     //Now that these have been set, we can create the list of Branches we need for the 'on demand'
00238     ProductRegistry::ProductList const& prodsList = prod_reg_->productList();
00239     for(ProductRegistry::ProductList::const_iterator itProdInfo = prodsList.begin(),
00240           itProdInfoEnd = prodsList.end();
00241         itProdInfo != itProdInfoEnd;
00242         ++itProdInfo) {
00243       if(processName_ == itProdInfo->second.processName() &&
00244          unscheduledLabels.end() != unscheduledLabels.find(itProdInfo->second.moduleLabel())) {
00245         boost::shared_ptr<ConstBranchDescription const> bd(new ConstBranchDescription(itProdInfo->second));
00246         demandBranches_.push_back(bd);
00247       }
00248     }
00249 
00250     // Sanity check: make sure nobody has added a worker after we've
00251     // already relied on all_workers_ being full.
00252     assert (all_workers_count == all_workers_.size());
00253       
00254   } // Schedule::Schedule
00255 
00256   void
00257   Schedule::limitOutput() {
00258     std::string const output("output");
00259 
00260     ParameterSet maxEventsPSet(pset_.getUntrackedParameter<ParameterSet>("maxEvents", ParameterSet()));
00261     int maxEventSpecs = 0; 
00262     int maxEventsOut = -1;
00263     ParameterSet vMaxEventsOut;
00264     std::vector<std::string> intNamesE = maxEventsPSet.getParameterNamesForType<int>(false);
00265     if (search_all(intNamesE, output)) {
00266       maxEventsOut = maxEventsPSet.getUntrackedParameter<int>(output);
00267       ++maxEventSpecs;
00268     }
00269     std::vector<std::string> psetNamesE;
00270     maxEventsPSet.getParameterSetNames(psetNamesE, false);
00271     if (search_all(psetNamesE, output)) {
00272       vMaxEventsOut = maxEventsPSet.getUntrackedParameter<ParameterSet>(output);
00273       ++maxEventSpecs;
00274     }
00275 
00276     if (maxEventSpecs > 1) {
00277       throw edm::Exception(edm::errors::Configuration) <<
00278         "\nAt most, one form of 'output' may appear in the 'maxEvents' parameter set";
00279     }
00280 
00281     if (maxEventSpecs == 0) {
00282       return;
00283     }
00284 
00285     for (AllOutputWorkers::const_iterator it = all_output_workers_.begin(), itEnd = all_output_workers_.end();
00286         it != itEnd; ++it) {
00287       OutputModuleDescription desc(maxEventsOut);
00288       if (!vMaxEventsOut.empty()) {
00289         std::string moduleLabel = (*it)->description().moduleLabel_;
00290         if (!vMaxEventsOut.empty()) {
00291           try {
00292             desc.maxEvents_ = vMaxEventsOut.getUntrackedParameter<int>(moduleLabel);
00293           } catch (edm::Exception) {
00294             throw edm::Exception(edm::errors::Configuration) <<
00295               "\nNo entry in 'maxEvents' for output module label '" << moduleLabel << "'.\n";
00296           }
00297         }
00298       }
00299       (*it)->configure(desc);
00300     }
00301   }
00302 
00303   bool const Schedule::terminate() const {
00304     if (all_output_workers_.empty()) {
00305       return false;
00306     }
00307     for (AllOutputWorkers::const_iterator it = all_output_workers_.begin(),
00308          itEnd = all_output_workers_.end();
00309          it != itEnd; ++it) {
00310       if (!(*it)->limitReached()) {
00311         // Found an output module that has not reached output event count.
00312         return false;
00313       }
00314     }
00315     LogInfo("SuccessfulTermination")
00316       << "The job is terminating successfully because each output module\n"
00317       << "has reached its configured limit.\n";
00318     return true;
00319   }
00320 
00321   void Schedule::fillWorkers(std::string const& name, PathWorkers& out) {
00322     vstring modnames = pset_.getParameter<vstring>(name);
00323     vstring::iterator it(modnames.begin()),ie(modnames.end());
00324     PathWorkers tmpworkers;
00325 
00326     for(; it != ie; ++it) {
00327 
00328       WorkerInPath::FilterAction filterAction = WorkerInPath::Normal;
00329       if ((*it)[0] == '!')       filterAction = WorkerInPath::Veto;
00330       else if ((*it)[0] == '-')  filterAction = WorkerInPath::Ignore;
00331 
00332       std::string realname = *it;
00333       if (filterAction != WorkerInPath::Normal) realname.erase(0,1);
00334 
00335       ParameterSet modpset;
00336       try {
00337         modpset= pset_.getParameter<ParameterSet>(realname);
00338       } catch(cms::Exception&) {
00339         std::string pathType("endpath");
00340         if(!search_all(end_path_name_list_, name)) {
00341           pathType = std::string("path");
00342         }
00343         throw edm::Exception(edm::errors::Configuration) <<
00344           "The unknown module label \"" << realname <<
00345           "\" appears in " << pathType << " \"" << name <<
00346           "\"\n please check spelling or remove that label from the path.";
00347       }
00348       WorkerParams params(pset_, modpset, *prod_reg_, *act_table_,
00349                           processName_, getReleaseVersion(), getPassID());
00350       WorkerInPath w(worker_reg_->getWorker(params), filterAction);
00351       tmpworkers.push_back(w);
00352     }
00353 
00354     out.swap(tmpworkers);
00355   }
00356 
00357   void Schedule::fillTrigPath(int bitpos, std::string const& name, TrigResPtr trptr) {
00358     PathWorkers tmpworkers;
00359     Workers holder;
00360     fillWorkers(name,tmpworkers);
00361 
00362     for(PathWorkers::iterator wi(tmpworkers.begin()),
00363           we(tmpworkers.end()); wi != we; ++wi) {
00364       holder.push_back(wi->getWorker());
00365     }
00366 
00367     // an empty path will cause an extra bit that is not used
00368     if(!tmpworkers.empty()) {
00369       Path p(bitpos,name,tmpworkers,trptr,pset_,*act_table_,actReg_,false);
00370       trig_paths_.push_back(p);
00371     }
00372     for_all(holder, boost::bind(&edm::Schedule::addToAllWorkers, this, _1));
00373   }
00374 
00375   void Schedule::fillEndPath(int bitpos, std::string const& name) {
00376     PathWorkers tmpworkers;
00377     fillWorkers(name,tmpworkers);
00378     Workers holder;
00379 
00380     for(PathWorkers::iterator wi(tmpworkers.begin()),
00381           we(tmpworkers.end()); wi != we; ++wi) {
00382       holder.push_back(wi->getWorker());
00383     }
00384 
00385     if (!tmpworkers.empty()) {
00386       Path p(bitpos,name,tmpworkers,endpath_results_,pset_,*act_table_,actReg_,true);
00387       end_paths_.push_back(p);
00388     }
00389     for_all(holder, boost::bind(&edm::Schedule::addToAllWorkers, this, _1));
00390   }
00391 
00392   void Schedule::endJob() {
00393     bool failure = false;
00394     cms::Exception accumulated("endJob");
00395     AllWorkers::iterator ai(workersBegin()),ae(workersEnd());
00396     for(; ai != ae; ++ai) {
00397       try {
00398         (*ai)->endJob();
00399       }
00400       catch (cms::Exception& e) {
00401         accumulated << "cms::Exception caught in Schedule::endJob\n"
00402                     << e.explainSelf();
00403         failure = true;
00404       }
00405       catch (std::exception& e) {
00406         accumulated << "Standard library exception caught in Schedule::endJob\n"
00407                     << e.what();
00408         failure = true;
00409       }
00410       catch (...) {
00411         accumulated << "Unknown exception caught in Schedule::endJob\n";
00412         failure = true;
00413       }
00414     }
00415     if (failure) {
00416       throw accumulated;
00417     }
00418 
00419 
00420     if(wantSummary_ == false) return;
00421 
00422     TrigPaths::const_iterator pi,pe;
00423 
00424     // The trigger report (pass/fail etc.):
00425 
00426     LogVerbatim("FwkSummary") << "";
00427     LogVerbatim("FwkSummary") << "TrigReport " << "---------- Event  Summary ------------";
00428     LogVerbatim("FwkSummary") << "TrigReport"
00429                               << " Events total = " << totalEvents()
00430                               << " passed = " << totalEventsPassed()
00431                               << " failed = " << (totalEventsFailed())
00432                               << "";
00433 
00434     LogVerbatim("FwkSummary") << "";
00435     LogVerbatim("FwkSummary") << "TrigReport " << "---------- Path   Summary ------------";
00436     LogVerbatim("FwkSummary") << "TrigReport "
00437                               << std::right << std::setw(10) << "Trig Bit#" << " "
00438                               << std::right << std::setw(10) << "Run" << " "
00439                               << std::right << std::setw(10) << "Passed" << " "
00440                               << std::right << std::setw(10) << "Failed" << " "
00441                               << std::right << std::setw(10) << "Error" << " "
00442                               << "Name" << "";
00443     pi=trig_paths_.begin();
00444     pe=trig_paths_.end();
00445     for(; pi != pe; ++pi) {
00446       LogVerbatim("FwkSummary") << "TrigReport "
00447                                 << std::right << std::setw( 5) << 1
00448                                 << std::right << std::setw( 5) << pi->bitPosition() << " "
00449                                 << std::right << std::setw(10) << pi->timesRun() << " "
00450                                 << std::right << std::setw(10) << pi->timesPassed() << " "
00451                                 << std::right << std::setw(10) << pi->timesFailed() << " "
00452                                 << std::right << std::setw(10) << pi->timesExcept() << " "
00453                                 << pi->name() << "";
00454     }
00455 
00456     LogVerbatim("FwkSummary") << "";
00457     LogVerbatim("FwkSummary") << "TrigReport " << "-------End-Path   Summary ------------";
00458     LogVerbatim("FwkSummary") << "TrigReport "
00459                               << std::right << std::setw(10) << "Trig Bit#" << " "
00460                               << std::right << std::setw(10) << "Run" << " "
00461                               << std::right << std::setw(10) << "Passed" << " "
00462                               << std::right << std::setw(10) << "Failed" << " "
00463                               << std::right << std::setw(10) << "Error" << " "
00464                               << "Name" << "";
00465     pi=end_paths_.begin();
00466     pe=end_paths_.end();
00467     for(; pi != pe; ++pi) {
00468       LogVerbatim("FwkSummary") << "TrigReport "
00469                                 << std::right << std::setw( 5) << 0
00470                                 << std::right << std::setw( 5) << pi->bitPosition() << " "
00471                                 << std::right << std::setw(10) << pi->timesRun() << " "
00472                                 << std::right << std::setw(10) << pi->timesPassed() << " "
00473                                 << std::right << std::setw(10) << pi->timesFailed() << " "
00474                                 << std::right << std::setw(10) << pi->timesExcept() << " "
00475                                 << pi->name() << "";
00476     }
00477 
00478     pi=trig_paths_.begin();
00479     pe=trig_paths_.end();
00480     for(; pi != pe; ++pi) {
00481       LogVerbatim("FwkSummary") << "";
00482       LogVerbatim("FwkSummary") << "TrigReport " << "---------- Modules in Path: " << pi->name() << " ------------";
00483       LogVerbatim("FwkSummary") << "TrigReport "
00484                                 << std::right << std::setw(10) << "Trig Bit#" << " "
00485                                 << std::right << std::setw(10) << "Visited" << " "
00486                                 << std::right << std::setw(10) << "Passed" << " "
00487                                 << std::right << std::setw(10) << "Failed" << " "
00488                                 << std::right << std::setw(10) << "Error" << " "
00489                                 << "Name" << "";
00490 
00491       for (unsigned int i = 0; i < pi->size(); ++i) {
00492         LogVerbatim("FwkSummary") << "TrigReport "
00493                                   << std::right << std::setw( 5) << 1
00494                                   << std::right << std::setw( 5) << pi->bitPosition() << " "
00495                                   << std::right << std::setw(10) << pi->timesVisited(i) << " "
00496                                   << std::right << std::setw(10) << pi->timesPassed(i) << " "
00497                                   << std::right << std::setw(10) << pi->timesFailed(i) << " "
00498                                   << std::right << std::setw(10) << pi->timesExcept(i) << " "
00499                                   << pi->getWorker(i)->description().moduleLabel_ << "";
00500       }
00501     }
00502 
00503     pi=end_paths_.begin();
00504     pe=end_paths_.end();
00505     for(; pi != pe; ++pi) {
00506       LogVerbatim("FwkSummary") << "";
00507       LogVerbatim("FwkSummary") << "TrigReport " << "------ Modules in End-Path: " << pi->name() << " ------------";
00508       LogVerbatim("FwkSummary") << "TrigReport "
00509                                 << std::right << std::setw(10) << "Trig Bit#" << " "
00510                                 << std::right << std::setw(10) << "Visited" << " "
00511                                 << std::right << std::setw(10) << "Passed" << " "
00512                                 << std::right << std::setw(10) << "Failed" << " "
00513                                 << std::right << std::setw(10) << "Error" << " "
00514                                 << "Name" << "";
00515 
00516       for (unsigned int i = 0; i < pi->size(); ++i) {
00517         LogVerbatim("FwkSummary") << "TrigReport "
00518                                   << std::right << std::setw( 5) << 0
00519                                   << std::right << std::setw( 5) << pi->bitPosition() << " "
00520                                   << std::right << std::setw(10) << pi->timesVisited(i) << " "
00521                                   << std::right << std::setw(10) << pi->timesPassed(i) << " "
00522                                   << std::right << std::setw(10) << pi->timesFailed(i) << " "
00523                                   << std::right << std::setw(10) << pi->timesExcept(i) << " "
00524                                   << pi->getWorker(i)->description().moduleLabel_ << "";
00525       }
00526     }
00527 
00528     LogVerbatim("FwkSummary") << "";
00529     LogVerbatim("FwkSummary") << "TrigReport " << "---------- Module Summary ------------";
00530     LogVerbatim("FwkSummary") << "TrigReport "
00531                               << std::right << std::setw(10) << "Visited" << " "
00532                               << std::right << std::setw(10) << "Run" << " "
00533                               << std::right << std::setw(10) << "Passed" << " "
00534                               << std::right << std::setw(10) << "Failed" << " "
00535                               << std::right << std::setw(10) << "Error" << " "
00536                               << "Name" << "";
00537     ai=workersBegin();
00538     ae=workersEnd();
00539     for(; ai != ae; ++ai) {
00540       LogVerbatim("FwkSummary") << "TrigReport "
00541                                 << std::right << std::setw(10) << (*ai)->timesVisited() << " "
00542                                 << std::right << std::setw(10) << (*ai)->timesRun() << " "
00543                                 << std::right << std::setw(10) << (*ai)->timesPassed() << " "
00544                                 << std::right << std::setw(10) << (*ai)->timesFailed() << " "
00545                                 << std::right << std::setw(10) << (*ai)->timesExcept() << " "
00546                                 << (*ai)->description().moduleLabel_ << "";
00547 
00548     }
00549     LogVerbatim("FwkSummary") << "";
00550 
00551     // The timing report (CPU and Real Time):
00552 
00553     LogVerbatim("FwkSummary") << "TimeReport " << "---------- Event  Summary ---[sec]----";
00554     LogVerbatim("FwkSummary") << "TimeReport"
00555                               << std::setprecision(6) << std::fixed
00556                               << " CPU/event = " << timeCpuReal().first/std::max(1,totalEvents())
00557                               << " Real/event = " << timeCpuReal().second/std::max(1,totalEvents())
00558                               << "";
00559 
00560     LogVerbatim("FwkSummary") << "";
00561     LogVerbatim("FwkSummary") << "TimeReport " << "---------- Path   Summary ---[sec]----";
00562     LogVerbatim("FwkSummary") << "TimeReport "
00563                               << std::right << std::setw(22) << "per event "
00564                               << std::right << std::setw(22) << "per path-run "
00565                               << "";
00566     LogVerbatim("FwkSummary") << "TimeReport "
00567                               << std::right << std::setw(10) << "CPU" << " "
00568                               << std::right << std::setw(10) << "Real" << " "
00569                               << std::right << std::setw(10) << "CPU" << " "
00570                               << std::right << std::setw(10) << "Real" << " "
00571                               << "Name" << "";
00572     pi=trig_paths_.begin();
00573     pe=trig_paths_.end();
00574     for(; pi != pe; ++pi) {
00575       LogVerbatim("FwkSummary") << "TimeReport "
00576                                 << std::setprecision(6) << std::fixed
00577                                 << std::right << std::setw(10) << pi->timeCpuReal().first/std::max(1,totalEvents()) << " "
00578                                 << std::right << std::setw(10) << pi->timeCpuReal().second/std::max(1,totalEvents()) << " "
00579                                 << std::right << std::setw(10) << pi->timeCpuReal().first/std::max(1,pi->timesRun()) << " "
00580                                 << std::right << std::setw(10) << pi->timeCpuReal().second/std::max(1,pi->timesRun()) << " "
00581                                 << pi->name() << "";
00582     }
00583     LogVerbatim("FwkSummary") << "TimeReport "
00584                               << std::right << std::setw(10) << "CPU" << " "
00585                               << std::right << std::setw(10) << "Real" << " "
00586                               << std::right << std::setw(10) << "CPU" << " "
00587                               << std::right << std::setw(10) << "Real" << " "
00588                               << "Name" << "";
00589     LogVerbatim("FwkSummary") << "TimeReport "
00590                               << std::right << std::setw(22) << "per event "
00591                               << std::right << std::setw(22) << "per path-run "
00592                               << "";
00593 
00594     LogVerbatim("FwkSummary") << "";
00595     LogVerbatim("FwkSummary") << "TimeReport " << "-------End-Path   Summary ---[sec]----";
00596     LogVerbatim("FwkSummary") << "TimeReport "
00597                               << std::right << std::setw(22) << "per event "
00598                               << std::right << std::setw(22) << "per endpath-run "
00599                               << "";
00600     LogVerbatim("FwkSummary") << "TimeReport "
00601                               << std::right << std::setw(10) << "CPU" << " "
00602                               << std::right << std::setw(10) << "Real" << " "
00603                               << std::right << std::setw(10) << "CPU" << " "
00604                               << std::right << std::setw(10) << "Real" << " "
00605                               << "Name" << "";
00606     pi=end_paths_.begin();
00607     pe=end_paths_.end();
00608     for(; pi != pe; ++pi) {
00609       LogVerbatim("FwkSummary") << "TimeReport "
00610                                 << std::setprecision(6) << std::fixed
00611                                 << std::right << std::setw(10) << pi->timeCpuReal().first/std::max(1,totalEvents()) << " "
00612                                 << std::right << std::setw(10) << pi->timeCpuReal().second/std::max(1,totalEvents()) << " "
00613                                 << std::right << std::setw(10) << pi->timeCpuReal().first/std::max(1,pi->timesRun()) << " "
00614                                 << std::right << std::setw(10) << pi->timeCpuReal().second/std::max(1,pi->timesRun()) << " "
00615                                 << pi->name() << "";
00616     }
00617     LogVerbatim("FwkSummary") << "TimeReport "
00618                               << std::right << std::setw(10) << "CPU" << " "
00619                               << std::right << std::setw(10) << "Real" << " "
00620                               << std::right << std::setw(10) << "CPU" << " "
00621                               << std::right << std::setw(10) << "Real" << " "
00622                               << "Name" << "";
00623     LogVerbatim("FwkSummary") << "TimeReport "
00624                               << std::right << std::setw(22) << "per event "
00625                               << std::right << std::setw(22) << "per endpath-run "
00626                               << "";
00627 
00628     pi=trig_paths_.begin();
00629     pe=trig_paths_.end();
00630     for(; pi != pe; ++pi) {
00631       LogVerbatim("FwkSummary") << "";
00632       LogVerbatim("FwkSummary") << "TimeReport " << "---------- Modules in Path: " << pi->name() << " ---[sec]----";
00633       LogVerbatim("FwkSummary") << "TimeReport "
00634                                 << std::right << std::setw(22) << "per event "
00635                                 << std::right << std::setw(22) << "per module-visit "
00636                                 << "";
00637       LogVerbatim("FwkSummary") << "TimeReport "
00638                                 << std::right << std::setw(10) << "CPU" << " "
00639                                 << std::right << std::setw(10) << "Real" << " "
00640                                 << std::right << std::setw(10) << "CPU" << " "
00641                                 << std::right << std::setw(10) << "Real" << " "
00642                                 << "Name" << "";
00643       for (unsigned int i = 0; i < pi->size(); ++i) {
00644         LogVerbatim("FwkSummary") << "TimeReport "
00645                                   << std::setprecision(6) << std::fixed
00646                                   << std::right << std::setw(10) << pi->timeCpuReal(i).first/std::max(1,totalEvents()) << " "
00647                                   << std::right << std::setw(10) << pi->timeCpuReal(i).second/std::max(1,totalEvents()) << " "
00648                                   << std::right << std::setw(10) << pi->timeCpuReal(i).first/std::max(1,pi->timesVisited(i)) << " "
00649                                   << std::right << std::setw(10) << pi->timeCpuReal(i).second/std::max(1,pi->timesVisited(i)) << " "
00650                                   << pi->getWorker(i)->description().moduleLabel_ << "";
00651       }
00652     }
00653     LogVerbatim("FwkSummary") << "TimeReport "
00654                               << std::right << std::setw(10) << "CPU" << " "
00655                               << std::right << std::setw(10) << "Real" << " "
00656                               << std::right << std::setw(10) << "CPU" << " "
00657                               << std::right << std::setw(10) << "Real" << " "
00658                               << "Name" << "";
00659     LogVerbatim("FwkSummary") << "TimeReport "
00660                               << std::right << std::setw(22) << "per event "
00661                               << std::right << std::setw(22) << "per module-visit "
00662                               << "";
00663 
00664     pi=end_paths_.begin();
00665     pe=end_paths_.end();
00666     for(; pi != pe; ++pi) {
00667       LogVerbatim("FwkSummary") << "";
00668       LogVerbatim("FwkSummary") << "TimeReport " << "------ Modules in End-Path: " << pi->name() << " ---[sec]----";
00669       LogVerbatim("FwkSummary") << "TimeReport "
00670                                 << std::right << std::setw(22) << "per event "
00671                                 << std::right << std::setw(22) << "per module-visit "
00672                                 << "";
00673       LogVerbatim("FwkSummary") << "TimeReport "
00674                                 << std::right << std::setw(10) << "CPU" << " "
00675                                 << std::right << std::setw(10) << "Real" << " "
00676                                 << std::right << std::setw(10) << "CPU" << " "
00677                                 << std::right << std::setw(10) << "Real" << " "
00678                                 << "Name" << "";
00679       for (unsigned int i = 0; i < pi->size(); ++i) {
00680         LogVerbatim("FwkSummary") << "TimeReport "
00681                                   << std::setprecision(6) << std::fixed
00682                                   << std::right << std::setw(10) << pi->timeCpuReal(i).first/std::max(1,totalEvents()) << " "
00683                                   << std::right << std::setw(10) << pi->timeCpuReal(i).second/std::max(1,totalEvents()) << " "
00684                                   << std::right << std::setw(10) << pi->timeCpuReal(i).first/std::max(1,pi->timesVisited(i)) << " "
00685                                   << std::right << std::setw(10) << pi->timeCpuReal(i).second/std::max(1,pi->timesVisited(i)) << " "
00686                                   << pi->getWorker(i)->description().moduleLabel_ << "";
00687       }
00688     }
00689     LogVerbatim("FwkSummary") << "TimeReport "
00690                               << std::right << std::setw(10) << "CPU" << " "
00691                               << std::right << std::setw(10) << "Real" << " "
00692                               << std::right << std::setw(10) << "CPU" << " "
00693                               << std::right << std::setw(10) << "Real" << " "
00694                               << "Name" << "";
00695     LogVerbatim("FwkSummary") << "TimeReport "
00696                               << std::right << std::setw(22) << "per event "
00697                               << std::right << std::setw(22) << "per module-visit "
00698                               << "";
00699 
00700     LogVerbatim("FwkSummary") << "";
00701     LogVerbatim("FwkSummary") << "TimeReport " << "---------- Module Summary ---[sec]----";
00702     LogVerbatim("FwkSummary") << "TimeReport "
00703                               << std::right << std::setw(22) << "per event "
00704                               << std::right << std::setw(22) << "per module-run "
00705                               << std::right << std::setw(22) << "per module-visit "
00706                               << "";
00707     LogVerbatim("FwkSummary") << "TimeReport "
00708                               << std::right << std::setw(10) << "CPU" << " "
00709                               << std::right << std::setw(10) << "Real" << " "
00710                               << std::right << std::setw(10) << "CPU" << " "
00711                               << std::right << std::setw(10) << "Real" << " "
00712                               << std::right << std::setw(10) << "CPU" << " "
00713                               << std::right << std::setw(10) << "Real" << " "
00714                               << "Name" << "";
00715     ai=workersBegin();
00716     ae=workersEnd();
00717     for(; ai != ae; ++ai) {
00718       LogVerbatim("FwkSummary") << "TimeReport "
00719                                 << std::setprecision(6) << std::fixed
00720                                 << std::right << std::setw(10) << (*ai)->timeCpuReal().first/std::max(1,totalEvents()) << " "
00721                                 << std::right << std::setw(10) << (*ai)->timeCpuReal().second/std::max(1,totalEvents()) << " "
00722                                 << std::right << std::setw(10) << (*ai)->timeCpuReal().first/std::max(1,(*ai)->timesRun()) << " "
00723                                 << std::right << std::setw(10) << (*ai)->timeCpuReal().second/std::max(1,(*ai)->timesRun()) << " "
00724                                 << std::right << std::setw(10) << (*ai)->timeCpuReal().first/std::max(1,(*ai)->timesVisited()) << " "
00725                                 << std::right << std::setw(10) << (*ai)->timeCpuReal().second/std::max(1,(*ai)->timesVisited()) << " "
00726                                 << (*ai)->description().moduleLabel_ << "";
00727     }
00728     LogVerbatim("FwkSummary") << "TimeReport "
00729                               << std::right << std::setw(10) << "CPU" << " "
00730                               << std::right << std::setw(10) << "Real" << " "
00731                               << std::right << std::setw(10) << "CPU" << " "
00732                               << std::right << std::setw(10) << "Real" << " "
00733                               << std::right << std::setw(10) << "CPU" << " "
00734                               << std::right << std::setw(10) << "Real" << " "
00735                               << "Name" << "";
00736     LogVerbatim("FwkSummary") << "TimeReport "
00737                               << std::right << std::setw(22) << "per event "
00738                               << std::right << std::setw(22) << "per module-run "
00739                               << std::right << std::setw(22) << "per module-visit "
00740                               << "";
00741 
00742     LogVerbatim("FwkSummary") << "";
00743     LogVerbatim("FwkSummary") << "T---Report end!" << "";
00744     LogVerbatim("FwkSummary") << "";
00745   }
00746 
00747   void Schedule::closeOutputFiles() {
00748     for_all(all_output_workers_, boost::bind(&OutputWorker::closeFile, _1));
00749   }
00750 
00751   void Schedule::openNewOutputFilesIfNeeded() {
00752     for_all(all_output_workers_, boost::bind(&OutputWorker::openNewFileIfNeeded, _1));
00753   }
00754 
00755   void Schedule::openOutputFiles(FileBlock & fb) {
00756     for_all(all_output_workers_, boost::bind(&OutputWorker::openFile, _1, boost::cref(fb)));
00757   }
00758 
00759   void Schedule::writeRun(RunPrincipal const& rp) {
00760     for_all(all_output_workers_, boost::bind(&OutputWorker::writeRun, _1, boost::cref(rp)));
00761   }
00762 
00763   void Schedule::writeLumi(LuminosityBlockPrincipal const& lbp) {
00764     for_all(all_output_workers_, boost::bind(&OutputWorker::writeLumi, _1, boost::cref(lbp)));
00765   }
00766 
00767   bool Schedule::shouldWeCloseOutput() const {
00768     // Return true iff at least one output module returns true.
00769     return (std::find_if(all_output_workers_.begin(), all_output_workers_.end(),
00770                      boost::bind(&OutputWorker::shouldWeCloseFile, _1))
00771                      != all_output_workers_.end());
00772   }
00773 
00774   void Schedule::respondToOpenInputFile(FileBlock const& fb) {
00775     for_all(all_workers_, boost::bind(&Worker::respondToOpenInputFile, _1, boost::cref(fb)));
00776   }
00777 
00778   void Schedule::respondToCloseInputFile(FileBlock const& fb) {
00779     for_all(all_workers_, boost::bind(&Worker::respondToCloseInputFile, _1, boost::cref(fb)));
00780   }
00781 
00782   void Schedule::respondToOpenOutputFiles(FileBlock const& fb) {
00783     for_all(all_workers_, boost::bind(&Worker::respondToOpenOutputFiles, _1, boost::cref(fb)));
00784   }
00785 
00786   void Schedule::respondToCloseOutputFiles(FileBlock const& fb) {
00787     for_all(all_workers_, boost::bind(&Worker::respondToCloseOutputFiles, _1, boost::cref(fb)));
00788   }
00789 
00790   void Schedule::beginJob(EventSetup const& es) {
00791     for_all(all_workers_, boost::bind(&Worker::beginJob, _1, boost::cref(es)));
00792   }
00793 
00794   std::vector<ModuleDescription const*>
00795   Schedule::getAllModuleDescriptions() const {
00796     AllWorkers::const_iterator i(workersBegin());
00797     AllWorkers::const_iterator e(workersEnd());
00798 
00799     std::vector<ModuleDescription const*> result;
00800     result.reserve(all_workers_.size());
00801 
00802     for (; i!=e; ++i) {
00803       ModuleDescription const* p = (*i)->descPtr();
00804       result.push_back(p);
00805     }
00806     return result;
00807   }
00808 
00809   void
00810   Schedule::enableEndPaths(bool active) {
00811     endpathsAreActive_ = active;
00812   }
00813 
00814   bool
00815   Schedule::endPathsEnabled() const {
00816     return endpathsAreActive_;
00817   }
00818 
00819   void
00820   fillModuleInPathSummary(Path const&, 
00821                           ModuleInPathSummary&) {
00822   }
00823 
00824 
00825   void
00826   fillModuleInPathSummary(Path const& path, 
00827                           size_t which, 
00828                           ModuleInPathSummary& sum) {
00829     sum.timesVisited = path.timesVisited(which);
00830     sum.timesPassed  = path.timesPassed(which);
00831     sum.timesFailed  = path.timesFailed(which);
00832     sum.timesExcept  = path.timesExcept(which);
00833     sum.moduleLabel  = 
00834       path.getWorker(which)->description().moduleLabel_;
00835   }
00836 
00837   void 
00838   fillPathSummary(Path const& path, PathSummary& sum) {
00839     sum.name        = path.name();
00840     sum.bitPosition = path.bitPosition();
00841     sum.timesRun    = path.timesRun();
00842     sum.timesPassed = path.timesPassed();
00843     sum.timesFailed = path.timesFailed();
00844     sum.timesExcept = path.timesExcept();
00845 
00846     Path::size_type sz = path.size();
00847     std::vector<ModuleInPathSummary> temp(sz);
00848     for (size_t i = 0; i != sz; ++i) {
00849       fillModuleInPathSummary(path, i, temp[i]);
00850     }
00851     sum.moduleInPathSummaries.swap(temp);
00852   }
00853 
00854   void 
00855   fillWorkerSummaryAux(Worker const& w, WorkerSummary& sum) {
00856     sum.timesVisited = w.timesVisited();
00857     sum.timesRun     = w.timesRun();
00858     sum.timesPassed  = w.timesPassed();
00859     sum.timesFailed  = w.timesFailed();
00860     sum.timesExcept  = w.timesExcept();
00861     sum.moduleLabel  = w.description().moduleLabel_;
00862   }
00863 
00864   void
00865   fillWorkerSummary(Worker const* pw, WorkerSummary& sum) {
00866     fillWorkerSummaryAux(*pw, sum);
00867   }
00868   
00869   void
00870   Schedule::getTriggerReport(TriggerReport& rep) const {
00871     rep.eventSummary.totalEvents = totalEvents();
00872     rep.eventSummary.totalEventsPassed = totalEventsPassed();
00873     rep.eventSummary.totalEventsFailed = totalEventsFailed();
00874 
00875     fill_summary(trig_paths_,  rep.trigPathSummaries, &fillPathSummary);
00876     fill_summary(end_paths_,   rep.endPathSummaries,  &fillPathSummary);
00877     fill_summary(all_workers_, rep.workerSummaries,   &fillWorkerSummary);
00878   }
00879 
00880   void
00881   Schedule::clearCounters() {
00882     total_events_ = total_passed_ = 0;
00883     for_all(trig_paths_, boost::bind(&Path::clearCounters, _1));
00884     for_all(end_paths_, boost::bind(&Path::clearCounters, _1));
00885     for_all(all_workers_, boost::bind(&Worker::clearCounters, _1));
00886   }
00887 
00888   void
00889   Schedule::resetAll() {
00890     for_all(all_workers_, boost::bind(&Worker::reset, _1));
00891     results_->reset();
00892     endpath_results_->reset();
00893   }
00894 
00895   void
00896   Schedule::addToAllWorkers(Worker* w) {
00897     if (!search_all(all_workers_, w)) all_workers_.push_back(w);
00898   }
00899 
00900   void 
00901   Schedule::setupOnDemandSystem(EventPrincipal& ep,
00902                                 EventSetup const& es) {
00903     // NOTE: who owns the productdescrption?  Just copied by value
00904     unscheduled_->setEventSetup(es);
00905     ep.setUnscheduledHandler(unscheduled_);
00906     typedef std::vector<boost::shared_ptr<ConstBranchDescription const> > branches;
00907     for(branches::iterator itBranch = demandBranches_.begin(), itBranchEnd = demandBranches_.end();
00908         itBranch != itBranchEnd;
00909         ++itBranch) {
00910       ep.addOnDemandGroup(**itBranch);
00911     }
00912   }
00913 
00914 }

Generated on Tue Jun 9 17:36:12 2009 for CMSSW by  doxygen 1.5.4