Belle II Software development
WeightedTreeTraversal< AStateRejecter, AState, AResult > Class Template Referenceabstract

General implementation of a tree search algorithm using a given classes as state and results and one strategy class to decide, which child states should be traversed next. More...

#include <WeightedTreeTraversal.h>

Inheritance diagram for WeightedTreeTraversal< AStateRejecter, AState, AResult >:
Findlet< AIOTypes > CompositeProcessingSignalListener ProcessingSignalListener

Public Types

using IOTypes = std::tuple< AIOTypes... >
 Types that should be served to apply on invokation.
 
using IOVectors = std::tuple< std::vector< AIOTypes >... >
 Vector types that should be served to apply on invokation.
 

Public Member Functions

 WeightedTreeTraversal ()
 Construct this findlet and add the subfindlet as listener.
 
void exposeParameters (ModuleParamList *moduleParamList, const std::string &prefix) final
 Expose the parameters of the subfindlet.
 
void apply (const std::vector< const AState * > &seededStates, const std::vector< WeightedRelation< AState > > &stateRelations, std::vector< AResult > &results) override
 Main function of this findlet: traverse a tree starting from a given seed states.
 
virtual std::string getDescription ()
 Brief description of the purpose of the concret findlet.
 
virtual void apply (ToVector< AIOTypes > &... ioVectors)=0
 Main function executing the algorithm.
 
void initialize () override
 Receive and dispatch signal before the start of the event processing.
 
void beginRun () override
 Receive and dispatch signal for the beginning of a new run.
 
void beginEvent () override
 Receive and dispatch signal for the start of a new event.
 
void endRun () override
 Receive and dispatch signal for the end of the run.
 
void terminate () override
 Receive and dispatch Signal for termination of the event processing.
 

Protected Types

template<class T >
using ToVector = typename ToVectorImpl< T >::Type
 Short hand for ToRangeImpl.
 

Protected Member Functions

void addProcessingSignalListener (ProcessingSignalListener *psl)
 Register a processing signal listener to be notified.
 
int getNProcessingSignalListener ()
 Get the number of currently registered listeners.
 

Private Types

using Super = Findlet< const AState *const, const WeightedRelation< AState >, AResult >
 Parent class.
 

Private Member Functions

void traverseTree (std::vector< const AState * > &path, const std::vector< WeightedRelation< AState > > &stateRelations, std::vector< AResult > &results)
 Implementation of the traverseTree function.
 

Private Attributes

AStateRejecter m_stateRejecter
 State rejecter to decide which available continuations should be traversed next.
 
std::vector< ProcessingSignalListener * > m_subordinaryProcessingSignalListeners
 References to subordinary signal processing listener contained in this findlet.
 
bool m_initialized = false
 Flag to keep track whether initialization happend before.
 
bool m_terminated = false
 Flag to keep track whether termination happend before.
 
std::string m_initializedAs
 Name of the type during initialisation.
 

Detailed Description

template<class AStateRejecter, class AState, class AResult = std::vector<const AState*>>
class Belle2::TrackFindingCDC::WeightedTreeTraversal< AStateRejecter, AState, AResult >

General implementation of a tree search algorithm using a given classes as state and results and one strategy class to decide, which child states should be traversed next.

Requirements for the template parameters:

  • AState: No requirements
  • AResult: Must be constructable from std::vector<const AState*>
  • AStateRejecter: Should be roughly of type Findlet<const AState* const, WithWeight<AState*> > with an apply methode like:

    apply(const std::vector<const AState*>& currentPath, std::vector<WithWeight<AState*> >& nextStates);

    Therefore it receives the current path and a list of potential next states with an apriori Weight, that it should sort out for viable continuations to traverse next.

    The StateRejecter is allowed to adjust the nextStates for book keeping purposes, but should generally avoid to adjust the states in the currentPath to not interfere with the traversal of earlier siblings.

Definition at line 52 of file WeightedTreeTraversal.h.

Member Typedef Documentation

◆ IOTypes

