CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/FWCore/Framework/src/CachedProducts.cc

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       // Set up one NamedEventSelector, with default configuration
00026       std::vector<std::string> paths;
00027       EventSelector es(paths, triggernames);
00028       NES nes("", es);
00029       selectors_.push_back(nes);
00030       //selectors_.push_back(NES("", EventSelector("",triggernames)));
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       // paths_for_process maps each PROCESS names to a sequence of
00039       // PATH names
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           // Default to current process if none specified
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       // Now go through all the PROCESS names, and create a
00056       // NamedEventSelector for each.
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           // For the current process we know the trigger names
00064           // from the configuration file
00065           if (i->first == process_name) {
00066             selectors_.push_back(NES(i->first, 
00067                                    EventSelector(i->second, 
00068                                                  triggernames)));
00069           }
00070           // For previous processes we do not know the trigger
00071           // names yet.
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       // We have to get all the TriggerResults objects before we test
00090       // any for a match, because we have to deal with the possibility
00091       // of multiple TriggerResults objects --- note that the presence
00092       // of more than one TriggerResults object in the event is
00093       // intended to lead to an exception throw *unless* either the
00094       // configuration has been set to match all events, or the
00095       // configuration is set to use specific process names.
00096 
00097       fill(ev);
00098 
00099       // Now we go through and see if anyone matches...
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);     // fill might throw...
00145               ++numberFound_ ; // so numberFound_ might be less than expected
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   } // namespace detail
00161 } // namespace edm