Belle II Software development
InfoWidget Class Reference

text-based info viewer showing DataStore contents. More...

#include <InfoWidget.h>

Inheritance diagram for InfoWidget:

Classes

struct  URI
 a parsed URI. More...
 

Public Member Functions

 InfoWidget (const TGWindow *p)
 ctor.
 
void update ()
 reset for new event (try to show same object if it exists).
 
void show (const char *uri="main:", bool clearSelection=true)
 Navigate to given URI.
 
void show (const TObject *obj)
 Navigate to page belonging to given object.
 
void back ()
 navigate to previous page, clearing current page from history.
 
virtual int IsVisited (const char *uri) override
 Used to colour visited links.
 

Private Member Functions

TString createMainPage () const
 create DataStore overview.
 
TString createArrayPage (const URI &uri) const
 create list of array contents.
 
TString createObjectPage (const URI &uri) const
 create object info.
 
TString getHeader (const URI &uri=URI()) const
 returns string with title, breadcrumbs, menu.
 
 ClassDefOverride (InfoWidget, 0)
 text-based info viewer showing DataStore contents.
 

Static Private Member Functions

static TString getContents (const TObject *obj)
 Get object contents (member data).
 
static TString getRelatedInfo (const TObject *obj)
 return HTML-formatted list of related objects.
 

Private Attributes

std::set< TString > m_visited
 list of all pages viewed in current event.
 
std::vector< TString > m_history
 ordered list of all pages viewed in current event.
 

Detailed Description

text-based info viewer showing DataStore contents.

Definition at line 27 of file InfoWidget.h.

Constructor & Destructor Documentation

◆ InfoWidget()

InfoWidget ( const TGWindow *  p)
explicit

ctor.

Definition at line 34 of file InfoWidget.cc.

34 :
35 TGHtml(p, 400, 600, -1)
36{
37 this->Connect("MouseDown(const char*)", "Belle2::InfoWidget", this, "show(const char*)");
38
39 //magic to prevent the frame being empty.
40 MapSubwindows();
41 Resize();
42 MapWindow();
43}

◆ ~InfoWidget()

~InfoWidget ( )

Definition at line 45 of file InfoWidget.cc.

46{
47}

Member Function Documentation

◆ back()

void back ( )

navigate to previous page, clearing current page from history.

Definition at line 79 of file InfoWidget.cc.

80{
81 m_history.pop_back(); //drop current page
82 const TString lastURI = m_history.back();
83 m_history.pop_back(); //we'll go there promptly and re-add it
84
85 show(lastURI);
86}
void show(const char *uri="main:", bool clearSelection=true)
Navigate to given URI.
Definition: InfoWidget.cc:93
std::vector< TString > m_history
ordered list of all pages viewed in current event.
Definition: InfoWidget.h:95

◆ createArrayPage()

TString createArrayPage ( const URI uri) const
private

create list of array contents.

Definition at line 179 of file InfoWidget.cc.

