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 gROOT->GetListOfFiles()->Remove(&memfile);
352
353 memfile.WriteObjectAny(obj_ptr, obj_cl, store_name);
354 memfile.Close();
355
356 res.resize(memfile.GetSize());
357 memfile.CopyTo(res.data(), memfile.GetSize());
358 }
359
360 return kTRUE;
361}
362
363
364////////////////////////////////////////////////////////////////////////////////
365/// Method to produce image from specified object
366///
367/// @param kind image kind TImage::kPng, TImage::kJpeg, TImage::kGif
368/// @param path path to object
369/// @param options extra options
370/// @param res std::string with binary data
371///
372/// By default, image 300x200 is produced
373/// In options string one could provide following parameters:
374///
375/// * w - image width
376/// * h - image height
377/// * opt - draw options
378///
379/// For instance:
380///
381/// http://localhost:8080/Files/hsimple.root/hpx/get.png?w=500&h=500&opt=lego1
382
383Bool_t TRootSnifferFull::ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res)
384{
385 if (path.empty())
386 return kFALSE;
387
388 const char *path_ = path.c_str();
389 if (*path_ == '/')
390 path_++;
391
392 TClass *obj_cl(nullptr);
394 if (!obj_ptr || !obj_cl)
395 return kFALSE;
396
397 if (obj_cl->GetBaseClassOffset(TObject::Class()) != 0) {
398 Error("TRootSniffer", "Only derived from TObject classes can be drawn");
399 return kFALSE;
400 }
401
402 TObject *obj = (TObject *)obj_ptr;
403
405 if (!img)
406 return kFALSE;
407
408 if (obj->InheritsFrom(TPad::Class())) {
409
410 if (gDebug > 1)
411 Info("TRootSniffer", "Crate IMAGE directly from pad");
412 img->FromPad((TPad *)obj);
413 } else if (CanDrawClass(obj->IsA())) {
414
415 if (gDebug > 1)
416 Info("TRootSniffer", "Crate IMAGE from object %s", obj->GetName());
417
418 Int_t width = 300, height = 200;
419 TString drawopt;
420
421 if (!options.empty()) {
422 TUrl url;
423 url.SetOptions(options.c_str());
424 url.ParseOptions();
425 Int_t w = url.GetIntValueFromOptions("w");
426 if (w > 10)
427 width = w;
428 Int_t h = url.GetIntValueFromOptions("h");
429 if (h > 10)
430 height = h;
431 drawopt = DecodeUrlOptionValue(url.GetValueFromOptions("opt"), kTRUE);
432 }
433
434 Bool_t isbatch = gROOT->IsBatch();
436
437 if (!isbatch)
438 gROOT->SetBatch(kTRUE);
439
440 TCanvas *c1 = new TCanvas("__online_draw_canvas__", "title", width, height);
441 obj->Draw(drawopt.Data());
442 img->FromPad(c1);
443 delete c1;
444
445 if (!isbatch)
446 gROOT->SetBatch(kFALSE);
447
448 } else {
449 delete img;
450 return kFALSE;
451 }
452
454 im->Append(img);
455
456 char *png_buffer = nullptr;
457 int size(0);
458
459 im->GetImageBuffer(&png_buffer, &size, (TImage::EImageFileTypes)kind);
460
461 if (png_buffer && (size > 0)) {
462 res.resize(size);
463 memcpy((void *)res.data(), png_buffer, size);
464 }
465
467 delete im;
468
469 return !res.empty();
470}
471
472////////////////////////////////////////////////////////////////////////////////
473/// Invokes TRootSniffer::ProduceIamge, converting kind into TImage::EImageFileTypes type
474
475Bool_t TRootSnifferFull::CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res)
476{
477 if (kind == "png")
478 return ProduceImage(TImage::kPng, path, options, res);
479
480 if (kind == "jpeg")
481 return ProduceImage(TImage::kJpeg, path, options, res);
482
483 if (kind == "gif")
484 return ProduceImage(TImage::kGif, path, options, res);
485
486 return kFALSE;
487}
488
489////////////////////////////////////////////////////////////////////////////////
490/// Produce XML data for specified item
491///
492/// For object conversion TBufferXML is used
493
494Bool_t TRootSnifferFull::ProduceXml(const std::string &path, const std::string & /*options*/, std::string &res)
495{
496 if (path.empty())
497 return kFALSE;
498 const char *path_ = path.c_str();
499 if (*path_ == '/')
500 path_++;
501
502 TClass *obj_cl = nullptr;
504 if (!obj_ptr || !obj_cl)
505 return kFALSE;
506
507 // TODO: support std::string in TBufferXML
509
510 return !res.empty();
511}
512
513////////////////////////////////////////////////////////////////////////////////
514/// Execute command for specified object
515///
516/// @param path the object path
517/// @param options include method and extra list of parameters
518/// sniffer should be not-readonly to allow execution of the commands
519/// @param reskind defines kind of result 0 - debug, 1 - json, 2 - binary
520/// @param res_str result string
521
522Bool_t TRootSnifferFull::ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res_str)
523{
524 std::string *debug = (reskind == 0) ? &res_str : nullptr;
525
526 if (path.empty()) {
527 if (debug)
528 debug->append("Item name not specified\n");
529 return debug != nullptr;
530 }
531
532 const char *path_ = path.c_str();
533 if (*path_ == '/')
534 path_++;
535
536 TClass *obj_cl = nullptr;
538 if (debug)
539 debug->append(TString::Format("Item:%s found:%s\n", path_, obj_ptr ? "true" : "false").Data());
540 if (!obj_ptr || !obj_cl)
541 return debug != nullptr;
542
543 TUrl url;
544 url.SetOptions(options.c_str());
545
546 const char *method_name = url.GetValueFromOptions("method");
547 TString prototype = DecodeUrlOptionValue(url.GetValueFromOptions("prototype"), kTRUE);
548 TString funcname = DecodeUrlOptionValue(url.GetValueFromOptions("func"), kTRUE);
549 TMethod *method = nullptr;
550 TFunction *func = nullptr;
551 if (method_name) {
552 if (prototype.Length() == 0) {
553 if (debug)
554 debug->append(TString::Format("Search for any method with name \'%s\'\n", method_name).Data());
555 method = obj_cl->GetMethodAllAny(method_name);
556 } else {
557 if (debug)
558 debug->append(
559 TString::Format("Search for method \'%s\' with prototype \'%s\'\n", method_name, prototype.Data())
560 .Data());
561 method = obj_cl->GetMethodWithPrototype(method_name, prototype);
562 }
563 }
564
565 if (method) {
566 if (debug)
567 debug->append(TString::Format("Method: %s\n", method->GetPrototype()).Data());
568 } else {
569 if (funcname.Length() > 0) {
570 if (prototype.Length() == 0) {
571 if (debug)
572 debug->append(TString::Format("Search for any function with name \'%s\'\n", funcname.Data()).Data());
573 func = gROOT->GetGlobalFunction(funcname);
574 } else {
575 if (debug)
576 debug->append(TString::Format("Search for function \'%s\' with prototype \'%s\'\n", funcname.Data(),
577 prototype.Data())
578 .Data());
579 func = gROOT->GetGlobalFunctionWithPrototype(funcname, prototype);
580 }
581 }
582
583 if (func && debug)
584 debug->append(TString::Format("Function: %s\n", func->GetPrototype()).Data());
585 }
586
587 if (!method && !func) {
588 if (debug)
589 debug->append("Method not found\n");
590 return debug != nullptr;
591 }
592
593 if ((fReadOnly && (fCurrentRestrict == 0)) || (fCurrentRestrict == 1)) {
594 if ((method != nullptr) && (fCurrentAllowedMethods.Index(method_name) == kNPOS)) {
595 if (debug)
596 debug->append("Server runs in read-only mode, method cannot be executed\n");
597 return debug != nullptr;
598 } else if ((func != nullptr) && (fCurrentAllowedMethods.Index(funcname) == kNPOS)) {
599 if (debug)
600 debug->append("Server runs in read-only mode, function cannot be executed\n");
601 return debug != nullptr;
602 } else {
603 if (debug)
604 debug->append("For that special method server allows access even read-only mode is specified\n");
605 }
606 }
607
608 TList *args = method ? method->GetListOfMethodArgs() : func->GetListOfMethodArgs();
609
611 garbage.SetOwner(kTRUE); // use as garbage collection
612 TObject *post_obj = nullptr; // object reconstructed from post request
614
615 TIter next(args);
616 while (auto arg = static_cast<TMethodArg *>(next())) {
617
618 if ((strcmp(arg->GetName(), "rest_url_opt") == 0) && (strcmp(arg->GetFullTypeName(), "const char*") == 0) &&
619 (args->GetSize() == 1)) {
620 // very special case - function requires list of options after method=argument
621
622 const char *pos = strstr(options.c_str(), "method=");
623 if (!pos || (strlen(pos) < strlen(method_name) + 7))
624 return debug != nullptr;
625 const char *rest_url = pos + strlen(method_name) + 7;
626 if (*rest_url == '&') ++rest_url;
627 call_args.Append("\"");
629 call_args.Append("\"");
630 break;
631 }
632
634 const char *val = url.GetValueFromOptions(arg->GetName());
635 if (val)
637
639
640 if (sval == "_this_") {
641 // special case - object itself is used as argument
642 sval.Form("(%s*)0x%zx", obj_cl->GetName(), (size_t)obj_ptr);
643 } else if ((fCurrentArg != nullptr) && (fCurrentArg->GetPostData() != nullptr)) {
644 // process several arguments which are specific for post requests
645 if (fAllowPostObject && (sval == "_post_object_xml_")) {
646 // post data has extra 0 at the end and can be used as null-terminated string
648 if (!post_obj)
649 sval = "0";
650 else {
651 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
652 if (url.HasOption("_destroy_post_"))
653 garbage.Add(post_obj);
654 }
655 } else if (fAllowPostObject && (sval == "_post_object_json_")) {
656 // post data has extra 0 at the end and can be used as null-terminated string
658 if (!post_obj)
659 sval = "0";
660 else {
661 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
662 if (url.HasOption("_destroy_post_"))
663 garbage.Add(post_obj);
664 }
665 } else if (fAllowPostObject && (sval == "_post_object_") && url.HasOption("_post_class_")) {
666 TString clname = DecodeUrlOptionValue(url.GetValueFromOptions("_post_class_"), kTRUE);
667 TClass *arg_cl = gROOT->GetClass(clname, kTRUE, kTRUE);
668 if ((arg_cl != nullptr) && (arg_cl->GetBaseClassOffset(TObject::Class()) == 0) && (post_obj == nullptr)) {
669 post_obj = (TObject *)arg_cl->New();
670 if (post_obj == nullptr) {
671 if (debug)
672 debug->append(TString::Format("Fail to create object of class %s\n", clname.Data()).Data());
673 } else {
674 if (debug)
675 debug->append(TString::Format("Reconstruct object of class %s from POST data\n", clname.Data()).Data());
678 post_obj->Streamer(buf);
679 if (url.HasOption("_destroy_post_"))
680 garbage.Add(post_obj);
681 }
682 }
683 if (!post_obj)
684 sval = "0";
685 else
686 sval.Form("(%s*)0x%zx", clname.Data(), (size_t)post_obj);
687 } else if (sval == "_post_data_")
688 sval.Form("(void*)0x%zx", (size_t)fCurrentArg->GetPostData());
689 else if (sval == "_post_length_")
690 sval.Form("%ld", (long)fCurrentArg->GetPostDataLength());
691 else
693 } else
695
696 if (sval.IsNull() && arg->GetDefault())
697 sval = arg->GetDefault();
698
699 if (debug)
700 debug->append(
701 TString::Format(" Argument:%s Type:%s Value:%s \n", arg->GetName(), arg->GetFullTypeName(), sval.Data())
702 .Data());
703
704 if (call_args.Length() > 0)
705 call_args += ", ";
706
707 Bool_t isstr = (strcmp(arg->GetFullTypeName(), "const char*") == 0) ||
708 (strcmp(arg->GetFullTypeName(), "Option_t*") == 0) ||
709 (strcmp(arg->GetFullTypeName(), "string") == 0);
710
711 if (isstr) {
712 // check that quotes provided for the string argument
713 // all special characters were escaped before
714 if (sval.IsNull())
715 sval = "\"\"";
716 else {
717 if (sval[0] != '"')
718 sval.Prepend("\"");
719 if (sval[sval.Length() - 1] != '"')
720 sval.Append("\"");
721 }
722 } else {
723 // for numeric types keep only numeric and alphabetic characters
724 // exclude others - especially remove all escape characters
725 if (sanitize_numeric) {
727 for(Size_t i = 0; i < sval.Length(); ++i) {
728 if (std::isalnum(sval[i]) || std::strchr(".:+-", sval[i]))
729 sanitized.Append(sval[i]);
730 }
731 sval = sanitized;
732 }
733 if (sval.IsNull())
734 sval = "0";
735 }
736
737 call_args.Append(sval);
738 }
739
740 TMethodCall *call = nullptr;
741
742 if (method != nullptr) {
743 call = new TMethodCall(obj_cl, method_name, call_args.Data());
744 if (debug)
745 debug->append(TString::Format("Calling obj->%s(%s);\n", method_name, call_args.Data()).Data());
746 } else {
747 call = new TMethodCall(funcname.Data(), call_args.Data());
748 if (debug)
749 debug->append(TString::Format("Calling %s(%s);\n", funcname.Data(), call_args.Data()).Data());
750 }
751
752 garbage.Add(call);
753
754 if (!call->IsValid()) {
755 if (debug)
756 debug->append("Fail: invalid TMethodCall\n");
757 return debug != nullptr;
758 }
759
760 Int_t compact = 0;
761 if (url.GetValueFromOptions("compact"))
762 compact = url.GetIntValueFromOptions("compact");
763
764 TString res = "null";
765 void *ret_obj = nullptr;
766 TClass *ret_cl = nullptr;
767 TBufferFile *resbuf = nullptr;
768 if (reskind == 2) {
769 resbuf = new TBufferFile(TBuffer::kWrite, 10000);
770 garbage.Add(resbuf);
771 }
772
773 switch (call->ReturnType()) {
774 case TMethodCall::kLong: {
775 Longptr_t l(0);
776 if (method)
777 call->Execute(obj_ptr, l);
778 else
779 call->Execute(l);
780 if (resbuf)
781 resbuf->WriteLong(l);
782 else
783 res.Form("%zd", (size_t)l);
784 break;
785 }
787 Double_t d(0.);
788 if (method)
789 call->Execute(obj_ptr, d);
790 else
791 call->Execute(d);
792 if (resbuf)
793 resbuf->WriteDouble(d);
794 else
796 break;
797 }
799 char *txt = nullptr;
800 if (method)
801 call->Execute(obj_ptr, &txt);
802 else
803 call->Execute(&txt);
804 if (txt != nullptr) {
805 if (resbuf)
806 resbuf->WriteString(txt);
807 else
808 res.Form("\"%s\"", txt);
809 }
810 break;
811 }
812 case TMethodCall::kOther: {
813 std::string ret_kind = func ? func->GetReturnTypeNormalizedName() : method->GetReturnTypeNormalizedName();
814 if ((ret_kind.length() > 0) && (ret_kind[ret_kind.length() - 1] == '*')) {
815 ret_kind.resize(ret_kind.length() - 1);
816 ret_cl = gROOT->GetClass(ret_kind.c_str(), kTRUE, kTRUE);
817 }
818
819 if (ret_cl != nullptr) {
820 Longptr_t l(0);
821 if (method)
822 call->Execute(obj_ptr, l);
823 else
824 call->Execute(l);
825 if (l != 0)
826 ret_obj = (void *)l;
827 } else {
828 if (method)
829 call->Execute(obj_ptr);
830 else
831 call->Execute();
832 }
833
834 break;
835 }
836 case TMethodCall::kNone: {
837 if (method)
838 call->Execute(obj_ptr);
839 else
840 call->Execute();
841 break;
842 }
843 }
844
845 const char *_ret_object_ = url.GetValueFromOptions("_ret_object_");
846 if (_ret_object_ != nullptr) {
847 TObject *obj = nullptr;
848 if (gDirectory)
849 obj = gDirectory->Get(_ret_object_);
850 if (debug)
851 debug->append(TString::Format("Return object %s found %s\n", _ret_object_, obj ? "true" : "false").Data());
852
853 if (obj == nullptr) {
854 res = "null";
855 } else {
856 ret_obj = obj;
857 ret_cl = obj->IsA();
858 }
859 }
860
861 if (ret_obj && ret_cl) {
862 if ((resbuf != nullptr) && (ret_cl->GetBaseClassOffset(TObject::Class()) == 0)) {
863 TObject *obj = (TObject *)ret_obj;
864 resbuf->MapObject(obj);
865 obj->Streamer(*resbuf);
866 if (fCurrentArg)
867 fCurrentArg->SetExtraHeader("RootClassName", ret_cl->GetName());
868 } else {
870 }
871 }
872
873 if ((resbuf != nullptr) && (resbuf->Length() > 0)) {
874 res_str.resize(resbuf->Length());
875 std::copy((const char *)resbuf->Buffer(), (const char *)resbuf->Buffer() + resbuf->Length(), res_str.begin());
876 }
877
878 if (debug)
879 debug->append(TString::Format("Result = %s\n", res.Data()).Data());
880
881 if (reskind == 1)
882 res_str = res.Data();
883
884 if (url.HasOption("_destroy_result_") && ret_obj && ret_cl) {
885 ret_cl->Destructor(ret_obj);
886 if (debug)
887 debug->append("Destroy result object at the end\n");
888 }
889
890 // delete all garbage objects, but should be also done with any return
891 garbage.Delete();
892
893 return kTRUE;
894}
#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:792
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
TLine l
Definition textangle.C:4