CMS 3D CMS Logo

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) {
9  addDaughter(*c.daughter(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  }
141 }
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
reco::CompositeCandidate::~CompositeCandidate
~CompositeCandidate() override
destructor
Definition: CompositeCandidate.cc:26
reco::CompositeCandidate::role_collection
std::vector< std::string > role_collection
Definition: CompositeCandidate.h:25
mps_fire.i
i
Definition: mps_fire.py:428
CompositeCandidate.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
reco::CompositeCandidate::roles_
role_collection roles_
candidate roles
Definition: CompositeCandidate.h:89
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
reco::CompositeCandidate::mother
const Candidate * mother(size_type i=0) const override
return pointer to mother
Definition: CompositeCandidate.cc:39
reco::CompositeCandidate::numberOfMothers
size_type numberOfMothers() const override
number of mothers (zero or one in most of but not all the cases)
Definition: CompositeCandidate.cc:43
alignCSCRings.s
s
Definition: alignCSCRings.py:92
reco::CompositeCandidate::overlap
bool overlap(const Candidate &) const override
check overlap with another daughter
Definition: CompositeCandidate.cc:45
N
#define N
Definition: blowfish.cc:9
reco::CompositeCandidate::applyRoles
void applyRoles()
Definition: CompositeCandidate.cc:49
reco::CompositeCandidate::addDaughter
void addDaughter(const Candidate &, const std::string &s="")
add a clone of the passed candidate as daughter
Definition: CompositeCandidate.cc:108
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::CompositeCandidate::clone
CompositeCandidate * clone() const override
returns a clone of the candidate
Definition: CompositeCandidate.cc:28
reco::Candidate::end
const_iterator end() const
last daughter const_iterator
Definition: Candidate.h:145
cand
Definition: decayParser.h:32
alignmentValidation.c1
c1
do drawing
Definition: alignmentValidation.py:1025
reco::CompositeCandidate::CompositeCandidate
CompositeCandidate(std::string name="")
default constructor
Definition: CompositeCandidate.h:27
reco::Candidate
Definition: Candidate.h:27
alignCSCRings.r
r
Definition: alignCSCRings.py:93
reco::CompositeCandidate::numberOfDaughters
size_type numberOfDaughters() const override
number of daughters
Definition: CompositeCandidate.cc:41
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::CompositeCandidate::dau
daughters dau
collection of daughters
Definition: CompositeCandidate.h:83
Exception
Definition: hltDiff.cc:245
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Exception.h
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
ztail.d
d
Definition: ztail.py:151
reco::LeafCandidate
Definition: LeafCandidate.h:16
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
reco::CompositeCandidate::daughter
const Candidate * daughter(size_type) const override
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
Definition: CompositeCandidate.cc:30
reco::Candidate::begin
const_iterator begin() const
first daughter const_iterator
Definition: Candidate.h:143
edm::OwnVector::size
size_type size() const
Definition: OwnVector.h:300
reco::Candidate::size_type
size_t size_type
Definition: Candidate.h:29
reco::CompositeCandidate
Definition: CompositeCandidate.h:21