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 void
140 ScanCollection(TRootSnifferScanRec &rec, TCollection *lst, const char *foldername = nullptr, TCollection *keys_lst = nullptr);
141
142 virtual void ScanRoot(TRootSnifferScanRec &rec);
143
144 TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes = kTRUE);
145
146 TObject *GetItem(const char *fullname, TFolder *&parent, Bool_t force = kFALSE, Bool_t within_objects = kTRUE);
147
148 TFolder *GetSubFolder(const char *foldername, Bool_t force = kFALSE);
149
150 const char *GetItemField(TFolder *parent, TObject *item, const char *name);
151
152 Bool_t IsItemField(TObject *obj) const;
153
154 Bool_t AccessField(TFolder *parent, TObject *item, const char *name, const char *value, TNamed **only_get = nullptr);
155
156 Int_t WithCurrentUserName(const char *option);
157
158 virtual Bool_t CanDrawClass(TClass *) { return kFALSE; }
159
160 virtual Bool_t HasStreamerInfo() const { return kFALSE; }
161
162 virtual Bool_t ProduceJson(const std::string &path, const std::string &options, std::string &res);
163
164 virtual Bool_t ProduceXml(const std::string &path, const std::string &options, std::string &res);
165
166 virtual Bool_t ProduceBinary(const std::string &path, const std::string &options, std::string &res);
167
168 virtual Bool_t ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res);
169
170 virtual Bool_t ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res);
171
172 virtual Bool_t ExecuteCmd(const std::string &path, const std::string &options, std::string &res);
173
174 virtual Bool_t
175 ProduceItem(const std::string &path, const std::string &options, std::string &res, Bool_t asjson = kTRUE);
176
177 virtual Bool_t
178 ProduceMulti(const std::string &path, const std::string &options, std::string &res, Bool_t asjson = kTRUE);
179
180public:
181 TRootSniffer(const char *name, const char *objpath = "Objects");
182 virtual ~TRootSniffer();
183
184 /** When readonly on (default), sniffer is not allowed to change ROOT structures
185 * For instance, it is not allowed to read new objects from files */
186 void SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; }
187
188 /** Returns readonly mode */
189 Bool_t IsReadOnly() const { return fReadOnly; }
190
191 void Restrict(const char *path, const char *options);
192
193 Bool_t HasRestriction(const char *item_name);
194
195 Int_t CheckRestriction(const char *item_name);
196
197 void CreateOwnTopFolder();
198
200
201 /** When enabled (default), sniffer scans gROOT for files, canvases, histograms */
203
204 void SetAutoLoad(const char *scripts = "");
205
206 const char *GetAutoLoad() const;
207
208 /** Returns true when sniffer allowed to scan global directories */
210
211 Bool_t RegisterObject(const char *subfolder, TObject *obj);
212
214
215 Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon);
216
217 Bool_t CreateItem(const char *fullname, const char *title);
218
219 Bool_t SetItemField(const char *fullname, const char *name, const char *value);
220
221 const char *GetItemField(const char *fullname, const char *name);
222
224
225 /** Method scans normal objects, registered in ROOT */
226 void ScanHierarchy(const char *topname, const char *path, TRootSnifferStore *store, Bool_t only_fields = kFALSE);
227
228 TObject *FindTObjectInHierarchy(const char *path);
229
230 virtual void *
231 FindInHierarchy(const char *path, TClass **cl = nullptr, TDataMember **member = nullptr, Int_t *chld = nullptr);
232
233 Bool_t CanDrawItem(const char *path);
234
235 Bool_t CanExploreItem(const char *path);
236
237 virtual Bool_t IsStreamerInfoItem(const char *) { return kFALSE; }
238
239 virtual ULong_t GetStreamerInfoHash() { return 0; }
240
241 virtual ULong_t GetItemHash(const char *itemname);
242
243 Bool_t Produce(const std::string &path, const std::string &file, const std::string &options, std::string &res);
244
245 ClassDefOverride(TRootSniffer, 0) // Sniffer of ROOT objects (basic version)
246};
247
248#endif
int Int_t
Definition RtypesCore.h:45
const Bool_t kFALSE
Definition RtypesCore.h:101
unsigned long ULong_t
Definition RtypesCore.h:55
bool Bool_t
Definition RtypesCore.h:63
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:325
#define BIT(n)
Definition Rtypes.h:85
#define ClassDefOverride(name, id)
Definition Rtypes.h:329
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:80
Collection abstract base class.
Definition TCollection.h:65
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
A TFolder object is a collection of objects and folders.
Definition TFolder.h:30
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
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
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
@ 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
Abstract interface for storage of hierarchy scan in TRootSniffer.
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.
void SetCurrentCallArg(THttpCallArg *arg)
set current http arguments, which then used in different process methods For instance,...
TList fRestrictions
! list of restrictions for different locations
Bool_t RegisterObject(const char *subfolder, TObject *obj)
Register object in subfolder structure subfolder parameter can have many levels like:
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 folder itself will remain even when it will be emp...
virtual void ScanKeyProperties(TRootSnifferScanRec &rec, TKey *key, TObject *&obj, TClass *&obj_class)
scans key 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 Parameter 'path' specifies object or object membe...
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 Options include method and extra list of parameters sniffer shou...
virtual Bool_t ProduceXml(const std::string &path, const std::string &options, std::string &res)
Produce XML data for specified item For object conversion TBufferXML is used.
TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes=kTRUE)
method replaces all kind of special symbols, which could appear in URL options
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 contrary to h.json request, only fields for specified item are st...
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.
Bool_t IsItemField(TObject *obj) const
return true when object is TNamed with kItemField bit set such objects used to keep field values for ...
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 if "zipped" option specified in query, buffer will be compress...
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 each field coded as TNamed object, placed after chld in the parent hie...
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 Input parameters should be c...
Bool_t CanDrawItem(const char *path)
Method verifies if object can be drawn.
Basic string class.
Definition TString.h:136
Definition file.py:1