Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:56

0001 #include "DataFormats/PatCandidates/interface/EventHypothesis.h"
0002 #include "DataFormats/PatCandidates/interface/EventHypothesisLooper.h"
0003 
0004 char *pat::EventHypothesis::getDemangledSymbol(const char *mangledSymbol) const {
0005   int status;
0006   char *demangledSymbol = abi::__cxa_demangle(mangledSymbol, nullptr, nullptr, &status);
0007   return (status == 0) ? demangledSymbol : nullptr;
0008 }
0009 
0010 void pat::EventHypothesis::add(const CandRefType &ref, const std::string &role) {
0011   particles_.push_back(value_type(role, ref));
0012 }
0013 
0014 const pat::EventHypothesis::CandRefType &pat::EventHypothesis::get(const std::string &role, int index) const {
0015   if (index >= 0) {
0016     const_iterator it = realGet(begin(), end(), ByRole(role), index);
0017     if (it == end()) {
0018       throw cms::Exception("Index not found")
0019           << "Can't find a particle with role " << role << " and index " << index << "\n";
0020     }
0021     return it->second;
0022   } else {
0023     const_reverse_iterator it = realGet(rbegin(), rend(), ByRole(role), -index);
0024     if (it == rend()) {
0025       throw cms::Exception("Index not found")
0026           << "Can't find a particle with role " << role << " and index " << index << "\n";
0027     }
0028     return it->second;
0029   }
0030 }
0031 
0032 const pat::EventHypothesis::CandRefType &pat::EventHypothesis::get(const ParticleFilter &filter, int index) const {
0033   if (index >= 0) {
0034     const_iterator it = realGet(begin(), end(), filter, index);
0035     if (it == end()) {
0036       throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n";
0037     }
0038     return it->second;
0039   } else {
0040     const_reverse_iterator it = realGet(rbegin(), rend(), filter, -index);
0041     if (it == rend()) {
0042       throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n";
0043     }
0044     return it->second;
0045   }
0046 }
0047 
0048 std::vector<pat::EventHypothesis::CandRefType> pat::EventHypothesis::all(const std::string &roleRegexp) const {
0049   return all(pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
0050 }
0051 
0052 std::vector<pat::EventHypothesis::CandRefType> pat::EventHypothesis::all(const ParticleFilter &filter) const {
0053   std::vector<pat::EventHypothesis::CandRefType> ret;
0054   for (const_iterator it = begin(); it != end(); ++it) {
0055     if (filter(*it))
0056       ret.push_back(it->second);
0057   }
0058   return ret;
0059 }
0060 
0061 size_t pat::EventHypothesis::count(const std::string &roleRegexp) const {
0062   return count(pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
0063 }
0064 
0065 size_t pat::EventHypothesis::count(const ParticleFilter &role) const {
0066   size_t n = 0;
0067   for (const_iterator it = begin(); it != end(); ++it) {
0068     if (role(*it))
0069       ++n;
0070   }
0071   return n;
0072 }
0073 
0074 pat::EventHypothesis::CandLooper pat::EventHypothesis::loop() const {
0075   return loop(pat::eventhypothesis::AcceptAllFilter::get());
0076 }
0077 
0078 pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const std::string &roleRegexp) const {
0079   return loop(new pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
0080 }
0081 
0082 pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const ParticleFilter &role) const {
0083   return CandLooper(*this, role);
0084 }
0085 
0086 pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const ParticleFilter *role) const {
0087   return CandLooper(*this, role);
0088 }
0089 
0090 pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const ParticleFilterPtr &role) const {
0091   return CandLooper(*this, role);
0092 }
0093 
0094 const pat::eventhypothesis::AcceptAllFilter pat::eventhypothesis::AcceptAllFilter::s_dummyFilter;