CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompositeCandidate.cc
Go to the documentation of this file.
1 // $Id: CompositeCandidate.cc,v 1.15 2010/12/06 20:04:17 wmtan Exp $
4 
5 using namespace reco;
6 
8  const std::string& name) :
9  LeafCandidate(c), name_(name) {
10  size_t n = c.numberOfDaughters();
11  for(size_t i = 0; i != n; ++i) {
12  addDaughter(*c.daughter(i));
13  }
14 }
15 
17  const std::string& name,
18  role_collection const & roles) :
19  LeafCandidate(c), name_(name), roles_(roles) {
20  size_t n = c.numberOfDaughters();
21  size_t r = roles_.size();
22  bool sameSize = (n == r);
23  for(size_t i = 0; i != n; ++i) {
24  if (sameSize && r > 0)
25  addDaughter(*c.daughter(i), roles_[i]);
26  else
27  addDaughter(*c.daughter(i));
28  }
29 }
30 
32 
34 
36 
38 
40 
42 
44  return (i < numberOfDaughters()) ? & dau[ i ] : 0; // i >= 0, since i is unsigned
45 }
46 
48  Candidate * d = (i < numberOfDaughters()) ? & dau[ i ] : 0; // i >= 0, since i is unsigned
49  return d;
50 }
51 
53  return 0;
54 }
55 
56 size_t CompositeCandidate::numberOfDaughters() const { return dau.size(); }
57 
58 size_t CompositeCandidate::numberOfMothers() const { return 0; }
59 
60 bool CompositeCandidate::overlap(const Candidate & c2) const {
61  throw cms::Exception("Error") << "can't check overlap internally for CompositeCanddate";
62 }
63 
65 
66  if (roles_.size() == 0)
67  return;
68 
69  // Check if there are the same number of daughters and roles
70  int N1 = roles_.size();
71  int N2 = numberOfDaughters();
72  if (N1 != N2) {
73  throw cms::Exception("InvalidReference")
74  << "CompositeCandidate::applyRoles : Number of roles and daughters differ, this is an error.\n";
75  }
76  // Set up the daughter roles
77  for (int i = 0 ; i < N1; ++i) {
78  std::string role = roles_[i];
80 
81  CompositeCandidate * c1 = dynamic_cast<CompositeCandidate *>(c);
82  if (c1 != 0) {
83  c1->setName(role);
84  }
85  }
86 }
87 
89  int ret = -1;
90  int i = 0, N = roles_.size();
91  bool found = false;
92  for (; i < N && !found; ++i) {
93  if (s == roles_[i]) {
94  found = true;
95  ret = i;
96  }
97  }
98 
99  if (ret < 0) {
100  throw cms::Exception("InvalidReference")
101  << "CompositeCandidate::daughter: Cannot find role " << s << "\n";
102  }
103 
104  return daughter(ret);
105 }
106 
108  int ret = -1;
109  int i = 0, N = roles_.size();
110  bool found = false;
111  for (; i < N && !found; ++i) {
112  if (s == roles_[i]) {
113  found = true;
114  ret = i;
115  }
116  }
117 
118  if (ret < 0) {
119  throw cms::Exception("InvalidReference")
120  << "CompositeCandidate::daughter: Cannot find role " << s << "\n";
121  }
122 
123  return daughter(ret);
124 }
125 
127  Candidate * c = cand.clone();
128  if (s != "") {
129  role_collection::iterator begin = roles_.begin(), end = roles_.end();
130  bool isFound = (find(begin, end, s) != end);
131  if (isFound) {
132  throw cms::Exception("InvalidReference")
133  << "CompositeCandidate::addDaughter: Already have role with name \"" << s
134  << "\", please clearDaughters, or use a new name\n";
135  }
136  roles_.push_back(s);
137  CompositeCandidate * c1 = dynamic_cast<CompositeCandidate*>(&*c);
138  if (c1 != 0) {
139  c1->setName(s);
140  }
141  }
142  dau.push_back(c);
143 }
144 
145 void CompositeCandidate::addDaughter(std::auto_ptr<Candidate> cand, const std::string& s) {
146  if (s != "") {
147  role_collection::iterator begin = roles_.begin(), end = roles_.end();
148  bool isFound = (find(begin, end, s) != end);
149  if (isFound) {
150  throw cms::Exception("InvalidReference")
151  << "CompositeCandidate::addDaughter: Already have role with name \"" << s
152  << "\", please clearDaughters, or use a new name\n";
153  }
154  roles_.push_back(s);
155  CompositeCandidate * c1 = dynamic_cast<CompositeCandidate*>(&*cand);
156  if (c1 != 0) {
157  c1->setName(s);
158  }
159  }
160  dau.push_back(cand);
161 }
162 
163 
int i
Definition: DBlmapReader.cc:9
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
virtual size_type numberOfMothers() const
number of mothers (zero or one in most of but not all the cases)
size_t size_type
Definition: Candidate.h:34
candidate::const_iterator const_iterator
Definition: Candidate.h:35
role_collection roles_
candidate roles
virtual const_iterator end() const
last daughter const_iterator
size_type size() const
Definition: OwnVector.h:247
candidate::const_iterator_imp_specific< daughters > const_iterator_imp_specific
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
virtual size_type numberOfDaughters() const
number of daughters
virtual bool overlap(const Candidate &) const
check overlap with another daughter
iterator begin()
Definition: OwnVector.h:227
virtual ~CompositeCandidate()
destructor
virtual size_type numberOfDaughters() const =0
number of daughters
void push_back(D *&d)
Definition: OwnVector.h:273
virtual const_iterator begin() const
first daughter const_iterator
CompositeCandidate(std::string name="")
default constructor
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
virtual Candidate * clone() const =0
returns a clone of the Candidate object
candidate::iterator iterator
Definition: Candidate.h:36
iterator end()
Definition: OwnVector.h:232
void setName(std::string name)
set the name of the candidate
#define N
Definition: blowfish.cc:9
virtual const Candidate * daughter(size_type) const
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
daughters dau
collection of daughters
virtual CompositeCandidate * clone() const
returns a clone of the candidate
std::vector< std::string > role_collection
virtual const Candidate * mother(size_type i=0) const
return pointer to mother
candidate::iterator_imp_specific< daughters > iterator_imp_specific