Belle II Software development
InfoWidget::URI Struct Reference

a parsed URI. More...

Public Member Functions

 URI (const TString &uri)
 Construct URI by parsing given string.
 

Static Public Member Functions

static TString getURI (const TObject *obj)
 get URI string to given object.
 

Public Attributes

const TObject * object = nullptr
 object referenced (or NULL).
 
TString scheme = ""
 scheme name (part before first colon).
 
TString entryName = ""
 name of DataStore entry.
 
int arrayIndex = -1
 index in array, only valid if arrayName and object are filled.
 

Detailed Description

a parsed URI.

allowed URI formats are

durability:[entryName[/arrayIndex]] (durability: event/persistent) raw:addressOfTObject (for objects not in DataStore) main: (the main page)

Definition at line 63 of file InfoWidget.h.

Constructor & Destructor Documentation

◆ URI() [1/2]

URI ( )
inline

Definition at line 64 of file InfoWidget.h.

64{}

◆ URI() [2/2]

URI ( const TString &  uri)
explicit

Construct URI by parsing given string.

Definition at line 340 of file InfoWidget.cc.

341{
342 //split uri into schema:path (no double slash: only path after scheme)
343 Ssiz_t protStart = uri.First(":");
344 Ssiz_t protEnd = protStart + 1;
345 if (protStart >= uri.Length())
346 B2FATAL("URI has invalid format: " << uri);
347 scheme = uri(0, protStart);
348 TString path = uri(protEnd, uri.Length() - 1);
349
350 if (scheme == "raw") {
351 //interpret path as pointer
352 object = reinterpret_cast<TObject*>(path.Atoll());
353 } else if (path.Length() > 0 and path != "/") {
354 //event/persistent
355 DataStore::EDurability durability = getDurability(scheme);
356
357 Ssiz_t delim = path.Last('/');
358 Ssiz_t idxFieldLength = path.Length() - delim - 1;
359 if (delim >= path.Length())
360 B2FATAL("URI has invalid format: " << path);
361 //ok, set entryName
362 entryName = path(0, delim);
363 if (idxFieldLength > 0) {
364 //array index found
365 arrayIndex = TString(path(delim + 1, idxFieldLength)).Atoi();
366 const StoreArray<TObject> arr(entryName.Data(), durability);
367 if (arrayIndex < arr.getEntries())
368 object = arr[arrayIndex];
369 }
370 const auto& entries = DataStore::Instance().getStoreEntryMap(durability);
371 const auto& it = entries.find(entryName.Data());
372 if (it == entries.end()) {
373 B2ERROR("Given entry '" << entryName << "' not found in DataStore, invalid URI?");
374 } else if (!it->second.isArray) {
375 //also set object for StoreObjPtr
376 object = it->second.object;
377 }
378 }
379}
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
Definition: DataStore.h:325
EDurability
Durability types.
Definition: DataStore.h:58
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
TString scheme
scheme name (part before first colon).
Definition: InfoWidget.h:72
int arrayIndex
index in array, only valid if arrayName and object are filled.
Definition: InfoWidget.h:74
TString entryName
name of DataStore entry.
Definition: InfoWidget.h:73

Member Function Documentation

◆ getURI()

TString getURI ( const TObject *  obj)
static

get URI string to given object.

Definition at line 272 of file InfoWidget.cc.

273{
274 auto pos = ObjectInfo::getDataStorePosition(obj);
275 if (pos.first.empty()) {
276 B2DEBUG(100, "No DataStore entry found for " << obj->GetName() << ", using raw pointer.");
277 return TString::Format("raw:%lu", (long)obj);
278 }
279 return TString::Format("event:%s/%d", pos.first.c_str(), pos.second);
280}
std::pair< std::string, int > getDataStorePosition(const TObject *obj)
return entry name & index for arrays, with index = -1 for objects.
Definition: ObjectInfo.cc:78

Member Data Documentation

◆ arrayIndex

int arrayIndex = -1

index in array, only valid if arrayName and object are filled.

Definition at line 74 of file InfoWidget.h.

◆ entryName

TString entryName = ""

name of DataStore entry.

Definition at line 73 of file InfoWidget.h.

◆ object

const TObject* object = nullptr

object referenced (or NULL).

Definition at line 71 of file InfoWidget.h.

◆ scheme

TString scheme = ""

scheme name (part before first colon).

Definition at line 72 of file InfoWidget.h.


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