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.
1 // $Id: NamedCompositeCandidate.cc,v 1.4 2008/07/22 06:07:44 llista Exp $
4 
5 #include <iostream>
6 
7 using namespace reco;
8 
11  const Candidate & c) :
13  name_(name),
14  roles_(roles)
15 {
16 
17  // Check if there are the same number of daughters and roles
18  int N1 = roles_.size();
19  int N2 = numberOfDaughters();
20 
21  if ( N1 != N2 ) {
22  throw cms::Exception("InvalidReference")
23  << "NamedCompositeCandidate constructor: Number of roles and daughters differ, this is an error. Name = " << name << "\n";
24  }
25 }
26 
28 
30 
32 {
33 
34  // Check if there are the same number of daughters and roles
35  int N1 = roles_.size();
36  int N2 = numberOfDaughters();
37  if ( N1 != N2 ) {
38  throw cms::Exception("InvalidReference")
39  << "NamedCompositeCandidate::applyRoles : Number of roles and daughters differ, this is an error.\n";
40  }
41  // Set up the daughter roles
42  for ( int i = 0 ; i < N1; ++i ) {
43  std::string role = roles_[i];
45 
47  if ( c1 != 0 ) {
48  c1->setName( role );
49  }
50  }
51 }
52 
54 {
55  int ret = -1;
56  int i = 0, N = roles_.size();
57  bool found = false;
58  for ( ; i < N && !found; ++i ) {
59  if ( s == roles_[i] ) {
60  found = true;
61  ret = i;
62  }
63  }
64 
65  if ( ret < 0 ) {
66  throw cms::Exception("InvalidReference")
67  << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
68  }
69 
70  return daughter(ret);
71 }
72 
74 {
75  int ret = -1;
76  int i = 0, N = roles_.size();
77  bool found = false;
78  for ( ; i < N && !found; ++i ) {
79  if ( s == roles_[i] ) {
80  found = true;
81  ret = i;
82  }
83  }
84 
85  if ( ret < 0 ) {
86  throw cms::Exception("InvalidReference")
87  << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
88  }
89 
90  return daughter(ret);
91 }
92 
94 {
95 
96  role_collection::iterator begin = roles_.begin(), end = roles_.end();
97  bool isFound = ( find( begin, end, s) != end );
98  if ( isFound ) {
99  throw cms::Exception("InvalidReference")
100  << "NamedCompositeCandidate::addDaughter: Already have role with name " << s
101  << ", please clearDaughters, or use a new name\n";
102  }
103 
104  roles_.push_back( s );
105  std::auto_ptr<Candidate> c( cand.clone() );
106  NamedCompositeCandidate * c1 = dynamic_cast<NamedCompositeCandidate*>(&*c);
107  if ( c1 != 0 ) {
108  c1->setName( s );
109  }
111 }
112 
113 void NamedCompositeCandidate::addDaughter( std::auto_ptr<Candidate> cand, const std::string& s )
114 {
115  role_collection::iterator begin = roles_.begin(), end = roles_.end();
116  bool isFound = ( find( begin, end, s) != end );
117  if ( isFound ) {
118  throw cms::Exception("InvalidReference")
119  << "NamedCompositeCandidate::addDaughter: Already have role with name " << s
120  << ", please clearDaughters, or use a new name\n";
121  }
122 
123  roles_.push_back( s );
124  NamedCompositeCandidate * c1 = dynamic_cast<NamedCompositeCandidate*>(&*cand);
125  if ( c1 != 0 ) {
126  c1->setName( s );
127  }
129 }
130 
131 
int i
Definition: DBlmapReader.cc:9
NamedCompositeCandidate(std::string name="")
default constructor
virtual const_iterator end() const
last daughter const_iterator
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 const_iterator begin() const
first daughter const_iterator
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)
virtual ~NamedCompositeCandidate()
destructor