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.
3 
4 using namespace reco;
5 
7  const std::string& name) :
8  LeafCandidate(c), name_(name) {
9  size_t n = c.numberOfDaughters();
10  for(size_t i = 0; i != n; ++i) {
11  addDaughter(*c.daughter(i));
12  }
13 }
14 
16  const std::string& name,
17  role_collection const & roles) :
18  LeafCandidate(c), name_(name), roles_(roles) {
19  size_t n = c.numberOfDaughters();
20  size_t r = roles_.size();
21  bool sameSize = (n == r);
22  for(size_t i = 0; i != n; ++i) {
23  if (sameSize && r > 0)
24  addDaughter(*c.daughter(i), roles_[i]);
25  else
26  addDaughter(*c.daughter(i));
27  }
28 }
29 
31 
33 
35 
37 
39 
41 
43  return (i < numberOfDaughters()) ? & dau[ i ] : 0; // i >= 0, since i is unsigned
44 }
45 
47  Candidate * d = (i < numberOfDaughters()) ? & dau[ i ] : 0; // i >= 0, since i is unsigned
48  return d;
49 }
50 
52  return 0;
53 }
54 
55 size_t CompositeCandidate::numberOfDaughters() const { return dau.size(); }
56 
57 size_t CompositeCandidate::numberOfMothers() const { return 0; }
58 
59 bool CompositeCandidate::overlap(const Candidate & c2) const {
60  throw cms::Exception("Error") << "can't check overlap internally for CompositeCanddate";
61 }
62 
64 
65  if (roles_.size() == 0)
66  return;
67 
68  // Check if there are the same number of daughters and roles
69  int N1 = roles_.size();
70  int N2 = numberOfDaughters();
71  if (N1 != N2) {
72  throw cms::Exception("InvalidReference")
73  << "CompositeCandidate::applyRoles : Number of roles and daughters differ, this is an error.\n";
74  }
75  // Set up the daughter roles
76  for (int i = 0 ; i < N1; ++i) {
77  std::string role = roles_[i];
79 
80  CompositeCandidate * c1 = dynamic_cast<CompositeCandidate *>(c);
81  if (c1 != 0) {
82  c1->setName(role);
83  }
84  }
85 }
86 
88  int ret = -1;
89  int i = 0, N = roles_.size();
90  bool found = false;
91  for (; i < N && !found; ++i) {
92  if (s == roles_[i]) {
93  found = true;
94  ret = i;
95  }
96  }
97 
98  if (ret < 0) {
99  throw cms::Exception("InvalidReference")
100  << "CompositeCandidate::daughter: Cannot find role " << s << "\n";
101  }
102 
103  return daughter(ret);
104 }
105 
107  int ret = -1;
108  int i = 0, N = roles_.size();
109  bool found = false;
110  for (; i < N && !found; ++i) {
111  if (s == roles_[i]) {
112  found = true;
113  ret = i;
114  }
115  }
116 
117  if (ret < 0) {
118  throw cms::Exception("InvalidReference")
119  << "CompositeCandidate::daughter: Cannot find role " << s << "\n";
120  }
121 
122  return daughter(ret);
123 }
124 
126  Candidate * c = cand.clone();
127  if (s != "") {
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")
132  << "CompositeCandidate::addDaughter: Already have role with name \"" << s
133  << "\", please clearDaughters, or use a new name\n";
134  }
135  roles_.push_back(s);
136  CompositeCandidate * c1 = dynamic_cast<CompositeCandidate*>(&*c);
137  if (c1 != 0) {
138  c1->setName(s);
139  }
140  }
141  dau.push_back(c);
142 }
143 
144 void CompositeCandidate::addDaughter(std::auto_ptr<Candidate> cand, const std::string& s) {
145  if (s != "") {
146  role_collection::iterator begin = roles_.begin(), end = roles_.end();
147  bool isFound = (find(begin, end, s) != end);
148  if (isFound) {
149  throw cms::Exception("InvalidReference")
150  << "CompositeCandidate::addDaughter: Already have role with name \"" << s
151  << "\", please clearDaughters, or use a new name\n";
152  }
153  roles_.push_back(s);
154  CompositeCandidate * c1 = dynamic_cast<CompositeCandidate*>(&*cand);
155  if (c1 != 0) {
156  c1->setName(s);
157  }
158  }
159  dau.push_back(cand);
160 }
161 
162 
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:248
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:228
virtual ~CompositeCandidate()
destructor
virtual size_type numberOfDaughters() const =0
number of daughters
void push_back(D *&d)
Definition: OwnVector.h:274
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:233
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