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
46Extends TRootSniffer for many ROOT classes
47
48Provides access to different ROOT collections and containers
49like TTree, TCanvas, TFile, ...
50*/
51
52
53////////////////////////////////////////////////////////////////////////////////
54/// constructor
55
59
60////////////////////////////////////////////////////////////////////////////////
61/// destructor
62
64{
65 delete fSinfo;
66
67 delete fMemFile;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// return true if given class can be drawn in JSROOT
72
74{
75 if (!cl)
76 return kFALSE;
77 if (cl->InheritsFrom(TH1::Class()))
78 return kTRUE;
79 if (cl->InheritsFrom(TGraph::Class()))
80 return kTRUE;
82 return kTRUE;
84 return kTRUE;
85 return kFALSE;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Scans object properties
90///
91/// here such fields as `_autoload` or `_icon` properties depending on class or object name could be assigned
92/// By default properties, coded in the Class title are scanned. Example:
93///
94/// ClassDef(UserClassName, 1) // class comments *SNIFF* _field1=value _field2="string value"
95///
96/// Here *SNIFF* mark is important. After it all expressions like field=value are parsed
97/// One could use double quotes to code string values with spaces.
98/// Fields separated from each other with spaces
99
101{
102 if (obj && obj->InheritsFrom(TLeaf::Class())) {
103 rec.SetField("_more", "false", kFALSE);
104 rec.SetField("_can_draw", "false", kFALSE);
105 rec.SetField("_player", "drawLeafPlayer");
106 rec.SetField("_module", "draw_tree");
107 return;
108 }
109
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Scans TKey properties
115///
116/// in special cases load objects from the file
117
119{
120 if (strcmp(key->GetClassName(), "TDirectoryFile") == 0) {
122 } else {
124 if (obj_class && obj_class->InheritsFrom(TTree::Class())) {
125 if (rec.CanExpandItem()) {
126 // it is requested to expand tree element - read it
127 obj = key->ReadObj();
128 if (obj)
129 obj_class = obj->IsA();
130 } else {
131 rec.SetField("_ttree", "true", kFALSE); // indicate ROOT TTree
132 rec.SetField("_player", "drawTreePlayerKey");
133 rec.SetField("_module", "draw_tree");
134 // rec.SetField("_more", "true", kFALSE); // one could allow to extend
135 }
136 }
137 }
138}
139
140////////////////////////////////////////////////////////////////////////////////
141/// Scans object childs (if any)
142///
143/// here one scans collection, branches, trees and so on
144
146{
147 if (obj->InheritsFrom(TTree::Class())) {
148 if (!rec.IsReadOnly(fReadOnly)) {
149 rec.SetField("_ttree", "true", kFALSE); // indicate ROOT TTree
150 rec.SetField("_player", "drawTreePlayer");
151 rec.SetField("_module", "draw_tree");
152 }
153 ScanCollection(rec, ((TTree *)obj)->GetListOfLeaves());
154 } else if (obj->InheritsFrom(TBranch::Class())) {
155 ScanCollection(rec, ((TBranch *)obj)->GetListOfLeaves());
156 } else {
158 }
159}
160
161////////////////////////////////////////////////////////////////////////////////
162/// Returns hash value for streamer infos
163///
164/// At the moment - just number of items in streamer infos list.
165
170
171////////////////////////////////////////////////////////////////////////////////
172/// Return true if it is streamer info item name
173
175{
176 if (!itemname || (*itemname == 0))
177 return kFALSE;
178
179 return (strcmp(itemname, "StreamerInfo") == 0) || (strcmp(itemname, "StreamerInfo/") == 0);
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Get hash function for specified item
184///
185/// Used to detect any changes in the specified object
186
194
195////////////////////////////////////////////////////////////////////////////////
196/// Creates TMemFile instance, which used for objects streaming
197///
198/// One could not use TBufferFile directly,
199/// while one also require streamer infos list
200
202{
203 if (fMemFile)
204 return;
205
207 TFile::TContext fileCtx{nullptr};
208
209 fMemFile = new TMemFile("dummy.file", "RECREATE");
210 gROOT->GetListOfFiles()->Remove(fMemFile);
211
212 TH1F *d = new TH1F("d", "d", 10, 0, 10);
213 fMemFile->WriteObject(d, "h1");
214 delete d;
215
216 TGraph *gr = new TGraph(10);
217 gr->SetName("abc");
218 // // gr->SetDrawOptions("AC*");
219 fMemFile->WriteObject(gr, "gr1");
220 delete gr;
221
223
224 // make primary list of streamer infos
225 TList *l = new TList();
226
227 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TGraph"));
228 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TH1F"));
229 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TH1"));
230 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TNamed"));
231 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TObject"));
232
233 fMemFile->WriteObject(l, "ll");
234 delete l;
235
237
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Search element with specified path
243///
244/// Returns pointer on element
245///
246/// Optionally one could obtain element class, member description
247/// and number of childs. When chld!=0, not only element is searched,
248/// but also number of childs are counted. When member!=0, any object
249/// will be scanned for its data members (disregard of extra options)
250
252{
253 if (IsStreamerInfoItem(path)) {
254 // special handling for streamer info
256 if (cl && fSinfo)
257 *cl = fSinfo->IsA();
258 return fSinfo;
259 }
260
261 return TRootSniffer::FindInHierarchy(path, cl, member, chld);
262}
263
264////////////////////////////////////////////////////////////////////////////////
265/// Produce binary data for specified item
266///
267/// if "zipped" option specified in query, buffer will be compressed
268
269Bool_t TRootSnifferFull::ProduceBinary(const std::string &path, const std::string & /*query*/, std::string &res)
270{
271 if (path.empty())
272 return kFALSE;
273
274 const char *path_ = path.c_str();
275 if (*path_ == '/')
276 path_++;
277
278 TClass *obj_cl = nullptr;
280 if (!obj_ptr || !obj_cl)
281 return kFALSE;
282
283 if (obj_cl->GetBaseClassOffset(TObject::Class()) != 0) {
284 Info("ProduceBinary", "Non-TObject class not supported");
285 return kFALSE;
286 }
287
288 // ensure that memfile exists
290
292 TFile::TContext fileCtx{nullptr};
293
294 TObject *obj = (TObject *)obj_ptr;
295
297 sbuf->SetParent(fMemFile);
298 sbuf->MapObject(obj);
299 obj->Streamer(*sbuf);
300 if (fCurrentArg)
301 fCurrentArg->SetExtraHeader("RootClassName", obj_cl->GetName());
302
303 // produce actual version of streamer info
304 delete fSinfo;
307
308 res.resize(sbuf->Length());
309 std::copy((const char *)sbuf->Buffer(), (const char *)sbuf->Buffer() + sbuf->Length(), res.begin());
310
311 delete sbuf;
312
313 return kTRUE;
314}
315
316////////////////////////////////////////////////////////////////////////////////
317/// Produce ROOT file for specified item
318///
319/// File created in memory using TMemFile class.
320
321Bool_t TRootSnifferFull::ProduceRootFile(const std::string &path, const std::string & /*query*/, std::string &res)
322{
323 if (path.empty())
324 return kFALSE;
325
326 const char *path_ = path.c_str();
327 if (*path_ == '/')
328 path_++;
329
330 TClass *obj_cl = nullptr;
332 if (!obj_ptr || !obj_cl)
333 return kFALSE;
334
335 const char *store_name = "object";
336
337 if (obj_cl->GetBaseClassOffset(TNamed::Class()) == 0) {
338 const char *obj_name = ((TNamed *) obj_ptr)->GetName();
339 if (obj_name && *obj_name)
341 }
342
344 struct RestoreGFile {
347 } restoreGFile;
348
349 {
350 TMemFile memfile("dummy.file", "RECREATE",
351 TString::Format("Object %s", path.c_str()),
353 gROOT->GetListOfFiles()->Remove(&memfile);
354
355 memfile.WriteObjectAny(obj_ptr, obj_cl, store_name);
356 memfile.Close();
357
358 res.resize(memfile.GetSize());
359 memfile.CopyTo(res.data(), memfile.GetSize());
360 }
361
362 return kTRUE;
363}
364
365
366////////////////////////////////////////////////////////////////////////////////
367/// Method to produce image from specified object
368///
369/// @param kind image kind TImage::kPng, TImage::kJpeg, TImage::kGif
370/// @param path path to object
371/// @param options extra options
372/// @param res std::string with binary data
373///
374/// By default, image 300x200 is produced
375/// In options string one could provide following parameters:
376///
377/// * w - image width
378/// * h - image height
379/// * opt - draw options
380///
381/// For instance:
382///
383/// http://localhost:8080/Files/hsimple.root/hpx/get.png?w=500&h=500&opt=lego1
384
385Bool_t TRootSnifferFull::ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res)
386{
387 if (path.empty())
388 return kFALSE;
389
390 const char *path_ = path.c_str();
391 if (*path_ == '/')
392 path_++;
393
394 TClass *obj_cl(nullptr);
396 if (!obj_ptr || !obj_cl)
397 return kFALSE;
398
399 if (obj_cl->GetBaseClassOffset(TObject::Class()) != 0) {
400 Error("TRootSniffer", "Only derived from TObject classes can be drawn");
401 return kFALSE;
402 }
403
404 TObject *obj = (TObject *)obj_ptr;
405
407 if (!img)
408 return kFALSE;
409
410 if (obj->InheritsFrom(TPad::Class())) {
411
412 if (gDebug > 1)
413 Info("TRootSniffer", "Crate IMAGE directly from pad");
414 img->FromPad((TPad *)obj);
415 } else if (CanDrawClass(obj->IsA())) {
416
417 if (gDebug > 1)
418 Info("TRootSniffer", "Crate IMAGE from object %s", obj->GetName());
419
420 Int_t width = 300, height = 200;
421 TString drawopt;
422
423 if (!options.empty()) {
424 TUrl url;
425 url.SetOptions(options.c_str());
426 url.ParseOptions();
427 Int_t w = url.GetIntValueFromOptions("w");
428 if (w > 10)
429 width = w;
430 Int_t h = url.GetIntValueFromOptions("h");
431 if (h > 10)
432 height = h;
433 drawopt = DecodeUrlOptionValue(url.GetValueFromOptions("opt"), kTRUE);
434 }
435
436 Bool_t isbatch = gROOT->IsBatch();
438
439 if (!isbatch)
440 gROOT->SetBatch(kTRUE);
441
442 TCanvas *c1 = new TCanvas("__online_draw_canvas__", "title", width, height);
443 obj->Draw(drawopt.Data());
444 img->FromPad(c1);
445 delete c1;
446
447 if (!isbatch)
448 gROOT->SetBatch(kFALSE);
449
450 } else {
451 delete img;
452 return kFALSE;
453 }
454
456 im->Append(img);
457
458 char *png_buffer = nullptr;
459 int size(0);
460
461 im->GetImageBuffer(&png_buffer, &size, (TImage::EImageFileTypes)kind);
462
463 if (png_buffer && (size > 0)) {
464 res.resize(size);
465 memcpy((void *)res.data(), png_buffer, size);
466 }
467
469 delete im;
470
471 return !res.empty();
472}
473
474////////////////////////////////////////////////////////////////////////////////
475/// Invokes TRootSniffer::ProduceIamge, converting kind into TImage::EImageFileTypes type
476
477Bool_t TRootSnifferFull::CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res)
478{
479 if (kind == "png")
480 return ProduceImage(TImage::kPng, path, options, res);
481
482 if (kind == "jpeg")
483 return ProduceImage(TImage::kJpeg, path, options, res);
484
485 if (kind == "gif")
486 return ProduceImage(TImage::kGif, path, options, res);
487
488 return kFALSE;
489}
490
491////////////////////////////////////////////////////////////////////////////////
492/// Produce XML data for specified item
493///
494/// For object conversion TBufferXML is used
495
496Bool_t TRootSnifferFull::ProduceXml(const std::string &path, const std::string & /*options*/, std::string &res)
497{
498 if (path.empty())
499 return kFALSE;
500 const char *path_ = path.c_str();
501 if (*path_ == '/')
502 path_++;
503
504 TClass *obj_cl = nullptr;
506 if (!obj_ptr || !obj_cl)
507 return kFALSE;
508
509 // TODO: support std::string in TBufferXML
511
512 return !res.empty();
513}
514
515////////////////////////////////////////////////////////////////////////////////
516/// Execute command for specified object
517///
518/// @param path the object path
519/// @param options include method and extra list of parameters
520/// sniffer should be not-readonly to allow execution of the commands
521/// @param reskind defines kind of result 0 - debug, 1 - json, 2 - binary
522/// @param res_str result string
523
524Bool_t TRootSnifferFull::ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res_str)
525{
526 std::string *debug = (reskind == 0) ? &res_str : nullptr;
527
528 if (path.empty()) {
529 if (debug)
530 debug->append("Item name not specified\n");
531 return debug != nullptr;
532 }
533
534 const char *path_ = path.c_str();
535 if (*path_ == '/')
536 path_++;
537
538 TClass *obj_cl = nullptr;
540 if (debug)
541 debug->append(TString::Format("Item:%s found:%s\n", path_, obj_ptr ? "true" : "false").Data());
542 if (!obj_ptr || !obj_cl)
543 return debug != nullptr;
544
545 TUrl url;
546 url.SetOptions(options.c_str());
547
548 const char *method_name = url.GetValueFromOptions("method");
549 TString prototype = DecodeUrlOptionValue(url.GetValueFromOptions("prototype"), kTRUE);
550 TString funcname = DecodeUrlOptionValue(url.GetValueFromOptions("func"), kTRUE);
551 TMethod *method = nullptr;
552 TFunction *func = nullptr;
553 if (method_name) {
554 if (prototype.Length() == 0) {
555 if (debug)
556 debug->append(TString::Format("Search for any method with name \'%s\'\n", method_name).Data());
557 method = obj_cl->GetMethodAllAny(method_name);
558 } else {
559 if (debug)
560 debug->append(
561 TString::Format("Search for method \'%s\' with prototype \'%s\'\n", method_name, prototype.Data())
562 .Data());
563 method = obj_cl->GetMethodWithPrototype(method_name, prototype);
564 }
565 }
566
567 if (method) {
568 if (debug)
569 debug->append(TString::Format("Method: %s\n", method->GetPrototype()).Data());
570 } else {
571 if (funcname.Length() > 0) {
572 if (prototype.Length() == 0) {
573 if (debug)
574 debug->append(TString::Format("Search for any function with name \'%s\'\n", funcname.Data()).Data());
575 func = gROOT->GetGlobalFunction(funcname);
576 } else {
577 if (debug)
578 debug->append(TString::Format("Search for function \'%s\' with prototype \'%s\'\n", funcname.Data(),
579 prototype.Data())
580 .Data());
581 func = gROOT->GetGlobalFunctionWithPrototype(funcname, prototype);
582 }
583 }
584
585 if (func && debug)
586 debug->append(TString::Format("Function: %s\n", func->GetPrototype()).Data());
587 }
588
589 if (!method && !func) {
590 if (debug)
591 debug->append("Method not found\n");
592 return debug != nullptr;
593 }
594
595 if ((fReadOnly && (fCurrentRestrict == 0)) || (fCurrentRestrict == 1)) {
596 if ((method != nullptr) && (fCurrentAllowedMethods.Index(method_name) == kNPOS)) {
597 if (debug)
598 debug->append("Server runs in read-only mode, method cannot be executed\n");
599 return debug != nullptr;
600 } else if ((func != nullptr) && (fCurrentAllowedMethods.Index(funcname) == kNPOS)) {
601 if (debug)
602 debug->append("Server runs in read-only mode, function cannot be executed\n");
603 return debug != nullptr;
604 } else {
605 if (debug)
606 debug->append("For that special method server allows access even read-only mode is specified\n");
607 }
608 }
609
610 TList *args = method ? method->GetListOfMethodArgs() : func->GetListOfMethodArgs();
611
613 garbage.SetOwner(kTRUE); // use as garbage collection
614 TObject *post_obj = nullptr; // object reconstructed from post request
616
617 TIter next(args);
618 while (auto arg = static_cast<TMethodArg *>(next())) {
619
620 if ((strcmp(arg->GetName(), "rest_url_opt") == 0) && (strcmp(arg->GetFullTypeName(), "const char*") == 0) &&
621 (args->GetSize() == 1)) {
622 // very special case - function requires list of options after method=argument
623
624 const char *pos = strstr(options.c_str(), "method=");
625 if (!pos || (strlen(pos) < strlen(method_name) + 7))
626 return debug != nullptr;
627 const char *rest_url = pos + strlen(method_name) + 7;
628 if (*rest_url == '&') ++rest_url;
629 call_args.Append("\"");
631 call_args.Append("\"");
632 break;
633 }
634
636 const char *val = url.GetValueFromOptions(arg->GetName());
637 if (val)
639
641
642 if (sval == "_this_") {
643 // special case - object itself is used as argument
644 sval.Form("(%s*)0x%zx", obj_cl->GetName(), (size_t)obj_ptr);
645 } else if ((fCurrentArg != nullptr) && (fCurrentArg->GetPostData() != nullptr)) {
646 // process several arguments which are specific for post requests
647 if (fAllowPostObject && (sval == "_post_object_xml_")) {
648 // post data has extra 0 at the end and can be used as null-terminated string
650 if (!post_obj)
651 sval = "0";
652 else {
653 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
654 if (url.HasOption("_destroy_post_"))
655 garbage.Add(post_obj);
656 }
657 } else if (fAllowPostObject && (sval == "_post_object_json_")) {
658 // post data has extra 0 at the end and can be used as null-terminated string
660 if (!post_obj)
661 sval = "0";
662 else {
663 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
664 if (url.HasOption("_destroy_post_"))
665 garbage.Add(post_obj);
666 }
667 } else if (fAllowPostObject && (sval == "_post_object_") && url.HasOption("_post_class_")) {
668 TString clname = DecodeUrlOptionValue(url.GetValueFromOptions("_post_class_"), kTRUE);
669 TClass *arg_cl = gROOT->GetClass(clname, kTRUE, kTRUE);
670 if ((arg_cl != nullptr) && (arg_cl->GetBaseClassOffset(TObject::Class()) == 0) && (post_obj == nullptr)) {
671 post_obj = (TObject *)arg_cl->New();
672 if (post_obj == nullptr) {
673 if (debug)
674 debug->append(TString::Format("Fail to create object of class %s\n", clname.Data()).Data());
675 } else {
676 if (debug)
677 debug->append(TString::Format("Reconstruct object of class %s from POST data\n", clname.Data()).Data());
680 post_obj->Streamer(buf);
681 if (url.HasOption("_destroy_post_"))
682 garbage.Add(post_obj);
683 }
684 }
685 if (!post_obj)
686 sval = "0";
687 else
688 sval.Form("(%s*)0x%zx", clname.Data(), (size_t)post_obj);
689 } else if (sval == "_post_data_")
690 sval.Form("(void*)0x%zx", (size_t)fCurrentArg->GetPostData());
691 else if (sval == "_post_length_")
692 sval.Form("%ld", (long)fCurrentArg->GetPostDataLength());
693 else
695 } else
697
698 if (sval.IsNull() && arg->GetDefault())
699 sval = arg->GetDefault();
700
701 if (debug)
702 debug->append(
703 TString::Format(" Argument:%s Type:%s Value:%s \n", arg->GetName(), arg->GetFullTypeName(), sval.Data())
704 .Data());
705
706 if (call_args.Length() > 0)
707 call_args += ", ";
708
709 Bool_t isstr = (strcmp(arg->GetFullTypeName(), "const char*") == 0) ||
710 (strcmp(arg->GetFullTypeName(), "Option_t*") == 0) ||
711 (strcmp(arg->GetFullTypeName(), "string") == 0);
712
713 if (isstr) {
714 // check that quotes provided for the string argument
715 // all special characters were escaped before
716 if (sval.IsNull())
717 sval = "\"\"";
718 else {
719 if (sval[0] != '"')
720 sval.Prepend("\"");
721 if (sval[sval.Length() - 1] != '"')
722 sval.Append("\"");
723 }
724 } else {
725 // for numeric types keep only numeric and alphabetic characters
726 // exclude others - especially remove all escape characters
727 if (sanitize_numeric) {
729 for(Size_t i = 0; i < sval.Length(); ++i) {
730 if (std::isalnum(sval[i]) || std::strchr(".:+-", sval[i]))
731 sanitized.Append(sval[i]);
732 }
733 sval = sanitized;
734 }
735 if (sval.IsNull())
736 sval = "0";
737 }
738
739 call_args.Append(sval);
740 }
741
742 TMethodCall *call = nullptr;
743
744 if (method != nullptr) {
745 call = new TMethodCall(obj_cl, method_name, call_args.Data());
746 if (debug)
747 debug->append(TString::Format("Calling obj->%s(%s);\n", method_name, call_args.Data()).Data());
748 } else {
749 call = new TMethodCall(funcname.Data(), call_args.Data());
750 if (debug)
751 debug->append(TString::Format("Calling %s(%s);\n", funcname.Data(), call_args.Data()).Data());
752 }
753
754 garbage.Add(call);
755
756 if (!call->IsValid()) {
757 if (debug)
758 debug->append("Fail: invalid TMethodCall\n");
759 return debug != nullptr;
760 }
761
762 Int_t compact = 0;
763 if (url.GetValueFromOptions("compact"))
764 compact = url.GetIntValueFromOptions("compact");
765
766 TString res = "null";
767 void *ret_obj = nullptr;
768 TClass *ret_cl = nullptr;
769 TBufferFile *resbuf = nullptr;
770 if (reskind == 2) {
771 resbuf = new TBufferFile(TBuffer::kWrite, 10000);
772 garbage.Add(resbuf);
773 }
774
775 switch (call->ReturnType()) {
776 case TMethodCall::kLong: {
777 Longptr_t l(0);
778 if (method)
779 call->Execute(obj_ptr, l);
780 else
781 call->Execute(l);
782 if (resbuf)
783 resbuf->WriteLong(l);
784 else
785 res.Form("%zd", (size_t)l);
786 break;
787 }
789 Double_t d(0.);
790 if (method)
791 call->Execute(obj_ptr, d);
792 else
793 call->Execute(d);
794 if (resbuf)
795 resbuf->WriteDouble(d);
796 else
798 break;
799 }
801 char *txt = nullptr;
802 if (method)
803 call->Execute(obj_ptr, &txt);
804 else
805 call->Execute(&txt);
806 if (txt != nullptr) {
807 if (resbuf)
808 resbuf->WriteString(txt);
809 else
810 res.Form("\"%s\"", txt);
811 }
812 break;
813 }
814 case TMethodCall::kOther: {
815 std::string ret_kind = func ? func->GetReturnTypeNormalizedName() : method->GetReturnTypeNormalizedName();
816 if ((ret_kind.length() > 0) && (ret_kind[ret_kind.length() - 1] == '*')) {
817 ret_kind.resize(ret_kind.length() - 1);
818 ret_cl = gROOT->GetClass(ret_kind.c_str(), kTRUE, kTRUE);
819 }
820
821 if (ret_cl != nullptr) {
822 Longptr_t l(0);
823 if (method)
824 call->Execute(obj_ptr, l);
825 else
826 call->Execute(l);
827 if (l != 0)
828 ret_obj = (void *)l;
829 } else {
830 if (method)
831 call->Execute(obj_ptr);
832 else
833 call->Execute();
834 }
835
836 break;
837 }
838 case TMethodCall::kNone: {
839 if (method)
840 call->Execute(obj_ptr);
841 else
842 call->Execute();
843 break;
844 }
845 }
846
847 const char *_ret_object_ = url.GetValueFromOptions("_ret_object_");
848 if (_ret_object_ != nullptr) {
849 TObject *obj = nullptr;
850 if (gDirectory)
851 obj = gDirectory->Get(_ret_object_);
852 if (debug)
853 debug->append(TString::Format("Return object %s found %s\n", _ret_object_, obj ? "true" : "false").Data());
854
855 if (obj == nullptr) {
856 res = "null";
857 } else {
858 ret_obj = obj;
859 ret_cl = obj->IsA();
860 }
861 }
862
863 if (ret_obj && ret_cl) {
864 if ((resbuf != nullptr) && (ret_cl->GetBaseClassOffset(TObject::Class()) == 0)) {
865 TObject *obj = (TObject *)ret_obj;
866 resbuf->MapObject(obj);
867 obj->Streamer(*resbuf);
868 if (fCurrentArg)
869 fCurrentArg->SetExtraHeader("RootClassName", ret_cl->GetName());
870 } else {
872 }
873 }
874
875 if ((resbuf != nullptr) && (resbuf->Length() > 0)) {
876 res_str.resize(resbuf->Length());
877 std::copy((const char *)resbuf->Buffer(), (const char *)resbuf->Buffer() + resbuf->Length(), res_str.begin());
878 }
879
880 if (debug)
881 debug->append(TString::Format("Result = %s\n", res.Data()).Data());
882
883 if (reskind == 1)
884 res_str = res.Data();
885
886 if (url.HasOption("_destroy_result_") && ret_obj && ret_cl) {
887 ret_cl->Destructor(ret_obj);
888 if (debug)
889 debug->append("Destroy result object at the end\n");
890 }
891
892 // delete all garbage objects, but should be also done with any return
893 garbage.Delete();
894
895 return kTRUE;
896}
#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
Attribute size (float)
Definition RtypesCore.h:103
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
Definition RtypesCore.h:131
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define gDirectory
Definition TDirectory.h:385
#define gFile
Definition TFile.h:439
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:148
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
Definition TROOT.cxx:777
#define gROOT
Definition TROOT.h:417
#define free
Definition civetweb.c:1578
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:4932
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:2994
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
TDirectory::TContext keeps track and restore the current directory.
Definition TDirectory.h:89
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:283
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
Definition TFile.h:130
virtual void WriteStreamerInfo()
Write the list of TStreamerInfo as a single object in this file The class Streamer description for al...
Definition TFile.cxx:3490
virtual TList * GetStreamerInfoList() final
Read the list of TStreamerInfo objects written to this file.
Definition TFile.cxx:1457
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:2426
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:878
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:34
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:77
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition TKey.cxx:804
static TClass * Class()
A doubly linked list.
Definition TList.h:38
TClass * IsA() const override
Definition TList.h:115
A TMemFile is like a normal TFile except that it reads and writes only from memory.
Definition TMemFile.h:27
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:42
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:462
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:997
static TClass * Class()
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:549
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1098
virtual TClass * IsA() const
Definition TObject.h:248
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:293
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1072
The most important graphics class in the ROOT system.
Definition TPad.h:28
static TClass * Class()
static TClass * Class()
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:138
const char * Data() const
Definition TString.h:384
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:2385
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2363
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition TString.h:660
A TTree represents a columnar dataset.
Definition TTree.h:89
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
return c1
Definition legend1.C:41
TGraphErrors * gr
Definition legend1.C:25
@ kUseCompiledDefault
Use the compile-time default setting.
Definition Compression.h:53
TLine l
Definition textangle.C:4