Logo ROOT   6.12/07
Reference Guide
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 
17 #include "TList.h"
18 
19 class TFolder;
20 class TMemFile;
21 class TBufferFile;
22 class TDataMember;
23 class THttpCallArg;
24 class TRootSnifferStore;
25 class TRootSniffer;
26 
28 
29  friend class TRootSniffer;
30 
31 protected:
32  // different bits used to scan hierarchy
33  enum {
34  kScan = 0x0001, ///< normal scan of hierarchy
35  kExpand = 0x0002, ///< expand of specified item - allowed to scan object members
36  kSearch = 0x0004, ///< search for specified item (only objects and collections)
37  kCheckChilds = 0x0008, ///< check if there childs, very similar to search
38  kOnlyFields = 0x0010, ///< if set, only fields for specified item will be set (but all fields)
39  kActions = 0x001F ///< mask for actions, only actions copied to child rec
40  };
41 
42  TRootSnifferScanRec *fParent; ///<! pointer on parent record
43  UInt_t fMask; ///<! defines operation kind
44  const char *fSearchPath; ///<! current path searched
45  Int_t fLevel; ///<! current level of hierarchy
46  TString fItemName; ///<! name of current item
47  TList fItemsNames; ///<! list of created items names, need to avoid duplication
48  Int_t fRestriction; ///<! restriction 0 - default, 1 - read-only, 2 - full access
49 
50  TRootSnifferStore *fStore; ///<! object to store results
51  Bool_t fHasMore; ///<! indicates that potentially there are more items can be found
52  Bool_t fNodeStarted; ///<! indicate if node was started
53  Int_t fNumFields; ///<! number of fields
54  Int_t fNumChilds; ///<! number of childs
55 
56 public:
58  virtual ~TRootSnifferScanRec();
59 
60  void CloseNode();
61 
62  /** return true when fields could be set to the hierarchy item */
63  Bool_t CanSetFields() const { return (fMask & kScan) && (fStore != 0); }
64 
65  /** return true when only fields are scanned by the sniffer */
66  Bool_t ScanOnlyFields() const { return (fMask & kOnlyFields) && (fMask & kScan); }
67 
68  /** Starts new node, must be closed at the end */
69  void CreateNode(const char *_node_name);
70 
71  void BeforeNextChild();
72 
73  /** Set item field only when creating is specified */
74  void SetField(const char *name, const char *value, Bool_t with_quotes = kTRUE);
75 
76  /** Mark item with ROOT class and correspondent streamer info */
77  void SetRootClass(TClass *cl);
78 
79  /** Returns true when item can be expanded */
81 
82  /** Checks if result will be accepted. Used to verify if sniffer should read object from the file */
83  Bool_t IsReadyForResult() const;
84 
85  /** Obsolete, use SetFoundResult instead */
86  Bool_t SetResult(void *obj, TClass *cl, TDataMember *member = 0);
87 
88  /** Set found element with class and datamember (optional) */
89  Bool_t SetFoundResult(void *obj, TClass *cl, TDataMember *member = 0);
90 
91  /** Returns depth of hierarchy */
92  Int_t Depth() const;
93 
94  /** Method indicates that scanning can be interrupted while result is set */
95  Bool_t Done() const;
96 
97  /** Construct item name, using object name as basis */
98  void MakeItemName(const char *objname, TString &itemname);
99 
100  /** Produces full name for the current item */
101  void BuildFullName(TString &buf, TRootSnifferScanRec *prnt = 0);
102 
103  /** Returns read-only flag for current item */
104  Bool_t IsReadOnly(Bool_t dflt = kTRUE);
105 
106  Bool_t GoInside(TRootSnifferScanRec &super, TObject *obj, const char *obj_name = 0, TRootSniffer *sniffer = 0);
107 
108  ClassDef(TRootSnifferScanRec, 0) // Scan record for objects sniffer
109 };
110 
111 //_______________________________________________________________________
112 
113 class TRootSniffer : public TNamed {
114  enum {
115  kItemField = BIT(21) // item property stored as TNamed
116  };
117 
118 protected:
119  TString fObjectsPath; ///<! default path for registered objects
120  TMemFile *fMemFile; ///<! file used to manage streamer infos
121  TList *fSinfo; ///<! last produced streamer info
122  Bool_t fReadOnly; ///<! indicate if sniffer allowed to change ROOT structures - for instance, read objects from files
123  Bool_t fScanGlobalDir; ///<! when enabled (default), scan gROOT for histograms, canvases, open files
124  THttpCallArg *fCurrentArg; ///<! current http arguments (if any)
125  Int_t fCurrentRestrict; ///<! current restriction for last-found object
126  TString fCurrentAllowedMethods; ///<! list of allowed methods, extracted when analyzed object restrictions
127  TList fRestrictions; ///<! list of restrictions for different locations
128  TString fAutoLoad; ///<! scripts names, which are add as _autoload parameter to h.json request
129 
130  void ScanObjectMembers(TRootSnifferScanRec &rec, TClass *cl, char *ptr);
131 
132  virtual void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj);
133 
134  virtual void ScanObjectChilds(TRootSnifferScanRec &rec, TObject *obj);
135 
136  void ScanCollection(TRootSnifferScanRec &rec, TCollection *lst, const char *foldername = 0,
137  TCollection *keys_lst = 0);
138 
139  /** Method is used to scan ROOT objects.
140  * Can be reimplemented to extend scanning */
141  virtual void ScanRoot(TRootSnifferScanRec &rec);
142 
143  void CreateMemFile();
144 
145  TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes = kTRUE);
146 
147  TObject *GetItem(const char *fullname, TFolder *&parent, Bool_t force = kFALSE, Bool_t within_objects = kTRUE);
148 
149  TFolder *GetSubFolder(const char *foldername, Bool_t force = kFALSE);
150 
151  const char *GetItemField(TFolder *parent, TObject *item, const char *name);
152 
153  Bool_t IsItemField(TObject *obj) const;
154 
155  Bool_t AccessField(TFolder *parent, TObject *item, const char *name, const char *value, TNamed **only_get = 0);
156 
157  Int_t WithCurrentUserName(const char *option);
158 
159 public:
160  TRootSniffer(const char *name, const char *objpath = "Objects");
161  virtual ~TRootSniffer();
162 
163  static Bool_t IsDrawableClass(TClass *cl);
164 
165  /** When readonly on (default), sniffer is not allowed to change ROOT structures
166  * For instance, it is not allowed to read new objects from files */
167  void SetReadOnly(Bool_t on = kTRUE) { fReadOnly = on; }
168 
169  /** Returns readonly mode */
170  Bool_t IsReadOnly() const { return fReadOnly; }
171 
172  void Restrict(const char *path, const char *options);
173 
174  Bool_t HasRestriction(const char *item_name);
175 
176  Int_t CheckRestriction(const char *item_name);
177 
178  /** When enabled (default), sniffer scans gROOT for files, canvases, histograms */
179  void SetScanGlobalDir(Bool_t on = kTRUE) { fScanGlobalDir = on; }
180 
181  void SetAutoLoad(const char *scripts = "");
182 
183  const char *GetAutoLoad() const;
184 
185  /** Returns true when sniffer allowed to scan global directories */
186  Bool_t IsScanGlobalDir() const { return fScanGlobalDir; }
187 
188  Bool_t RegisterObject(const char *subfolder, TObject *obj);
189 
190  Bool_t UnregisterObject(TObject *obj);
191 
192  Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon);
193 
194  Bool_t CreateItem(const char *fullname, const char *title);
195 
196  Bool_t SetItemField(const char *fullname, const char *name, const char *value);
197 
198  const char *GetItemField(const char *fullname, const char *name);
199 
200  void SetCurrentCallArg(THttpCallArg *arg);
201 
202  /** Method scans normal objects, registered in ROOT */
203  void ScanHierarchy(const char *topname, const char *path, TRootSnifferStore *store, Bool_t only_fields = kFALSE);
204 
205  TObject *FindTObjectInHierarchy(const char *path);
206 
207  virtual void *FindInHierarchy(const char *path, TClass **cl = 0, TDataMember **member = 0, Int_t *chld = 0);
208 
209  Bool_t CanDrawItem(const char *path);
210 
211  Bool_t CanExploreItem(const char *path);
212 
213  Bool_t IsStreamerInfoItem(const char *itemname);
214 
215  ULong_t GetStreamerInfoHash();
216 
217  ULong_t GetItemHash(const char *itemname);
218 
219  Bool_t ProduceJson(const char *path, const char *options, TString &res);
220 
221  Bool_t ProduceXml(const char *path, const char *options, TString &res);
222 
223  Bool_t ProduceBinary(const char *path, const char *options, void *&ptr, Long_t &length);
224 
225  Bool_t ProduceImage(Int_t kind, const char *path, const char *options, void *&ptr, Long_t &length);
226 
227  Bool_t ProduceExe(const char *path, const char *options, Int_t reskind, TString *ret_str, void **ret_ptr = 0,
228  Long_t *ret_length = 0);
229 
230  Bool_t ExecuteCmd(const char *path, const char *options, TString &res);
231 
232  Bool_t ProduceItem(const char *path, const char *options, TString &res, Bool_t asjson = kTRUE);
233 
234  Bool_t ProduceMulti(const char *path, const char *options, void *&ptr, Long_t &length, TString &str,
235  Bool_t asjson = kTRUE);
236 
237  Bool_t Produce(const char *path, const char *file, const char *options, void *&ptr, Long_t &length, TString &str);
238 
239  ClassDef(TRootSniffer, 0) // Sniffer of ROOT objects
240 };
241 
242 #endif
TString fItemName
! name of current item
Definition: TRootSniffer.h:46
Bool_t SetResult(void *obj, TClass *cl, TDataMember *member=0)
Obsolete, use SetFoundResult instead.
A TFolder object is a collection of objects and folders.
Definition: TFolder.h:30
Bool_t fScanGlobalDir
! when enabled (default), scan gROOT for histograms, canvases, open files
Definition: TRootSniffer.h:123
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket...
Definition: TBufferFile.h:47
if set, only fields for specified item will be set (but all fields)
Definition: TRootSniffer.h:38
UInt_t fMask
! defines operation kind
Definition: TRootSniffer.h:43
Bool_t IsReadOnly() const
Returns readonly mode.
Definition: TRootSniffer.h:170
void BeforeNextChild()
indicates that new child for current element will be started
Bool_t IsReadyForResult() const
Checks if result will be accepted.
TMemFile * fMemFile
! file used to manage streamer infos
Definition: TRootSniffer.h:120
All ROOT classes may have RTTI (run time type identification) support added.
Definition: TDataMember.h:31
#define BIT(n)
Definition: Rtypes.h:78
Bool_t GoInside(TRootSnifferScanRec &super, TObject *obj, const char *obj_name=0, TRootSniffer *sniffer=0)
Method verifies if new level of hierarchy should be started with provided object. ...
Basic string class.
Definition: TString.h:125
Bool_t SetFoundResult(void *obj, TClass *cl, TDataMember *member=0)
Set found element with class and datamember (optional)
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
search for specified item (only objects and collections)
Definition: TRootSniffer.h:36
Int_t fRestriction
! restriction 0 - default, 1 - read-only, 2 - full access
Definition: TRootSniffer.h:48
Abstract interface for storage of hierarchy scan in TRootSniffer.
TString fCurrentAllowedMethods
! list of allowed methods, extracted when analyzed object restrictions
Definition: TRootSniffer.h:126
void CloseNode()
close started node
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition: TMemFile.h:17
Bool_t CanExpandItem()
Returns true when item can be expanded.
Bool_t IsReadOnly(Bool_t dflt=kTRUE)
Returns read-only flag for current item.
#define ClassDef(name, id)
Definition: Rtypes.h:320
THttpCallArg * fCurrentArg
! current http arguments (if any)
Definition: TRootSniffer.h:124
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Bool_t fReadOnly
! indicate if sniffer allowed to change ROOT structures - for instance, read objects from files ...
Definition: TRootSniffer.h:122
Bool_t ScanOnlyFields() const
return true when only fields are scanned by the sniffer
Definition: TRootSniffer.h:66
const char * fSearchPath
! current path searched
Definition: TRootSniffer.h:44
check if there childs, very similar to search
Definition: TRootSniffer.h:37
void SetRootClass(TClass *cl)
Mark item with ROOT class and correspondent streamer info.
Int_t fNumChilds
! number of childs
Definition: TRootSniffer.h:54
A doubly linked list.
Definition: TList.h:44
Int_t fLevel
! current level of hierarchy
Definition: TRootSniffer.h:45
Collection abstract base class.
Definition: TCollection.h:63
unsigned int UInt_t
Definition: RtypesCore.h:42
TString fObjectsPath
! default path for registered objects
Definition: TRootSniffer.h:119
Int_t fNumFields
! number of fields
Definition: TRootSniffer.h:53
mask for actions, only actions copied to child rec
Definition: TRootSniffer.h:39
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:75
RooCmdArg Restrict(const char *catName, const char *stateNameList)
virtual ~TRootSnifferScanRec()
destructor
TString fAutoLoad
! scripts names, which are add as _autoload parameter to h.json request
Definition: TRootSniffer.h:128
TRootSnifferScanRec()
constructor
const Bool_t kFALSE
Definition: RtypesCore.h:88
long Long_t
Definition: RtypesCore.h:50
TList fItemsNames
! list of created items names, need to avoid duplication
Definition: TRootSniffer.h:47
TRootSnifferStore * fStore
! object to store results
Definition: TRootSniffer.h:50
unsigned long ULong_t
Definition: RtypesCore.h:51
normal scan of hierarchy
Definition: TRootSniffer.h:34
TList * fSinfo
! last produced streamer info
Definition: TRootSniffer.h:121
TRootSnifferScanRec * fParent
! pointer on parent record
Definition: TRootSniffer.h:42
Bool_t Done() const
Method indicates that scanning can be interrupted while result is set.
Mother of all ROOT objects.
Definition: TObject.h:37
Int_t Depth() const
Returns depth of hierarchy.
void SetField(const char *name, const char *value, Bool_t with_quotes=kTRUE)
Set item field only when creating is specified.
void SetReadOnly(Bool_t on=kTRUE)
When readonly on (default), sniffer is not allowed to change ROOT structures For instance, it is not allowed to read new objects from files.
Definition: TRootSniffer.h:167
friend class TRootSniffer
Definition: TRootSniffer.h:29
Definition: file.py:1
Bool_t CanSetFields() const
return true when fields could be set to the hierarchy item
Definition: TRootSniffer.h:63
Bool_t fHasMore
! indicates that potentially there are more items can be found
Definition: TRootSniffer.h:51
Bool_t fNodeStarted
! indicate if node was started
Definition: TRootSniffer.h:52
void MakeItemName(const char *objname, TString &itemname)
Construct item name, using object name as basis.
const Bool_t kTRUE
Definition: RtypesCore.h:87
expand of specified item - allowed to scan object members
Definition: TRootSniffer.h:35
void SetScanGlobalDir(Bool_t on=kTRUE)
When enabled (default), sniffer scans gROOT for files, canvases, histograms.
Definition: TRootSniffer.h:179
void BuildFullName(TString &buf, TRootSnifferScanRec *prnt=0)
Produces full name for the current item.
Int_t fCurrentRestrict
! current restriction for last-found object
Definition: TRootSniffer.h:125
Bool_t IsScanGlobalDir() const
Returns true when sniffer allowed to scan global directories.
Definition: TRootSniffer.h:186
char name[80]
Definition: TGX11.cxx:109
void CreateNode(const char *_node_name)
Starts new node, must be closed at the end.
TList fRestrictions
! list of restrictions for different locations
Definition: TRootSniffer.h:127