CMS 3D CMS Logo

NamedCompositeCandidate.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 
6 using namespace reco;
7 
10  const Candidate& c)
11  : CompositeCandidate(c), name_(name), roles_(roles) {
12  // Check if there are the same number of daughters and roles
13  int N1 = roles_.size();
14  int N2 = numberOfDaughters();
15 
16  if (N1 != N2) {
17  throw cms::Exception("InvalidReference")
18  << "NamedCompositeCandidate constructor: Number of roles and daughters differ, this is an error. Name = "
19  << name << "\n";
20  }
21 }
22 
25  clearRoles();
26 }
27 
29 
31  // Check if there are the same number of daughters and roles
32  int N1 = roles_.size();
33  int N2 = numberOfDaughters();
34  if (N1 != N2) {
35  throw cms::Exception("InvalidReference")
36  << "NamedCompositeCandidate::applyRoles : Number of roles and daughters differ, this is an error.\n";
37  }
38  // Set up the daughter roles
39  for (int i = 0; i < N1; ++i) {
40  std::string role = roles_[i];
42 
43  NamedCompositeCandidate* c1 = dynamic_cast<NamedCompositeCandidate*>(c);
44  if (c1 != nullptr) {
45  c1->setName(role);
46  }
47  }
48 }
49 
51  int ret = -1;
52  int i = 0, N = roles_.size();
53  bool found = false;
54  for (; i < N && !found; ++i) {
55  if (s == roles_[i]) {
56  found = true;
57  ret = i;
58  }
59  }
60 
61  if (ret < 0) {
62  throw cms::Exception("InvalidReference") << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
63  }
64 
65  return daughter(ret);
66 }
67 
69  int ret = -1;
70  int i = 0, N = roles_.size();
71  bool found = false;
72  for (; i < N && !found; ++i) {
73  if (s == roles_[i]) {
74  found = true;
75  ret = i;
76  }
77  }
78 
79  if (ret < 0) {
80  throw cms::Exception("InvalidReference") << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
81  }
82 
83  return daughter(ret);
84 }
85 
87  role_collection::iterator begin = roles_.begin(), end = roles_.end();
88  bool isFound = (find(begin, end, s) != end);
89  if (isFound) {
90  throw cms::Exception("InvalidReference") << "NamedCompositeCandidate::addDaughter: Already have role with name "
91  << s << ", please clearDaughters, or use a new name\n";
92  }
93 
94  roles_.push_back(s);
95  std::unique_ptr<Candidate> c(cand.clone());
96  NamedCompositeCandidate* c1 = dynamic_cast<NamedCompositeCandidate*>(&*c);
97  if (c1 != nullptr) {
98  c1->setName(s);
99  }
101 }
102 
103 void NamedCompositeCandidate::addDaughter(std::unique_ptr<Candidate> cand, const std::string& s) {
104  role_collection::iterator begin = roles_.begin(), end = roles_.end();
105  bool isFound = (find(begin, end, s) != end);
106  if (isFound) {
107  throw cms::Exception("InvalidReference") << "NamedCompositeCandidate::addDaughter: Already have role with name "
108  << s << ", please clearDaughters, or use a new name\n";
109  }
110 
111  roles_.push_back(s);
112  NamedCompositeCandidate* c1 = dynamic_cast<NamedCompositeCandidate*>(&*cand);
113  if (c1 != nullptr) {
114  c1->setName(s);
115  }
117 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
reco::NamedCompositeCandidate::name
std::string name() const
Definition: NamedCompositeCandidate.h:47
mps_fire.i
i
Definition: mps_fire.py:428
reco::NamedCompositeCandidate::role_collection
std::vector< std::string > role_collection
Definition: NamedCompositeCandidate.h:23
NamedCompositeCandidate.h
reco::NamedCompositeCandidate::clone
NamedCompositeCandidate * clone() const override
returns a clone of the candidate
Definition: NamedCompositeCandidate.cc:28
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
reco::NamedCompositeCandidate::addDaughter
void addDaughter(const Candidate &, const std::string &s)
Definition: NamedCompositeCandidate.cc:86
alignCSCRings.s
s
Definition: alignCSCRings.py:92
N
#define N
Definition: blowfish.cc:9
reco::NamedCompositeCandidate::NamedCompositeCandidate
NamedCompositeCandidate(std::string name="")
default constructor
Definition: NamedCompositeCandidate.h:26
reco::NamedCompositeCandidate
Definition: NamedCompositeCandidate.h:21
reco::NamedCompositeCandidate::~NamedCompositeCandidate
~NamedCompositeCandidate() override
destructor
Definition: NamedCompositeCandidate.cc:23
reco::CompositeCandidate::addDaughter
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
Definition: CompositeCandidate.cc:108
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::NamedCompositeCandidate::applyRoles
void applyRoles()
Definition: NamedCompositeCandidate.cc:30
reco::Candidate::end
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:145
cand
Definition: decayParser.h:32
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
reco::NamedCompositeCandidate::roles_
role_collection roles_
Definition: NamedCompositeCandidate.h:74
reco::Candidate
Definition: Candidate.h:27
reco::CompositeCandidate::numberOfDaughters
size_type numberOfDaughters() const override
number of daughters
Definition: CompositeCandidate.cc:41
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::NamedCompositeCandidate::clearDaughters
void clearDaughters()
Definition: NamedCompositeCandidate.h:67
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
reco::NamedCompositeCandidate::clearRoles
void clearRoles()
Definition: NamedCompositeCandidate.h:68
Exception.h
reco::NamedCompositeCandidate::daughter
Candidate * daughter(const std::string &s) override
return daughter with a specified role name
Definition: NamedCompositeCandidate.cc:50
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
reco::CompositeCandidate::daughter
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
Definition: CompositeCandidate.cc:30
reco::Candidate::begin
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:143
reco::CompositeCandidate
Definition: CompositeCandidate.h:21