using IOTypes = std::tuple<AIOTypes...>
inherited

Types that should be served to apply on invokation.

Definition at line 30 of file Findlet.h.

◆ IOVectors

using IOVectors = std::tuple< std::vector<AIOTypes>... >
inherited

Vector types that should be served to apply on invokation.

Definition at line 53 of file Findlet.h.

◆ Super

using Super = Findlet<const AState* const, const WeightedRelation<AState>, AResult>
private

Parent class.

Definition at line 56 of file WeightedTreeTraversal.h.

◆ ToVector

using ToVector = typename ToVectorImpl<T>::Type
protectedinherited

Short hand for ToRangeImpl.

Definition at line 49 of file Findlet.h.

Constructor & Destructor Documentation

◆ WeightedTreeTraversal()

Construct this findlet and add the subfindlet as listener.

Definition at line 60 of file WeightedTreeTraversal.h.

61 : Super()
62 {
64 }
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Findlet< const AState *const, const WeightedRelation< AState >, AResult > Super
Parent class.
AStateRejecter m_stateRejecter
State rejecter to decide which available continuations should be traversed next.

Member Function Documentation

◆ addProcessingSignalListener()

void addProcessingSignalListener ( ProcessingSignalListener psl)
protectedinherited

Register a processing signal listener to be notified.

Definition at line 55 of file CompositeProcessingSignalListener.cc.

56{
58}
std::vector< ProcessingSignalListener * > m_subordinaryProcessingSignalListeners
References to subordinary signal processing listener contained in this findlet.

◆ apply()

void apply ( const std::vector< const AState * > &  seededStates,
const std::vector< WeightedRelation< AState > > &  stateRelations,
std::vector< AResult > &  results 
)
override

Main function of this findlet: traverse a tree starting from a given seed states.

ATTENTION: As described above, the states themselves can be altered during the tree traversal.

Definition at line 94 of file WeightedTreeTraversal.h.

98 {
99 std::vector<const AState*> path;
100 for (const AState* state : seededStates) {
101 B2DEBUG(25, "Starting with new seed...");
102 path.push_back(state);
103 traverseTree(path, stateRelations, results);
104 path.pop_back();
105 B2DEBUG(25, "... finished with seed");
106 }
107 assert(path.empty());
108 }
void traverseTree(std::vector< const AState * > &path, const std::vector< WeightedRelation< AState > > &stateRelations, std::vector< AResult > &results)
Implementation of the traverseTree function.

◆ beginEvent()

void beginEvent ( )
overridevirtualinherited

Receive and dispatch signal for the start of a new event.

Reimplemented from ProcessingSignalListener.

Reimplemented in SpacePointTagger< Belle2::CKFToPXDResult, Belle2::PXDCluster >, SpacePointTagger< Belle2::CKFToSVDResult, Belle2::SVDCluster >, BaseEventTimeExtractor< RecoTrack * >, BaseEventTimeExtractor< TrackFindingCDC::CDCWireHit & >, SharingHitsMatcher< Belle2::TrackFindingCDC::CDCTrack, Belle2::TrackFindingCDC::CDCSegment2D >, MCSymmetric< BaseAxialSegmentPairFilter >, MCSymmetric< BaseFacetFilter >, MCSymmetric< BaseFacetRelationFilter >, MCSymmetric< BaseSegmentPairFilter >, MCSymmetric< BaseSegmentPairRelationFilter >, MCSymmetric< BaseSegmentRelationFilter >, MCSymmetric< BaseSegmentTripleFilter >, MCSymmetric< BaseSegmentTripleRelationFilter >, MCSymmetric< BaseTrackRelationFilter >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCFacet >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCWireHit, true >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegment2D >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCTrack >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentPair >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentTriple >, RecoTrackStorer, ROIFinder, and SVDHoughTracking.

Definition at line 31 of file CompositeProcessingSignalListener.cc.

32{
35 psl->beginEvent();
36 }
37}
Interface for an algorithm part that needs to receive the module processing signals.
virtual void beginEvent()
Receive signal for the start of a new event.

