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