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 
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());
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);
113  if (c1 != nullptr) {
114  c1->setName(s);
115  }
117 }
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
ret
prodAgent to be discontinued
NamedCompositeCandidate(std::string name="")
default constructor
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
~NamedCompositeCandidate() override
destructor
Candidate * daughter(const std::string &s) override
return daughter with a specified role name
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:145
std::vector< std::string > role_collection
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
#define N
Definition: blowfish.cc:9
size_type numberOfDaughters() const override
number of daughters
void addDaughter(const Candidate &, const std::string &s)
fixed size matrix
NamedCompositeCandidate * clone() const override
returns a clone of the candidate
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:143