Gaudi Framework, version v23r0

Home   Generated: Mon Jan 30 2012
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes

SharedObjectsContainer< TYPE > Class Template Reference

Very simple class to represent the container of objects which are not ownered by the container. More...

#include <SharedObjectsContainer.h>

Inheritance diagram for SharedObjectsContainer< TYPE >:
Inheritance graph
[legend]
Collaboration diagram for SharedObjectsContainer< TYPE >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::vector< const TYPE * > ConstVector
 the actual container type
typedef ConstVector::value_type value_type
 various types (to make STL happy)
typedef ConstVector::size_type size_type
 size_type, to conform the STL container interface
typedef ConstVector::reference reference
typedef
ConstVector::const_reference 
const_reference
typedef ConstVector::iterator iterator
typedef ConstVector::const_iterator const_iterator
typedef
ConstVector::reverse_iterator 
reverse_iterator
typedef
ConstVector::const_reverse_iterator 
const_reverse_iterator

Public Member Functions

 SharedObjectsContainer ()
 SharedObjectsContainer (const ConstVector &data)
template<class DATA >
 SharedObjectsContainer (DATA first, DATA last)
 the templated constructor from the pair of iterators
template<class DATA , class PREDICATE >
 SharedObjectsContainer (DATA first, DATA last, const PREDICATE &cut)
 the templated constructor from the pair of iterators and the predicate.
virtual ~SharedObjectsContainer ()
 destructor
virtual const CLIDclID () const
 Retrieve the unique class ID (virtual)
const ConstVectordata () const
 get the access to the underlying container (const)
 operator const ConstVector & () const
 cast to the underlying container
size_type size () const
 get the actual size of the container
bool empty () const
 empty container?
void push_back (const TYPE *object)
 insert one object into the container
void insert (const TYPE *object)
 insert one object into the container
template<class DATA >
void insert (DATA first, DATA last)
 add the sequence of objects into the container
template<class DATA , class PREDICATE >
void insert (DATA first, DATA last, const PREDICATE &cut)
 add the sequence of 'good'objects into the container
template<class OUTPUT , class PREDICATE >
OUTPUT get (const PREDICATE &cut, OUTPUT output) const
 get from the container all objects which satisfy the certain criteria
void erase (iterator i)
 erase the object by iterator
template<class PREDICATE >
void erase (const PREDICATE &cut)
 erase the objects which satisfy the criteria
bool erase (const TYPE *object)
 erase the first occurance of the certain element
reference operator[] (size_type index)
 index access
const_reference operator[] (size_type index) const
 index access (const-version)
reference operator() (size_type index)
 'functional'-access
const_reference operator() (size_type index) const
 'functional'-access (const version)
reference at (size_type index)
 checked access
const_reference at (size_type index) const
 checked access (const-version)
iterator begin ()
iterator end ()
const_iterator begin () const
const_iterator end () const
reverse_iterator rbegin ()
reverse_iterator rend ()
const_reverse_iterator rbegin () const
const_reverse_iterator rend () const
reference front ()
 the first element (only for non-empty vectors)
const_reference front () const
 the first element (only for non-empty vectors) (const-version)
reference back ()
 the last element (only for non-empty vectors)
const_reference back () const
 the last element (only for non-empty vectors) (const-version)
bool operator== (const SharedObjectsContainer &right) const
 equal content with other container ?
bool operator== (const ConstVector &right) const
 equal content with corresponding vector ?
bool operator< (const SharedObjectsContainer &right) const
 comparisons with other container
bool operator< (const ConstVector &right) const
 comparisons with corresponding vector
virtual long index (const ContainedObject *object) const
 Distance of a given object from the beginning of its container.
virtual ContainedObjectcontainedObject (long index) const
 Pointer to an object of a given distance.
virtual size_type numberOfObjects () const
 Number of objects in the container.
virtual long add (ContainedObject *object)
 Virtual functions (forwards to the concrete container definitions) Add an object to the container.
virtual long remove (ContainedObject *value)
 Release object from the container (the pointer will be removed from the container, but the object itself will remain alive).

Static Public Member Functions

static const CLIDclassID ()
 Retrieve the unuqie class ID (static)

Private Attributes

ConstVector m_data

Detailed Description

template<class TYPE>
class SharedObjectsContainer< TYPE >

Very simple class to represent the container of objects which are not ownered by the container.

This concept seem to be very useful for LHCb HLT, DaVinci, tracking, alignments.

Warning:
the container is not persistable (on-purpose)
Author:
Vanya BELYAEV Ivan.Belyaev@nikhef.nl
Date:
2008-07-23

Definition at line 30 of file SharedObjectsContainer.h.