◆ beginRun()

void beginRun ( )
overridevirtualinherited

Receive and dispatch signal for the beginning of a new run.

Reimplemented from ProcessingSignalListener.

Reimplemented in LayerRelationFilter< AFilter >, FourHitFilter, QualityIndicatorFilter, ThreeHitFilter, TwoHitVirtualIPFilter, TwoHitVirtualIPQIFilter, RecoTrackStorer, ROIFinder, SpacePointLoaderAndPreparer, and TrackCandidateResultRefiner.

Definition at line 23 of file CompositeProcessingSignalListener.cc.

24{
27 psl->beginRun();
28 }
29}
virtual void beginRun()
Receive signal for the beginning of a new run.

◆ endRun()

void endRun ( )
overridevirtualinherited

Receive and dispatch signal for the end of the run.

Reimplemented from ProcessingSignalListener.

Definition at line 39 of file CompositeProcessingSignalListener.cc.

40{
42 psl->endRun();
43 }
45}
virtual void endRun()
Receive signal for the end of the run.

◆ exposeParameters()

void exposeParameters ( ModuleParamList moduleParamList,
const std::string &  prefix 
)
inlinefinalvirtual

Expose the parameters of the subfindlet.

Reimplemented from Findlet< AIOTypes >.

Definition at line 67 of file WeightedTreeTraversal.h.

68 {
69 m_stateRejecter.exposeParameters(moduleParamList, prefix);
70 }

◆ getDescription()

virtual std::string getDescription ( )
inlinevirtualinherited

Brief description of the purpose of the concret findlet.

Reimplemented in CosmicsTrackMergerFindlet, CDCTrackingEventLevelMdstInfoFillerFromHitsFindlet, CDCTrackingEventLevelMdstInfoFillerFromSegmentsFindlet, AxialStraightTrackFinder, AxialTrackFinderHough, AxialTrackFinderLegendre, ClusterPreparer, MonopoleAxialTrackFinderLegendre, MonopoleStereoHitFinder, MonopoleStereoHitFinderQuadratic, SegmentFinderFacetAutomaton, SegmentTrackCombiner, StereoHitFinder, TrackFinderSegmentPairAutomaton, TrackFinderSegmentTripleAutomaton, TrackQualityEstimator, WireHitPreparer, AsicBackgroundLibraryCreator, TrackFinderCosmics, AsicBackgroundDetector, AxialSegmentPairCreator, AxialStraightTrackCreator, AxialTrackCreatorHitHough, AxialTrackCreatorHitLegendre, AxialTrackCreatorMCTruth, AxialTrackCreatorSegmentHough, AxialTrackHitMigrator, AxialTrackMerger, CDCMCCloneLookUpFiller, ClusterBackgroundDetector, ClusterCreator< AWireHitRelationFilter >, ClusterRefiner< AWireHitRelationFilter >, ClusterRefiner< BridgingWireHitRelationFilter >, ClusterRefiner< Belle2::TrackFindingCDC::BridgingWireHitRelationFilter >, FacetCreator, HitReclaimer, RLTaggedWireHitCreator, SegmentAliasResolver, SegmentCreatorFacetAutomaton, SegmentCreatorMCTruth, SegmentLinker, SegmentOrienter, SegmentPairCreator, SegmentRejecter, SegmentTripleCreator, SuperClusterCreator, TrackCombiner, TrackCreatorSegmentPairAutomaton, TrackCreatorSegmentTripleAutomaton, TrackCreatorSingleSegments, TrackExporter, TrackFlightTimeAdjuster, TrackInspector, TrackLinker, TrackNormalizer, TrackOrienter, TrackRejecter, TrackSZFitter, WeightedRelationCreator< AObject, ARelationFilter >, WeightedRelationCreator< const Belle2::TrackFindingCDC::WithAutomatonCell, Belle2::PhiRecoTrackRelationFilter >, WeightedRelationCreator< const Belle2::TrackFindingCDC::CDCFacet, Belle2::TrackFindingCDC::ChooseableFilter >, WeightedRelationCreator< const Belle2::TrackFindingCDC::CDCSegment2D, Belle2::TrackFindingCDC::ChooseableFilter >, WeightedRelationCreator< const Belle2::TrackFindingCDC::CDCSegmentPair, Belle2::TrackFindingCDC::ChooseableFilter >, WeightedRelationCreator< const Belle2::TrackFindingCDC::CDCSegmentTriple, Belle2::TrackFindingCDC::ChooseableFilter >, WeightedRelationCreator< const Belle2::TrackFindingCDC::CDCTrack, Belle2::TrackFindingCDC::ChooseableFilter >, WireHitBackgroundBlocker, WireHitBackgroundDetector, WireHitCreator, WireHitMCMultiLoopBlocker, StoreArrayLoader< IOType >, StoreArrayLoader< const Belle2::SpacePoint >, StoreArrayLoader< DataStoreInputTypeRefType >, StoreVectorSwapper< IOType, a_alwaysWrite >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCFacet >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCWireHit, true >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegment2D >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCTrack >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentPair >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentTriple >, TrackFinder, TrackFinderAutomaton, SegmentFitter, SegmentTrackAdderWithNormalization, TrackQualityAsserter, HitBasedT0Extractor, and FindletStoreArrayInput< TWrappedFindlet >.

