CMS 3D CMS Logo

Public Types | Public Member Functions | Private Attributes

pat::helper::RefHelper< T > Class Template Reference

#include <RefHelper.h>

List of all members.

Public Types

typedef edm::Ptr< TRef

Public Member Functions

template<typename V , typename SomeRef >
ancestorLookup (const SomeRef &ref, const edm::ValueMap< V > &map) const
Ref ancestorOrSelf (const Ref &ref) const
 Climbs back the Ref chain and returns the root of the branch starting from "ref".
bool isAncestorOf (const Ref &old, const Ref &young) const
 true if old is some ancestor of young (it does not have to be the root)
bool isRoot (const Ref &ref) const
Ref parentOrNull (const Ref &ref) const
 Returns a Ref to the direct parent of "ref", or a null Ref if "ref" is already root.
Ref parentOrSelf (const Ref &ref) const
 Returns a Ref to the direct parent of "ref", or "ref" itself if it's already root.
template<typename V , typename SomeRef >
recursiveLookup (const SomeRef &ref, const edm::ValueMap< V > &map) const
 RefHelper (const edm::ValueMap< Ref > &backRefMap)
 Constructor taking a ValueMap of back-references daughter => mother.
bool sharedAncestor (const Ref &ref1, const Ref &ref2) const
 true if the two share the same root

Private Attributes

const edm::ValueMap< Ref > & backRefMap_

Detailed Description

template<typename T>
class pat::helper::RefHelper< T >

Definition at line 10 of file RefHelper.h.


Member Typedef Documentation

template<typename T >
typedef edm::Ptr<T> pat::helper::RefHelper< T >::Ref

Definition at line 12 of file RefHelper.h.


Constructor & Destructor Documentation

template<typename T >
pat::helper::RefHelper< T >::RefHelper ( const edm::ValueMap< Ref > &  backRefMap) [inline]

Constructor taking a ValueMap of back-references daughter => mother.

Definition at line 15 of file RefHelper.h.

: backRefMap_(backRefMap) { }

Member Function Documentation

template<typename T >
template<typename V , typename SomeRef >
V pat::helper::RefHelper< T >::ancestorLookup ( const SomeRef &  ref,
const edm::ValueMap< V > &  map 
) const

Looks up map to find something associated to the root ancestor of "ref" Throws edm::Exception(edm::errors::InvalidReference) if there's no match

Definition at line 124 of file RefHelper.h.

                                                                                  {
    Ref tref(ref);
    return map[ancestorOrSelf(tref)];
}
template<typename T >
RefHelper< T >::Ref pat::helper::RefHelper< T >::ancestorOrSelf ( const Ref ref) const

Climbs back the Ref chain and returns the root of the branch starting from "ref".

Definition at line 72 of file RefHelper.h.

References edm::Ptr< T >::isNull(), and runTheMatrix::ret.

                                                                                      {
    Ref ret = ref;
    do {
        Ref test = parentOrNull(ret);
        if (test.isNull()) return ret;
        ret = test;
    } while (true);
}
template<typename T >
bool pat::helper::RefHelper< T >::isAncestorOf ( const Ref old,
const Ref young 
) const

true if old is some ancestor of young (it does not have to be the root)

Definition at line 88 of file RefHelper.h.

References edm::Ptr< T >::isNonnull().

                                                                                              { 
    Ref test = young;
    do {
        if (test == old) return true;
        test = parentOrNull(test);
    } while (test.isNonnull());
    return false;
}
template<typename T >
bool pat::helper::RefHelper< T >::isRoot ( const Ref ref) const

Definition at line 83 of file RefHelper.h.

                                                          { 
    return parentOrNull(ref).isNull(); 
}
template<typename T >
RefHelper< T >::Ref pat::helper::RefHelper< T >::parentOrNull ( const Ref ref) const

Returns a Ref to the direct parent of "ref", or a null Ref if "ref" is already root.

Definition at line 49 of file RefHelper.h.

References edm::Exception::categoryCode(), alignCSCRings::e, edm::Ptr< T >::id(), and edm::errors::InvalidReference.

                                                                                    { 
    if (backRefMap_.contains(ref.id())) {
        try {
            return backRefMap_[ref];
        } catch (edm::Exception &e) {
            if (e.categoryCode() == edm::errors::InvalidReference) {
                return Ref();
            } else {
                throw;
            }
        }
    } else {
        return Ref();
    }
}
template<typename T >
RefHelper< T >::Ref pat::helper::RefHelper< T >::parentOrSelf ( const Ref ref) const

Returns a Ref to the direct parent of "ref", or "ref" itself if it's already root.

Definition at line 66 of file RefHelper.h.

References edm::Ptr< T >::isNonnull(), and runTheMatrix::ret.

                                                                                    {
    Ref ret = parentOrNull(ref);
    return ret.isNonnull() ? ret : ref;
}
template<typename T >
template<typename V , typename SomeRef >
V pat::helper::RefHelper< T >::recursiveLookup ( const SomeRef &  ref,
const edm::ValueMap< V > &  map 
) const

Recursively looks up map to find something associated to ref, or one of its parents. Throws edm::Exception(edm::errors::InvalidReference) if there's no match

Definition at line 104 of file RefHelper.h.

References edm::Exception::categoryCode(), edm::ValueMap< T >::contains(), alignCSCRings::e, Exception, edm::Ptr< T >::id(), edm::errors::InvalidReference, and edm::Ptr< T >::isNonnull().

                                                                                   {
    Ref test(ref);
    do {
        if (map.contains(test.id())) {
            try {
                return map[test];
            } catch (edm::Exception &e) {
                if (e.categoryCode() != edm::errors::InvalidReference) {
                    throw;
                }
            }
        } 
        test = parentOrNull(test);
    } while (test.isNonnull());
    throw edm::Exception(edm::errors::InvalidReference) <<
        "RefHelper: recursive Lookup failed: neither the specified ref nor any of its parents are in the map.\n";
}
template<typename T >
bool pat::helper::RefHelper< T >::sharedAncestor ( const Ref ref1,
const Ref ref2 
) const

true if the two share the same root

Definition at line 98 of file RefHelper.h.

                                                                                                { 
    return ( ancestorOrSelf(ref1) == ancestorOrSelf(ref2) );
}

Member Data Documentation

template<typename T >
const edm::ValueMap< Ref >& pat::helper::RefHelper< T >::backRefMap_ [private]

Definition at line 45 of file RefHelper.h.