Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
#include "DataFormats/PatCandidates/interface/EventHypothesis.h"
#include "DataFormats/PatCandidates/interface/EventHypothesisLooper.h"

char *pat::EventHypothesis::getDemangledSymbol(const char *mangledSymbol) const {
  int status;
  char *demangledSymbol = abi::__cxa_demangle(mangledSymbol, nullptr, nullptr, &status);
  return (status == 0) ? demangledSymbol : nullptr;
}

void pat::EventHypothesis::add(const CandRefType &ref, const std::string &role) {
  particles_.push_back(value_type(role, ref));
}

const pat::EventHypothesis::CandRefType &pat::EventHypothesis::get(const std::string &role, int index) const {
  if (index >= 0) {
    const_iterator it = realGet(begin(), end(), ByRole(role), index);
    if (it == end()) {
      throw cms::Exception("Index not found")
          << "Can't find a particle with role " << role << " and index " << index << "\n";
    }
    return it->second;
  } else {
    const_reverse_iterator it = realGet(rbegin(), rend(), ByRole(role), -index);
    if (it == rend()) {
      throw cms::Exception("Index not found")
          << "Can't find a particle with role " << role << " and index " << index << "\n";
    }
    return it->second;
  }
}

const pat::EventHypothesis::CandRefType &pat::EventHypothesis::get(const ParticleFilter &filter, int index) const {
  if (index >= 0) {
    const_iterator it = realGet(begin(), end(), filter, index);
    if (it == end()) {
      throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n";
    }
    return it->second;
  } else {
    const_reverse_iterator it = realGet(rbegin(), rend(), filter, -index);
    if (it == rend()) {
      throw cms::Exception("Index not found") << "Can't find a particle matching filter with index " << index << "\n";
    }
    return it->second;
  }
}

std::vector<pat::EventHypothesis::CandRefType> pat::EventHypothesis::all(const std::string &roleRegexp) const {
  return all(pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
}

std::vector<pat::EventHypothesis::CandRefType> pat::EventHypothesis::all(const ParticleFilter &filter) const {
  std::vector<pat::EventHypothesis::CandRefType> ret;
  for (const_iterator it = begin(); it != end(); ++it) {
    if (filter(*it))
      ret.push_back(it->second);
  }
  return ret;
}

size_t pat::EventHypothesis::count(const std::string &roleRegexp) const {
  return count(pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
}

size_t pat::EventHypothesis::count(const ParticleFilter &role) const {
  size_t n = 0;
  for (const_iterator it = begin(); it != end(); ++it) {
    if (role(*it))
      ++n;
  }
  return n;
}

pat::EventHypothesis::CandLooper pat::EventHypothesis::loop() const {
  return loop(pat::eventhypothesis::AcceptAllFilter::get());
}

pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const std::string &roleRegexp) const {
  return loop(new pat::eventhypothesis::RoleRegexpFilter(roleRegexp));
}

pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const ParticleFilter &role) const {
  return CandLooper(*this, role);
}

pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const ParticleFilter *role) const {
  return CandLooper(*this, role);
}

pat::EventHypothesis::CandLooper pat::EventHypothesis::loop(const ParticleFilterPtr &role) const {
  return CandLooper(*this, role);
}

const pat::eventhypothesis::AcceptAllFilter pat::eventhypothesis::AcceptAllFilter::s_dummyFilter;