CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

reco::NamedCompositeCandidate Class Reference

#include <NamedCompositeCandidate.h>

Inheritance diagram for reco::NamedCompositeCandidate:
reco::CompositeCandidate reco::LeafCandidate reco::Candidate

List of all members.

Public Types

typedef std::vector< std::string > role_collection

Public Member Functions

void addDaughter (const Candidate &, const std::string &s)
 add a clone of the passed candidate as daughter
void addDaughter (std::auto_ptr< Candidate >, const std::string &s)
 add a clone of the passed candidate as daughter
void applyRoles ()
void clearDaughters ()
 clear daughters
void clearRoles ()
virtual NamedCompositeCandidateclone () const
 returns a clone of the candidate
virtual Candidatedaughter (const std::string &s)
 return daughter with a specified role name
virtual const Candidatedaughter (size_type i) const
 return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
virtual Candidatedaughter (size_type i)
 return daughter at a given position, i = 0, ... numberOfDaughters() - 1
virtual const Candidatedaughter (const std::string &s) const
 return daughter with a specified role name
std::string name () const
 get the name of the candidate
 NamedCompositeCandidate (std::string name="")
 default constructor
 NamedCompositeCandidate (std::string name, const role_collection &roles, const Candidate &p)
 constructor from values
 NamedCompositeCandidate (std::string name, const role_collection &roles)
 NamedCompositeCandidate (std::string name, const role_collection &roles, Charge q, const LorentzVector &p4, const Point &vtx=Point(0, 0, 0), int pdgId=0, int status=0, bool integerCharge=true)
 constructor from values
const
NamedCompositeCandidate::role_collection
roles () const
 get the roles
void setName (std::string n)
 set the name of the candidate
void setRoles (const NamedCompositeCandidate::role_collection &roles)
 set the roles
virtual ~NamedCompositeCandidate ()
 destructor

Private Attributes

std::string name_
 candidate name
role_collection roles_
 candidate roles

Detailed Description

A Candidate composed of daughters. The daughters are owned by the composite candidate.

Author:
Luca Lista, INFN
Version:
Id:
NamedCompositeCandidate.h,v 1.5 2008/12/05 12:15:18 hegner Exp

Definition at line 23 of file NamedCompositeCandidate.h.


Member Typedef Documentation

typedef std::vector<std::string> reco::NamedCompositeCandidate::role_collection

Reimplemented from reco::CompositeCandidate.

Definition at line 25 of file NamedCompositeCandidate.h.


Constructor & Destructor Documentation

reco::NamedCompositeCandidate::NamedCompositeCandidate ( std::string  name = "") [inline]

default constructor

Definition at line 28 of file NamedCompositeCandidate.h.

Referenced by clone().

reco::NamedCompositeCandidate::NamedCompositeCandidate ( std::string  name,
const role_collection roles 
) [inline]

Definition at line 29 of file NamedCompositeCandidate.h.

reco::NamedCompositeCandidate::NamedCompositeCandidate ( std::string  name,
const role_collection roles,
Charge  q,
const LorentzVector p4,
const Point vtx = Point( 0, 0, 0 ),
int  pdgId = 0,
int  status = 0,
bool  integerCharge = true 
) [inline]

constructor from values

Definition at line 33 of file NamedCompositeCandidate.h.

                                                                                        :
      CompositeCandidate( q, p4, vtx, pdgId, status, integerCharge ), 
      name_ (name), roles_(roles) { }
NamedCompositeCandidate::NamedCompositeCandidate ( std::string  name,
const role_collection roles,
const Candidate p 
)

constructor from values

Definition at line 9 of file NamedCompositeCandidate.cc.

References Exception, reco::CompositeCandidate::numberOfDaughters(), and roles_.

                                                                      :
  CompositeCandidate(c),
  name_(name),
  roles_(roles)
{

  // Check if there are the same number of daughters and roles
  int N1 = roles_.size();
  int N2 = numberOfDaughters();

  if ( N1 != N2 ) {
    throw cms::Exception("InvalidReference")
      << "NamedCompositeCandidate constructor: Number of roles and daughters differ, this is an error. Name = " << name << "\n";
  }
}
NamedCompositeCandidate::~NamedCompositeCandidate ( ) [virtual]

