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
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) {
124 } else {
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
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
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
209 gDirectory = nullptr;
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
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
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;
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
299 gDirectory = nullptr;
301 gFile = nullptr;
302
303 TObject *obj = (TObject *)obj_ptr;
304
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
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;
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)
353 }
354
356 gDirectory = nullptr;
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
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);
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
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 drawopt = DecodeUrlOptionValue(url.GetValueFromOptions("opt"), kTRUE);
446 }
447
448 Bool_t isbatch = gROOT->IsBatch();
450
451 if (!isbatch)
452 gROOT->SetBatch(kTRUE);
453
454 TCanvas *c1 = new TCanvas("__online_draw_canvas__", "title", width, height);
455 obj->Draw(drawopt.Data());
456 img->FromPad(c1);
457 delete c1;
458
459 if (!isbatch)
460 gROOT->SetBatch(kFALSE);
461
462 } else {
463 delete img;
464 return kFALSE;
465 }
466
468 im->Append(img);
469
470 char *png_buffer = nullptr;
471 int size(0);
472
473 im->GetImageBuffer(&png_buffer, &size, (TImage::EImageFileTypes)kind);
474
475 if (png_buffer && (size > 0)) {
476 res.resize(size);
477 memcpy((void *)res.data(), png_buffer, size);
478 }
479
481 delete im;
482
483 return !res.empty();
484}
485
486////////////////////////////////////////////////////////////////////////////////
487/// Invokes TRootSniffer::ProduceIamge, converting kind into TImage::EImageFileTypes type
488
489Bool_t TRootSnifferFull::CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res)
490{
491 if (kind == "png")
492 return ProduceImage(TImage::kPng, path, options, res);
493
494 if (kind == "jpeg")
495 return ProduceImage(TImage::kJpeg, path, options, res);
496
497 if (kind == "gif")
498 return ProduceImage(TImage::kGif, path, options, res);
499
500 return kFALSE;
501}
502
503////////////////////////////////////////////////////////////////////////////////
504/// Produce XML data for specified item
505///
506/// For object conversion TBufferXML is used
507
508Bool_t TRootSnifferFull::ProduceXml(const std::string &path, const std::string & /*options*/, std::string &res)
509{
510 if (path.empty())
511 return kFALSE;
512 const char *path_ = path.c_str();
513 if (*path_ == '/')
514 path_++;
515
516 TClass *obj_cl = nullptr;
518 if (!obj_ptr || !obj_cl)
519 return kFALSE;
520
521 // TODO: support std::string in TBufferXML
523
524 return !res.empty();
525}
526
527////////////////////////////////////////////////////////////////////////////////
528/// Execute command for specified object
529///
530/// @param path the object path
531/// @param options include method and extra list of parameters
532/// sniffer should be not-readonly to allow execution of the commands
533/// @param reskind defines kind of result 0 - debug, 1 - json, 2 - binary
534/// @param res_str result string
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;
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
625 garbage.SetOwner(kTRUE); // use as garbage collection
626 TObject *post_obj = nullptr; // object reconstructed from post request
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.Append("\"");
643 call_args.Append("\"");
644 break;
645 }
646
648 const char *val = url.GetValueFromOptions(arg->GetName());
649 if (val)
651
653
654 if (sval == "_this_") {
655 // special case - object itself is used as argument
656 sval.Form("(%s*)0x%zx", obj_cl->GetName(), (size_t)obj_ptr);
657 } else if ((fCurrentArg != nullptr) && (fCurrentArg->GetPostData() != nullptr)) {
658 // process several arguments which are specific for post requests
659 if (fAllowPostObject && (sval == "_post_object_xml_")) {
660 // post data has extra 0 at the end and can be used as null-terminated string
662 if (!post_obj)
663 sval = "0";
664 else {
665 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
666 if (url.HasOption("_destroy_post_"))
667 garbage.Add(post_obj);
668 }
669 } else if (fAllowPostObject && (sval == "_post_object_json_")) {
670 // post data has extra 0 at the end and can be used as null-terminated string
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 } else if (fAllowPostObject && (sval == "_post_object_") && url.HasOption("_post_class_")) {
680 TString clname = DecodeUrlOptionValue(url.GetValueFromOptions("_post_class_"), kTRUE);
681 TClass *arg_cl = gROOT->GetClass(clname, kTRUE, kTRUE);
682 if ((arg_cl != nullptr) && (arg_cl->GetBaseClassOffset(TObject::Class()) == 0) && (post_obj == nullptr)) {
683 post_obj = (TObject *)arg_cl->New();
684 if (post_obj == nullptr) {
685 if (debug)
686 debug->append(TString::Format("Fail to create object of class %s\n", clname.Data()).Data());
687 } else {
688 if (debug)
689 debug->append(TString::Format("Reconstruct object of class %s from POST data\n", clname.Data()).Data());
692 post_obj->Streamer(buf);
693 if (url.HasOption("_destroy_post_"))
694 garbage.Add(post_obj);
695 }
696 }
697 if (!post_obj)
698 sval = "0";
699 else
700 sval.Form("(%s*)0x%zx", clname.Data(), (size_t)post_obj);
701 } else if (sval == "_post_data_")
702 sval.Form("(void*)0x%zx", (size_t)fCurrentArg->GetPostData());
703 else if (sval == "_post_length_")
704 sval.Form("%ld", (long)fCurrentArg->GetPostDataLength());
705 else
707 } else
709
710 if (sval.IsNull() && arg->GetDefault())
711 sval = arg->GetDefault();
712
713 if (debug)
714 debug->append(
715 TString::Format(" Argument:%s Type:%s Value:%s \n", arg->GetName(), arg->GetFullTypeName(), sval.Data())
716 .Data());
717
718 if (call_args.Length() > 0)
719 call_args += ", ";
720
721 Bool_t isstr = (strcmp(arg->GetFullTypeName(), "const char*") == 0) ||
722 (strcmp(arg->GetFullTypeName(), "Option_t*") == 0) ||
723 (strcmp(arg->GetFullTypeName(), "string") == 0);
724
725 if (isstr) {
726 // check that quotes provided for the string argument
727 // all special characters were escaped before
728 if (sval.IsNull())
729 sval = "\"\"";
730 else {
731 if (sval[0] != '"')
732 sval.Prepend("\"");
733 if (sval[sval.Length() - 1] != '"')
734 sval.Append("\"");
735 }
736 } else {
737 // for numeric types keep only numeric and alphabetic characters
738 // exclude others - especially remove all escape characters
739 if (sanitize_numeric) {
741 for(Size_t i = 0; i < sval.Length(); ++i) {
742 if (std::isalnum(sval[i]) || std::strchr(".:+-", sval[i]))
743 sanitized.Append(sval[i]);
744 }
745 sval = sanitized;
746 }
747 if (sval.IsNull())
748 sval = "0";
749 }
750
751 call_args.Append(sval);
752 }
753
754 TMethodCall *call = nullptr;
755
756 if (method != nullptr) {
757 call = new TMethodCall(obj_cl, method_name, call_args.Data());
758 if (debug)
759 debug->append(TString::Format("Calling obj->%s(%s);\n", method_name, call_args.Data()).Data());
760 } else {
761 call = new TMethodCall(funcname.Data(), call_args.Data());
762 if (debug)
763 debug->append(TString::Format("Calling %s(%s);\n", funcname.Data(), call_args.Data()).Data());
764 }
765
766 garbage.Add(call);
767
768 if (!call->IsValid()) {
769 if (debug)
770 debug->append("Fail: invalid TMethodCall\n");
771 return debug != nullptr;
772 }
773
774 Int_t compact = 0;
775 if (url.GetValueFromOptions("compact"))
776 compact = url.GetIntValueFromOptions("compact");
777
778 TString res = "null";
779 void *ret_obj = nullptr;
780 TClass *ret_cl = nullptr;
781 TBufferFile *resbuf = nullptr;
782 if (reskind == 2) {
783 resbuf = new TBufferFile(TBuffer::kWrite, 10000);
784 garbage.Add(resbuf);
785 }
786
787 switch (call->ReturnType()) {
788 case TMethodCall::kLong: {
789 Longptr_t l(0);
790 if (method)
791 call->Execute(obj_ptr, l);
792 else
793 call->Execute(l);
794 if (resbuf)
795 resbuf->WriteLong(l);
796 else
797 res.Form("%zd", (size_t)l);
798 break;
799 }
801 Double_t d(0.);
802 if (method)
803 call->Execute(obj_ptr, d);
804 else
805 call->Execute(d);
806 if (resbuf)
807 resbuf->WriteDouble(d);
808 else
810 break;
811 }
813 char *txt = nullptr;
814 if (method)
815 call->Execute(obj_ptr, &txt);
816 else
817 call->Execute(0, &txt); // here 0 is artificial, there is no proper signature
818 if (txt != nullptr) {
819 if (resbuf)
820 resbuf->WriteString(txt);
821 else
822 res.Form("\"%s\"", txt);
823 }
824 break;
825 }
826 case TMethodCall::kOther: {
827 std::string ret_kind = func ? func->GetReturnTypeNormalizedName() : method->GetReturnTypeNormalizedName();
828 if ((ret_kind.length() > 0) && (ret_kind[ret_kind.length() - 1] == '*')) {
829 ret_kind.resize(ret_kind.length() - 1);
830 ret_cl = gROOT->GetClass(ret_kind.c_str(), kTRUE, kTRUE);
831 }
832
833 if (ret_cl != nullptr) {
834 Longptr_t l(0);
835 if (method)
836 call->Execute(obj_ptr, l);
837 else
838 call->Execute(l);
839 if (l != 0)
840 ret_obj = (void *)l;
841 } else {
842 if (method)
843 call->Execute(obj_ptr);
844 else
845 call->Execute();
846 }
847
848 break;
849 }
850 case TMethodCall::kNone: {
851 if (method)
852 call->Execute(obj_ptr);
853 else
854 call->Execute();
855 break;
856 }
857 }
858
859 const char *_ret_object_ = url.GetValueFromOptions("_ret_object_");
860 if (_ret_object_ != nullptr) {
861 TObject *obj = nullptr;
862 if (gDirectory)
863 obj = gDirectory->Get(_ret_object_);
864 if (debug)
865 debug->append(TString::Format("Return object %s found %s\n", _ret_object_, obj ? "true" : "false").Data());
866
867 if (obj == nullptr) {
868 res = "null";
869 } else {
870 ret_obj = obj;
871 ret_cl = obj->IsA();
872 }
873 }
874
875 if (ret_obj && ret_cl) {
876 if ((resbuf != nullptr) && (ret_cl->GetBaseClassOffset(TObject::Class()) == 0)) {
877 TObject *obj = (TObject *)ret_obj;
878 resbuf->MapObject(obj);
879 obj->Streamer(*resbuf);
880 if (fCurrentArg)
881 fCurrentArg->SetExtraHeader("RootClassName", ret_cl->GetName());
882 } else {
884 }
885 }
886
887 if ((resbuf != nullptr) && (resbuf->Length() > 0)) {
888 res_str.resize(resbuf->Length());
889 std::copy((const char *)resbuf->Buffer(), (const char *)resbuf->Buffer() + resbuf->Length(), res_str.begin());
890 }
891
892 if (debug)
893 debug->append(TString::Format("Result = %s\n", res.Data()).Data());
894
895 if (reskind == 1)
896 res_str = res.Data();
897
898 if (url.HasOption("_destroy_result_") && ret_obj && ret_cl) {
899 ret_cl->Destructor(ret_obj);
900 if (debug)
901 debug->append("Destroy result object at the end\n");
902 }
903
904 // delete all garbage objects, but should be also done with any return
905 garbage.Delete();
906
907 return kTRUE;
908}
#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
float Size_t
Definition RtypesCore.h:89
long Longptr_t
Definition RtypesCore.h:75
unsigned long ULong_t
Definition RtypesCore.h:55
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:117
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gDirectory
Definition TDirectory.h:384
#define gFile
Definition TFile.h:434
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:622
#define gROOT
Definition TROOT.h:414
#define free
Definition civetweb.c:1539
const_iterator begin() const
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 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.
@ kWrite
Definition TBuffer.h:73
@ kRead
Definition TBuffer.h:73
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:84
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
Definition TClass.cxx:5002
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:3074
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
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 file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:131
virtual void WriteStreamerInfo()
Write the list of TStreamerInfo as a single object in this file The class Streamer description for al...
Definition TFile.cxx:3852
virtual TList * GetStreamerInfoList() final
Read the list of TStreamerInfo objects written to this file.
Definition TFile.cxx:1468
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:2330
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:877
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
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
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:759
static TClass * Class()
A doubly linked list.
Definition TList.h:38
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
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
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
static TClass * Class()
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:457
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:972
static TClass * Class()
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:543
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
virtual TClass * IsA() const
Definition TObject.h:249
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:293
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.
Bool_t fAllowPostObject
! when true allow to deserialize objects received via POST requests
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
const char * Data() const
Definition TString.h:376
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:84
static TClass * Class()
This class represents a WWW compatible URL.
Definition TUrl.h:33
small helper class to store/restore gPad context in TPad methods
Definition TVirtualPad.h:61
std::ostream & Info()
Definition hadd.cxx:171
return c1
Definition legend1.C:41
TGraphErrors * gr
Definition legend1.C:25
TLine l
Definition textangle.C:4