CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NamedCompositeCandidate.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 
6 using namespace reco;
7 
10  const Candidate & c) :
12  name_(name),
13  roles_(roles)
14 {
15 
16  // Check if there are the same number of daughters and roles
17  int N1 = roles_.size();
18  int N2 = numberOfDaughters();
19 
20  if ( N1 != N2 ) {
21  throw cms::Exception("InvalidReference")
22  << "NamedCompositeCandidate constructor: Number of roles and daughters differ, this is an error. Name = " << name << "\n";
23  }
24 }
25 
27 
29 
31 {
32 
33  // Check if there are the same number of daughters and roles
34  int N1 = roles_.size();
35  int N2 = numberOfDaughters();
36  if ( N1 != N2 ) {
37  throw cms::Exception("InvalidReference")
38  << "NamedCompositeCandidate::applyRoles : Number of roles and daughters differ, this is an error.\n";
39  }
40  // Set up the daughter roles
41  for ( int i = 0 ; i < N1; ++i ) {
42  std::string role = roles_[i];
44 
46  if ( c1 != 0 ) {
47  c1->setName( role );
48  }
49  }
50 }
51 
53 {
54  int ret = -1;
55  int i = 0, N = roles_.size();
56  bool found = false;
57  for ( ; i < N && !found; ++i ) {
58  if ( s == roles_[i] ) {
59  found = true;
60  ret = i;
61  }
62  }
63 
64  if ( ret < 0 ) {
65  throw cms::Exception("InvalidReference")
66  << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
67  }
68 
69  return daughter(ret);
70 }
71 
73 {
74  int ret = -1;
75  int i = 0, N = roles_.size();
76  bool found = false;
77  for ( ; i < N && !found; ++i ) {
78  if ( s == roles_[i] ) {
79  found = true;
80  ret = i;
81  }
82  }
83 
84  if ( ret < 0 ) {
85  throw cms::Exception("InvalidReference")
86  << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
87  }
88 
89  return daughter(ret);
90 }
91 
93 {
94 
95  role_collection::iterator begin = roles_.begin(), end = roles_.end();
96  bool isFound = ( find( begin, end, s) != end );
97  if ( isFound ) {
98  throw cms::Exception("InvalidReference")
99  << "NamedCompositeCandidate::addDaughter: Already have role with name " << s
100  << ", please clearDaughters, or use a new name\n";
101  }
102 
103  roles_.push_back( s );
104  std::auto_ptr<Candidate> c( cand.clone() );
105  NamedCompositeCandidate * c1 = dynamic_cast<NamedCompositeCandidate*>(&*c);
106  if ( c1 != 0 ) {
107  c1->setName( s );
108  }
110 }
111 
112 void NamedCompositeCandidate::addDaughter( std::auto_ptr<Candidate> cand, const std::string& s )
113 {
114  role_collection::iterator begin = roles_.begin(), end = roles_.end();
115  bool isFound = ( find( begin, end, s) != end );
116  if ( isFound ) {
117  throw cms::Exception("InvalidReference")
118  << "NamedCompositeCandidate::addDaughter: Already have role with name " << s
119  << ", please clearDaughters, or use a new name\n";
120  }
121 
122  roles_.push_back( s );
123  NamedCompositeCandidate * c1 = dynamic_cast<NamedCompositeCandidate*>(&*cand);
124  if ( c1 != 0 ) {
125  c1->setName( s );
126  }
128 }
129 
130 
int i
Definition: DBlmapReader.cc:9
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:7
virtual size_type numberOfDaughters() const
number of daughters
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:146
virtual Candidate * daughter(const std::string &s)
return daughter with a specified role name
std::vector< std::string > role_collection
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
#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) ...
virtual NamedCompositeCandidate * clone() const
returns a clone of the candidate
void addDaughter(const Candidate &, const std::string &s)
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:144
virtual ~NamedCompositeCandidate()
destructor