CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CompositeCandidate.cc
Go to the documentation of this file.
3 
4 using namespace reco;
5 
7  size_t n = c.numberOfDaughters();
8  for (size_t i = 0; i != n; ++i) {
10  }
11 }
12 
14  : LeafCandidate(c), name_(name), roles_(roles) {
15  size_t n = c.numberOfDaughters();
16  size_t r = roles_.size();
17  bool sameSize = (n == r);
18  for (size_t i = 0; i != n; ++i) {
19  if (sameSize && r > 0)
20  addDaughter(*c.daughter(i), roles_[i]);
21  else
22  addDaughter(*c.daughter(i));
23  }
24 }
25 
27 
29 
31  return (i < numberOfDaughters()) ? &dau[i] : nullptr; // i >= 0, since i is unsigned
32 }
33 
35  Candidate* d = (i < numberOfDaughters()) ? &dau[i] : nullptr; // i >= 0, since i is unsigned
36  return d;
37 }
38 
39 const Candidate* CompositeCandidate::mother(size_type i) const { return nullptr; }
40 
41 size_t CompositeCandidate::numberOfDaughters() const { return dau.size(); }
42 
43 size_t CompositeCandidate::numberOfMothers() const { return 0; }
44 
45 bool CompositeCandidate::overlap(const Candidate& c2) const {
46  throw cms::Exception("Error") << "can't check overlap internally for CompositeCanddate";
47 }
48 
50  if (roles_.empty())
51  return;
52 
53  // Check if there are the same number of daughters and roles
54  int N1 = roles_.size();
55  int N2 = numberOfDaughters();
56  if (N1 != N2) {
57  throw cms::Exception("InvalidReference")
58  << "CompositeCandidate::applyRoles : Number of roles and daughters differ, this is an error.\n";
59  }
60  // Set up the daughter roles
61  for (int i = 0; i < N1; ++i) {
62  std::string role = roles_[i];
64 
65  CompositeCandidate* c1 = dynamic_cast<CompositeCandidate*>(c);
66  if (c1 != nullptr) {
67  c1->setName(role);
68  }
69  }
70 }
71 
73  int ret = -1;
74  int i = 0, N = roles_.size();
75  bool found = false;
76  for (; i < N && !found; ++i) {
77  if (s == roles_[i]) {
78  found = true;
79  ret = i;
80  }
81  }
82 
83  if (ret < 0) {
84  throw cms::Exception("InvalidReference") << "CompositeCandidate::daughter: Cannot find role " << s << "\n";
85  }
86 
87  return daughter(ret);
88 }
89 
91  int ret = -1;
92  int i = 0, N = roles_.size();
93  bool found = false;
94  for (; i < N && !found; ++i) {
95  if (s == roles_[i]) {
96  found = true;
97  ret = i;
98  }
99  }
100 
101  if (ret < 0) {
102  throw cms::Exception("InvalidReference") << "CompositeCandidate::daughter: Cannot find role " << s << "\n";
103  }
104 
105  return daughter(ret);
106 }
107 
109  Candidate* c = cand.clone();
110  if (!s.empty()) {
111  role_collection::iterator begin = roles_.begin(), end = roles_.end();
112  bool isFound = (find(begin, end, s) != end);
113  if (isFound) {
114  throw cms::Exception("InvalidReference") << "CompositeCandidate::addDaughter: Already have role with name \"" << s
115  << "\", please clearDaughters, or use a new name\n";
116  }
117  roles_.push_back(s);
118  CompositeCandidate* c1 = dynamic_cast<CompositeCandidate*>(&*c);
119  if (c1 != nullptr) {
120  c1->setName(s);
121  }
122  }
123  dau.push_back(c);
124 }
125 
126 void CompositeCandidate::addDaughter(std::unique_ptr<Candidate> cand, const std::string& s) {
127  if (!s.empty()) {
128  role_collection::iterator begin = roles_.begin(), end = roles_.end();
129  bool isFound = (find(begin, end, s) != end);
130  if (isFound) {
131  throw cms::Exception("InvalidReference") << "CompositeCandidate::addDaughter: Already have role with name \"" << s
132  << "\", please clearDaughters, or use a new name\n";
133  }
134  roles_.push_back(s);
135  CompositeCandidate* c1 = dynamic_cast<CompositeCandidate*>(&*cand);
136  if (c1 != nullptr) {
137  c1->setName(s);
138  }
139  }
140  dau.push_back(std::move(cand));
141 }
~CompositeCandidate() override
destructor
tuple ret
prodAgent to be discontinued
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
const edm::EventSetup & c
size_t size_type
Definition: Candidate.h:29
role_collection roles_
candidate roles
size_type size() const
Definition: OwnVector.h:300
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool overlap(const Candidate &) const override
check overlap with another daughter
tuple d
Definition: ztail.py:151
virtual size_type numberOfDaughters() const =0
number of daughters
void push_back(D *&d)
Definition: OwnVector.h:326
const Candidate * mother(size_type i=0) const override
return pointer to mother
size_type numberOfMothers() const override
number of mothers (zero or one in most of but not all the cases)
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:145
def move
Definition: eostools.py:511
CompositeCandidate(std::string name="")
default constructor
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
CompositeCandidate * clone() const override
returns a clone of the candidate
virtual Candidate * clone() const =0
returns a clone of the Candidate object
void setName(std::string name)
set the name of the candidate
#define N
Definition: blowfish.cc:9
size_type numberOfDaughters() const override
number of daughters
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:143
daughters dau
collection of daughters
std::vector< std::string > role_collection