Definition at line 60 of file Findlet.h.

61 {
62 return "(no description)";
63 }

◆ getNProcessingSignalListener()

int getNProcessingSignalListener ( )
protectedinherited

Get the number of currently registered listeners.

Definition at line 60 of file CompositeProcessingSignalListener.cc.

61{
63}

◆ initialize()

void initialize ( )
overridevirtualinherited

Receive and dispatch signal before the start of the event processing.

Reimplemented from ProcessingSignalListener.

Reimplemented in UnionVarSet< AObject >, UnionVarSet< Object >, VariadicUnionVarSet< AVarSets >, ResultStorer< Belle2::CKFToPXDResult >, ResultStorer< Belle2::CKFToSVDResult >, BaseEventTimeExtractor< RecoTrack * >, BaseEventTimeExtractor< TrackFindingCDC::CDCWireHit & >, StereoHitTrackQuadTreeMatcher< Belle2::TrackFindingCDC::HyperHough >, StereoHitTrackQuadTreeMatcher< Belle2::TrackFindingCDC::QuadraticLegendre >, StereoHitTrackQuadTreeMatcher< Belle2::TrackFindingCDC::Z0TanLambdaLegendre >, OnVarSet< Filter< ATruthVarSet::Object > >, OnVarSet< Filter< AVarSet::Object > >, OnVarSet< BaseFacetFilter >, OnVarSet< BaseFacetRelationFilter >, OnVarSet< BaseAxialSegmentPairFilter >, OnVarSet< BaseSegmentRelationFilter >, OnVarSet< BaseTrackRelationFilter >, OnVarSet< BaseSegmentPairRelationFilter >, MCSymmetric< BaseAxialSegmentPairFilter >, MCSymmetric< BaseFacetFilter >, MCSymmetric< BaseFacetRelationFilter >, MCSymmetric< BaseSegmentPairFilter >, MCSymmetric< BaseSegmentPairRelationFilter >, MCSymmetric< BaseSegmentRelationFilter >, MCSymmetric< BaseSegmentTripleFilter >, MCSymmetric< BaseSegmentTripleRelationFilter >, MCSymmetric< BaseTrackRelationFilter >, StoreArrayLoader< const Belle2::SpacePoint >, StoreArrayLoader< DataStoreInputTypeRefType >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCFacet >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCWireHit, true >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegment2D >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCTrack >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentPair >, StoreVectorSwapper< Belle2::TrackFindingCDC::CDCSegmentTriple >, RelationVarSet< ABaseVarSet >, QualityIndicatorFilter, TwoHitVirtualIPQIFilter, MultiHoughSpaceFastInterceptFinder, RawTrackCandCleaner< AHit >, RawTrackCandCleaner< Belle2::vxdHoughTracking::VXDHoughState >, RecoTrackStorer, ROIFinder, SingleHoughSpaceFastInterceptFinder, SpacePointLoaderAndPreparer, TrackCandidateOverlapResolver, and TrackCandidateResultRefiner.

