Belle II Software development
VisualRepMap Class Reference

defines a bidirectional (many to many) mapping between TObjects in DataStore and their visual representation. More...

#include <VisualRepMap.h>

Classes

class  DataStoreEveElementMap
 Hide implementation in private class. More...
 

Public Member Functions

void select (const TObject *object) const
 Select the representation of the given object.
 
void selectOnly (const TEveElement *eveObj) const
 Deselect all other objects.
 
void selectRelated (TEveElement *eveObj) const
 Select related objects.
 
void clearSelection () const
 Clear existing selection in Eve Browser.
 
bool isCurrentlySelecting () const
 are we currently in a select() call?
 
const TObject * getDataStoreObject (TEveElement *elem) const
 Get object represented by given visual representation.
 
TEveElement * getEveElement (const TObject *obj) const
 Get (first) visual representation of given object.
 
bool isVisualized (const TObject *obj)
 Does obj have a visualization?
 
void clear ()
 Remove all contents in map.
 
void add (const TObject *dataStoreObject, TEveElement *visualRepresentation)
 Generic function to keep track of which objects have which visual representation.
 
void addCluster (const TObject *dataStoreObject, TEveCaloData *caloData, int towerID)
 Selection inside TEveCalo* is complicated, use this to keep track of ECL clusters.
 

Static Public Member Functions

static VisualRepMapgetInstance ()
 get instance pointer.
 

Private Member Functions

 VisualRepMap ()
 default constructor
 
 VisualRepMap (const VisualRepMap &)=delete
 no copy ctor
 
VisualRepMapoperator= (const VisualRepMap &)=delete
 no assignment
 
 ~VisualRepMap ()
 destructor
 

Private Attributes

bool m_currentlySelecting
 are we currently in a select() call?
 
DataStoreEveElementMapm_dataStoreEveElementMap
 Map DataStore contents in current event with their visual representation.
 
std::vector< EveTower * > m_eclTowers
 individual ECL towers (getting them out of TEve is hard).
 

Detailed Description

defines a bidirectional (many to many) mapping between TObjects in DataStore and their visual representation.

This is used to allow retrieving the original objects for a given TEveElement (to show additional info), and vice versa.

Definition at line 28 of file VisualRepMap.h.

Constructor & Destructor Documentation

◆ VisualRepMap()

VisualRepMap ( )
private

default constructor

Definition at line 42 of file VisualRepMap.cc.

42: m_currentlySelecting(false), m_dataStoreEveElementMap(new DataStoreEveElementMap) { }
bool m_currentlySelecting
are we currently in a select() call?
Definition: VisualRepMap.h:90
DataStoreEveElementMap * m_dataStoreEveElementMap
Map DataStore contents in current event with their visual representation.
Definition: VisualRepMap.h:93

◆ ~VisualRepMap()

~VisualRepMap ( )
private

destructor

Definition at line 44 of file VisualRepMap.cc.

void clear()
Remove all contents in map.
Definition: VisualRepMap.cc:46

Member Function Documentation

◆ add()

void add ( const TObject *  dataStoreObject,
TEveElement *  visualRepresentation 
)

Generic function to keep track of which objects have which visual representation.

Should be called by functions adding TEveElements to the event scene (Hits are currently excluded).

Does not take ownership of given objects, just stores mapping between pointers.

Definition at line 134 of file VisualRepMap.cc.

135{
136 if (!dataStoreObject) {
137 B2ERROR("Trying to insert NULL for object represented by " << visualRepresentation->GetElementName());
138 return;
139 }
140 auto ret = m_dataStoreEveElementMap->insert(DataStoreEveElementMap::value_type(dataStoreObject, visualRepresentation));
141 if (!ret.second) {
142 B2DEBUG(100, "Failed to insert object represented by " << visualRepresentation->GetElementName() << "! Duplicate?");
143 }
144}

◆ addCluster()

void addCluster ( const TObject *  dataStoreObject,
TEveCaloData *  caloData,
int  towerID 
)

Selection inside TEveCalo* is complicated, use this to keep track of ECL clusters.

Definition at line 146 of file VisualRepMap.cc.

147{
148 EveTower* tower = new EveTower(caloData, towerID);
149 tower->IncDenyDestroy(); //otherwise the selection wants to own this.
150 m_eclTowers.push_back(tower);
151
152 add(dataStoreObject, tower);
153}
handles selection of individual ECLClusters (getting them out of TEve is hard).
Definition: EveTower.h:20
std::vector< EveTower * > m_eclTowers
individual ECL towers (getting them out of TEve is hard).
Definition: VisualRepMap.h:96
void add(const TObject *dataStoreObject, TEveElement *visualRepresentation)
Generic function to keep track of which objects have which visual representation.

◆ clear()

void clear ( )

Remove all contents in map.

(call this after each event)

Definition at line 46 of file VisualRepMap.cc.

47{
49
50 for (EveTower* t : m_eclTowers)
51 delete t;
52 m_eclTowers.clear();
53}

◆ clearSelection()

void clearSelection ( ) const

Clear existing selection in Eve Browser.

