CompositeCandidateMaker

CompositePtrCandidateMaker

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 105 106 107 108
#ifndef CandUtils_makeCompositeCandidate_h
#define CandUtils_makeCompositeCandidate_h
#include "DataFormats/Candidate/interface/CompositeCandidate.h"
#include "DataFormats/Candidate/interface/CompositePtrCandidate.h"
#include "DataFormats/Candidate/interface/ShallowCloneCandidate.h"
#include <memory>

namespace helpers {
  struct CompositeCandidateMaker {
    CompositeCandidateMaker(std::unique_ptr<reco::CompositeCandidate> cmp) : cmp_(std::move(cmp)) {}
    void addDaughter(const reco::Candidate& dau) { cmp_->addDaughter(dau); }
    template <typename S>
    std::unique_ptr<reco::Candidate> operator[](const S& setup) {
      setup.set(*cmp_);
      return release();
    }

  private:
    std::unique_ptr<reco::CompositeCandidate> cmp_;
    std::unique_ptr<reco::Candidate> release() {
      std::unique_ptr<reco::Candidate> ret(cmp_.get());
      cmp_.release();
      return ret;
    }
  };

  struct CompositePtrCandidateMaker {
    CompositePtrCandidateMaker(std::unique_ptr<reco::CompositePtrCandidate> cmp) : cmp_(std::move(cmp)) {}
    void addDaughter(const reco::CandidatePtr& dau) { cmp_->addDaughter(dau); }
    template <typename S>
    std::unique_ptr<reco::Candidate> operator[](const S& setup) {
      setup.set(*cmp_);
      return release();
    }

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

helpers::CompositeCandidateMaker makeCompositeCandidate(const reco::Candidate& c1, const reco::Candidate& c2);

helpers::CompositeCandidateMaker makeCompositeCandidate(const reco::Candidate& c1,
                                                        const reco::Candidate& c2,
                                                        const reco::Candidate& c3);

helpers::CompositeCandidateMaker makeCompositeCandidate(const reco::Candidate& c1,
                                                        const reco::Candidate& c2,
                                                        const reco::Candidate& c3);

helpers::CompositeCandidateMaker makeCompositeCandidate(const reco::Candidate& c1,
                                                        const reco::Candidate& c2,
                                                        const reco::Candidate& c3,
                                                        const reco::Candidate& c4);

template <typename C>
helpers::CompositeCandidateMaker makeCompositeCandidate(const typename C::const_iterator& begin,
                                                        const typename C::const_iterator& end) {
  helpers::CompositeCandidateMaker cmp(std::make_unique<reco::CompositeCandidate>());
  for (typename C::const_iterator i = begin; i != end; ++i)
    cmp.addDaughter(*i);
  return cmp;
}

helpers::CompositeCandidateMaker makeCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
                                                                        const reco::CandidateRef& c2);

helpers::CompositeCandidateMaker makeCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
                                                                        const reco::CandidateRef& c2,
                                                                        const reco::CandidateRef& c3);

helpers::CompositeCandidateMaker makeCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
                                                                        const reco::CandidateRef& c2,
                                                                        const reco::CandidateRef& c3,
                                                                        const reco::CandidateRef& c4);

template <typename C>
helpers::CompositeCandidateMaker makeCompositeCandidateWithRefsToMaster(const typename C::const_iterator& begin,
                                                                        const typename C::const_iterator& end) {
  helpers::CompositeCandidateMaker cmp(std::make_unique<reco::CompositeCandidate>());
  for (typename C::const_iterator i = begin; i != end; ++i)
    cmp.addDaughter(ShallowCloneCandidate(CandidateBaseRef(*i)));
  return cmp;
}

helpers::CompositePtrCandidateMaker makeCompositePtrCandidate(const reco::CandidatePtr& c1,
                                                              const reco::CandidatePtr& c2);

helpers::CompositePtrCandidateMaker makeCompositePtrCandidate(const reco::CandidatePtr& c1,
                                                              const reco::CandidatePtr& c2,
                                                              const reco::CandidatePtr& c3);

helpers::CompositePtrCandidateMaker makeCompositePtrCandidate(const reco::CandidatePtr& c1,
                                                              const reco::CandidatePtr& c2,
                                                              const reco::CandidatePtr& c3);

helpers::CompositePtrCandidateMaker makeCompositePtrCandidate(const reco::CandidatePtr& c1,
                                                              const reco::CandidatePtr& c2,
                                                              const reco::CandidatePtr& c3,
                                                              const reco::CandidatePtr& c4);

#endif