Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TRootSnifferFull.cxx
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#include "TRootSnifferFull.h"
13
14#include "TH1.h"
15#include "TGraph.h"
16#include "TProfile.h"
17#include "TCanvas.h"
18#include "TFile.h"
19#include "TKey.h"
20#include "TList.h"
21#include "TMemFile.h"
22#include "TBufferFile.h"
23#include "TBufferJSON.h"
24#include "TBufferXML.h"
25#include "TROOT.h"
26#include "TFolder.h"
27#include "TTree.h"
28#include "TBranch.h"
29#include "TLeaf.h"
30#include "TClass.h"
31#include "TMethod.h"
32#include "TFunction.h"
33#include "TMethodArg.h"
34#include "TMethodCall.h"
35#include "TUrl.h"
36#include "TImage.h"
37#include "TVirtualMutex.h"
38#include "TRootSnifferStore.h"
39#include "THttpCallArg.h"
40
41#include <cstdlib>
42#include <cstring>
43
44/** \class TRootSnifferFull
45\ingroup http
46
47Extends TRootSniffer for many ROOT classes
48
49Provides access to different ROOT collections and containers
50like TTree, TCanvas, TFile, ...
51*/
52
54
55////////////////////////////////////////////////////////////////////////////////
56/// constructor
57
58TRootSnifferFull::TRootSnifferFull(const char *name, const char *objpath) : TRootSniffer(name, objpath)
59{
60}
61
62////////////////////////////////////////////////////////////////////////////////
63/// destructor
64
66{
67 delete fSinfo;
68
69 delete fMemFile;
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// return true if given class can be drawn in JSROOT
74
76{
77 if (!cl)
78 return kFALSE;
79 if (cl->InheritsFrom(TH1::Class()))
80 return kTRUE;
81 if (cl->InheritsFrom(TGraph::Class()))
82 return kTRUE;
84 return kTRUE;
86 return kTRUE;
87 return kFALSE;
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Scans object properties
92///
93/// here such fields as `_autoload` or `_icon` properties depending on class or object name could be assigned
94/// By default properties, coded in the Class title are scanned. Example:
95///
96/// ClassDef(UserClassName, 1) // class comments *SNIFF* _field1=value _field2="string value"
97///
98/// Here *SNIFF* mark is important. After it all expressions like field=value are parsed
99/// One could use double quotes to code string values with spaces.
100/// Fields separated from each other with spaces
101
103{
104 if (obj && obj->InheritsFrom(TLeaf::Class())) {
105 rec.SetField("_more", "false", kFALSE);
106 rec.SetField("_can_draw", "false", kFALSE);
107 rec.SetField("_player", "drawLeafPlayer");
108 rec.SetField("_module", "draw_tree");
109 return;
110 }
111
113}
114
115////////////////////////////////////////////////////////////////////////////////
116/// Scans TKey properties
117///
118/// in special cases load objects from the file
119
121{
122 if (strcmp(key->GetClassName(), "TDirectoryFile") == 0) {
123 TRootSniffer::ScanKeyProperties(rec, key, obj, obj_class);
124 } else {
125 obj_class = TClass::GetClass(key->GetClassName());
126 if (obj_class && obj_class->InheritsFrom(TTree::Class())) {
127 if (rec.CanExpandItem()) {
128 // it is requested to expand tree element - read it
129 obj = key->ReadObj();
130 if (obj)
131 obj_class = obj->IsA();
132 } else {
133 rec.SetField("_ttree", "true", kFALSE); // indicate ROOT TTree
134 rec.SetField("_player", "drawTreePlayerKey");
135 rec.SetField("_module", "draw_tree");
136 // rec.SetField("_more", "true", kFALSE); // one could allow to extend
137 }
138 }
139 }
140}
141
142////////////////////////////////////////////////////////////////////////////////
143/// Scans object childs (if any)
144///
145/// here one scans collection, branches, trees and so on
146
148{
149 if (obj->InheritsFrom(TTree::Class())) {
150 if (!rec.IsReadOnly(fReadOnly)) {
151 rec.SetField("_ttree", "true", kFALSE); // indicate ROOT TTree
152 rec.SetField("_player", "drawTreePlayer");
153 rec.SetField("_module", "draw_tree");
154 }
155 ScanCollection(rec, ((TTree *)obj)->GetListOfLeaves());
156 } else if (obj->InheritsFrom(TBranch::Class())) {
157 ScanCollection(rec, ((TBranch *)obj)->GetListOfLeaves());
158 } else {
160 }
161}
162
163////////////////////////////////////////////////////////////////////////////////
164/// Returns hash value for streamer infos
165///
166/// At the moment - just number of items in streamer infos list.
167
169{
170 return fSinfo ? fSinfo->GetSize() : 0;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Return true if it is streamer info item name
175
177{
178 if (!itemname || (*itemname == 0))
179 return kFALSE;
180
181 return (strcmp(itemname, "StreamerInfo") == 0) || (strcmp(itemname, "StreamerInfo/") == 0);
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Get hash function for specified item
186///
187/// Used to detect any changes in the specified object
188
190{
191 if (IsStreamerInfoItem(itemname))
192 return GetStreamerInfoHash();
193
194 return TRootSniffer::GetItemHash(itemname);
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Creates TMemFile instance, which used for objects streaming
199///
200/// One could not use TBufferFile directly,
201/// while one also require streamer infos list
202
204{
205 if (fMemFile)
206 return;
207
208 TDirectory *olddir = gDirectory;
209 gDirectory = nullptr;
210 TFile *oldfile = gFile;
211 gFile = nullptr;
212
213 fMemFile = new TMemFile("dummy.file", "RECREATE");
214 gROOT->GetListOfFiles()->Remove(fMemFile);
215
216 TH1F *d = new TH1F("d", "d", 10, 0, 10);
217 fMemFile->WriteObject(d, "h1");
218 delete d;
219
220 TGraph *gr = new TGraph(10);
221 gr->SetName("abc");
222 // // gr->SetDrawOptions("AC*");
223 fMemFile->WriteObject(gr, "gr1");
224 delete gr;
225
227
228 // make primary list of streamer infos
229 TList *l = new TList();
230
231 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TGraph"));
232 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TH1F"));
233 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TH1"));
234 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TNamed"));
235 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TObject"));
236
237 fMemFile->WriteObject(l, "ll");
238 delete l;
239
241
243
244 gDirectory = olddir;
245 gFile = oldfile;
246}
247
248////////////////////////////////////////////////////////////////////////////////
249/// Search element with specified path
250///
251/// Returns pointer on element
252///
253/// Optionally one could obtain element class, member description
254/// and number of childs. When chld!=0, not only element is searched,
255/// but also number of childs are counted. When member!=0, any object
256/// will be scanned for its data members (disregard of extra options)
257
258void *TRootSnifferFull::FindInHierarchy(const char *path, TClass **cl, TDataMember **member, Int_t *chld)
259{
260 if (IsStreamerInfoItem(path)) {
261 // special handling for streamer info
263 if (cl && fSinfo)
264 *cl = fSinfo->IsA();
265 return fSinfo;
266 }
267
268 return TRootSniffer::FindInHierarchy(path, cl, member, chld);
269}
270
271////////////////////////////////////////////////////////////////////////////////
272/// Produce binary data for specified item
273///
274/// if "zipped" option specified in query, buffer will be compressed
275
276Bool_t TRootSnifferFull::ProduceBinary(const std::string &path, const std::string & /*query*/, std::string &res)
277{
278 if (path.empty())
279 return kFALSE;
280
281 const char *path_ = path.c_str();
282 if (*path_ == '/')
283 path_++;
284
285 TClass *obj_cl = nullptr;
286 void *obj_ptr = FindInHierarchy(path_, &obj_cl);
287 if (!obj_ptr || !obj_cl)
288 return kFALSE;
289
290 if (obj_cl->GetBaseClassOffset(TObject::Class()) != 0) {
291 Info("ProduceBinary", "Non-TObject class not supported");
292 return kFALSE;
293 }
294
295 // ensure that memfile exists
297
298 TDirectory *olddir = gDirectory;
299 gDirectory = nullptr;
300 TFile *oldfile = gFile;
301 gFile = nullptr;
302
303 TObject *obj = (TObject *)obj_ptr;
304
305 TBufferFile *sbuf = new TBufferFile(TBuffer::kWrite, 100000);
306 sbuf->SetParent(fMemFile);
307 sbuf->MapObject(obj);
308 obj->Streamer(*sbuf);
309 if (fCurrentArg)
310 fCurrentArg->SetExtraHeader("RootClassName", obj_cl->GetName());
311
312 // produce actual version of streamer info
313 delete fSinfo;
316
317 gDirectory = olddir;
318 gFile = oldfile;
319
320 res.resize(sbuf->Length());
321 std::copy((const char *)sbuf->Buffer(), (const char *)sbuf->Buffer() + sbuf->Length(), res.begin());
322
323 delete sbuf;
324
325 return kTRUE;
326}
327
328////////////////////////////////////////////////////////////////////////////////
329/// Produce ROOT file for specified item
330///
331/// File created in memory using TMemFile class.
332
333Bool_t TRootSnifferFull::ProduceRootFile(const std::string &path, const std::string & /*query*/, std::string &res)
334{
335 if (path.empty())
336 return kFALSE;
337
338 const char *path_ = path.c_str();
339 if (*path_ == '/')
340 path_++;
341
342 TClass *obj_cl = nullptr;
343 void *obj_ptr = FindInHierarchy(path_, &obj_cl);
344 if (!obj_ptr || !obj_cl)
345 return kFALSE;
346
347 const char *store_name = "object";
348
349 if (obj_cl->GetBaseClassOffset(TNamed::Class()) == 0) {
350 const char *obj_name = ((TNamed *) obj_ptr)->GetName();
351 if (obj_name && *obj_name)
352 store_name = obj_name;
353 }
354
355 TDirectory *olddir = gDirectory;
356 gDirectory = nullptr;
357 TFile *oldfile = gFile;
358 gFile = nullptr;
359
360 {
361 TMemFile memfile("dummy.file", "RECREATE");
362 gROOT->GetListOfFiles()->Remove(&memfile);
363
364 memfile.WriteObjectAny(obj_ptr, obj_cl, store_name);
365 memfile.Close();
366
367 res.resize(memfile.GetSize());
368 memfile.CopyTo(res.data(), memfile.GetSize());
369 }
370
371 gDirectory = olddir;
372 gFile = oldfile;
373
374 return kTRUE;
375}
376
377
378////////////////////////////////////////////////////////////////////////////////
379/// Method to produce image from specified object
380///
381/// @param kind image kind TImage::kPng, TImage::kJpeg, TImage::kGif
382/// @param path path to object
383/// @param options extra options
384/// @param res std::string with binary data
385///
386/// By default, image 300x200 is produced
387/// In options string one could provide following parameters:
388///
389/// * w - image width
390/// * h - image height
391/// * opt - draw options
392///
393/// For instance:
394///
395/// http://localhost:8080/Files/hsimple.root/hpx/get.png?w=500&h=500&opt=lego1
396
397Bool_t TRootSnifferFull::ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res)
398{
399 if (path.empty())
400 return kFALSE;
401
402 const char *path_ = path.c_str();
403 if (*path_ == '/')
404 path_++;
405
406 TClass *obj_cl(nullptr);
407 void *obj_ptr = FindInHierarchy(path_, &obj_cl);
408 if (!obj_ptr || !obj_cl)
409 return kFALSE;
410
411 if (obj_cl->GetBaseClassOffset(TObject::Class()) != 0) {
412 Error("TRootSniffer", "Only derived from TObject classes can be drawn");
413 return kFALSE;
414 }
415
416 TObject *obj = (TObject *)obj_ptr;
417
418 TImage *img = TImage::Create();
419 if (!img)
420 return kFALSE;
421
422 if (obj->InheritsFrom(TPad::Class())) {
423
424 if (gDebug > 1)
425 Info("TRootSniffer", "Crate IMAGE directly from pad");
426 img->FromPad((TPad *)obj);
427 } else if (CanDrawClass(obj->IsA())) {
428
429 if (gDebug > 1)
430 Info("TRootSniffer", "Crate IMAGE from object %s", obj->GetName());
431
432 Int_t width(300), height(200);
433 TString drawopt;
434
435 if (!options.empty()) {
436 TUrl url;
437 url.SetOptions(options.c_str());
438 url.ParseOptions();
439 Int_t w = url.GetIntValueFromOptions("w");
440 if (w > 10)
441 width = w;
442 Int_t h = url.GetIntValueFromOptions("h");
443 if (h > 10)
444 height = h;
445 const char *opt = url.GetValueFromOptions("opt");
446 if (opt)
447 drawopt = opt;
448 }
449
450 Bool_t isbatch = gROOT->IsBatch();
451 TVirtualPad::TContext ctxt(false);
452
453 if (!isbatch)
454 gROOT->SetBatch(kTRUE);
455
456 TCanvas *c1 = new TCanvas("__online_draw_canvas__", "title", width, height);
457 obj->Draw(drawopt.Data());
458 img->FromPad(c1);
459 delete c1;
460
461 if (!isbatch)
462 gROOT->SetBatch(kFALSE);
463
464 } else {
465 delete img;
466 return kFALSE;
467 }
468
469 TImage *im = TImage::Create();
470 im->Append(img);
471
472 char *png_buffer = nullptr;
473 int size(0);
474
475 im->GetImageBuffer(&png_buffer, &size, (TImage::EImageFileTypes)kind);
476
477 if (png_buffer && (size > 0)) {
478 res.resize(size);
479 memcpy((void *)res.data(), png_buffer, size);
480 }
481
482 free(png_buffer);
483 delete im;
484
485 return !res.empty();
486}
487
488////////////////////////////////////////////////////////////////////////////////
489/// Invokes TRootSniffer::ProduceIamge, converting kind into TImage::EImageFileTypes type
490
491Bool_t TRootSnifferFull::CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res)
492{
493 if (kind == "png")
494 return ProduceImage(TImage::kPng, path, options, res);
495
496 if (kind == "jpeg")
497 return ProduceImage(TImage::kJpeg, path, options, res);
498
499 if (kind == "gif")
500 return ProduceImage(TImage::kGif, path, options, res);
501
502 return kFALSE;
503}
504
505////////////////////////////////////////////////////////////////////////////////
506/// Produce XML data for specified item
507///
508/// For object conversion TBufferXML is used
509
510Bool_t TRootSnifferFull::ProduceXml(const std::string &path, const std::string & /*options*/, std::string &res)
511{
512 if (path.empty())
513 return kFALSE;
514 const char *path_ = path.c_str();
515 if (*path_ == '/')
516 path_++;
517
518 TClass *obj_cl = nullptr;
519 void *obj_ptr = FindInHierarchy(path_, &obj_cl);
520 if (!obj_ptr || !obj_cl)
521 return kFALSE;
522
523 // TODO: support std::string in TBufferXML
524 res = TBufferXML::ConvertToXML(obj_ptr, obj_cl).Data();
525
526 return !res.empty();
527}
528
529////////////////////////////////////////////////////////////////////////////////
530/// Execute command for specified object
531///
532/// options include method and extra list of parameters
533/// sniffer should be not-readonly to allow execution of the commands
534/// @param reskind defines kind of result 0 - debug, 1 - json, 2 - binary
535
536Bool_t TRootSnifferFull::ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res_str)
537{
538 std::string *debug = (reskind == 0) ? &res_str : nullptr;
539
540 if (path.empty()) {
541 if (debug)
542 debug->append("Item name not specified\n");
543 return debug != nullptr;
544 }
545
546 const char *path_ = path.c_str();
547 if (*path_ == '/')
548 path_++;
549
550 TClass *obj_cl = nullptr;
551 void *obj_ptr = FindInHierarchy(path_, &obj_cl);
552 if (debug)
553 debug->append(TString::Format("Item:%s found:%s\n", path_, obj_ptr ? "true" : "false").Data());
554 if (!obj_ptr || !obj_cl)
555 return debug != nullptr;
556
557 TUrl url;
558 url.SetOptions(options.c_str());
559
560 const char *method_name = url.GetValueFromOptions("method");
561 TString prototype = DecodeUrlOptionValue(url.GetValueFromOptions("prototype"), kTRUE);
562 TString funcname = DecodeUrlOptionValue(url.GetValueFromOptions("func"), kTRUE);
563 TMethod *method = nullptr;
564 TFunction *func = nullptr;
565 if (method_name) {
566 if (prototype.Length() == 0) {
567 if (debug)
568 debug->append(TString::Format("Search for any method with name \'%s\'\n", method_name).Data());
569 method = obj_cl->GetMethodAllAny(method_name);
570 } else {
571 if (debug)
572 debug->append(
573 TString::Format("Search for method \'%s\' with prototype \'%s\'\n", method_name, prototype.Data())
574 .Data());
575 method = obj_cl->GetMethodWithPrototype(method_name, prototype);
576 }
577 }
578
579 if (method) {
580 if (debug)
581 debug->append(TString::Format("Method: %s\n", method->GetPrototype()).Data());
582 } else {
583 if (funcname.Length() > 0) {
584 if (prototype.Length() == 0) {
585 if (debug)
586 debug->append(TString::Format("Search for any function with name \'%s\'\n", funcname.Data()).Data());
587 func = gROOT->GetGlobalFunction(funcname);
588 } else {
589 if (debug)
590 debug->append(TString::Format("Search for function \'%s\' with prototype \'%s\'\n", funcname.Data(),
591 prototype.Data())
592 .Data());
593 func = gROOT->GetGlobalFunctionWithPrototype(funcname, prototype);
594 }
595 }
596
597 if (func && debug)
598 debug->append(TString::Format("Function: %s\n", func->GetPrototype()).Data());
599 }
600
601 if (!method && !func) {
602 if (debug)
603 debug->append("Method not found\n");
604 return debug != nullptr;
605 }
606
607 if ((fReadOnly && (fCurrentRestrict == 0)) || (fCurrentRestrict == 1)) {
608 if ((method != nullptr) && (fCurrentAllowedMethods.Index(method_name) == kNPOS)) {
609 if (debug)
610 debug->append("Server runs in read-only mode, method cannot be executed\n");
611 return debug != nullptr;
612 } else if ((func != nullptr) && (fCurrentAllowedMethods.Index(funcname) == kNPOS)) {
613 if (debug)
614 debug->append("Server runs in read-only mode, function cannot be executed\n");
615 return debug != nullptr;
616 } else {
617 if (debug)
618 debug->append("For that special method server allows access even read-only mode is specified\n");
619 }
620 }
621
622 TList *args = method ? method->GetListOfMethodArgs() : func->GetListOfMethodArgs();
623
624 TList garbage;
625 garbage.SetOwner(kTRUE); // use as garbage collection
626 TObject *post_obj = nullptr; // object reconstructed from post request
627 TString call_args;
628
629 TIter next(args);
630 while (auto arg = static_cast<TMethodArg *>(next())) {
631
632 if ((strcmp(arg->GetName(), "rest_url_opt") == 0) && (strcmp(arg->GetFullTypeName(), "const char*") == 0) &&
633 (args->GetSize() == 1)) {
634 // very special case - function requires list of options after method=argument
635
636 const char *pos = strstr(options.c_str(), "method=");
637 if (!pos || (strlen(pos) < strlen(method_name) + 7))
638 return debug != nullptr;
639 const char *rest_url = pos + strlen(method_name) + 7;
640 if (*rest_url == '&') ++rest_url;
641 call_args.Form("\"%s\"", rest_url);
642 break;
643 }
644
645 TString sval;
646 const char *val = url.GetValueFromOptions(arg->GetName());
647 if (val) {
648 sval = DecodeUrlOptionValue(val, kFALSE);
649 val = sval.Data();
650 }
651
652 if ((val != nullptr) && (strcmp(val, "_this_") == 0)) {
653 // special case - object itself is used as argument
654 sval.Form("(%s*)0x%zx", obj_cl->GetName(), (size_t)obj_ptr);
655 val = sval.Data();
656 } else if ((val != nullptr) && (fCurrentArg != nullptr) && (fCurrentArg->GetPostData() != nullptr)) {
657 // process several arguments which are specific for post requests
658 if (strcmp(val, "_post_object_xml_") == 0) {
659 // post data has extra 0 at the end and can be used as null-terminated string
660 post_obj = TBufferXML::ConvertFromXML((const char *)fCurrentArg->GetPostData());
661 if (!post_obj) {
662 sval = "0";
663 } else {
664 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
665 if (url.HasOption("_destroy_post_"))
666 garbage.Add(post_obj);
667 }
668 val = sval.Data();
669 } else if (strcmp(val, "_post_object_json_") == 0) {
670 // post data has extra 0 at the end and can be used as null-terminated string
671 post_obj = TBufferJSON::ConvertFromJSON((const char *)fCurrentArg->GetPostData());
672 if (!post_obj) {
673 sval = "0";
674 } else {
675 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
676 if (url.HasOption("_destroy_post_"))
677 garbage.Add(post_obj);
678 }
679 val = sval.Data();
680 } else if ((strcmp(val, "_post_object_") == 0) && url.HasOption("_post_class_")) {
681 TString clname = url.GetValueFromOptions("_post_class_");
682 TClass *arg_cl = gROOT->GetClass(clname, kTRUE, kTRUE);
683 if ((arg_cl != nullptr) && (arg_cl->GetBaseClassOffset(TObject::Class()) == 0) && (post_obj == nullptr)) {
684 post_obj = (TObject *)arg_cl->New();
685 if (post_obj == nullptr) {
686 if (debug)
687 debug->append(TString::Format("Fail to create object of class %s\n", clname.Data()).Data());
688 } else {
689 if (debug)
690 debug->append(TString::Format("Reconstruct object of class %s from POST data\n", clname.Data()).Data());
692 buf.MapObject(post_obj, arg_cl);
693 post_obj->Streamer(buf);
694 if (url.HasOption("_destroy_post_"))
695 garbage.Add(post_obj);
696 }
697 }
698 sval.Form("(%s*)0x%zx", clname.Data(), (size_t)post_obj);
699 val = sval.Data();
700 } else if (strcmp(val, "_post_data_") == 0) {
701 sval.Form("(void*)0x%zx", (size_t)fCurrentArg->GetPostData());
702 val = sval.Data();
703 } else if (strcmp(val, "_post_length_") == 0) {
704 sval.Form("%ld", (long)fCurrentArg->GetPostDataLength());
705 val = sval.Data();
706 }
707 }
708
709 if (!val)
710 val = arg->GetDefault();
711
712 if (debug)
713 debug->append(TString::Format(" Argument:%s Type:%s Value:%s \n", arg->GetName(), arg->GetFullTypeName(),
714 val ? val : "<missed>")
715 .Data());
716 if (!val)
717 return debug != nullptr;
718
719 if (call_args.Length() > 0)
720 call_args += ", ";
721
722 if ((strcmp(arg->GetFullTypeName(), "const char*") == 0) || (strcmp(arg->GetFullTypeName(), "Option_t*") == 0)) {
723 int len = strlen(val);
724 if ((strlen(val) < 2) || (*val != '\"') || (val[len - 1] != '\"'))
725 call_args.Append(TString::Format("\"%s\"", val));
726 else
727 call_args.Append(val);
728 } else {
729 call_args.Append(val);
730 }
731 }
732
733 TMethodCall *call = nullptr;
734
735 if (method != nullptr) {
736 call = new TMethodCall(obj_cl, method_name, call_args.Data());
737 if (debug)
738 debug->append(TString::Format("Calling obj->%s(%s);\n", method_name, call_args.Data()).Data());
739 } else {
740 call = new TMethodCall(funcname.Data(), call_args.Data());
741 if (debug)
742 debug->append(TString::Format("Calling %s(%s);\n", funcname.Data(), call_args.Data()).Data());
743 }
744
745 garbage.Add(call);
746
747 if (!call->IsValid()) {
748 if (debug)
749 debug->append("Fail: invalid TMethodCall\n");
750 return debug != nullptr;
751 }
752
753 Int_t compact = 0;
754 if (url.GetValueFromOptions("compact"))
755 compact = url.GetIntValueFromOptions("compact");
756
757 TString res = "null";
758 void *ret_obj = nullptr;
759 TClass *ret_cl = nullptr;
760 TBufferFile *resbuf = nullptr;
761 if (reskind == 2) {
762 resbuf = new TBufferFile(TBuffer::kWrite, 10000);
763 garbage.Add(resbuf);
764 }
765
766 switch (call->ReturnType()) {
767 case TMethodCall::kLong: {
768 Longptr_t l(0);
769 if (method)
770 call->Execute(obj_ptr, l);
771 else
772 call->Execute(l);
773 if (resbuf)
774 resbuf->WriteLong(l);
775 else
776 res.Form("%zd", (size_t)l);
777 break;
778 }
780 Double_t d(0.);
781 if (method)
782 call->Execute(obj_ptr, d);
783 else
784 call->Execute(d);
785 if (resbuf)
786 resbuf->WriteDouble(d);
787 else
789 break;
790 }
792 char *txt = nullptr;
793 if (method)
794 call->Execute(obj_ptr, &txt);
795 else
796 call->Execute(0, &txt); // here 0 is artificial, there is no proper signature
797 if (txt != nullptr) {
798 if (resbuf)
799 resbuf->WriteString(txt);
800 else
801 res.Form("\"%s\"", txt);
802 }
803 break;
804 }
805 case TMethodCall::kOther: {
806 std::string ret_kind = func ? func->GetReturnTypeNormalizedName() : method->GetReturnTypeNormalizedName();
807 if ((ret_kind.length() > 0) && (ret_kind[ret_kind.length() - 1] == '*')) {
808 ret_kind.resize(ret_kind.length() - 1);
809 ret_cl = gROOT->GetClass(ret_kind.c_str(), kTRUE, kTRUE);
810 }
811
812 if (ret_cl != nullptr) {
813 Longptr_t l(0);
814 if (method)
815 call->Execute(obj_ptr, l);
816 else
817 call->Execute(l);
818 if (l != 0)
819 ret_obj = (void *)l;
820 } else {
821 if (method)
822 call->Execute(obj_ptr);
823 else
824 call->Execute();
825 }
826
827 break;
828 }
829 case TMethodCall::kNone: {
830 if (method)
831 call->Execute(obj_ptr);
832 else
833 call->Execute();
834 break;
835 }
836 }
837
838 const char *_ret_object_ = url.GetValueFromOptions("_ret_object_");
839 if (_ret_object_ != nullptr) {
840 TObject *obj = nullptr;
841 if (gDirectory)
842 obj = gDirectory->Get(_ret_object_);
843 if (debug)
844 debug->append(TString::Format("Return object %s found %s\n", _ret_object_, obj ? "true" : "false").Data());
845
846 if (obj == nullptr) {
847 res = "null";
848 } else {
849 ret_obj = obj;
850 ret_cl = obj->IsA();
851 }
852 }
853
854 if (ret_obj && ret_cl) {
855 if ((resbuf != nullptr) && (ret_cl->GetBaseClassOffset(TObject::Class()) == 0)) {
856 TObject *obj = (TObject *)ret_obj;
857 resbuf->MapObject(obj);
858 obj->Streamer(*resbuf);
859 if (fCurrentArg)
860 fCurrentArg->SetExtraHeader("RootClassName", ret_cl->GetName());
861 } else {
862 res = TBufferJSON::ConvertToJSON(ret_obj, ret_cl, compact);
863 }
864 }
865
866 if ((resbuf != nullptr) && (resbuf->Length() > 0)) {
867 res_str.resize(resbuf->Length());
868 std::copy((const char *)resbuf->Buffer(), (const char *)resbuf->Buffer() + resbuf->Length(), res_str.begin());
869 }
870
871 if (debug)
872 debug->append(TString::Format("Result = %s\n", res.Data()).Data());
873
874 if (reskind == 1)
875 res_str = res.Data();
876
877 if (url.HasOption("_destroy_result_") && ret_obj && ret_cl) {
878 ret_cl->Destructor(ret_obj);
879 if (debug)
880 debug->append("Destroy result object at the end\n");
881 }
882
883 // delete all garbage objects, but should be also done with any return
884 garbage.Delete();
885
886 return kTRUE;
887}
#define d(i)
Definition RSha256.hxx:102
#define h(i)
Definition RSha256.hxx:106
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
long Longptr_t
Definition RtypesCore.h:82
unsigned long ULong_t
Definition RtypesCore.h:55
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:124
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
#define gDirectory
Definition TDirectory.h:384
#define gFile
Definition TFile.h:347
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
char name[80]
Definition TGX11.cxx:110
Int_t gDebug
Definition TROOT.cxx:595
#define gROOT
Definition TROOT.h:406
#define free
Definition civetweb.c:1539
A TTree is a list of TBranches.
Definition TBranch.h:93
static TClass * Class()
The concrete implementation of TBuffer for writing/reading to/from a ROOT file or socket.
Definition TBufferFile.h:47
void WriteLong(Long_t l) override
void WriteString(const char *s) override
Write string to I/O buffer.
void WriteDouble(Double_t d) override
void MapObject(const TObject *obj, UInt_t offset=1) override
Add object to the fMap container.
static TObject * ConvertFromJSON(const char *str)
Read TObject-based class from JSON, produced by ConvertToJSON() method.
static TString ConvertToJSON(const TObject *obj, Int_t compact=0, const char *member_name=nullptr)
Converts object, inherited from TObject class, to JSON string Lower digit of compact parameter define...
static const char * GetFloatFormat()
return current printf format for float members, default "%e"
static TString ConvertToXML(const TObject *obj, Bool_t GenericLayout=kFALSE, Bool_t UseNamespaces=kFALSE)
Converts object, inherited from TObject class, to XML string GenericLayout defines layout choice for ...
static TObject * ConvertFromXML(const char *str, Bool_t GenericLayout=kFALSE, Bool_t UseNamespaces=kFALSE)
Read object from XML, produced by ConvertToXML() method.
void SetParent(TObject *parent)
Set parent owning this buffer.
Definition TBuffer.cxx:270
@ kWrite
Definition TBuffer.h:73
@ kRead
Definition TBuffer.h:73
Int_t Length() const
Definition TBuffer.h:100
char * Buffer() const
Definition TBuffer.h:96
The Canvas class.
Definition TCanvas.h:23
static TClass * Class()
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition TClass.h:81
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Definition TClass.cxx:4978
TMethod * GetMethodWithPrototype(const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Find the method with a given prototype.
Definition TClass.cxx:4456
void Destructor(void *obj, Bool_t dtorOnly=kFALSE)
Explicitly call destructor for object.
Definition TClass.cxx:5400
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:4874
Int_t GetBaseClassOffset(const TClass *toBase, void *address=nullptr, bool isDerivedObject=true)
Definition TClass.cxx:2791
TMethod * GetMethodAllAny(const char *method)
Return pointer to method without looking at parameters.
Definition TClass.cxx:4384
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Definition TClass.cxx:2968
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
All ROOT classes may have RTTI (run time type identification) support added.
Definition TDataMember.h:31
Int_t WriteObjectAny(const void *obj, const char *classname, const char *name, Option_t *option="", Int_t bufsize=0) override
Write object from pointer of class classname in this directory.
Describe directory structure in memory.
Definition TDirectory.h:45
std::enable_if_t<!std::is_base_of< TObject, T >::value, Int_t > WriteObject(const T *obj, const char *name, Option_t *option="", Int_t bufsize=0)
Write an object with proper type checking.
Definition TDirectory.h:282
A ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
Definition TFile.h:53
virtual void WriteStreamerInfo()
Write the list of TStreamerInfo as a single object in this file The class Streamer description for al...
Definition TFile.cxx:3785
void Close(Option_t *option="") override
Close a file.
Definition TFile.cxx:943
virtual TList * GetStreamerInfoList() final
Read the list of TStreamerInfo objects written to this file.
Definition TFile.cxx:1438
Global functions class (global functions are obtained from CINT).
Definition TFunction.h:30
virtual const char * GetPrototype() const
Returns the prototype of a function as defined by CINT, or 0 in case of error.
TList * GetListOfMethodArgs()
Return list containing the TMethodArgs of a TFunction.
std::string GetReturnTypeNormalizedName() const
Get the normalized name of the return type.
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
static TClass * Class()
void SetName(const char *name="") override
Set graph name.
Definition TGraph.cxx:2358
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
static TClass * Class()
const void * GetPostData() const
return pointer on posted with request data
void SetExtraHeader(const char *name, const char *value)
add extra http header value to the reply
Long_t GetPostDataLength() const
return length of posted with request data
An abstract interface to image processing library.
Definition TImage.h:29
virtual void FromPad(TVirtualPad *, Int_t=0, Int_t=0, UInt_t=0, UInt_t=0)
Definition TImage.h:122
EImageFileTypes
Definition TImage.h:36
@ kPng
Definition TImage.h:40
@ kJpeg
Definition TImage.h:41
@ kGif
Definition TImage.h:48
static TImage * Create()
Create an image.
Definition TImage.cxx:35
virtual void Append(const TImage *, const char *="+", const char *="#00000000")
Definition TImage.h:175
virtual void GetImageBuffer(char **, int *, EImageFileTypes=TImage::kPng)
Definition TImage.h:241
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition TKey.h:28
virtual const char * GetClassName() const
Definition TKey.h:75
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:758
static TClass * Class()
A doubly linked list.
Definition TList.h:38
void Add(TObject *obj) override
Definition TList.h:81
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
Definition TList.cxx:468
TClass * IsA() const override
Definition TList.h:110
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:19
Long64_t GetSize() const override
Return the current size of the memory file.
Definition TMemFile.cxx:290
virtual Long64_t CopyTo(void *to, Long64_t maxsize) const
Copy the binary representation of the TMemFile into the memory area starting at 'to' and of length at...
Definition TMemFile.cxx:255
Each ROOT method (see TMethod) has a linked list of its arguments.
Definition TMethodArg.h:36
Method or function calling interface.
Definition TMethodCall.h:37
EReturnType ReturnType()
Returns the return type of the method.
static const EReturnType kLong
Definition TMethodCall.h:43
static const EReturnType kString
Definition TMethodCall.h:45
static const EReturnType kOther
Definition TMethodCall.h:46
static const EReturnType kNone
Definition TMethodCall.h:49
void Execute(const char *, const char *, int *=nullptr) override
Execute method on this object with the given parameter string, e.g.
Definition TMethodCall.h:64
Bool_t IsValid() const
Return true if the method call has been properly initialized and is usable.
static const EReturnType kDouble
Definition TMethodCall.h:44
Each ROOT class (see TClass) has a linked list of methods.
Definition TMethod.h:38
virtual TList * GetListOfMethodArgs()
Returns methodarg list and additionally updates fDataMember in TMethod by calling FindDataMember();.
Definition TMethod.cxx:307
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:439
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:888
virtual const char * ClassName() const
Returns name of class to which the object belongs.
Definition TObject.cxx:207
static TClass * Class()
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:525
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
virtual TClass * IsA() const
Definition TObject.h:245
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:961
The most important graphics class in the ROOT system.
Definition TPad.h:28
static TClass * Class()
static TClass * Class()
Extends TRootSniffer for many ROOT classes.
void * FindInHierarchy(const char *path, TClass **cl=nullptr, TDataMember **member=nullptr, Int_t *chld=nullptr) override
Search element with specified path.
Bool_t IsStreamerInfoItem(const char *itemname) override
Return true if it is streamer info item name.
static Bool_t IsDrawableClass(TClass *cl)
return true if given class can be drawn in JSROOT
Bool_t ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res) override
Execute command for specified object.
TList * fSinfo
! last produced streamer info
TRootSnifferFull(const char *name="sniff", const char *objpath="Objects")
constructor
Bool_t CanDrawClass(TClass *cl) override
void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj) override
Scans object properties.
virtual ~TRootSnifferFull()
destructor
void ScanObjectChilds(TRootSnifferScanRec &rec, TObject *obj) override
Scans object childs (if any)
Bool_t ProduceRootFile(const std::string &path, const std::string &options, std::string &res) override
Produce ROOT file for specified item.
ULong_t GetItemHash(const char *itemname) override
Get hash function for specified item.
Bool_t ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res) override
Method to produce image from specified object.
Bool_t CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res) override
Invokes TRootSniffer::ProduceIamge, converting kind into TImage::EImageFileTypes type.
Bool_t ProduceXml(const std::string &path, const std::string &options, std::string &res) override
Produce XML data for specified item.
void CreateMemFile()
Creates TMemFile instance, which used for objects streaming.
Bool_t ProduceBinary(const std::string &path, const std::string &options, std::string &res) override
Produce binary data for specified item.
TMemFile * fMemFile
! file used to manage streamer infos
ULong_t GetStreamerInfoHash() override
Returns hash value for streamer infos.
void ScanKeyProperties(TRootSnifferScanRec &rec, TKey *key, TObject *&obj, TClass *&obj_class) override
Scans TKey properties.
Structure used to scan hierarchies of ROOT objects.
Sniffer of ROOT objects, data provider for THttpServer.
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 void ScanKeyProperties(TRootSnifferScanRec &rec, TKey *key, TObject *&obj, TClass *&obj_class)
Scans TKey properties in special cases load objects from the file.
virtual void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj)
Scans object properties here such fields as _autoload or _icon properties depending on class or objec...
TString DecodeUrlOptionValue(const char *value, Bool_t remove_quotes=kTRUE)
Method replaces all kind of special symbols, which could appear in URL options.
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
THttpCallArg * fCurrentArg
! current http arguments (if any)
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...
Int_t fCurrentRestrict
! current restriction for last-found object
void ScanCollection(TRootSnifferScanRec &rec, TCollection *lst, const char *foldername=nullptr, TCollection *keys_lst=nullptr)
Scan collection content.
Basic string class.
Definition TString.h:139
Ssiz_t Length() const
Definition TString.h:417
const char * Data() const
Definition TString.h:376
TString & Append(const char *cs)
Definition TString.h:572
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Definition TString.cxx:2378
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:651
A TTree represents a columnar dataset.
Definition TTree.h:79
static TClass * Class()
This class represents a WWW compatible URL.
Definition TUrl.h:33
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Definition TUrl.cxx:660
Int_t GetIntValueFromOptions(const char *key) const
Return a value for a given key from the URL options as an Int_t, a missing key returns -1.
Definition TUrl.cxx:672
void SetOptions(const char *opt)
Definition TUrl.h:87
void ParseOptions() const
Parse URL options into a key/value map.
Definition TUrl.cxx:626
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
Definition TUrl.cxx:683
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:61
return c1
Definition legend1.C:41
TGraphErrors * gr
Definition legend1.C:25
TLine l
Definition textangle.C:4