destructor

Definition at line 27 of file NamedCompositeCandidate.cc.

References clearDaughters(), and clearRoles().


Member Function Documentation

void NamedCompositeCandidate::addDaughter ( const Candidate cand,
const std::string &  s 
)

add a clone of the passed candidate as daughter

Reimplemented from reco::CompositeCandidate.

Definition at line 93 of file NamedCompositeCandidate.cc.

References reco::CompositeCandidate::begin(), trackerHits::c, alignmentValidation::c1, reco::Candidate::clone(), reco::CompositeCandidate::end(), Exception, spr::find(), roles_, and setName().

Referenced by addDaughter().

{

  role_collection::iterator begin = roles_.begin(), end = roles_.end();
  bool isFound = ( find( begin, end, s) != end );
  if ( isFound ) {
    throw cms::Exception("InvalidReference")
      << "NamedCompositeCandidate::addDaughter: Already have role with name " << s 
      << ", please clearDaughters, or use a new name\n";
  }

  roles_.push_back( s );
  std::auto_ptr<Candidate> c( cand.clone() );
  NamedCompositeCandidate * c1 =  dynamic_cast<NamedCompositeCandidate*>(&*c);
  if ( c1 != 0 ) {
    c1->setName( s );
  }
  CompositeCandidate::addDaughter( c );
}
void NamedCompositeCandidate::addDaughter ( std::auto_ptr< Candidate cand,
const std::string &  s 
)

add a clone of the passed candidate as daughter

Reimplemented from reco::CompositeCandidate.

Definition at line 113 of file NamedCompositeCandidate.cc.

References addDaughter(), reco::CompositeCandidate::begin(), alignmentValidation::c1, reco::CompositeCandidate::end(), Exception, spr::find(), roles_, and setName().

{
  role_collection::iterator begin = roles_.begin(), end = roles_.end();
  bool isFound = ( find( begin, end, s) != end );
  if ( isFound ) {
    throw cms::Exception("InvalidReference")
      << "NamedCompositeCandidate::addDaughter: Already have role with name " << s 
      << ", please clearDaughters, or use a new name\n";
  }

  roles_.push_back( s );
  NamedCompositeCandidate * c1 = dynamic_cast<NamedCompositeCandidate*>(&*cand);
  if ( c1 != 0 ) {
    c1->setName( s );
  }
  CompositeCandidate::addDaughter( cand );
}
void NamedCompositeCandidate::applyRoles ( )

Reimplemented from reco::CompositeCandidate.

Definition at line 31 of file NamedCompositeCandidate.cc.

References trackerHits::c, alignmentValidation::c1, daughter(), Exception, i, reco::CompositeCandidate::numberOfDaughters(), roles_, and setName().

{

  // Check if there are the same number of daughters and roles
  int N1 = roles_.size();
  int N2 = numberOfDaughters();
  if ( N1 != N2 ) {
    throw cms::Exception("InvalidReference")
      << "NamedCompositeCandidate::applyRoles : Number of roles and daughters differ, this is an error.\n";
  }
  // Set up the daughter roles
  for ( int i = 0 ; i < N1; ++i ) {
    std::string role = roles_[i];
    Candidate * c = CompositeCandidate::daughter( i );

    NamedCompositeCandidate * c1 = dynamic_cast<NamedCompositeCandidate *>(c);
    if ( c1 != 0 ) {
      c1->setName( role );
    }
  }
}
void reco::NamedCompositeCandidate::clearDaughters ( ) [inline]

clear daughters

Reimplemented from reco::CompositeCandidate.

Definition at line 66 of file NamedCompositeCandidate.h.

Referenced by ~NamedCompositeCandidate().

void reco::NamedCompositeCandidate::clearRoles ( ) [inline]

Reimplemented from reco::CompositeCandidate.

Definition at line 67 of file NamedCompositeCandidate.h.

References roles_.

Referenced by ~NamedCompositeCandidate().