Member Typedef Documentation

template<class TYPE >
typedef ConstVector::const_iterator SharedObjectsContainer< TYPE >::const_iterator

Definition at line 42 of file SharedObjectsContainer.h.

Definition at line 40 of file SharedObjectsContainer.h.

Definition at line 44 of file SharedObjectsContainer.h.

template<class TYPE >
typedef std::vector<const TYPE*> SharedObjectsContainer< TYPE >::ConstVector

the actual container type

Definition at line 35 of file SharedObjectsContainer.h.

template<class TYPE >
typedef ConstVector::iterator SharedObjectsContainer< TYPE >::iterator

Definition at line 41 of file SharedObjectsContainer.h.

template<class TYPE >
typedef ConstVector::reference SharedObjectsContainer< TYPE >::reference

Definition at line 39 of file SharedObjectsContainer.h.

Definition at line 43 of file SharedObjectsContainer.h.

template<class TYPE >
typedef ConstVector::size_type SharedObjectsContainer< TYPE >::size_type

size_type, to conform the STL container interface

Reimplemented from ObjectContainerBase.

Definition at line 38 of file SharedObjectsContainer.h.

template<class TYPE >
typedef ConstVector::value_type SharedObjectsContainer< TYPE >::value_type

various types (to make STL happy)

Definition at line 37 of file SharedObjectsContainer.h.


Constructor & Destructor Documentation

template<class TYPE >
SharedObjectsContainer< TYPE >::SharedObjectsContainer (  ) [inline]

Definition at line 49 of file SharedObjectsContainer.h.

    : ObjectContainerBase  () , m_data() {} ;
template<class TYPE >
SharedObjectsContainer< TYPE >::SharedObjectsContainer ( const ConstVector data ) [inline]

Definition at line 52 of file SharedObjectsContainer.h.

template<class TYPE >
template<class DATA >
SharedObjectsContainer< TYPE >::SharedObjectsContainer ( DATA  first,
DATA  last 
) [inline]

the templated constructor from the pair of iterators

Parameters:
first'begin'-iterator of the input sequence
last'last'-iterator of the input sequence

Definition at line 60 of file SharedObjectsContainer.h.

    : DataObject ()
    , m_data ( first , last )
  {}
template<class TYPE >
template<class DATA , class PREDICATE >
SharedObjectsContainer< TYPE >::SharedObjectsContainer ( DATA  first,
DATA  last,
const PREDICATE &  cut 
) [inline]

the templated constructor from the pair of iterators and the predicate.

Only the elements which satisfy the criteria goes into the container e.g. create the container only with "basic" particles:

   typedef SharedObjectsContainer<LHCb::Particle>  PARTICLES ;

   // some sequence of someting, convertiblle to "const LHCb::Particle*":
   SEQUENCE source = ... ;

   PARTICLES* particles = new PARTICLES
          ( source.begin() ,
            source.end  () ,
            std::mem_fun(&LHCb::Particle::isBasic) ) ;
Parameters:
first'begin'-iterator if the input sequence
last'last'-iterator of the input sequence
cutpre predicate

Definition at line 90 of file SharedObjectsContainer.h.

    : DataObject ()
    , m_data     ()
  {
    insert ( first , last , cut ) ;
  }
template<class TYPE >
virtual SharedObjectsContainer< TYPE >::~SharedObjectsContainer (  ) [inline, virtual]

destructor

Definition at line 99 of file SharedObjectsContainer.h.

{ m_data.clear() ; }

Member Function Documentation

template<class TYPE >
virtual long SharedObjectsContainer< TYPE >::add ( ContainedObject object ) [inline, virtual]

Virtual functions (forwards to the concrete container definitions) Add an object to the container.

On success the object's index is returned.

Implements ObjectContainerBase.

Definition at line 346 of file SharedObjectsContainer.h.

  {
    if ( 0 == object ) { return -1 ; }                           // RETURN
    TYPE* _obj = dynamic_cast<TYPE*> ( object ) ;
    if ( 0 == _obj   ) { return -1 ; }                           // RETURN
    const size_type pos = size() ;
    push_back ( _obj ) ;
    return pos ;
  }
template<class TYPE >
reference SharedObjectsContainer< TYPE >::at ( size_type  index ) [inline]

checked access

Definition at line 279 of file SharedObjectsContainer.h.

{ return m_data.at(index) ; }
template<class TYPE >
const_reference SharedObjectsContainer< TYPE >::at ( size_type  index ) const [inline]

checked access (const-version)

Definition at line 281 of file SharedObjectsContainer.h.

