33using namespace std::string_literals;
70 fCleanupHandle = std::make_unique<RBrowserDataCleanup>(*
this);
72 gROOT->GetListOfCleanups()->Add(fCleanupHandle.get());
82 gROOT->GetListOfCleanups()->Remove(fCleanupHandle.get());
102 ResetLastRequestData(
true);
110 auto comp = std::make_shared<Browsable::RGroup>(
"top",
"Root browser");
114 std::unique_ptr<Browsable::RHolder>
rootfold = std::make_unique<Browsable::TObjectHolder>(
gROOT->GetRootFolder(),
kFALSE);
117 comp->Add(std::make_shared<Browsable::RWrapper>(
"root",
elem_root));
119 std::unique_ptr<Browsable::RHolder>
rootfiles = std::make_unique<Browsable::TObjectHolder>(
gROOT->GetListOfFiles(),
kFALSE);
122 auto files = std::make_shared<Browsable::RWrapper>(
"ROOT Files",
elem_files);
123 files->SetExpandByDefault(
true);
140 fLastAllChilds =
false;
141 fLastSortedItems.clear();
142 fLastSortMethod.clear();
146 fLastElement.reset();
173 auto path = fWorkingPath;
174 path.insert(path.end(), request.
path.begin(), request.
path.end());
176 if ((path != fLastPath) || !fLastElement) {
178 auto elem = GetSubElement(path);
179 if (!
elem)
return false;
181 ResetLastRequestData(
true);
184 fLastElement = std::move(
elem);
187 }
else if (request.
reload) {
189 ResetLastRequestData(
false);
193 if (fLastItems.empty()) {
195 auto iter = fLastElement->GetChildsIter();
197 if (!iter)
return false;
199 fLastAllChilds =
true;
201 while (iter->Next() && fLastAllChilds) {
202 fLastItems.emplace_back(iter->CreateItem());
204 fLastAllChilds =
false;
207 fLastSortedItems.clear();
208 fLastSortMethod.clear();
212 if ((fLastSortedItems.size() != fLastItems.size()) ||
213 (fLastSortMethod != request.
sort) ||
214 (fLastSortReverse != request.
reverse)) {
215 fLastSortedItems.resize(fLastItems.size(),
nullptr);
217 if (request.
sort.empty() || (request.
sort ==
"none")) {
219 for (
auto &
item : fLastItems)
220 if (
item->IsFolder())
221 fLastSortedItems[
id++] =
item.get();
222 for (
auto &
item : fLastItems)
223 if (!
item->IsFolder())
224 fLastSortedItems[
id++] =
item.get();
227 for (
auto &
item : fLastItems)
228 fLastSortedItems[
id++] =
item.get();
230 if (request.
sort !=
"unsorted")
231 std::sort(fLastSortedItems.begin(), fLastSortedItems.end(),
236 std::reverse(fLastSortedItems.begin(), fLastSortedItems.end());
238 fLastSortMethod = request.
sort;
239 fLastSortReverse = request.
reverse;
245 for (
auto &
item : fLastSortedItems) {
251 if (!request.
regex.empty() && !
item->IsFolder() && !std::regex_match(
item->GetName(),
expr))
277 ProcessBrowserRequest(request,
reply);
287 auto path = DecomposePath(str,
true);
289 return GetSubElement(path);
297 return GetSubElement(path);
309 RemoveFromCache(
nullptr);
312 for (
auto &
entry : fCache)
313 if (
entry.first == path)
318 auto elem = fTopElement;
320 for (
auto &
entry : fCache) {
321 if (
entry.first.size() >= path.size())
332 while (pos < (
int) path.size()) {
333 std::string
subname = path[pos];
336 auto iter =
elem->GetChildsIter();
343 iter =
elem->GetChildsIter();
344 if (!iter || !iter->Find(
subname))
348 elem = iter->GetElement();
381 while (pos < fCache.size()) {
382 if (obj ? !fCache[pos].second->IsObject(obj) : fCache[pos].second->CheckValid()) {
388 auto path = fCache[pos].first;
389 fCache.erase(fCache.begin() + pos);
390 if (RemoveFromCache(path))
403 if (path.size() == 0)
408 while (pos < fCache.size()) {
410 fCache.erase(fCache.begin() + pos);
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
R__EXTERN TVirtualMutex * gROOTMutex
#define R__LOCKGUARD(mutex)
static int ExtractItemIndex(std::string &name)
Extract index from name Index coded by client with ###<indx>$$$ suffix Such coding used by browser to...
static int ComparePaths(const RElementPath_t &path1, const RElementPath_t &path2)
Compare two paths, Returns number of elements matches in both paths.
static RElementPath_t ParsePath(const std::string &str)
Parse string path to produce RElementPath_t One should avoid to use string pathes as much as possible...
Representation of single item in the browser.
static std::shared_ptr< RElement > Browse(std::unique_ptr< RHolder > &obj)
Create browsable element for the object Created element may take ownership over the object.
static RElementPath_t ProvideTopEntries(std::shared_ptr< RGroup > &comp, const std::string &workdir="")
Provide top entries for file system On windows it is list of existing drivers, on Linux it is "File s...
RBrowserDataCleanup(RBrowserData &_data)
void RecursiveRemove(TObject *obj) override
Recursively remove this object from a list.
Way to browse (hopefully) everything in ROOT.
void SetTopElement(std::shared_ptr< Browsable::RElement > elem)
set top element for browsing
bool RemoveFromCache(void *obj)
Remove object from cache If nullptr specified - removes no-longer-valid elements Returns true if any ...
std::shared_ptr< Browsable::RElement > GetSubElement(const Browsable::RElementPath_t &path)
Returns sub-element starting from top, using cached data.
Browsable::RElementPath_t DecomposePath(const std::string &path, bool relative_to_work_element)
Decompose path to elements Returns array of names for each element in the path, first element either ...
virtual ~RBrowserData()
Destructor.
bool ProcessBrowserRequest(const RBrowserRequest &request, RBrowserReply &reply)
Process browser request.
std::shared_ptr< Browsable::RElement > GetElementFromTop(const Browsable::RElementPath_t &path)
Returns element with path, specified as Browsable::RElementPath_t.
void ClearCache()
Clear internal objects cache.
std::string ProcessRequest(const RBrowserRequest &request)
Process browser request, returns string with JSON of RBrowserReply data.
void SetWorkingPath(const Browsable::RElementPath_t &path)
set working directory relative to top element
std::shared_ptr< Browsable::RElement > GetElement(const std::string &str)
Returns element with path, specified as string.
void ResetLastRequestData(bool with_element)
Reset all data correspondent to last request.
void CreateDefaultElements()
Create default elements shown in the RBrowser.
RBrowserData()
Default constructor.
Reply on browser request.
Request send from client to get content of path element.
bool hidden
show hidden files
int number
number of childs to request, 0 - all childs
bool reverse
reverse item order
std::string sort
kind of sorting
std::vector< std::string > path
requested path
bool reload
force items reload
int first
first child to request
std::string regex
applied regex
A log configuration for a channel, e.g.
const_iterator begin() const
const_iterator end() const
static TString ToJSON(const T *obj, Int_t compact=0, const char *member_name=nullptr)
@ kSkipTypeInfo
do not store typenames in JSON
@ kNoSpaces
no new lines plus remove all spaces around "," and ":" symbols
Mother of all ROOT objects.
std::vector< std::string > RElementPath_t
ROOT::RLogChannel & BrowserLog()
Log channel for Browser diagnostics.