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
53
54////////////////////////////////////////////////////////////////////////////////
55/// constructor
56
60
61////////////////////////////////////////////////////////////////////////////////
62/// destructor
63
65{
66 delete fSinfo;
67
68 delete fMemFile;
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// return true if given class can be drawn in JSROOT
73
75{
76 if (!cl)
77 return kFALSE;
78 if (cl->InheritsFrom(TH1::Class()))
79 return kTRUE;
80 if (cl->InheritsFrom(TGraph::Class()))
81 return kTRUE;
83 return kTRUE;
85 return kTRUE;
86 return kFALSE;
87}
88
89////////////////////////////////////////////////////////////////////////////////
90/// Scans object properties
91///
92/// here such fields as `_autoload` or `_icon` properties depending on class or object name could be assigned
93/// By default properties, coded in the Class title are scanned. Example:
94///
95/// ClassDef(UserClassName, 1) // class comments *SNIFF* _field1=value _field2="string value"
96///
97/// Here *SNIFF* mark is important. After it all expressions like field=value are parsed
98/// One could use double quotes to code string values with spaces.
99/// Fields separated from each other with spaces
100
102{
103 if (obj && obj->InheritsFrom(TLeaf::Class())) {
104 rec.SetField("_more", "false", kFALSE);
105 rec.SetField("_can_draw", "false", kFALSE);
106 rec.SetField("_player", "drawLeafPlayer");
107 rec.SetField("_module", "draw_tree");
108 return;
109 }
110
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// Scans TKey properties
116///
117/// in special cases load objects from the file
118
120{
121 if (strcmp(key->GetClassName(), "TDirectoryFile") == 0) {
123 } else {
125 if (obj_class && obj_class->InheritsFrom(TTree::Class())) {
126 if (rec.CanExpandItem()) {
127 // it is requested to expand tree element - read it
128 obj = key->ReadObj();
129 if (obj)
130 obj_class = obj->IsA();
131 } else {
132 rec.SetField("_ttree", "true", kFALSE); // indicate ROOT TTree
133 rec.SetField("_player", "drawTreePlayerKey");
134 rec.SetField("_module", "draw_tree");
135 // rec.SetField("_more", "true", kFALSE); // one could allow to extend
136 }
137 }
138 }
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Scans object childs (if any)
143///
144/// here one scans collection, branches, trees and so on
145
147{
148 if (obj->InheritsFrom(TTree::Class())) {
149 if (!rec.IsReadOnly(fReadOnly)) {
150 rec.SetField("_ttree", "true", kFALSE); // indicate ROOT TTree
151 rec.SetField("_player", "drawTreePlayer");
152 rec.SetField("_module", "draw_tree");
153 }
154 ScanCollection(rec, ((TTree *)obj)->GetListOfLeaves());
155 } else if (obj->InheritsFrom(TBranch::Class())) {
156 ScanCollection(rec, ((TBranch *)obj)->GetListOfLeaves());
157 } else {
159 }
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Returns hash value for streamer infos
164///
165/// At the moment - just number of items in streamer infos list.
166
171
172////////////////////////////////////////////////////////////////////////////////
173/// Return true if it is streamer info item name
174
176{
177 if (!itemname || (*itemname == 0))
178 return kFALSE;
179
180 return (strcmp(itemname, "StreamerInfo") == 0) || (strcmp(itemname, "StreamerInfo/") == 0);
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Get hash function for specified item
185///
186/// Used to detect any changes in the specified object
187
195
196////////////////////////////////////////////////////////////////////////////////
197/// Creates TMemFile instance, which used for objects streaming
198///
199/// One could not use TBufferFile directly,
200/// while one also require streamer infos list
201
203{
204 if (fMemFile)
205 return;
206
208 TFile::TContext fileCtx{nullptr};
209
210 fMemFile = new TMemFile("dummy.file", "RECREATE");
211 gROOT->GetListOfFiles()->Remove(fMemFile);
212
213 TH1F *d = new TH1F("d", "d", 10, 0, 10);
214 fMemFile->WriteObject(d, "h1");
215 delete d;
216
217 TGraph *gr = new TGraph(10);
218 gr->SetName("abc");
219 // // gr->SetDrawOptions("AC*");
220 fMemFile->WriteObject(gr, "gr1");
221 delete gr;
222
224
225 // make primary list of streamer infos
226 TList *l = new TList();
227
228 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TGraph"));
229 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TH1F"));
230 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TH1"));
231 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TNamed"));
232 l->Add(gROOT->GetListOfStreamerInfo()->FindObject("TObject"));
233
234 fMemFile->WriteObject(l, "ll");
235 delete l;
236
238
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Search element with specified path
244///
245/// Returns pointer on element
246///
247/// Optionally one could obtain element class, member description
248/// and number of childs. When chld!=0, not only element is searched,
249/// but also number of childs are counted. When member!=0, any object
250/// will be scanned for its data members (disregard of extra options)
251
253{
254 if (IsStreamerInfoItem(path)) {
255 // special handling for streamer info
257 if (cl && fSinfo)
258 *cl = fSinfo->IsA();
259 return fSinfo;
260 }
261
262 return TRootSniffer::FindInHierarchy(path, cl, member, chld);
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Produce binary data for specified item
267///
268/// if "zipped" option specified in query, buffer will be compressed
269
270Bool_t TRootSnifferFull::ProduceBinary(const std::string &path, const std::string & /*query*/, std::string &res)
271{
272 if (path.empty())
273 return kFALSE;
274
275 const char *path_ = path.c_str();
276 if (*path_ == '/')
277 path_++;
278
279 TClass *obj_cl = nullptr;
281 if (!obj_ptr || !obj_cl)
282 return kFALSE;
283
284 if (obj_cl->GetBaseClassOffset(TObject::Class()) != 0) {
285 Info("ProduceBinary", "Non-TObject class not supported");
286 return kFALSE;
287 }
288
289 // ensure that memfile exists
291
293 TFile::TContext fileCtx{nullptr};
294
295 TObject *obj = (TObject *)obj_ptr;
296
298 sbuf->SetParent(fMemFile);
299 sbuf->MapObject(obj);
300 obj->Streamer(*sbuf);
301 if (fCurrentArg)
302 fCurrentArg->SetExtraHeader("RootClassName", obj_cl->GetName());
303
304 // produce actual version of streamer info
305 delete fSinfo;
308
309 res.resize(sbuf->Length());
310 std::copy((const char *)sbuf->Buffer(), (const char *)sbuf->Buffer() + sbuf->Length(), res.begin());
311
312 delete sbuf;
313
314 return kTRUE;
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Produce ROOT file for specified item
319///
320/// File created in memory using TMemFile class.
321
322Bool_t TRootSnifferFull::ProduceRootFile(const std::string &path, const std::string & /*query*/, std::string &res)
323{
324 if (path.empty())
325 return kFALSE;
326
327 const char *path_ = path.c_str();
328 if (*path_ == '/')
329 path_++;
330
331 TClass *obj_cl = nullptr;
333 if (!obj_ptr || !obj_cl)
334 return kFALSE;
335
336 const char *store_name = "object";
337
338 if (obj_cl->GetBaseClassOffset(TNamed::Class()) == 0) {
339 const char *obj_name = ((TNamed *) obj_ptr)->GetName();
340 if (obj_name && *obj_name)
342 }
343
345 struct RestoreGFile {
348 } restoreGFile;
349
350 {
351 TMemFile memfile("dummy.file", "RECREATE");
352 gROOT->GetListOfFiles()->Remove(&memfile);
353
354 memfile.WriteObjectAny(obj_ptr, obj_cl, store_name);
355 memfile.Close();
356
357 res.resize(memfile.GetSize());
358 memfile.CopyTo(res.data(), memfile.GetSize());
359 }
360
361 return kTRUE;
362}
363
364
365////////////////////////////////////////////////////////////////////////////////
366/// Method to produce image from specified object
367///
368/// @param kind image kind TImage::kPng, TImage::kJpeg, TImage::kGif
369/// @param path path to object
370/// @param options extra options
371/// @param res std::string with binary data
372///
373/// By default, image 300x200 is produced
374/// In options string one could provide following parameters:
375///
376/// * w - image width
377/// * h - image height
378/// * opt - draw options
379///
380/// For instance:
381///
382/// http://localhost:8080/Files/hsimple.root/hpx/get.png?w=500&h=500&opt=lego1
383
384Bool_t TRootSnifferFull::ProduceImage(Int_t kind, const std::string &path, const std::string &options, std::string &res)
385{
386 if (path.empty())
387 return kFALSE;
388
389 const char *path_ = path.c_str();
390 if (*path_ == '/')
391 path_++;
392
393 TClass *obj_cl(nullptr);
395 if (!obj_ptr || !obj_cl)
396 return kFALSE;
397
398 if (obj_cl->GetBaseClassOffset(TObject::Class()) != 0) {
399 Error("TRootSniffer", "Only derived from TObject classes can be drawn");
400 return kFALSE;
401 }
402
403 TObject *obj = (TObject *)obj_ptr;
404
406 if (!img)
407 return kFALSE;
408
409 if (obj->InheritsFrom(TPad::Class())) {
410
411 if (gDebug > 1)
412 Info("TRootSniffer", "Crate IMAGE directly from pad");
413 img->FromPad((TPad *)obj);
414 } else if (CanDrawClass(obj->IsA())) {
415
416 if (gDebug > 1)
417 Info("TRootSniffer", "Crate IMAGE from object %s", obj->GetName());
418
419 Int_t width = 300, height = 200;
420 TString drawopt;
421
422 if (!options.empty()) {
423 TUrl url;
424 url.SetOptions(options.c_str());
425 url.ParseOptions();
426 Int_t w = url.GetIntValueFromOptions("w");
427 if (w > 10)
428 width = w;
429 Int_t h = url.GetIntValueFromOptions("h");
430 if (h > 10)
431 height = h;
432 drawopt = DecodeUrlOptionValue(url.GetValueFromOptions("opt"), kTRUE);
433 }
434
435 Bool_t isbatch = gROOT->IsBatch();
437
438 if (!isbatch)
439 gROOT->SetBatch(kTRUE);
440
441 TCanvas *c1 = new TCanvas("__online_draw_canvas__", "title", width, height);
442 obj->Draw(drawopt.Data());
443 img->FromPad(c1);
444 delete c1;
445
446 if (!isbatch)
447 gROOT->SetBatch(kFALSE);
448
449 } else {
450 delete img;
451 return kFALSE;
452 }
453
455 im->Append(img);
456
457 char *png_buffer = nullptr;
458 int size(0);
459
460 im->GetImageBuffer(&png_buffer, &size, (TImage::EImageFileTypes)kind);
461
462 if (png_buffer && (size > 0)) {
463 res.resize(size);
464 memcpy((void *)res.data(), png_buffer, size);
465 }
466
468 delete im;
469
470 return !res.empty();
471}
472
473////////////////////////////////////////////////////////////////////////////////
474/// Invokes TRootSniffer::ProduceIamge, converting kind into TImage::EImageFileTypes type
475
476Bool_t TRootSnifferFull::CallProduceImage(const std::string &kind, const std::string &path, const std::string &options, std::string &res)
477{
478 if (kind == "png")
479 return ProduceImage(TImage::kPng, path, options, res);
480
481 if (kind == "jpeg")
482 return ProduceImage(TImage::kJpeg, path, options, res);
483
484 if (kind == "gif")
485 return ProduceImage(TImage::kGif, path, options, res);
486
487 return kFALSE;
488}
489
490////////////////////////////////////////////////////////////////////////////////
491/// Produce XML data for specified item
492///
493/// For object conversion TBufferXML is used
494
495Bool_t TRootSnifferFull::ProduceXml(const std::string &path, const std::string & /*options*/, std::string &res)
496{
497 if (path.empty())
498 return kFALSE;
499 const char *path_ = path.c_str();
500 if (*path_ == '/')
501 path_++;
502
503 TClass *obj_cl = nullptr;
505 if (!obj_ptr || !obj_cl)
506 return kFALSE;
507
508 // TODO: support std::string in TBufferXML
510
511 return !res.empty();
512}
513
514class TArgHolderBase : public TObject {
515 public:
517 virtual const void *GetPtr() const { return nullptr; }
518};
519
520template<typename T>
522 public:
525 const void *GetPtr() const override { return &fValue; }
526};
527
529 public:
531 const char *fBuf = nullptr;
532 TArgHolderConstChar(const char *v) : fValue(v) { fBuf = fValue.Data(); }
533 const void *GetPtr() const override { return &fBuf; }
534};
535
536
537////////////////////////////////////////////////////////////////////////////////
538/// Execute command for specified object
539///
540/// @param path the object path
541/// @param options include method and extra list of parameters
542/// sniffer should be not-readonly to allow execution of the commands
543/// @param reskind defines kind of result 0 - debug, 1 - json, 2 - binary
544/// @param res_str result string
545
546Bool_t TRootSnifferFull::ProduceExe(const std::string &path, const std::string &options, Int_t reskind, std::string &res_str)
547{
548 std::string *debug = (reskind == 0) ? &res_str : nullptr;
549
550 if (path.empty()) {
551 if (debug)
552 debug->append("Item name not specified\n");
553 return debug != nullptr;
554 }
555
556 const char *path_ = path.c_str();
557 if (*path_ == '/')
558 path_++;
559
560 TClass *obj_cl = nullptr;
562 if (debug)
563 debug->append(TString::Format("Item:%s found:%s\n", path_, obj_ptr ? "true" : "false").Data());
564 if (!obj_ptr || !obj_cl)
565 return debug != nullptr;
566
567 TUrl url;
568 url.SetOptions(options.c_str());
569
570 const char *method_name = url.GetValueFromOptions("method");
571 TString prototype = DecodeUrlOptionValue(url.GetValueFromOptions("prototype"), kTRUE);
572 TString funcname = DecodeUrlOptionValue(url.GetValueFromOptions("func"), kTRUE);
573 TMethod *method = nullptr;
574 TFunction *func = nullptr;
575 if (method_name) {
576 if (prototype.Length() == 0) {
577 if (debug)
578 debug->append(TString::Format("Search for any method with name \'%s\'\n", method_name).Data());
579 method = obj_cl->GetMethodAllAny(method_name);
580 } else {
581 if (debug)
582 debug->append(
583 TString::Format("Search for method \'%s\' with prototype \'%s\'\n", method_name, prototype.Data())
584 .Data());
585 method = obj_cl->GetMethodWithPrototype(method_name, prototype);
586 }
587 }
588
589 if (method) {
590 if (debug)
591 debug->append(TString::Format("Method: %s\n", method->GetPrototype()).Data());
592 } else {
593 if (funcname.Length() > 0) {
594 if (prototype.Length() == 0) {
595 if (debug)
596 debug->append(TString::Format("Search for any function with name \'%s\'\n", funcname.Data()).Data());
597 func = gROOT->GetGlobalFunction(funcname);
598 } else {
599 if (debug)
600 debug->append(TString::Format("Search for function \'%s\' with prototype \'%s\'\n", funcname.Data(),
601 prototype.Data())
602 .Data());
603 func = gROOT->GetGlobalFunctionWithPrototype(funcname, prototype);
604 }
605 }
606
607 if (func && debug)
608 debug->append(TString::Format("Function: %s\n", func->GetPrototype()).Data());
609 }
610
611 if (!method && !func) {
612 if (debug)
613 debug->append("Method not found\n");
614 return debug != nullptr;
615 }
616
617 if ((fReadOnly && (fCurrentRestrict == 0)) || (fCurrentRestrict == 1)) {
618 if ((method != nullptr) && (fCurrentAllowedMethods.Index(method_name) == kNPOS)) {
619 if (debug)
620 debug->append("Server runs in read-only mode, method cannot be executed\n");
621 return debug != nullptr;
622 } else if ((func != nullptr) && (fCurrentAllowedMethods.Index(funcname) == kNPOS)) {
623 if (debug)
624 debug->append("Server runs in read-only mode, function cannot be executed\n");
625 return debug != nullptr;
626 } else {
627 if (debug)
628 debug->append("For that special method server allows access even read-only mode is specified\n");
629 }
630 }
631
632 TList *args = method ? method->GetListOfMethodArgs() : func->GetListOfMethodArgs();
633
635 garbage.SetOwner(kTRUE); // use as garbage collection
636 TObject *post_obj = nullptr; // object reconstructed from post request
638 std::vector<const void *> plain_args;
640
642 plain_args.emplace_back(arg->GetPtr());
643 garbage.Add(arg);
645 };
646
647 TIter next(args);
648 while (auto arg = static_cast<TMethodArg *>(next())) {
650
651 if ((strcmp(arg->GetName(), "rest_url_opt") == 0) && (strcmp(arg->GetFullTypeName(), "const char*") == 0) &&
652 (args->GetSize() == 1)) {
653 // very special case - function requires list of options after method=argument
654
655 const char *pos = strstr(options.c_str(), "method=");
656 if (!pos || (strlen(pos) < strlen(method_name) + 7))
657 return debug != nullptr;
658 const char *rest_url = pos + strlen(method_name) + 7;
659 if (*rest_url == '&') ++rest_url;
660 call_args.Append("\"");
662 call_args.Append("\"");
664 break;
665 }
666
668 const char *val = url.GetValueFromOptions(arg->GetName());
669 if (val)
671
673
674 if (sval == "_this_") {
675 // special case - object itself is used as argument
676 sval.Form("(%s*)0x%zx", obj_cl->GetName(), (size_t)obj_ptr);
678 } else if ((fCurrentArg != nullptr) && (fCurrentArg->GetPostData() != nullptr)) {
679 // process several arguments which are specific for post requests
680 if (fAllowPostObject && (sval == "_post_object_xml_")) {
681 // post data has extra 0 at the end and can be used as null-terminated string
683 if (!post_obj)
684 sval = "0";
685 else {
686 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
687 if (url.HasOption("_destroy_post_"))
688 garbage.Add(post_obj);
689 }
691 } else if (fAllowPostObject && (sval == "_post_object_json_")) {
692 // post data has extra 0 at the end and can be used as null-terminated string
694 if (!post_obj)
695 sval = "0";
696 else {
697 sval.Form("(%s*)0x%zx", post_obj->ClassName(), (size_t)post_obj);
698 if (url.HasOption("_destroy_post_"))
699 garbage.Add(post_obj);
700 }
702 } else if (fAllowPostObject && (sval == "_post_object_") && url.HasOption("_post_class_")) {
703 TString clname = DecodeUrlOptionValue(url.GetValueFromOptions("_post_class_"), kTRUE);
704 TClass *arg_cl = gROOT->GetClass(clname, kTRUE, kTRUE);
705 if ((arg_cl != nullptr) && (arg_cl->GetBaseClassOffset(TObject::Class()) == 0) && (post_obj == nullptr)) {
706 post_obj = (TObject *)arg_cl->New();
707 if (post_obj == nullptr) {
708 if (debug)
709 debug->append(TString::Format("Fail to create object of class %s\n", clname.Data()).Data());
710 } else {
711 if (debug)
712 debug->append(TString::Format("Reconstruct object of class %s from POST data\n", clname.Data()).Data());
715 post_obj->Streamer(buf);
716 if (url.HasOption("_destroy_post_"))
717 garbage.Add(post_obj);
718 }
719 }
720 if (!post_obj)
721 sval = "0";
722 else
723 sval.Form("(%s*)0x%zx", clname.Data(), (size_t)post_obj);
725 } else if (sval == "_post_data_") {
726 sval.Form("(void*)0x%zx", (size_t)fCurrentArg->GetPostData());
728 } else if (sval == "_post_length_")
729 sval.Form("%ld", (long)fCurrentArg->GetPostDataLength());
730 else
732 } else
734
735 if (sval.IsNull() && arg->GetDefault())
736 sval = arg->GetDefault();
737
738 if (debug)
739 debug->append(
740 TString::Format(" Argument:%s Type:%s Value:%s \n", arg->GetName(), arg->GetFullTypeName(), sval.Data())
741 .Data());
742
743 if (call_args.Length() > 0)
744 call_args += ", ";
745
746 if (!add_plain) {
747 std::string tname = arg->GetTypeNormalizedName();
748 if (tname == "const char*")
749 // one can use original string, just remove optional quotes
751 else if (tname == "bool")
752 add_plain_arg(new TArgHolder<bool>(!sval.IsNull() && (sval != "0") && (sval != "false")));
753 else if (tname == "double")
754 add_plain_arg(new TArgHolder<double>(std::stod(sval.Data())));
755 else if (tname == "float")
756 add_plain_arg(new TArgHolder<float>(std::stof(sval.Data())));
757 else if (tname == "int")
758 add_plain_arg(new TArgHolder<int>(std::stol(sval.Data())));
759 else if (tname == "long")
760 add_plain_arg(new TArgHolder<long>(std::stol(sval.Data())));
761 else if (tname == "short")
762 add_plain_arg(new TArgHolder<short>(std::stol(sval.Data())));
763 else if (tname == "char")
764 add_plain_arg(new TArgHolder<char>(std::stol(sval.Data())));
765 else if (tname == "unsigned int")
766 add_plain_arg(new TArgHolder<unsigned int>(std::stoul(sval.Data())));
767 else if (tname == "unisgned long")
768 add_plain_arg(new TArgHolder<unsigned long>(std::stoul(sval.Data())));
769 else if (tname == "unsigned short")
770 add_plain_arg(new TArgHolder<unsigned short>(std::stoul(sval.Data())));
771 else if (tname == "unsigned char")
772 add_plain_arg(new TArgHolder<unsigned char>(std::stoul(sval.Data())));
773 else if (!tname.empty() && tname.back() == '*' && (sval == "0" || sval == "null" || sval == "nullptr"))
775 else
776 can_use_plain = kFALSE; // unsupported type, plain args cannot be used
777 }
778
779 Bool_t isstr = (strcmp(arg->GetFullTypeName(), "const char*") == 0) ||
780 (strcmp(arg->GetFullTypeName(), "Option_t*") == 0) ||
781 (strcmp(arg->GetFullTypeName(), "string") == 0);
782
783 if (isstr) {
784 // check that quotes provided for the string argument
785 // all special characters were escaped before
786 if (sval.IsNull())
787 sval = "\"\"";
788 else {
789 if (sval[0] != '"')
790 sval.Prepend("\"");
791 if (sval[sval.Length() - 1] != '"')
792 sval.Append("\"");
793 }
794 } else {
795 // for numeric types keep only numeric and alphabetic characters
796 // exclude others - especially remove all escape characters
797 if (sanitize_numeric) {
799 for(Size_t i = 0; i < sval.Length(); ++i) {
800 if (std::isalnum(sval[i]) || std::strchr(".:+-", sval[i]))
801 sanitized.Append(sval[i]);
802 }
803 sval = sanitized;
804 }
805 if (sval.IsNull())
806 sval = "0";
807 }
808
809 call_args.Append(sval);
810 }
811
812 TMethodCall *call = nullptr;
813
814 if (method != nullptr) {
815 if (can_use_plain) {
816 // prevent creation of huge cache
817 if (fExeCache.size() > 1000)
818 fExeCache.clear();
819 auto iter = fExeCache.find(method);
820 if (iter != fExeCache.end()) {
821 call = iter->second.get();
822 } else {
823 call = new TMethodCall();
824 call->InitWithPrototype(obj_cl, method_name, prototype.IsNull() ? nullptr : prototype.Data());
825 fExeCache.emplace(method, std::unique_ptr<TMethodCall>(call));
826 }
827 } else {
828 call = new TMethodCall(obj_cl, method_name, call_args.Data());
829 garbage.Add(call);
830 }
831 if (debug)
832 debug->append(TString::Format("Calling obj->%s(%s);\n", method_name, call_args.Data()).Data());
833 } else {
834 call = new TMethodCall(funcname.Data(), call_args.Data());
835 garbage.Add(call);
836 if (debug)
837 debug->append(TString::Format("Calling %s(%s);\n", funcname.Data(), call_args.Data()).Data());
838 }
839
840 if (!call->IsValid()) {
841 if (debug)
842 debug->append("Fail: invalid TMethodCall\n");
843 return debug != nullptr;
844 }
845
846 Int_t compact = 0;
847 if (url.GetValueFromOptions("compact"))
848 compact = url.GetIntValueFromOptions("compact");
849
850 TString res = "null";
851 void *ret_obj = nullptr;
852 TClass *ret_cl = nullptr;
853 TBufferFile *resbuf = nullptr;
854 if (reskind == 2) {
855 resbuf = new TBufferFile(TBuffer::kWrite, 10000);
856 garbage.Add(resbuf);
857 }
858
859 auto ret_type = call->ReturnType();
860 if (ret_type == TMethodCall::kOther) {
861 std::string ret_kind = func ? func->GetReturnTypeNormalizedName() : method->GetReturnTypeNormalizedName();
862 if ((ret_kind.length() > 0) && (ret_kind[ret_kind.length() - 1] == '*')) {
863 ret_kind.resize(ret_kind.length() - 1);
864 ret_cl = gROOT->GetClass(ret_kind.c_str(), kTRUE, kTRUE);
865 }
866 if (!ret_cl)
867 ret_type = TMethodCall::kNone;
868 }
869
870 switch (ret_type) {
871 case TMethodCall::kLong: {
872 Longptr_t l = 0;
873 if (method && can_use_plain)
874 call->Execute(obj_ptr, plain_args.data(), plain_args.size(), &l);
875 else if (method)
876 call->Execute(obj_ptr, l);
877 else
878 call->Execute(l);
879 if (resbuf)
880 resbuf->WriteLong(l);
881 else
882 res.Form("%zd", (size_t)l);
883 break;
884 }
886 Double_t d = 0.;
887 if (method && can_use_plain)
888 call->Execute(obj_ptr, plain_args.data(), plain_args.size(), &d);
889 else if (method)
890 call->Execute(obj_ptr, d);
891 else
892 call->Execute(d);
893 if (resbuf)
894 resbuf->WriteDouble(d);
895 else
897 break;
898 }
900 char *txt = nullptr;
901 if (method && can_use_plain)
902 call->Execute(obj_ptr, plain_args.data(), plain_args.size(), &txt);
903 else if (method)
904 call->Execute(obj_ptr, &txt);
905 else
906 call->Execute(&txt);
907 if (txt != nullptr) {
908 if (resbuf)
909 resbuf->WriteString(txt);
910 else
911 res.Form("\"%s\"", txt);
912 }
913 break;
914 }
915 case TMethodCall::kOther: {
916 Longptr_t l = 0;
917 if (method && can_use_plain)
918 call->Execute(obj_ptr, plain_args.data(), plain_args.size(), &l);
919 else if (method)
920 call->Execute(obj_ptr, l);
921 else
922 call->Execute(l);
923 if (l != 0)
924 ret_obj = (void *)l;
925 break;
926 }
927 case TMethodCall::kNone: {
928 if (method && can_use_plain)
929 call->Execute(obj_ptr, plain_args.data(), plain_args.size());
930 else if (method)
931 call->Execute(obj_ptr);
932 else
933 call->Execute();
934 break;
935 }
936 }
937
938 const char *_ret_object_ = url.GetValueFromOptions("_ret_object_");
939 if (_ret_object_ != nullptr) {
940 TObject *obj = nullptr;
941 if (gDirectory)
942 obj = gDirectory->Get(_ret_object_);
943 if (debug)
944 debug->append(TString::Format("Return object %s found %s\n", _ret_object_, obj ? "true" : "false").Data());
945
946 if (obj == nullptr) {
947 res = "null";
948 } else {
949 ret_obj = obj;
950 ret_cl = obj->IsA();
951 }
952 }
953
954 if (ret_obj && ret_cl) {
955 if ((resbuf != nullptr) && (ret_cl->GetBaseClassOffset(TObject::Class()) == 0)) {
956 TObject *obj = (TObject *)ret_obj;
957 resbuf->MapObject(obj);
958 obj->Streamer(*resbuf);
959 if (fCurrentArg)
960 fCurrentArg->SetExtraHeader("RootClassName", ret_cl->GetName());
961 } else {
963 }
964 }
965
966 if ((resbuf != nullptr) && (resbuf->Length() > 0)) {
967 res_str.resize(resbuf->Length());
968 std::copy((const char *)resbuf->Buffer(), (const char *)resbuf->Buffer() + resbuf->Length(), res_str.begin());
969 }
970
971 if (debug)
972 debug->append(TString::Format("Result = %s\n", res.Data()).Data());
973
974 if (reskind == 1)
975 res_str = res.Data();
976
977 if (url.HasOption("_destroy_result_") && ret_obj && ret_cl) {
978 ret_cl->Destructor(ret_obj);
979 if (debug)
980 debug->append("Destroy result object at the end\n");
981 }
982
983 // delete all garbage objects, but should be also done with any return
984 garbage.Delete();
985
986 return kTRUE;
987}
#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
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:145
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:783
#define gROOT
Definition TROOT.h:426
#define free
Definition civetweb.c:1578
const_iterator begin() const
virtual const void * GetPtr() const
TArgHolderConstChar(const char *v)
const void * GetPtr() const override
const void * GetPtr() const override
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:1456
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.
void InitWithPrototype(TClass *cl, const char *method, const char *proto, Bool_t objectIsConst=kFALSE, ROOT::EFunctionMatchMode mode=ROOT::kConversionMatch)
Initialize the method invocation environment.
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:459
virtual void Streamer(TBuffer &)
Stream an object of class TObject.
Definition TObject.cxx:994
static TClass * Class()
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Definition TObject.cxx:546
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1095
virtual TClass * IsA() const
Definition TObject.h:248
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:290
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition TObject.cxx:1069
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)
std::map< const TMethod *, std::unique_ptr< TMethodCall > > fExeCache
! cache for exe.json invocation
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 DecodeUrlOptionValue(const char *value, Bool_t remove_quotes=kTRUE, Bool_t escape_special=kTRUE)
Method replaces all kind of special symbols, which could appear in URL options.
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...
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