{ return m_data.at(index) ; }
template<class TYPE >
const_reference SharedObjectsContainer< TYPE >::back ( void   ) const [inline]

the last element (only for non-empty vectors) (const-version)

Definition at line 303 of file SharedObjectsContainer.h.

{ return m_data . back  () ; }
template<class TYPE >
reference SharedObjectsContainer< TYPE >::back ( void   ) [inline]

the last element (only for non-empty vectors)

Definition at line 301 of file SharedObjectsContainer.h.

{ return m_data . back  () ; }
template<class TYPE >
iterator SharedObjectsContainer< TYPE >::begin ( void   ) [inline]

Definition at line 285 of file SharedObjectsContainer.h.

{ return m_data .  begin () ; }
template<class TYPE >
const_iterator SharedObjectsContainer< TYPE >::begin ( void   ) const [inline]

Definition at line 287 of file SharedObjectsContainer.h.

{ return m_data .  begin () ; }
template<class TYPE >
static const CLID& SharedObjectsContainer< TYPE >::classID (  ) [inline, static]

Retrieve the unuqie class ID (static)

Reimplemented from DataObject.

Definition at line 107 of file SharedObjectsContainer.h.

  {
    static const CLID s_clid =
      ( ( static_cast<CLID>  ( -1 ) << 16 )  // 16 used and 16 empty bits
        & !CLID_ObjectVector                 // not an ObjectVector
        & !CLID_ObjectList                   // not an ObjectList
        & !static_cast<CLID> ( 0x00030000 )  // not a  KeyedContainer/map
        & !static_cast<CLID> ( 0x00040000 ) )// not a  KeyedContainer/hashmap
      + TYPE::classID() ;                // the specific CLID from the contents
    //
    return s_clid;
  }
template<class TYPE >
virtual const CLID& SharedObjectsContainer< TYPE >::clID (  ) const [inline, virtual]

Retrieve the unique class ID (virtual)

Reimplemented from DataObject.

Definition at line 104 of file SharedObjectsContainer.h.

template<class TYPE >
virtual ContainedObject* SharedObjectsContainer< TYPE >::containedObject ( long  index ) const [inline, virtual]

Pointer to an object of a given distance.

Parameters:
indexth eindex to be checked
Returns:
the object

Implements ObjectContainerBase.

Definition at line 334 of file SharedObjectsContainer.h.

  {
    if ( 0 > index || !(index < (long) size () ) ) { return 0 ; }    // RETURN
    const ContainedObject* co = m_data[index] ;
    return const_cast<ContainedObject*>( co ) ;
  }
template<class TYPE >
const ConstVector& SharedObjectsContainer< TYPE >::data (  ) const [inline]

get the access to the underlying container (const)

Definition at line 123 of file SharedObjectsContainer.h.

{ return m_data ; }
template<class TYPE >
bool SharedObjectsContainer< TYPE >::empty ( void   ) const [inline]

empty container?

Definition at line 132 of file SharedObjectsContainer.h.

{ return m_data.empty () ; }
template<class TYPE >
iterator SharedObjectsContainer< TYPE >::end ( void   ) [inline]

Definition at line 286 of file SharedObjectsContainer.h.

{ return m_data .  end   () ; }
template<class TYPE >
const_iterator SharedObjectsContainer< TYPE >::end ( void   ) const [inline]

Definition at line 288 of file SharedObjectsContainer.h.

{ return m_data .  end   () ; }
template<class TYPE >
void SharedObjectsContainer< TYPE >::erase ( iterator  i ) [inline]

erase the object by iterator

Definition at line 221 of file SharedObjectsContainer.h.

{ m_data.erase ( i ) ; }
template<class TYPE >
template<class PREDICATE >
void SharedObjectsContainer< TYPE >::erase ( const PREDICATE &  cut ) [inline]

erase the objects which satisfy the criteria

E.g. remove all particles with small transverse momentum

   namespace bl = boost::lambda ;
   typedef SharedObjectsContainer<LHCb::Particle>  PARTICLES ;

   PARTICLES* particles = ... ;
   particles -> erase
         ( bl::bind(&LHCb::Particle::pt,bl::_1) < 1 * Gaudi::Units::GeV ) ;
See also:
std::remove_if
Parameters:
cutpredicate

Definition at line 240 of file SharedObjectsContainer.h.

  { m_data.erase( std::remove_if (  begin() , end() , cut ) , end() ) ; }
template<class TYPE >
bool SharedObjectsContainer< TYPE >::erase ( const TYPE *  object ) [inline]

erase the first occurance of the certain element

