NamedCompositeCandidateMaker

Macros

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 95 96 97 98 99 100 101 102 103 104
#ifndef CandUtils_makeNamedCompositeCandidate_h
#define CandUtils_makeNamedCompositeCandidate_h
#include "DataFormats/Candidate/interface/NamedCompositeCandidate.h"
#include "DataFormats/Candidate/interface/ShallowCloneCandidate.h"
#include <memory>
#include <string>

namespace helpers {
  struct NamedCompositeCandidateMaker {
    NamedCompositeCandidateMaker(std::unique_ptr<reco::NamedCompositeCandidate> cmp) : cmp_(std::move(cmp)) {}

    void addDaughter(const reco::Candidate& dau, std::string name) { cmp_->addDaughter(dau, name); }
    template <typename S>
    std::unique_ptr<reco::Candidate> operator[](const S& setup) {
      setup.set(*cmp_);
      return release();
    }

  private:
    std::unique_ptr<reco::NamedCompositeCandidate> cmp_;
    std::unique_ptr<reco::Candidate> release() {
      std::unique_ptr<reco::Candidate> ret(cmp_.get());
      cmp_.release();
      return ret;
    }
  };
}  // namespace helpers

helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
                                                                  std::string s1,
                                                                  const reco::Candidate& c2,
                                                                  std::string s2);

helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
                                                                  std::string s1,
                                                                  const reco::Candidate& c2,
                                                                  std::string s2,
                                                                  const reco::Candidate& c3,
                                                                  std::string s3);

helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
                                                                  std::string s1,
                                                                  const reco::Candidate& c2,
                                                                  std::string s2,
                                                                  const reco::Candidate& c3,
                                                                  std::string s3);

helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
                                                                  std::string s1,
                                                                  const reco::Candidate& c2,
                                                                  std::string s2,
                                                                  const reco::Candidate& c3,
                                                                  std::string s3,
                                                                  const reco::Candidate& c4,
                                                                  std::string s4);

template <typename C>
helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const typename C::const_iterator& begin,
                                                                  const typename C::const_iterator& end,
                                                                  const std::vector<std::string>::const_iterator sbegin,
                                                                  const std::vector<std::string>::const_iterator send) {
  helpers::NamedCompositeCandidateMaker cmp(std::make_unique<reco::NamedCompositeCandidate>());
  std::vector<std::string>::const_iterator si = sbegin;
  for (typename C::const_iterator i = begin; i != end && si != send; ++i, ++si)
    cmp.addDaughter(*i, *si);
  return cmp;
}

helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
                                                                                  std::string s1,
                                                                                  const reco::CandidateRef& c2,
                                                                                  std::string s2);

helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
                                                                                  std::string s1,
                                                                                  const reco::CandidateRef& c2,
                                                                                  std::string s2,
                                                                                  const reco::CandidateRef& c3,
                                                                                  std::string s3);

helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
                                                                                  std::string s1,
                                                                                  const reco::CandidateRef& c2,
                                                                                  std::string s2,
                                                                                  const reco::CandidateRef& c3,
                                                                                  std::string s3,
                                                                                  const reco::CandidateRef& c4,
                                                                                  std::string s4);

template <typename C>
helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(
    const typename C::const_iterator& begin,
    const typename C::const_iterator& end,
    const std::vector<std::string>::const_iterator sbegin,
    const std::vector<std::string>::const_iterator send) {
  helpers::NamedCompositeCandidateMaker cmp(std::make_unique<reco::NamedCompositeCandidate>());
  std::vector<std::string>::const_iterator si = sbegin;
  for (typename C::const_iterator i = begin; i != end && si != send; ++i, ++si)
    cmp.addDaughter(ShallowCloneCandidate(CandidateBaseRef(*i)), *si);
  return cmp;
}

#endif