180{
181 const StoreArray<TObject> array(uri.entryName.Data(), getDurability(uri.scheme));
182 TString info = getHeader(uri);
183 if (array.getEntries() != 0) {
184 info += HtmlClassInspector::getClassInfo(array[0]->IsA());
185 }
186
187 for (int i = 0; i < array.getEntries(); i++) {
188 TString name = ObjectInfo::getName(array[i]);
189 if (name != "")
190 name = " - " + name;
191 info += TString::Format("<a href='%s:%s/%d'>%s[%d]%s</a><br>",
192 uri.scheme.Data(), uri.entryName.Data(), i,
193 uri.entryName.Data(), i, name.Data());
194 }
195 return info;
196}
static TString getClassInfo(const TClass *obj)
Get class name + description from comment after ClassDef().
TString getHeader(const URI &uri=URI()) const
returns string with title, breadcrumbs, menu.
Definition: InfoWidget.cc:207
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
TString getName(const TObject *obj)
human-readable name (e.g.
Definition: ObjectInfo.cc:45

◆ createMainPage()

TString createMainPage ( ) const
private

create DataStore overview.

Definition at line 127 of file InfoWidget.cc.

128{
129 TString info = getHeader();
130
131 const char* schemes[] = {"event", "persistent"};
133 const char* durabilyNames[] = {"c_Event", "c_Persistent"};
134
135 for (int i = 0; i < 2; i++) {
136 const TString scheme = schemes[i];
137 auto arrayNames = DataStore::Instance().getListOfArrays(TObject::Class(), durabilities[i]);
138 if (!arrayNames.empty()) {
139 info += "<h2>Arrays";
140 if (i > 0) {
141 info += " (<tt>";
142 info += durabilyNames[i];
143 info += "</tt>)";
144 }
145 info += "</h2>";
146 }
147 for (std::string name : arrayNames) {
148 const StoreArray<TObject> array(name, durabilities[i]);
149 int nEntries = array.getEntries();
150 if (nEntries)
151 info += TString::Format("<a href='%s:%s/'>%s (%d)</a><br>", scheme.Data(), name.c_str(), name.c_str(), nEntries);
152 else
153 info += TString::Format("%s (%d)<br>", name.c_str(), nEntries);
154 }
155
156 auto objNames = DataStore::Instance().getListOfObjects(TObject::Class(), durabilities[i]);
157 if (!objNames.empty()) {
158 info += "<h2>Objects";
159 if (i > 0) {
160 info += " (<tt>";
161 info += durabilyNames[i];
162 info += "</tt>)";
163 }
164 info += "</h2>";
165 }
166 for (std::string name : objNames) {
167 const StoreObjPtr<TObject> obj(name, durabilities[i]);
168 if (obj)
169 info += TString::Format("<a href='%s:%s/'>%s</a><br>", scheme.Data(), name.c_str(), name.c_str());
170 else
171 info += TString::Format("%s<br>", name.c_str());
172 }
173 if (i == 0)
174 info += "<hr>";
175 }
176 return info;
177}
std::vector< std::string > getListOfArrays(const TClass *arrayClass, EDurability durability) const
Returns a list of names of arrays which are of type (or inherit from) arrayClass.
Definition: DataStore.cc:666
std::vector< std::string > getListOfObjects(const TClass *objClass, EDurability durability) const
Returns a list of names of StoreObjPtr-objects whose class is (or inherits from) objClass.
Definition: DataStore.cc:671
EDurability
Durability types.
Definition: DataStore.h:58
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96

◆ createObjectPage()

TString createObjectPage ( const URI uri) const
private

create object info.

Definition at line 198 of file InfoWidget.cc.

199{
200 TString info = getHeader(uri);
201 info += ObjectInfo::getInfo(uri.object);
202 info += getRelatedInfo(uri.object);
203 info += getContents(uri.object);
204
205 return info;
206}
static TString getRelatedInfo(const TObject *obj)
return HTML-formatted list of related objects.
Definition: InfoWidget.cc:282
static TString getContents(const TObject *obj)
Get object contents (member data).
Definition: InfoWidget.cc:329
TString getInfo(const TObject *obj)
Get object info HTML (e.g.
Definition: ObjectInfo.cc:55

◆ getContents()

TString getContents ( const TObject *  obj)
staticprivate

Get object contents (member data).

Definition at line 329 of file InfoWidget.cc.

330{
331 TString info;
332
333 info += "<h4>Object Details</h4>";
334 info += HtmlClassInspector::getClassInfo(obj->IsA());
336
337 return info;
338}
static TString getMemberData(const TObject *obj)
Return table with member data contents.

◆ getHeader()

TString getHeader ( const URI uri = URI()) const
private

returns string with title, breadcrumbs, menu.

Definition at line 207 of file InfoWidget.cc.

208{
209 int numEntries = -1;
210 if (uri.entryName.Length() != 0 and (!uri.object or uri.arrayIndex != -1)) {
211 const StoreArray<TObject> array(uri.entryName.Data(), getDurability(uri.scheme));
212 numEntries = array.getEntries();
213 }
214
215 TString col;
216 if (uri.object and VisualRepMap::getInstance()->isVisualized(uri.object))
217 col = "#d2ede4"; //needs to be lighter than purple/blue used for links
218 else
219 col = TangoPalette::getHex("Aluminium", 1);
220 TString info;
221 info += "<table border=0 width=100% bgcolor=" + col + "><tr>";
222 //breadcrumbs
223 info += "<td>";
224 info += "<a href='main:'>DataStore</a> / ";
225 if (uri.arrayIndex != -1) {
226 info += "<a href='" + uri.scheme + ":" + uri.entryName + "/'>" + uri.entryName + "</a>";
227 info += TString::Format("<b>[%d]</b>", uri.arrayIndex);
228 } else {
229 info += "<b>" + uri.entryName + "</b>";
230 }
231 info += "</td>";
232
233 //back button
234 if (m_history.size() <= 1) //current page is part of history, so we need at least two
235 info += "<td align=right>Back</td>";
236 else
237 info += "<td align=right><a href='back:'>Back</a></td>";
238
239
240 info += "</tr></table>";
241
242 //short header for DataStore overview
243 if (uri.entryName == "")
244 return info;
245
246 //title
247 if (uri.object) {
248 TString name = ObjectInfo::getName(uri.object);
249 if (name != "")
250 name = " - " + name;
251 info += "<h2>" + ObjectInfo::getIdentifier(uri.object) + name + "</h2>";
252 } else {
253 info += TString::Format("<h2>%s (%d)</h2>", uri.entryName.Data(), numEntries);
254 }
255
256
257 if (uri.arrayIndex != -1) { //this is an array
258 if (uri.arrayIndex == 0)
259 info += "Previous";
260 else
261 info += "<a href='" + uri.scheme + ":" + TString::Format("%s/%d", uri.entryName.Data(), uri.arrayIndex - 1) + "'>Previous</a>";
262 info += " ";
263 if (uri.arrayIndex == numEntries - 1)
264 info += "Next";
265 else
266 info += "<a href='" + uri.scheme + ":" + TString::Format("%s/%d", uri.entryName.Data(), uri.arrayIndex + 1) + "'>Next</a>";
267 info += "<br> <br>";
268 }
269
270 return info;
271}
static VisualRepMap * getInstance()
get instance pointer.
Definition: VisualRepMap.cc:36
bool isVisualized(const TObject *obj)
Does obj have a visualization?
Definition: VisualRepMap.h:62
TString getIdentifier(const TObject *obj)
Where is this object in the datastore?
Definition: ObjectInfo.cc:105
const char * getHex(const std::string &tangoName, int tangoId=1)
Get six-digit hex code (#abcdef) for given name in tango colour palette.
Definition: ColorPalette.cc:18

◆ getRelatedInfo()

TString getRelatedInfo ( const TObject *  obj)
staticprivate

return HTML-formatted list of related objects.

Definition at line 282 of file InfoWidget.cc.

283{
284 TString info;
285 info += "<h4>Related Objects</h4>";
286
287 StoreEntry* storeEntry = nullptr;
288 int index = -1;
289 {
290 //relations from this
291 const RelationVector<TObject> relatedObjects(DataStore::Instance().getRelationsWith(DataStore::c_ToSide, obj, storeEntry, index,
292 TObject::Class(), "ALL", ""));
293 const TString pref = "this <b>-&gt;</b> ";
294 for (size_t i = 0; i < relatedObjects.size(); i++) {
295 const TObject* relObj = relatedObjects.object(i);
296 double weight = relatedObjects.weight(i);
297 TString name = ObjectInfo::getName(relObj);
298 if (name != "")
299 name = " - " + name;
300 info += pref + "<a href='" + URI::getURI(relObj) + "'>" + ObjectInfo::getIdentifier(relObj) + name + "</a>";
301 if (weight != 1.0)
302 info += TString::Format(" (weight: %.3g)", weight);
303 info += "<br>";
304 }
305 }
306
307 info += " <br>"; //extra space needed!
308 {
309 //relations to this
310 const RelationVector<TObject> relatedObjects(DataStore::Instance().getRelationsWith(DataStore::c_FromSide, obj, storeEntry, index,
311 TObject::Class(), "ALL", ""));
312
313 const TString pref = "this <b>&lt;-</b> ";
314 for (size_t i = 0; i < relatedObjects.size(); i++) {
315 const TObject* relObj = relatedObjects.object(i);
316 double weight = relatedObjects.weight(i);
317 TString name = ObjectInfo::getName(relObj);
318 if (name != "")
319 name = " - " + name;
320 info += pref + "<a href='" + URI::getURI(relObj) + "'>" + ObjectInfo::getIdentifier(relObj) + name + "</a>";
321 if (weight != 1.0)
322 info += TString::Format(" (weight: %.3g)", weight);
323 info += "<br>";
324 }
325 }
326 return info;
327}
@ c_FromSide
Return relations/objects pointed from (to a given object).
Definition: DataStore.h:77
@ c_ToSide
Return relations/objects pointed to (from a given object).
Definition: DataStore.h:78
Class for type safe access to objects that are referred to in relations.
static TString getURI(const TObject *obj)
get URI string to given object.
Definition: InfoWidget.cc:272
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: StoreEntry.h:22

◆ IsVisited()

int IsVisited ( const char *  uri)
overridevirtual

Used to colour visited links.

Definition at line 49 of file InfoWidget.cc.

50{
51 //not actually sure why return type is 'int'...
52 return (bool)m_visited.count(uri);
53}
std::set< TString > m_visited
list of all pages viewed in current event.
Definition: InfoWidget.h:93

◆ show() [1/2]

void show ( const char *  uri = "main:",
bool  clearSelection = true 
)

Navigate to given URI.

Parameters
uriwhat to show, see InfoWidget::URI
clearSelectionwhen showing an object, this determines wether to clear an existing selection

Definition at line 93 of file InfoWidget.cc.

94{
95 B2DEBUG(100, "Navigating to: " << uri);
96
97 if (std::string(uri) == "back:") {
98 back();
99 return;
100 }
101
102 m_visited.insert(uri);
103 m_history.push_back(uri);
104
105 URI parsedURI = URI(uri);
106 TString info;
107 if (parsedURI.object) {
108 info = createObjectPage(parsedURI);
109
110 //highlight in display
111 if (clearSelection)
113 VisualRepMap::getInstance()->select(parsedURI.object);
114 } else if (parsedURI.entryName != "") {
115 info = createArrayPage(parsedURI);
116 } else {
117 info = createMainPage();
118 }
119 info = "<html><body>" + info + "</body></html>";
120
121 Clear();
122 //string only passed to function taking const char*...
123 ParseText(const_cast<char*>(info.Data()));
124 Layout();
125}
void back()
navigate to previous page, clearing current page from history.
Definition: InfoWidget.cc:79
TString createObjectPage(const URI &uri) const
create object info.
Definition: InfoWidget.cc:198
TString createArrayPage(const URI &uri) const
create list of array contents.
Definition: InfoWidget.cc:179
TString createMainPage() const
create DataStore overview.
Definition: InfoWidget.cc:127
void clearSelection() const
Clear existing selection in Eve Browser.
void select(const TObject *object) const
Select the representation of the given object.
Definition: VisualRepMap.cc:87

◆ show() [2/2]

void show ( const TObject *  obj)

Navigate to page belonging to given object.

Special in that it doesn't clear the current selection.

Definition at line 88 of file InfoWidget.cc.

89{
90 show(URI::getURI(obj).Data(), false);
91}

◆ update()

void update ( )

reset for new event (try to show same object if it exists).

Definition at line 55 of file InfoWidget.cc.

56{
57 TString lastURI = "";
58 if (!m_history.empty()) {
59 lastURI = m_history.back();
60 }
61 m_visited.clear();
62 m_history.clear();
63
64 //check if the object given by lastURI exists in the new event, too.
65 //array pages are ok, too
66 if (lastURI != "") {
67 URI parsedURI(lastURI);
68 if (!parsedURI.object and !lastURI.EndsWith("/")) {
69 //doesn't exist, go to main page
70 lastURI = "";
71 }
72 }
73
74 if (lastURI == "")
75 lastURI = "main:";
76 show(lastURI);
77}

Member Data Documentation

◆ m_history

std::vector<TString> m_history
private

ordered list of all pages viewed in current event.

Definition at line 95 of file InfoWidget.h.

◆ m_visited

std::set<TString> m_visited
private

list of all pages viewed in current event.

Definition at line 93 of file InfoWidget.h.


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