Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-12 03:09:04

0001 #ifndef CandUtils_makeNamedCompositeCandidate_h
0002 #define CandUtils_makeNamedCompositeCandidate_h
0003 #include "DataFormats/Candidate/interface/NamedCompositeCandidate.h"
0004 #include "DataFormats/Candidate/interface/ShallowCloneCandidate.h"
0005 #include <memory>
0006 #include <string>
0007 
0008 namespace helpers {
0009   struct NamedCompositeCandidateMaker {
0010     NamedCompositeCandidateMaker(std::unique_ptr<reco::NamedCompositeCandidate> cmp) : cmp_(std::move(cmp)) {}
0011 
0012     void addDaughter(const reco::Candidate& dau, std::string name) { cmp_->addDaughter(dau, name); }
0013     template <typename S>
0014     std::unique_ptr<reco::Candidate> operator[](const S& setup) {
0015       setup.set(*cmp_);
0016       return release();
0017     }
0018 
0019   private:
0020     std::unique_ptr<reco::NamedCompositeCandidate> cmp_;
0021     std::unique_ptr<reco::Candidate> release() {
0022       std::unique_ptr<reco::Candidate> ret(cmp_.get());
0023       cmp_.release();
0024       return ret;
0025     }
0026   };
0027 }  // namespace helpers

0028 
0029 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
0030                                                                   std::string s1,
0031                                                                   const reco::Candidate& c2,
0032                                                                   std::string s2);
0033 
0034 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
0035                                                                   std::string s1,
0036                                                                   const reco::Candidate& c2,
0037                                                                   std::string s2,
0038                                                                   const reco::Candidate& c3,
0039                                                                   std::string s3);
0040 
0041 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
0042                                                                   std::string s1,
0043                                                                   const reco::Candidate& c2,
0044                                                                   std::string s2,
0045                                                                   const reco::Candidate& c3,
0046                                                                   std::string s3);
0047 
0048 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const reco::Candidate& c1,
0049                                                                   std::string s1,
0050                                                                   const reco::Candidate& c2,
0051                                                                   std::string s2,
0052                                                                   const reco::Candidate& c3,
0053                                                                   std::string s3,
0054                                                                   const reco::Candidate& c4,
0055                                                                   std::string s4);
0056 
0057 template <typename C>
0058 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidate(const typename C::const_iterator& begin,
0059                                                                   const typename C::const_iterator& end,
0060                                                                   const std::vector<std::string>::const_iterator sbegin,
0061                                                                   const std::vector<std::string>::const_iterator send) {
0062   helpers::NamedCompositeCandidateMaker cmp(std::make_unique<reco::NamedCompositeCandidate>());
0063   std::vector<std::string>::const_iterator si = sbegin;
0064   for (typename C::const_iterator i = begin; i != end && si != send; ++i, ++si)
0065     cmp.addDaughter(*i, *si);
0066   return cmp;
0067 }
0068 
0069 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
0070                                                                                   std::string s1,
0071                                                                                   const reco::CandidateRef& c2,
0072                                                                                   std::string s2);
0073 
0074 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
0075                                                                                   std::string s1,
0076                                                                                   const reco::CandidateRef& c2,
0077                                                                                   std::string s2,
0078                                                                                   const reco::CandidateRef& c3,
0079                                                                                   std::string s3);
0080 
0081 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(const reco::CandidateRef& c1,
0082                                                                                   std::string s1,
0083                                                                                   const reco::CandidateRef& c2,
0084                                                                                   std::string s2,
0085                                                                                   const reco::CandidateRef& c3,
0086                                                                                   std::string s3,
0087                                                                                   const reco::CandidateRef& c4,
0088                                                                                   std::string s4);
0089 
0090 template <typename C>
0091 helpers::NamedCompositeCandidateMaker makeNamedCompositeCandidateWithRefsToMaster(
0092     const typename C::const_iterator& begin,
0093     const typename C::const_iterator& end,
0094     const std::vector<std::string>::const_iterator sbegin,
0095     const std::vector<std::string>::const_iterator send) {
0096   helpers::NamedCompositeCandidateMaker cmp(std::make_unique<reco::NamedCompositeCandidate>());
0097   std::vector<std::string>::const_iterator si = sbegin;
0098   for (typename C::const_iterator i = begin; i != end && si != send; ++i, ++si)
0099     cmp.addDaughter(ShallowCloneCandidate(CandidateBaseRef(*i)), *si);
0100   return cmp;
0101 }
0102 
0103 #endif