To remove all occurances one can use:

   typedef SharedObjectsContainer<LHCb::Particle>  PARTICLES ;
   PARTICLES* particles = ... ;

   const LHCb::Particle* B = ... ;

   // remove all occurances
   while ( particles -> erase ( B ) ) {} ;
Parameters:
objectthe element to be removed
Returns:
true if the element is removed

Definition at line 260 of file SharedObjectsContainer.h.

  {
    iterator i = std::find ( begin() , end() , object ) ;
    if ( end() == i ) { return false ; }
    m_data.erase ( i ) ;
    return true ;
  }
template<class TYPE >
reference SharedObjectsContainer< TYPE >::front (  ) [inline]

the first element (only for non-empty vectors)

Definition at line 297 of file SharedObjectsContainer.h.

{ return m_data . front () ; }
template<class TYPE >
const_reference SharedObjectsContainer< TYPE >::front ( void   ) const [inline]

the first element (only for non-empty vectors) (const-version)

Definition at line 299 of file SharedObjectsContainer.h.

{ return m_data . front () ; }
template<class TYPE >
template<class OUTPUT , class PREDICATE >
OUTPUT SharedObjectsContainer< TYPE >::get ( const PREDICATE &  cut,
OUTPUT  output 
) const [inline]

get from the container all objects which satisfy the certain criteria

E.g. get all particles with transverse momentum in excess of 1 * GeV

   namespace bl = boost::lambda ;
   typedef SharedObjectsContainer<LHCb::Particle>  PARTICLES ;
   typedef std::vector<const LHCb::Particle*>      TARGET    ;

   PARTICLES* particles = ... ;

   TARGET target ;

   particles -> get
         ( bl::bind(&LHCb::Particle::pt,bl::_1) > 1 * Gaudi::Units::GeV ,
           std::back_inserter ( target ) ) ;

Essentially this functionality is very useful due to missing "std::copy_if".

Parameters:
cutthe predicate
outptutthe output iterator
Returns:
the current position of the output itrator (almost useless)

Definition at line 213 of file SharedObjectsContainer.h.

  {
    for ( const_iterator iobj = begin() ; end() != iobj ; ++iobj )
    { if ( cut ( *iobj ) ) { *output = *iobj ; ++output ; } }
    return output ;
  }
template<class TYPE >
virtual long SharedObjectsContainer< TYPE >::index ( const ContainedObject object ) const [inline, virtual]

Distance of a given object from the beginning of its container.

Parameters:
objectthe object to be checked

Implements ObjectContainerBase.

Definition at line 325 of file SharedObjectsContainer.h.

  {
    const_iterator _i = std::find ( begin() , end() , object ) ;
    return end() != _i ? ( _i - begin() ) : -1 ;                  // RETURN
  }
template<class TYPE >
void SharedObjectsContainer< TYPE >::insert ( const TYPE *  object ) [inline]

insert one object into the container

Parameters:
objectobject to be added

Definition at line 140 of file SharedObjectsContainer.h.

{ m_data.push_back ( object ) ; }
template<class TYPE >
template<class DATA , class PREDICATE >
void SharedObjectsContainer< TYPE >::insert ( DATA  first,
DATA  last,
const PREDICATE &  cut 
) [inline]

add the sequence of 'good'objects into the container

Only the objects which satisfy the predicate go to the container, e.g. put into container only particles which transverse momentum in excess of 1 * GeV:

   namespace bl = boost::lambda ;
   typedef SharedObjectsContainer<LHCb::Particle>  PARTICLES ;

   // some sequence of someting, convertible to "const LHCb::Particle*":
   SEQUENCE source = ... ;

   PARTICLES* particles = ... ;

   particles -> insert
         ( source.begin() ,
           source.end  () ,
           bl::bind(&LHCb::Particle::pt,bl::_1) > 1 * Gaudi::Units::GeV ) ;
Parameters:
first'begin'-iterator for the sequnce
last'end'-iterator for the sequence
cutthe predicate to be applied

Definition at line 177 of file SharedObjectsContainer.h.

  {
    m_data.reserve ( m_data.size() + std::distance ( first , last ) ) ;
    for ( ; first != last ; ++first )
    { if ( cut ( *first ) ) { m_data.push_back ( *first ) ; } }
  }
template<class TYPE >
template<class DATA >
void SharedObjectsContainer< TYPE >::insert ( DATA  first,
DATA  last 
) [inline]

add the sequence of objects into the container

Parameters:
first'begin'-iterator for the sequnce
last'end'-iterator for the sequence

Definition at line 147 of file SharedObjectsContainer.h.

                 { m_data.insert ( end() , first ,last ) ; }
template<class TYPE >
virtual size_type SharedObjectsContainer< TYPE >::numberOfObjects (  ) const [inline, virtual]

