Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRootSniffer.h
Go to the documentation of this file.
1// $Id$
2// Author: Sergey Linev 22/12/2013
3
4/*************************************************************************
5 * Copyright (C) 1995-2013, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TRootSniffer
13#define ROOT_TRootSniffer
14
15#include "TNamed.h"
16#include "TList.h"
17#include <memory>
18#include <string>
19
20class TFolder;
21class TKey;
22class TBufferFile;
23class TDataMember;
24class THttpCallArg;
26class TRootSniffer;
27
29
30 friend class TRootSniffer;
31
32protected:
33 // different bits used to scan hierarchy
34 enum {
35 kScan = 0x0001, ///< normal scan of hierarchy
36 kExpand = 0x0002, ///< expand of specified item - allowed to scan object members
37 kSearch = 0x0004, ///< search for specified item (only objects and collections)
38 kCheckChilds = 0x0008, ///< check if there childs, very similar to search
39 kOnlyFields = 0x0010, ///< if set, only fields for specified item will be set (but all fields)
40 kActions = 0x001F ///< mask for actions, only actions copied to child rec
41 };
42
43 TRootSnifferScanRec *fParent{nullptr}; ///<! pointer on parent record
44 UInt_t fMask{0}; ///<! defines operation kind
45 const char *fSearchPath{nullptr}; ///<! current path searched
46 Int_t fLevel{0}; ///<! current level of hierarchy
47 TString fItemName; ///<! name of current item
48 TList fItemsNames; ///<! list of created items names, need to avoid duplication
49 Int_t fRestriction{0}; ///<! restriction 0 - default, 1 - read-only, 2 - full access
50
51 TRootSnifferStore *fStore{nullptr}; ///<! object to store results
52 Bool_t fHasMore{kFALSE}; ///<! indicates that potentially there are more items can be found
53 Bool_t fNodeStarted{kFALSE}; ///<! indicate if node was started
54 Int_t fNumFields{0}; ///<! number of fields
55 Int_t fNumChilds{0}; ///<! number of childs
56
57public:
59 virtual ~TRootSnifferScanRec();
60
61 void CloseNode();
62
63 /** return true when fields could be set to the hierarchy item */
64 Bool_t CanSetFields() const { return (fMask & kScan) && (fStore != nullptr); }
65
66 /** return true when only fields are scanned by the sniffer */
67 Bool_t ScanOnlyFields() const { return (fMask & kOnlyFields) && (fMask & kScan); }
68
69 /** Starts new node, must be closed at the end */
70 void CreateNode(const char *_node_name);
71
72 void BeforeNextChild();
73
74 /** Set item field only when creating is specified */
75 void SetField(const char *name, const char *value, Bool_t with_quotes = kTRUE);
76
77 /** Mark item with ROOT class and correspondent streamer info */
78 void SetRootClass(TClass *cl);
79
80 /** Returns true when item can be expanded */
82
83 /** Checks if result will be accepted. Used to verify if sniffer should read object from the file */
85
86 /** Obsolete, use SetFoundResult instead */
87 Bool_t SetResult(void *obj, TClass *cl, TDataMember *member = nullptr);
88
89 /** Set found element with class and datamember (optional) */
90 Bool_t SetFoundResult(void *obj, TClass *cl, TDataMember *member = nullptr);
91
92 /** Returns depth of hierarchy */
93 Int_t Depth() const;
94
95 /** Method indicates that scanning can be interrupted while result is set */
96 Bool_t Done() const;
97
98 /** Construct item name, using object name as basis */
99 void MakeItemName(const char *objname, TString &itemname);
100
101 /** Produces full name for the current item */
102 void BuildFullName(TString &buf, TRootSnifferScanRec *prnt = nullptr);
103
104 /** Returns read-only flag for current item */
106
107 Bool_t GoInside(TRootSnifferScanRec &super, TObject *obj, const char *obj_name = nullptr,
108 TRootSniffer *sniffer = nullptr);
109
110 ClassDef(TRootSnifferScanRec, 0) // Scan record for objects sniffer
111};
112
113//_______________________________________________________________________
114
115class TRootSniffer : public TNamed {
116 enum {
117 kItemField = BIT(21) // item property stored as TNamed
118 };
119
120protected:
121 TString fObjectsPath; ///<! default path for registered objects
122 Bool_t fReadOnly{kTRUE}; ///<! indicate if sniffer allowed to change ROOT structures - like read objects from file
123 Bool_t fScanGlobalDir{kTRUE}; ///<! when enabled (default), scan gROOT for histograms, canvases, open files
124 std::unique_ptr<TFolder> fTopFolder; ///<! own top TFolder object, used for registering objects
125 THttpCallArg *fCurrentArg{nullptr}; ///<! current http arguments (if any)
126 Int_t fCurrentRestrict{0}; ///<! current restriction for last-found object
127 TString fCurrentAllowedMethods; ///<! list of allowed methods, extracted when analyzed object restrictions
128 TList fRestrictions; ///<! list of restrictions for different locations
129 TString fAutoLoad; ///<! scripts names, which are add as _autoload parameter to h.json request
130
131 void ScanObjectMembers(TRootSnifferScanRec &rec, TClass *cl, char *ptr);
132
133 virtual void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj);
134
135 virtual void ScanKeyProperties(TRootSnifferScanRec &rec, TKey *key, TObject *&obj, TClass *&obj_class);
136
137 virtual void ScanObjectChilds(TRootSnifferScanRec &rec, TObject *obj);
138
139 virtual Bool_t CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res);
140
141 void
142 ScanCollection(TRootSnifferScanRec &rec, TCollection *lst, const char *foldername = nullptr, TCollection *keys_lst = nullptr);
143
144 virtual void ScanRoot(TRootSnifferScanRec &rec);
145
146 TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes = kTRUE);
147
148 TObject *GetItem(const char *fullname, TFolder *&parent, Bool_t force = kFALSE, Bool_t within_objects = kTRUE);
149
150 TFolder *GetSubFolder(const char *foldername, Bool_t force = kFALSE);
151
152 const char *GetItemField(TFolder *parent, TObject *item, const char *name);
153
154 Bool_t IsItemField(TObject *obj) const;
155
156 Bool_t AccessField(TFolder *parent, TObject *item, const char *name, const char *value, TNamed **only_get = nullptr);
157
158 Int_t WithCurrentUserName(const char *option);
159
160 virtual Bool_t CanDrawClass(TClass *) { return kFALSE; }
161
162 virtual Bool_t HasStreamerInfo() const { return kFALSE; }
163
164 virtual Bool_t ProduceJson(const std::string &path, const std::string &options, std::string &res);
165
166 virtual Bool_t ProduceXml(const std::string &path, const std::string &options, std::string &res);
167
168 virtual Bool_t ProduceBinary(const std::string &path, const std::string &options, std::string &res);
169
170 virtual Bool_t ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res);
171
172 virtual Bool_t ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res);
173
174 virtual Bool_t ExecuteCmd(const std::string &path, const std::string &options, std::string &res);
175
176 virtual Bool_t
177 ProduceItem(const std::string &path, const std::string &options, std::string &res, Bool_t asjson = kTRUE);
178
179 virtual Bool_t
180 ProduceMulti(const std::string &path, const std::string &options, std::string &res, Bool_t asjson = kTRUE);
181
182public:
183 TRootSniffer(const char *name, const char *objpath = "Objects");
184 virtual ~TRootSniffer();
185
186 /** When readonly on (default), sniffer is not allowed to change ROOT structures
187 * For instance, it is not allowed to read new objects from files */
189
190 /** Returns readonly mode */
191 Bool_t IsReadOnly() const { return fReadOnly; }
192
193 void Restrict(const char *path, const char *options);
194
195 Bool_t HasRestriction(const char *item_name);
196
197 Int_t CheckRestriction(const char *item_name);
198
199 void CreateOwnTopFolder();
200
202
203 /** When enabled (default), sniffer scans gROOT for files, canvases, histograms */
205
206 void SetAutoLoad(const char *scripts = "");
207
208 const char *GetAutoLoad() const;
209
210 /** Returns true when sniffer allowed to scan global directories */
212
213 Bool_t RegisterObject(const char *subfolder, TObject *obj);
214
216
217 Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon);
218
219 Bool_t CreateItem(const char *fullname, const char *title);
220
221 Bool_t SetItemField(const char *fullname, const char *name, const char *value);
222
223 const char *GetItemField(const char *fullname, const char *name);
224
226
227 /** Method scans normal objects, registered in ROOT */
228 void ScanHierarchy(const char *topname, const char *path, TRootSnifferStore *store, Bool_t only_fields = kFALSE);
229
230 TObject *FindTObjectInHierarchy(const char *path);
231
232 virtual void *
233 FindInHierarchy(const char *path, TClass **cl = nullptr, TDataMember **member = nullptr, Int_t *chld = nullptr);
234
235 Bool_t CanDrawItem(const char *path);
236
237 Bool_t CanExploreItem(const char *path);
238
239 virtual Bool_t IsStreamerInfoItem(const char *) { return kFALSE; }
240
241 virtual ULong_t GetStreamerInfoHash() { return 0; }
242
243 virtual ULong_t GetItemHash(const char *itemname);
244
245 Bool_t Produce(const std::string &path, const std::string &file, const std::string &options, std::string &res);
246
247 ClassDefOverride(TRootSniffer, 0) // Sniffer of ROOT objects (basic version)
248};
249
250#endif
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
unsigned long ULong_t
Definition RtypesCore.h:55
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:337
#define BIT(n)
Definition Rtypes.h:85
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
Collection abstract base class.
Definition TCollection.h:65
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
<div class="legacybox"><h2>Legacy Code</h2> TFolder is a legacy interface: there will be no bug fixes...
Definition TFolder.h:30
Contains arguments for single HTTP call.
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
A doubly linked list.
Definition TList.h:38
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
Structure used to scan hierarchies of ROOT objects.
TString fItemName
! name of current item
Int_t fLevel
! current level of hierarchy
Int_t fRestriction
! restriction 0 - default, 1 - read-only, 2 - full access
Bool_t CanExpandItem()
Returns true when item can be expanded.
TRootSnifferStore * fStore
! object to store results
@ kSearch
search for specified item (only objects and collections)
@ kOnlyFields
if set, only fields for specified item will be set (but all fields)
@ kExpand
expand of specified item - allowed to scan object members
@ kCheckChilds
check if there childs, very similar to search
@ kScan
normal scan of hierarchy
@ kActions
mask for actions, only actions copied to child rec
virtual ~TRootSnifferScanRec()
destructor
void SetField(const char *name, const char *value, Bool_t with_quotes=kTRUE)
Set item field only when creating is specified.
void CloseNode()
Close started node.
Bool_t CanSetFields() const
return true when fields could be set to the hierarchy item
UInt_t fMask
! defines operation kind
void MakeItemName(const char *objname, TString &itemname)
Construct item name, using object name as basis.
Bool_t IsReadyForResult() const
Checks if result will be accepted.
Bool_t SetResult(void *obj, TClass *cl, TDataMember *member=nullptr)
Obsolete, use SetFoundResult instead.
Bool_t fHasMore
! indicates that potentially there are more items can be found
Bool_t IsReadOnly(Bool_t dflt=kTRUE)
Returns read-only flag for current item.
Bool_t GoInside(TRootSnifferScanRec &super, TObject *obj, const char *obj_name=nullptr, TRootSniffer *sniffer=nullptr)
Method verifies if new level of hierarchy should be started with provided object.
void BeforeNextChild()
Indicates that new child for current element will be started.
TRootSnifferScanRec * fParent
! pointer on parent record
void SetRootClass(TClass *cl)
Mark item with ROOT class and correspondent streamer info.
void CreateNode(const char *_node_name)
Starts new node, must be closed at the end.
Int_t fNumChilds
! number of childs
Int_t fNumFields
! number of fields
Bool_t fNodeStarted
! indicate if node was started
Bool_t SetFoundResult(void *obj, TClass *cl, TDataMember *member=nullptr)
Set found element with class and datamember (optional)
const char * fSearchPath
! current path searched
Int_t Depth() const
Returns depth of hierarchy.
TList fItemsNames
! list of created items names, need to avoid duplication
Bool_t Done() const
Method indicates that scanning can be interrupted while result is set.
Bool_t ScanOnlyFields() const
return true when only fields are scanned by the sniffer
void BuildFullName(TString &buf, TRootSnifferScanRec *prnt=nullptr)
Produces full name for the current item.
TRootSnifferScanRec()
constructor
Abstract interface for storage of hierarchy scan in TRootSniffer.
Sniffer of ROOT objects, data provider for THttpServer.
void ScanObjectMembers(TRootSnifferScanRec &rec, TClass *cl, char *ptr)
scan object data members some members like enum or static members will be excluded
const char * GetAutoLoad() const
return name of configured autoload scripts (or 0)
TString fObjectsPath
! default path for registered objects
void ScanHierarchy(const char *topname, const char *path, TRootSnifferStore *store, Bool_t only_fields=kFALSE)
Method scans normal objects, registered in ROOT.
TList fRestrictions
! list of restrictions for different locations
Bool_t RegisterObject(const char *subfolder, TObject *obj)
Register object in subfolder structure.
virtual void ScanObjectChilds(TRootSnifferScanRec &rec, TObject *obj)
scans object childs (if any) here one scans collection, branches, trees and so on
TString fCurrentAllowedMethods
! list of allowed methods, extracted when analyzed object restrictions
virtual Bool_t HasStreamerInfo() const
Bool_t IsReadOnly() const
Returns readonly mode.
Bool_t UnregisterObject(TObject *obj)
Unregister (remove) object from folders structures.
virtual void ScanKeyProperties(TRootSnifferScanRec &rec, TKey *key, TObject *&obj, TClass *&obj_class)
Scans TKey properties in special cases load objects from the file.
Bool_t CreateItem(const char *fullname, const char *title)
Create item element.
virtual Bool_t ExecuteCmd(const std::string &path, const std::string &options, std::string &res)
Execute command marked as _kind=='Command'.
Bool_t HasRestriction(const char *item_name)
Made fast check if item with specified name is in restriction list If returns true,...
virtual void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj)
Scans object properties here such fields as _autoload or _icon properties depending on class or objec...
virtual void ScanRoot(TRootSnifferScanRec &rec)
scan complete ROOT objects hierarchy For the moment it includes objects in gROOT directory and list o...
virtual Bool_t IsStreamerInfoItem(const char *)
Bool_t Produce(const std::string &path, const std::string &file, const std::string &options, std::string &res)
Method produce different kind of data out of object.
virtual Bool_t ProduceJson(const std::string &path, const std::string &options, std::string &res)
Produce JSON data for specified item For object conversion TBufferJSON is used.
void CreateOwnTopFolder()
Create own TFolder structures independent from gROOT This allows to have many independent TRootSniffe...
virtual Bool_t ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res)
Execute command for specified object.
virtual Bool_t ProduceXml(const std::string &path, const std::string &options, std::string &res)
Produce XML data for specified item.
TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes=kTRUE)
Method replaces all kind of special symbols, which could appear in URL options.
THttpCallArg * SetCurrentCallArg(THttpCallArg *arg)
set current http arguments, which then used in different process methods For instance,...
Bool_t fScanGlobalDir
! when enabled (default), scan gROOT for histograms, canvases, open files
void Restrict(const char *path, const char *options)
Restrict access to the specified location.
void SetReadOnly(Bool_t on=kTRUE)
When readonly on (default), sniffer is not allowed to change ROOT structures For instance,...
virtual ULong_t GetItemHash(const char *itemname)
Get hash function for specified item used to detect any changes in the specified object.
Bool_t fReadOnly
! indicate if sniffer allowed to change ROOT structures - like read objects from file
void SetScanGlobalDir(Bool_t on=kTRUE)
When enabled (default), sniffer scans gROOT for files, canvases, histograms.
TObject * GetItem(const char *fullname, TFolder *&parent, Bool_t force=kFALSE, Bool_t within_objects=kTRUE)
Return item from the subfolders structure.
THttpCallArg * fCurrentArg
! current http arguments (if any)
virtual Bool_t ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res)
Method to produce image from specified object.
TObject * FindTObjectInHierarchy(const char *path)
Search element in hierarchy, derived from TObject.
void SetAutoLoad(const char *scripts="")
When specified, _autoload attribute will be always add to top element of h.json/h....
virtual void * FindInHierarchy(const char *path, TClass **cl=nullptr, TDataMember **member=nullptr, Int_t *chld=nullptr)
Search element with specified path Returns pointer on element Optionally one could obtain element cla...
virtual Bool_t ProduceItem(const std::string &path, const std::string &options, std::string &res, Bool_t asjson=kTRUE)
Produce JSON/XML for specified item.
Int_t CheckRestriction(const char *item_name)
Checked if restriction is applied to the item full_item_name should have full path to the item.
virtual Bool_t CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res)
Invokes TRootSniffer::ProduceIamge, converting kind into TImage::EImageFileTypes type.
Bool_t IsItemField(TObject *obj) const
Return true when object is TNamed with kItemField bit set.
virtual ~TRootSniffer()
destructor
virtual Bool_t CanDrawClass(TClass *)
Int_t fCurrentRestrict
! current restriction for last-found object
TFolder * GetTopFolder(Bool_t force=kFALSE)
Returns top TFolder instance for the sniffer.
const char * GetItemField(TFolder *parent, TObject *item, const char *name)
Return field for specified item.
virtual ULong_t GetStreamerInfoHash()
std::unique_ptr< TFolder > fTopFolder
! own top TFolder object, used for registering objects
Bool_t CanExploreItem(const char *path)
Method returns true when object has childs or one could try to expand item.
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
Set field for specified item.
Int_t WithCurrentUserName(const char *option)
return 2 when option match to current user name return 1 when option==all return 0 when option does n...
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon)
Register command which can be executed from web interface.
TString fAutoLoad
! scripts names, which are add as _autoload parameter to h.json request
Bool_t IsScanGlobalDir() const
Returns true when sniffer allowed to scan global directories.
virtual Bool_t ProduceBinary(const std::string &path, const std::string &options, std::string &res)
Produce binary data for specified item.
TFolder * GetSubFolder(const char *foldername, Bool_t force=kFALSE)
Creates subfolder where objects can be registered.
void ScanCollection(TRootSnifferScanRec &rec, TCollection *lst, const char *foldername=nullptr, TCollection *keys_lst=nullptr)
Scan collection content.
Bool_t AccessField(TFolder *parent, TObject *item, const char *name, const char *value, TNamed **only_get=nullptr)
Set or get field for the child.
virtual Bool_t ProduceMulti(const std::string &path, const std::string &options, std::string &res, Bool_t asjson=kTRUE)
Process several requests, packing all results into binary or JSON buffer.
Bool_t CanDrawItem(const char *path)
Method verifies if object can be drawn.
Basic string class.
Definition TString.h:139
Definition file.py:1