Definition at line 127 of file VisualRepMap.cc.

128{
129 if (!gEve)
130 return;
131 //equivalent to clicking into empty space
132 gEve->GetSelection()->UserPickedElement(nullptr);
133}

◆ getDataStoreObject()

const TObject * getDataStoreObject ( TEveElement *  elem) const

Get object represented by given visual representation.

(elem is pretty much const, but boost refuses to search for it then. )

Definition at line 56 of file VisualRepMap.cc.

57{
58 //special handling for TEveCaloData
59 if (TEveCaloData* caloData = dynamic_cast<TEveCaloData*>(elem)) {
60 const auto& selectedCells = caloData->GetCellsSelected();
61 if (selectedCells.empty())
62 return nullptr;
63 int id = selectedCells[0].fTower;
64 for (EveTower* eveTower : m_eclTowers) {
65 if (eveTower->getID() == id) {
66 elem = eveTower;
67 break;
68 }
69 }
70 }
71
72 const auto& it = m_dataStoreEveElementMap->right.find(elem);
73 if (it != m_dataStoreEveElementMap->right.end())
74 return it->second;
75 return nullptr;
76}

◆ getEveElement()

TEveElement * getEveElement ( const TObject *  obj) const

Get (first) visual representation of given object.

Definition at line 78 of file VisualRepMap.cc.

79{
80 const auto& it = m_dataStoreEveElementMap->left.find(obj);
81 if (it != m_dataStoreEveElementMap->left.end())
82 return it->second;
83 return nullptr;
84}

◆ getInstance()

VisualRepMap * getInstance ( )
static

get instance pointer.

Definition at line 36 of file VisualRepMap.cc.

37{
38 static VisualRepMap instance;
39 return &instance;
40}
defines a bidirectional (many to many) mapping between TObjects in DataStore and their visual represe...
Definition: VisualRepMap.h:28

◆ isCurrentlySelecting()

bool isCurrentlySelecting ( ) const
inline

are we currently in a select() call?

Call this in your selection handler and abort if true. (otherwise we end up recursively calling ourselves).

Definition at line 50 of file VisualRepMap.h.

50{ return m_currentlySelecting; }

◆ isVisualized()

bool isVisualized ( const TObject *  obj)
inline

Does obj have a visualization?

Definition at line 62 of file VisualRepMap.h.

62{ return getEveElement(obj) != nullptr; }
TEveElement * getEveElement(const TObject *obj) const
Get (first) visual representation of given object.
Definition: VisualRepMap.cc:78

◆ select()

void select ( const TObject *  object) const

Select the representation of the given object.

Definition at line 87 of file VisualRepMap.cc.

88{
90 B2FATAL("recursive select() call detected. Please check isCurrentlySelecting().");
92 auto range = m_dataStoreEveElementMap->left.equal_range(object);
93 for (auto it = range.first; it != range.second; ++it) {
94 TEveElement* elem = it->second;
95 if (elem and !gEve->GetSelection()->HasChild(elem)) {
96 //select this object in addition to existing selection
97 gEve->GetSelection()->UserPickedElement(elem, true);
98 }
99 }
100 m_currentlySelecting = false;
101}

◆ selectOnly()

void selectOnly ( const TEveElement *  eveObj) const

Deselect all other objects.

Definition at line 103 of file VisualRepMap.cc.

104{
105 //copy current selection, then deselect each element
106 const std::list<TEveElement*> sel(gEve->GetSelection()->BeginChildren(), gEve->GetSelection()->EndChildren());
107 for (TEveElement* el : sel) {
108 if (el == eveObj or el->IsA() == EveTower::Class())
109 continue;
110 gEve->GetSelection()->UserUnPickedElement(el);
111 }
112}

◆ selectRelated()

void selectRelated ( TEveElement *  eveObj) const

Select related objects.

Definition at line 114 of file VisualRepMap.cc.

115{
116 const TObject* representedObject = getDataStoreObject(eveObj);
117 if (representedObject) {
118 //representedObject->Dump();
119
120 const RelationVector<TObject>& relatedObjects = DataStore::getRelationsWithObj<TObject>(representedObject, "ALL");
121 for (const TObject& relObj : relatedObjects) {
122 select(&relObj);
123 }
124 }
125}
Class for type safe access to objects that are referred to in relations.
const TObject * getDataStoreObject(TEveElement *elem) const
Get object represented by given visual representation.
Definition: VisualRepMap.cc:56
void select(const TObject *object) const
Select the representation of the given object.
Definition: VisualRepMap.cc:87

Member Data Documentation

◆ m_currentlySelecting

bool m_currentlySelecting
mutableprivate

are we currently in a select() call?

Definition at line 90 of file VisualRepMap.h.

◆ m_dataStoreEveElementMap

DataStoreEveElementMap* m_dataStoreEveElementMap
private

Map DataStore contents in current event with their visual representation.

Definition at line 93 of file VisualRepMap.h.

◆ m_eclTowers

std::vector<EveTower*> m_eclTowers
private

individual ECL towers (getting them out of TEve is hard).

Definition at line 96 of file VisualRepMap.h.


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