Number of objects in the container.

Implements ObjectContainerBase.

Definition at line 341 of file SharedObjectsContainer.h.

{ return m_data.size() ; }
template<class TYPE >
SharedObjectsContainer< TYPE >::operator const ConstVector & (  ) const [inline]

cast to the underlying container

Definition at line 125 of file SharedObjectsContainer.h.

{ return data () ; }
template<class TYPE >
reference SharedObjectsContainer< TYPE >::operator() ( size_type  index ) [inline]

'functional'-access

Definition at line 275 of file SharedObjectsContainer.h.

{ return m_data   [index] ; }
template<class TYPE >
const_reference SharedObjectsContainer< TYPE >::operator() ( size_type  index ) const [inline]

'functional'-access (const version)

Definition at line 277 of file SharedObjectsContainer.h.

{ return m_data   [index] ; }
template<class TYPE >
bool SharedObjectsContainer< TYPE >::operator< ( const ConstVector right ) const [inline]

comparisons with corresponding vector

Definition at line 317 of file SharedObjectsContainer.h.

  { return m_data <  right        ; }
template<class TYPE >
bool SharedObjectsContainer< TYPE >::operator< ( const SharedObjectsContainer< TYPE > &  right ) const [inline]

comparisons with other container

Definition at line 314 of file SharedObjectsContainer.h.

  { return m_data <  right.m_data ; }
template<class TYPE >
bool SharedObjectsContainer< TYPE >::operator== ( const ConstVector right ) const [inline]

equal content with corresponding vector ?

Definition at line 311 of file SharedObjectsContainer.h.

  { return m_data == right ; }
template<class TYPE >
bool SharedObjectsContainer< TYPE >::operator== ( const SharedObjectsContainer< TYPE > &  right ) const [inline]

equal content with other container ?

Definition at line 308 of file SharedObjectsContainer.h.

  { return &right == this || right.m_data == m_data ; }
template<class TYPE >
reference SharedObjectsContainer< TYPE >::operator[] ( size_type  index ) [inline]

index access

Definition at line 271 of file SharedObjectsContainer.h.

{ return m_data   [index] ; }
template<class TYPE >
const_reference SharedObjectsContainer< TYPE >::operator[] ( size_type  index ) const [inline]

index access (const-version)

Definition at line 273 of file SharedObjectsContainer.h.

{ return m_data   [index] ; }
template<class TYPE >
void SharedObjectsContainer< TYPE >::push_back ( const TYPE *  object ) [inline]

insert one object into the container

Parameters:
objectobject to be added

Definition at line 136 of file SharedObjectsContainer.h.

{ m_data.push_back ( object ) ; }
template<class TYPE >
const_reverse_iterator SharedObjectsContainer< TYPE >::rbegin (  ) const [inline]

Definition at line 291 of file SharedObjectsContainer.h.

{ return m_data . rbegin () ; }
template<class TYPE >
reverse_iterator SharedObjectsContainer< TYPE >::rbegin ( void   ) [inline]

Definition at line 289 of file SharedObjectsContainer.h.

{ return m_data . rbegin () ; }
template<class TYPE >
virtual long SharedObjectsContainer< TYPE >::remove ( ContainedObject value ) [inline, virtual]

Release object from the container (the pointer will be removed from the container, but the object itself will remain alive).

If the object was found it's index is returned.

Implements ObjectContainerBase.

Definition at line 359 of file SharedObjectsContainer.h.

  {
    iterator _i = std::find ( begin() , end() , value ) ;
    if ( end() == _i ) { return -1 ; }                          // RETURN
    const size_type pos = _i - begin() ;
    m_data.erase ( _i ) ;
    return pos ;                                                // RETURN
  }
template<class TYPE >
reverse_iterator SharedObjectsContainer< TYPE >::rend (  ) [inline]

Definition at line 290 of file SharedObjectsContainer.h.

{ return m_data . rend   () ; }
template<class TYPE >
const_reverse_iterator SharedObjectsContainer< TYPE >::rend ( void   ) const [inline]

Definition at line 292 of file SharedObjectsContainer.h.

{ return m_data . rend   () ; }
template<class TYPE >
size_type SharedObjectsContainer< TYPE >::size ( void   ) const [inline]

get the actual size of the container

Definition at line 130 of file SharedObjectsContainer.h.

{ return m_data.size  () ; }

Member Data Documentation

template<class TYPE >
ConstVector SharedObjectsContainer< TYPE >::m_data [private]

Definition at line 371 of file SharedObjectsContainer.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Jan 30 2012 13:53:22 for Gaudi Framework, version v23r0 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004