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 const char *opt = url.GetValueFromOptions("opt");
446 if (opt)
447 drawopt = opt;
448 }
449
450 Bool_t isbatch = gROOT->IsBatch();
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
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
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;
520 if (!obj_ptr || !obj_cl)
521 return kFALSE;
522
523 // TODO: support std::string in TBufferXML
525
526 return !res.empty();
527}
528
529////////////////////////////////////////////////////////////////////////////////
530/// Execute command for specified object
531///
532/// @param path the object path
533/// @param options include method and extra list of parameters
534/// sniffer should be not-readonly to allow execution of the commands
535/// @param reskind defines kind of result 0 - debug, 1 - json, 2 - binary
536/// @param res_str result string
537
538Bool_t TRootSnifferFull::ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res_str)
539{
540 std::string *debug = (reskind == 0) ? &res_str : nullptr;
541
542 if (path.empty()) {
543 if (debug)
544 debug->append("Item name not specified\n");
545 return debug != nullptr;
546 }
547
548 const char *path_ = path.c_str();
549 if (*path_ == '/')
550 path_++;
551
552 TClass *obj_cl = nullptr;
554 if (debug)
555 debug->append(TString::Format("Item:%s found:%s\n", path_, obj_ptr ? "true" : "false").Data());
556 if (!obj_ptr || !obj_cl)
557 return debug != nullptr;
558
559 TUrl url;
560 url.SetOptions(options.c_str());
561
562 const char *method_name = url.GetValueFromOptions("method");
563 TString prototype = DecodeUrlOptionValue(url.GetValueFromOptions("prototype"), kTRUE);
564 TString funcname = DecodeUrlOptionValue(url.GetValueFromOptions("func"), kTRUE);
565 TMethod *method = nullptr;
566 TFunction *func = nullptr;
567 if (method_name) {
568 if (prototype.Length() == 0) {
569 if (debug)
570 debug->append(TString::Format("Search for any method with name \'%s\'\n", method_name).Data());
571 method = obj_cl->GetMethodAllAny(method_name);
572 } else {
573 if (debug)
574 debug->append(
575 TString::Format("Search for method \'%s\' with prototype \'%s\'\n", method_name, prototype.Data())
576 .Data());
577 method = obj_cl->GetMethodWithPrototype(method_name, prototype);
578 }
579 }
580
581 if (method) {
582 if (debug)
583 debug->append(TString::Format("Method: %s\n", method->GetPrototype()).Data());
584 } else {
585 if (funcname.Length() > 0) {
586 if (prototype.Length() == 0) {
587 if (debug)
588 debug->append(TString::Format("Search for any function with name \'%s\'\n", funcname.Data()).Data());
589 func = gROOT->GetGlobalFunction(funcname);
590 } else {
591 if (debug)
592 debug->append(TString::Format("Search for function \'%s\' with prototype \'%s\'\n", funcname.Data(),
593 prototype.Data())
594 .Data());
595 func = gROOT->GetGlobalFunctionWithPrototype(funcname, prototype);
596 }
597 }
598
599 if (func && debug)
600 debug->append(TString::Format("Function: %s\n", func->GetPrototype()).Data());
601 }
602
603 if (!method && !func) {
604 if (debug)
605 debug->append("Method not found\n");
606 return debug != nullptr;
607 }
608
609 if ((fReadOnly && (fCurrentRestrict == 0)) || (fCurrentRestrict == 1)) {
610 if ((method != nullptr) && (fCurrentAllowedMethods.Index(method_name) == kNPOS)) {
611 if (debug)
612 debug->append("Server runs in read-only mode, method cannot be executed\n");
613 return debug != nullptr;
614 } else if ((func != nullptr) && (fCurrentAllowedMethods.Index(funcname) == kNPOS)) {
615 if (debug)
616 debug->append("Server runs in read-only mode, function cannot be executed\n");
617 return debug != nullptr;
618 } else {
619 if (debug)
620 debug->append("For that special method server allows access even read-only mode is specified\n");
621 }
622 }
623
624 TList *args = method ? method->GetListOfMethodArgs() : func->GetListOfMethodArgs();
625
627 garbage.SetOwner(kTRUE); // use as garbage collection
628 TObject *post_obj = nullptr; // object reconstructed from post request
630
631 TIter next(args);
632 while (auto arg = static_cast<TMethodArg *>(next())) {
633
634 if ((strcmp(arg->GetName(), "rest_url_opt") == 0) && (strcmp(arg->GetFullTypeName(), "const char*") == 0) &&
635 (args->GetSize() == 1)) {
636 // very special case - function requires list of options after method=argument
637
638 const char *pos = strstr(options.c_str(), "method=");
639 if (!pos || (strlen(pos) < strlen(method_name) + 7))
640 return debug != nullptr;
641 const char *rest_url = pos + strlen(method_name) + 7;
642 if (*rest_url == '&') ++rest_url;
643 call_args.Form("\"%s\"", rest_url);
644 break;
645 }
646
648 const char *val = url.GetValueFromOptions(arg->GetName());
649 if (val) {
651 val = sval.Data();
652 }
653
654 if ((val != nullptr) && (strcmp(val, "_this_") == 0)) {
655 // special case - object itself is used as argument
656 sval.Form("(%s*)0x%zx", obj_cl->GetName(), (size_t)obj_ptr);
657 val = sval.Data();
658 } else if ((val != nullptr) && (fCurrentArg != nullptr) && (fCurrentArg->GetPostData() != nullptr)) {
659 // process several arguments which are specific for post requests
660 if (strcmp(val, "_post_object_xml_") == 0) {
661 // post data has extra 0 at the end and can be used as null-terminated string
663 if (!post_obj) {
664 sval = "0";
665 } else {
666 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
667 if (url.HasOption("_destroy_post_"))
668 garbage.Add(post_obj);
669 }
670 val = sval.Data();
671 } else if (strcmp(val, "_post_object_json_") == 0) {
672 // post data has extra 0 at the end and can be used as null-terminated string
674 if (!post_obj) {
675 sval = "0";
676 } else {
677 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
678 if (url.HasOption("_destroy_post_"))
679 garbage.Add(post_obj);
680 }
681 val = sval.Data();
682 } else if ((strcmp(val, "_post_object_") == 0) && url.HasOption("_post_class_")) {
683 TString clname = url.GetValueFromOptions("_post_class_");
684 TClass *arg_cl = gROOT->GetClass(clname, kTRUE, kTRUE);
685 if ((arg_cl != nullptr) && (arg_cl->GetBaseClassOffset(TObject::Class()) == 0) && (post_obj == nullptr)) {
686 post_obj = (TObject *)arg_cl->New();
687 if (post_obj == nullptr) {
688 if (debug)
689 debug->append(TString::Format("Fail to create object of class %s\n", clname.Data()).Data());
690 } else {
691 if (debug)
692 debug->append(TString::Format("Reconstruct object of class %s from POST data\n", clname.Data()).Data());
695 post_obj->Streamer(buf);
696 if (url.HasOption("_destroy_post_"))
697 garbage.Add(post_obj);
698 }
699 }
700 sval.Form("(%s*)0x%zx", clname.Data(), (size_t)post_obj);
701 val = sval.Data();
702 } else if (strcmp(val, "_post_data_") == 0) {
703 sval.Form("(void*)0x%zx", (size_t)fCurrentArg->GetPostData());
704 val = sval.Data();
705 } else if (strcmp(val, "_post_length_") == 0) {
706 sval.Form("%ld", (long)fCurrentArg->GetPostDataLength());
707 val = sval.Data();
708 }
709 }
710
711 if (!val)
712 val = arg->GetDefault();
713
714 if (debug)
715 debug->append(TString::Format(" Argument:%s Type:%s Value:%s \n", arg->GetName(), arg->GetFullTypeName(),
716 val ? val : "<missed>")
717 .Data());
718 if (!val)
719 return debug != nullptr;
720
721 if (call_args.Length() > 0)
722 call_args += ", ";
723
724 if ((strcmp(arg->GetFullTypeName(), "const char*") == 0) || (strcmp(arg->GetFullTypeName(), "Option_t*") == 0)) {
725 int len = strlen(val);
726 if ((strlen(val) < 2) || (*val != '\"') || (val[len - 1] != '\"'))
727 call_args.Append(TString::Format("\"%s\"", val));
728 else
729 call_args.Append(val);
730 } else {
731 call_args.Append(val);
732 }
733 }
734
735 TMethodCall *call = nullptr;
736
737 if (method != nullptr) {
738 call = new TMethodCall(obj_cl, method_name, call_args.Data());
739 if (debug)
740 debug->append(TString::Format("Calling obj->%s(%s);\n", method_name, call_args.Data()).Data());
741 } else {
742 call = new TMethodCall(funcname.Data(), call_args.Data());
743 if (debug)
744 debug->append(TString::Format("Calling %s(%s);\n", funcname.Data(), call_args.Data()).Data());
745 }
746
747 garbage.Add(call);
748
749 if (!call->IsValid()) {
750 if (debug)
751 debug->append("Fail: invalid TMethodCall\n");
752 return debug != nullptr;
753 }
754
755 Int_t compact = 0;
756 if (url.GetValueFromOptions("compact"))
757 compact = url.GetIntValueFromOptions("compact");
758
759 TString res = "null";
760 void *ret_obj = nullptr;
761 TClass *ret_cl = nullptr;
762 TBufferFile *resbuf = nullptr;
763 if (reskind == 2) {
764 resbuf = new TBufferFile(TBuffer::kWrite, 10000);
765 garbage.Add(resbuf);
766 }
767
768 switch (call->ReturnType()) {
769 case TMethodCall::kLong: {
770 Longptr_t l(0);
771 if (method)
772 call->Execute(obj_ptr, l);
773 else
774 call->Execute(l);
775 if (resbuf)
776 resbuf->WriteLong(l);
777 else
778 res.Form("%zd", (size_t)l);
779 break;
780 }
782 Double_t d(0.);
783 if (method)
784 call->Execute(obj_ptr, d);
785 else
786 call->Execute(d);
787 if (resbuf)
788 resbuf->WriteDouble(d);
789 else
791 break;
792 }
794 char *txt = nullptr;
795 if (method)
796 call->Execute(obj_ptr, &txt);
797 else
798 call->Execute(0, &txt); // here 0 is artificial, there is no proper signature
799 if (txt != nullptr) {
800 if (resbuf)
801 resbuf->WriteString(txt);
802 else
803 res.Form("\"%s\"", txt);
804 }
805 break;
806 }
807 case TMethodCall::kOther: {
808 std::string ret_kind = func ? func->GetReturnTypeNormalizedName() : method->GetReturnTypeNormalizedName();
809 if ((ret_kind.length() > 0) && (ret_kind[ret_kind.length() - 1] == '*')) {
810 ret_kind.resize(ret_kind.length() - 1);
811 ret_cl = gROOT->GetClass(ret_kind.c_str(), kTRUE, kTRUE);
812 }
813
814 if (ret_cl != nullptr) {
815 Longptr_t l(0);
816 if (method)
817 call->Execute(obj_ptr, l);
818 else
819 call->Execute(l);
820 if (l != 0)
821 ret_obj = (void *)l;
822 } else {
823 if (method)
824 call->Execute(obj_ptr);
825 else
826 call->Execute();
827 }
828
829 break;
830 }
831 case TMethodCall::kNone: {
832 if (method)
833 call->Execute(obj_ptr);
834 else
835 call->Execute();
836 break;
837 }
838 }
839
840 const char *_ret_object_ = url.GetValueFromOptions("_ret_object_");
841 if (_ret_object_ != nullptr) {
842 TObject *obj = nullptr;
843 if (gDirectory)
844 obj = gDirectory->Get(_ret_object_);
845 if (debug)
846 debug->append(TString::Format("Return object %s found %s\n", _ret_object_, obj ? "true" : "false").Data());
847
848 if (obj == nullptr) {
849 res = "null";
850 } else {
851 ret_obj = obj;
852 ret_cl = obj->IsA();
853 }
854 }
855
856 if (ret_obj && ret_cl) {
857 if ((resbuf != nullptr) && (ret_cl->GetBaseClassOffset(TObject::Class()) == 0)) {
858 TObject *obj = (TObject *)ret_obj;
859 resbuf->MapObject(obj);
860 obj->Streamer(*resbuf);
861 if (fCurrentArg)
862 fCurrentArg->SetExtraHeader("RootClassName", ret_cl->GetName());
863 } else {
865 }
866 }
867
868 if ((resbuf != nullptr) && (resbuf->Length() > 0)) {
869 res_str.resize(resbuf->Length());
870 std::copy((const char *)resbuf->Buffer(), (const char *)resbuf->Buffer() + resbuf->Length(), res_str.begin());
871 }
872
873 if (debug)
874 debug->append(TString::Format("Result = %s\n", res.Data()).Data());
875
876 if (reskind == 1)
877 res_str = res.Data();
878
879 if (url.HasOption("_destroy_result_") && ret_obj && ret_cl) {
880 ret_cl->Destructor(ret_obj);
881 if (debug)
882 debug->append("Destroy result object at the end\n");
883 }
884
885 // delete all garbage objects, but should be also done with any return
886 garbage.Delete();
887
888 return kTRUE;
889}
#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: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 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: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 ROOT file is an on-disk file, usually with extension .root, that stores objects in a file-system-li...
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:3834
virtual TList * GetStreamerInfoList() final
Read the list of TStreamerInfo objects written to this file.
Definition TFile.cxx:1450
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:758
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.
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