CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/PatCandidates/src/EventHypothesis.cc

Go to the documentation of this file.
00001 #include "DataFormats/PatCandidates/interface/EventHypothesis.h"
00002 #include "DataFormats/PatCandidates/interface/EventHypothesisLooper.h"
00003 
00004 void pat::EventHypothesis::add(const CandRefType &ref, const std::string &role) {
00005     particles_.push_back(value_type(role,ref));
00006 }
00007 
00008 const pat::EventHypothesis::CandRefType & 
00009 pat::EventHypothesis::get(const std::string &role, int index) const 
00010 {
00011     if (index >= 0) {
00012         const_iterator it = realGet(begin(), end(), ByRole(role), index);
00013         if (it == end()) { throw cms::Exception("Index not found") << "Can't find a particle with role " << role << " and index " << index << "\n"; }
00014         return it->second;
00015     } else {
00016         const_reverse_iterator it = realGet(rbegin(), rend(), ByRole(role), -index);
00017         if (it == rend()) { throw cms::Exception("Index not found") << "Can't find a particle with role " << role << " and index " << index << "\n"; }
00018         return it->second;
00019     }
00020 }
00021 
00022 const pat::EventHypothesis::CandRefType &
00023 pat::EventHypothesis::get(const ParticleFilter &filter, int index) const 
00024 {
00025     if (index >= 0) {
00026         const_iterator it = realGet(begin(), end(), filter, index);
00027         if (it == end()) { throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n"; }
00028         return it->second;
00029     } else {
00030         const_reverse_iterator it = realGet(rbegin(), rend(), filter, -index);
00031         if (it == rend()) { throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n"; }
00032         return it->second;
00033     }
00034 }
00035 
00036 
00037 std::vector<pat::EventHypothesis::CandRefType> 
00038 pat::EventHypothesis::all(const std::string &roleRegexp) const 
00039 {
00040     return all(pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
00041 }
00042 
00043 std::vector<pat::EventHypothesis::CandRefType> 
00044 pat::EventHypothesis::all(const ParticleFilter &filter) const 
00045 {
00046     std::vector<pat::EventHypothesis::CandRefType> ret;
00047     for (const_iterator it = begin(); it != end(); ++it) {
00048         if (filter(*it)) ret.push_back(it->second);
00049     }
00050     return ret;
00051 }
00052 
00053 size_t
00054 pat::EventHypothesis::count(const std::string &roleRegexp) const 
00055 {
00056     return count(pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
00057 }
00058 
00059 size_t
00060 pat::EventHypothesis::count(const ParticleFilter &role) const 
00061 {
00062     size_t n = 0;
00063     for (const_iterator it = begin(); it != end(); ++it) {
00064         if (role(*it)) ++n;
00065     }
00066     return n;
00067 }
00068 
00069 pat::EventHypothesis::CandLooper
00070 pat::EventHypothesis::loop() const 
00071 {
00072     return loop(pat::eventhypothesis::AcceptAllFilter::get());
00073 }
00074 
00075 pat::EventHypothesis::CandLooper
00076 pat::EventHypothesis::loop(const std::string &roleRegexp) const
00077 {
00078     return loop(new pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
00079 }
00080 
00081 pat::EventHypothesis::CandLooper
00082 pat::EventHypothesis::loop(const ParticleFilter &role) const 
00083 {
00084     return CandLooper(*this, role); 
00085 }
00086 
00087 pat::EventHypothesis::CandLooper
00088 pat::EventHypothesis::loop(const ParticleFilter *role) const 
00089 {
00090     return CandLooper(*this, role); 
00091 }
00092 
00093 pat::EventHypothesis::CandLooper
00094 pat::EventHypothesis::loop(const ParticleFilterPtr &role) const 
00095 {
00096     return CandLooper(*this, role); 
00097 }
00098 
00099