CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Attributes
pat::helper::RefHelper< T > Class Template Reference

#include <RefHelper.h>

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". More...
 
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) More...
 
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. More...
 
Ref parentOrSelf (const Ref &ref) const
 Returns a Ref to the direct parent of "ref", or "ref" itself if it's already root. More...
 
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. More...
 
bool sharedAncestor (const Ref &ref1, const Ref &ref2) const
 true if the two share the same root More...
 

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

◆ Ref

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

Definition at line 12 of file RefHelper.h.

Constructor & Destructor Documentation

◆ RefHelper()

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.

15 : backRefMap_(backRefMap) { }

Member Function Documentation

◆ ancestorLookup()

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.

124  {
125  Ref tref(ref);
126  return map[ancestorOrSelf(tref)];
127 }

References genParticles_cff::map.

◆ ancestorOrSelf()

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.

72  {
73  Ref ret = ref;
74  do {
76  if (test.isNull()) return ret;
77  ret = test;
78  } while (true);
79 }

References runTheMatrix::ret, and ctpps_dqm_sourceclient-live_cfg::test.

◆ isAncestorOf()

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.

88  {
89  Ref test = young;
90  do {
91  if (test == old) return true;
93  } while (test.isNonnull());
94  return false;
95 }

◆ isRoot()

template<typename T >
bool pat::helper::RefHelper< T >::isRoot ( const Ref ref) const

Definition at line 83 of file RefHelper.h.

83  {
84  return parentOrNull(ref).isNull();
85 }

◆ parentOrNull()

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.

49  {
50  if (backRefMap_.contains(ref.id())) {
51  try {
52  return backRefMap_[ref];
53  } catch (edm::Exception &e) {
54  if (e.categoryCode() == edm::errors::InvalidReference) {
55  return Ref();
56  } else {
57  throw;
58  }
59  }
60  } else {
61  return Ref();
62  }
63 }

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

◆ parentOrSelf()

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.

66  {
67  Ref ret = parentOrNull(ref);
68  return ret.isNonnull() ? ret : ref;
69 }

References runTheMatrix::ret.

◆ recursiveLookup()

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.

104  {
105  Ref test(ref);
106  do {
107  if (map.contains(test.id())) {
108  try {
109  return map[test];
110  } catch (edm::Exception &e) {
111  if (e.categoryCode() != edm::errors::InvalidReference) {
112  throw;
113  }
114  }
115  }
117  } while (test.isNonnull());
119  "RefHelper: recursive Lookup failed: neither the specified ref nor any of its parents are in the map.\n";
120 }

References MillePedeFileConverter_cfg::e, Exception, edm::errors::InvalidReference, genParticles_cff::map, and ctpps_dqm_sourceclient-live_cfg::test.

◆ sharedAncestor()

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.

98  {
99  return ( ancestorOrSelf(ref1) == ancestorOrSelf(ref2) );
100 }

Member Data Documentation

◆ backRefMap_

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

Definition at line 45 of file RefHelper.h.

runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
edm::errors::InvalidReference
Definition: EDMException.h:39
pat::helper::RefHelper::parentOrNull
Ref parentOrNull(const Ref &ref) const
Returns a Ref to the direct parent of "ref", or a null Ref if "ref" is already root.
Definition: RefHelper.h:49
edm::Exception
Definition: EDMException.h:77
test
Definition: SmallWORMDict.h:13
ctpps_dqm_sourceclient-live_cfg.test
test
Definition: ctpps_dqm_sourceclient-live_cfg.py:7
pat::helper::RefHelper::Ref
edm::Ptr< T > Ref
Definition: RefHelper.h:12
pat::helper::RefHelper::backRefMap_
const edm::ValueMap< Ref > & backRefMap_
Definition: RefHelper.h:45
Exception
Definition: hltDiff.cc:246
genParticles_cff.map
map
Definition: genParticles_cff.py:11
edm::Ptr::isNull
bool isNull() const
Checks for null.
Definition: Ptr.h:142
pat::helper::RefHelper::ancestorOrSelf
Ref ancestorOrSelf(const Ref &ref) const
Climbs back the Ref chain and returns the root of the branch starting from "ref".
Definition: RefHelper.h:72
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37