{ roles_.clear(); }
NamedCompositeCandidate * NamedCompositeCandidate::clone ( void  ) const [virtual]

returns a clone of the candidate

Reimplemented from reco::CompositeCandidate.

Definition at line 29 of file NamedCompositeCandidate.cc.

References NamedCompositeCandidate().

{ return new NamedCompositeCandidate( * this ); }
virtual const Candidate* reco::NamedCompositeCandidate::daughter ( size_type  i) const [inline, virtual]

return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)

Reimplemented from reco::CompositeCandidate.

Definition at line 61 of file NamedCompositeCandidate.h.

References daughter().

const Candidate * NamedCompositeCandidate::daughter ( const std::string &  s) const [virtual]

return daughter with a specified role name

Reimplemented from reco::CompositeCandidate.

Definition at line 73 of file NamedCompositeCandidate.cc.

References daughter(), Exception, newFWLiteAna::found, i, N, runTheMatrix::ret, and roles_.

{
  int ret = -1;
  int i = 0, N = roles_.size();
  bool found = false;
  for ( ; i < N && !found; ++i ) {
    if ( s == roles_[i] ) {
      found = true;
      ret = i;
    }
  }

  if ( ret < 0 ) {
    throw cms::Exception("InvalidReference")
      << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
  }
  
  return daughter(ret);
}
Candidate * NamedCompositeCandidate::daughter ( const std::string &  s) [virtual]

return daughter with a specified role name

Reimplemented from reco::CompositeCandidate.

Definition at line 53 of file NamedCompositeCandidate.cc.

References Exception, newFWLiteAna::found, i, N, runTheMatrix::ret, and roles_.

Referenced by applyRoles(), and daughter().

{
  int ret = -1;
  int i = 0, N = roles_.size();
  bool found = false;
  for ( ; i < N && !found; ++i ) {
    if ( s == roles_[i] ) {
      found = true;
      ret = i;
    }
  }

  if ( ret < 0 ) {
    throw cms::Exception("InvalidReference")
      << "NamedCompositeCandidate::daughter: Cannot find role " << s << "\n";
  }
  
  return daughter(ret);
}
virtual Candidate* reco::NamedCompositeCandidate::daughter ( size_type  i) [inline, virtual]

return daughter at a given position, i = 0, ... numberOfDaughters() - 1

Reimplemented from reco::CompositeCandidate.

Definition at line 60 of file NamedCompositeCandidate.h.

References daughter().

std::string reco::NamedCompositeCandidate::name ( ) const [inline]

get the name of the candidate

Reimplemented from reco::CompositeCandidate.

Definition at line 49 of file NamedCompositeCandidate.h.

References name_.

{ return name_; }
const NamedCompositeCandidate::role_collection& reco::NamedCompositeCandidate::roles ( ) const [inline]

get the roles

Reimplemented from reco::CompositeCandidate.

Definition at line 53 of file NamedCompositeCandidate.h.

References roles_.

Referenced by setRoles().

{ return roles_;}
void reco::NamedCompositeCandidate::setName ( std::string  name) [inline]

set the name of the candidate

Reimplemented from reco::CompositeCandidate.

Definition at line 51 of file NamedCompositeCandidate.h.

References n, and name_.

Referenced by addDaughter(), and applyRoles().

{ name_ = n; }
void reco::NamedCompositeCandidate::setRoles ( const NamedCompositeCandidate::role_collection roles) [inline]

set the roles

Reimplemented from reco::CompositeCandidate.

Definition at line 55 of file NamedCompositeCandidate.h.

References roles(), and roles_.

{ roles_.clear(); roles_ = roles; }

Member Data Documentation

std::string reco::NamedCompositeCandidate::name_ [private]

candidate name

Reimplemented from reco::CompositeCandidate.

Definition at line 71 of file NamedCompositeCandidate.h.

Referenced by name(), and setName().

candidate roles

Reimplemented from reco::CompositeCandidate.

Definition at line 72 of file NamedCompositeCandidate.h.

Referenced by addDaughter(), applyRoles(), clearRoles(), daughter(), NamedCompositeCandidate(), roles(), and setRoles().