Definition at line 15 of file CompositeProcessingSignalListener.cc.

16{
19 psl->initialize();
20 }
21}
virtual void initialize()
Receive signal before the start of the event processing.

◆ terminate()

void terminate ( )
overridevirtualinherited

Receive and dispatch Signal for termination of the event processing.

Reimplemented from ProcessingSignalListener.

Reimplemented in StereoHitTrackQuadTreeMatcher< Belle2::TrackFindingCDC::HyperHough >, StereoHitTrackQuadTreeMatcher< Belle2::TrackFindingCDC::QuadraticLegendre >, and StereoHitTrackQuadTreeMatcher< Belle2::TrackFindingCDC::Z0TanLambdaLegendre >.

Definition at line 47 of file CompositeProcessingSignalListener.cc.

48{
50 psl->terminate();
51 }
53}
virtual void terminate()
Receive Signal for termination of the event processing.

◆ traverseTree()

void traverseTree ( std::vector< const AState * > &  path,
const std::vector< WeightedRelation< AState > > &  stateRelations,
std::vector< AResult > &  results 
)
private

Implementation of the traverseTree function.

Definition at line 111 of file WeightedTreeTraversal.h.

115 {
116 // Implement only graph traversal logic and leave the extrapolation and selection to the
117 // rejecter.
118 const AState* currentState = path.back();
119 auto continuations =
120 std::equal_range(stateRelations.begin(), stateRelations.end(), currentState);
121
122 std::vector<WithWeight<AState*>> childStates;
123 for (const WeightedRelation<AState>& continuation : asRange(continuations)) {
124 AState* childState = continuation.getTo();
125 Weight weight = continuation.getWeight();
126 childStates.push_back({childState, weight});
127 }
128
129 // Do everything with child states, linking, extrapolation, teaching, discarding, what have
130 // you.
131 const std::vector<const AState*>& constPath = path;
132 m_stateRejecter.apply(constPath, childStates);
133
134 if (childStates.empty()) {
135 B2DEBUG(25, "Terminating this route, as there are no possible child states.");
136 results.emplace_back(path);
137 return;
138 }
139
140 // Traverse the tree from each new state on
141 B2DEBUG(25, "Having found " << childStates.size() << " child states.");
142 for (WithWeight<AState*> childState : childStates) {
143 if (std::count(path.begin(), path.end(), childState)) {
144 // Cycle detected -- is this the best handling?
145 // Other options: Raise and exception and bail out of this seed
146 continue;
147 }
148 path.push_back(childState);
149 traverseTree(path, stateRelations, results);
150 path.pop_back();
151 }
152 }

Member Data Documentation

◆ m_initialized

bool m_initialized = false
privateinherited

Flag to keep track whether initialization happend before.

Definition at line 52 of file ProcessingSignalListener.h.

◆ m_initializedAs

std::string m_initializedAs
privateinherited

Name of the type during initialisation.

Definition at line 58 of file ProcessingSignalListener.h.

◆ m_stateRejecter

AStateRejecter m_stateRejecter
private

State rejecter to decide which available continuations should be traversed next.

Definition at line 90 of file WeightedTreeTraversal.h.

◆ m_subordinaryProcessingSignalListeners

std::vector<ProcessingSignalListener*> m_subordinaryProcessingSignalListeners
privateinherited

References to subordinary signal processing listener contained in this findlet.

Definition at line 52 of file CompositeProcessingSignalListener.h.

◆ m_terminated

bool m_terminated = false
privateinherited

Flag to keep track whether termination happend before.

Definition at line 55 of file ProcessingSignalListener.h.


The documentation for this class was generated from the following file: