Go to the documentation of this file.00001 #include <algorithm>
00002
00003 #include "boost/bind.hpp"
00004
00005 #include "FWCore/Framework/interface/CachedProducts.h"
00006 #include "FWCore/Utilities/interface/Algorithms.h"
00007
00008 namespace edm
00009 {
00010 namespace detail
00011 {
00012 typedef detail::NamedEventSelector NES;
00013
00014
00015 CachedProducts::CachedProducts() :
00016 fillDone_(false),
00017 numberFound_(0),
00018 selectors_()
00019 { }
00020
00021 void
00022 CachedProducts::setupDefault(std::vector<std::string> const& triggernames)
00023 {
00024
00025
00026 std::vector<std::string> paths;
00027 EventSelector es(paths, triggernames);
00028 NES nes("", es);
00029 selectors_.push_back(nes);
00030
00031 }
00032
00033 void
00034 CachedProducts::setup(std::vector<parsed_path_spec_t> const& path_specs,
00035 std::vector<std::string> const& triggernames,
00036 const std::string& process_name)
00037 {
00038
00039
00040 std::map<std::string, std::vector<std::string> > paths_for_process;
00041 for (std::vector<parsed_path_spec_t>::const_iterator
00042 i = path_specs.begin(),
00043 e = path_specs.end();
00044 i != e;
00045 ++i)
00046 {
00047
00048 if (i->second == "") {
00049 paths_for_process[process_name].push_back(i->first);
00050 }
00051 else {
00052 paths_for_process[i->second].push_back(i->first);
00053 }
00054 }
00055
00056
00057 for (std::map<std::string, std::vector<std::string> >::const_iterator
00058 i = paths_for_process.begin(),
00059 e = paths_for_process.end();
00060 i != e;
00061 ++i)
00062 {
00063
00064
00065 if (i->first == process_name) {
00066 selectors_.push_back(NES(i->first,
00067 EventSelector(i->second,
00068 triggernames)));
00069 }
00070
00071
00072 else {
00073 selectors_.push_back(NES(i->first,
00074 EventSelector(i->second)));
00075 }
00076 }
00077 }
00078
00079 CachedProducts::handle_t
00080 CachedProducts::getOneTriggerResults(Event const& ev)
00081 {
00082 fill(ev);
00083 return returnOneHandleOrThrow();
00084 }
00085
00086 bool
00087 CachedProducts::wantEvent(Event const& ev)
00088 {
00089
00090
00091
00092
00093
00094
00095
00096
00097 fill(ev);
00098
00099
00100 iter i = selectors_.begin();
00101 iter e = selectors_.end();
00102 bool match_found = false;
00103 while (!match_found && (i!=e))
00104 {
00105 match_found = i->match();
00106 ++i;
00107 }
00108 return match_found;
00109 }
00110
00111 CachedProducts::handle_t
00112 CachedProducts::returnOneHandleOrThrow()
00113 {
00114 switch (numberFound_)
00115 {
00116 case 0:
00117 throw edm::Exception(edm::errors::ProductNotFound,
00118 "TooFewProducts")
00119 << "CachedProducts::returnOneHandleOrThrow: "
00120 << " too few products found, "
00121 << "exepcted one, got zero\n";
00122 case 1:
00123
00124 break;
00125 default:
00126 throw edm::Exception(edm::errors::ProductNotFound,
00127 "TooManyMatches")
00128 << "CachedProducts::returnOneHandleOrThrow: "
00129 << "too many products found, "
00130 << "expected one, got " << numberFound_ << '\n';
00131 }
00132 return selectors_[0].product();
00133 }
00134
00135 CachedProducts::size_type
00136 CachedProducts::fill(Event const& ev)
00137 {
00138 if (!fillDone_)
00139 {
00140 fillDone_ = true;
00141 for (iter i = selectors_.begin(), e = selectors_.end();
00142 i != e; ++i)
00143 {
00144 i->fill(ev);
00145 ++numberFound_ ;
00146 }
00147 }
00148 return numberFound_;
00149 }
00150
00151 void
00152 CachedProducts::clear()
00153 {
00154 for_all(selectors_, boost::bind(&NamedEventSelector::clear, _1));
00155 fillDone_ = false;
00156 numberFound_ = 0;
00157 }
00158
00159
00160 }
00161 }