20#include "THttpServer.h"
21#include "TBufferJSON.h"
24#include "TTimeStamp.h"
28#include "TMethodCall.h"
29#include "TGo4HistogramStatus.h"
31#include "TGo4AnalysisImp.h"
32#include "TGo4AnalysisObjectManager.h"
33#include "TGo4AnalysisClientImp.h"
35#include "TGo4Parameter.h"
36#include "TGo4Condition.h"
37#include "TGo4AnalysisWebStatus.h"
38#include "TGo4EventElement.h"
39#include "TGo4Ratemeter.h"
40#include "TGo4DynamicEntry.h"
63 TBufferJSON::SetFloatFormat(
"%15.9e");
66 if (strstr(args,
"jsroot:") == args) {
76 TRootSnifferFull(name),
83 SetScanGlobalDir(kFALSE);
85#ifdef __ROOT_HAVE_POST_ALLOWED__
86 SetAllowPostObject(kTRUE);
89 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,33,0)
106 SetItemField(
"/Status/Log",
"_hidden",
"true");
107 SetItemField(
"/Status/Msg",
"_hidden",
"true");
109 CreateItem(
"/Status/Message",
"Last message from analysis");
110 SetItemField(
"/Status/Message",
"_kind",
"Text");
111 SetItemField(
"/Status/Message",
"value",
"---");
113 CreateItem(
"/Status/DebugOutput",
"Go4 debug output");
114 SetItemField(
"/Status/DebugOutput",
"_kind",
"Text");
115 SetItemField(
"/Status/DebugOutput",
"value",
"---");
124 fEventRate->SetTitle(
"Events processing rate");
126 fEventRate->GetXaxis()->SetTimeFormat(
"%H:%M:%S");
128 fEventRate->GetHistogram()->SetDirectory(
nullptr);
133 SetItemField(
"/Status/Ratemeter",
"_hidden",
"true");
134 SetItemField(
"/Status/Ratemeter",
"_status",
"GO4.DrawAnalysisRatemeter");
136 RegisterCommand(
"/Control/CmdClear",
"this->CmdClear();",
"button;go4sys/icons/clear.png");
137 SetItemField(
"/Control/CmdClear",
"_title",
"Clear histograms and conditions in analysis");
138 SetItemField(
"/Control/CmdClear",
"_hidden",
"true");
140 RegisterCommand(
"/Control/CmdStart",
"this->CmdStart();",
"button;go4sys/icons/start.png");
141 SetItemField(
"/Control/CmdStart",
"_title",
"Start analysis");
142 SetItemField(
"/Control/CmdStart",
"_hidden",
"true");
144 RegisterCommand(
"/Control/CmdStop",
"this->CmdStop();",
"button;go4sys/icons/Stop.png");
145 SetItemField(
"/Control/CmdStop",
"_title",
"Stop analysis");
146 SetItemField(
"/Control/CmdStop",
"_hidden",
"true");
148 RegisterCommand(
"/Control/CmdClose",
"this->CmdClose();",
"");
149 SetItemField(
"/Control/CmdClose",
"_title",
"Close analysis");
150 SetItemField(
"/Control/CmdClose",
"_hidden",
"true");
152 RegisterCommand(
"/Control/CmdRestart",
"this->CmdRestart();",
"button;go4sys/icons/restart.png");
153 SetItemField(
"/Control/CmdRestart",
"_title",
"Resubmit analysis configuration and start again");
154 SetItemField(
"/Control/CmdRestart",
"_hidden",
"true");
156 RegisterCommand(
"/Control/CmdExit",
"this->CmdExit();",
"");
157 SetItemField(
"/Control/CmdExit",
"_title",
"Exit analysis process");
158 SetItemField(
"/Control/CmdExit",
"_hidden",
"true");
164 RegisterCommand(
"/Control/CmdOpenFile",
"this->CmdOpenFile(\"%arg1%\");",
"button;go4sys/icons/fileopen.png");
165 SetItemField(
"/Control/CmdOpenFile",
"_title",
"Open ROOT file in analysis");
166 SetItemField(
"/Control/CmdOpenFile",
"_hreload",
"true");
169 RegisterCommand(
"/Control/CmdCloseFiles",
"this->CmdCloseFiles();",
"go4sys/icons/fileclose.png");
170 SetItemField(
"/Control/CmdCloseFiles",
"_title",
"Close all opened files");
171 SetItemField(
"/Control/CmdCloseFiles",
"_hreload",
"true");
174 RegisterCommand(
"/Control/CmdClearObject",
"this->CmdClearObject(\"%arg1%\");",
"");
175 SetItemField(
"/Control/CmdClearObject",
"_title",
"Clear object content");
176 SetItemField(
"/Control/CmdClearObject",
"_hidden",
"true");
178 RegisterCommand(
"/Control/CmdDeleteObject",
"this->CmdDeleteObject(\"%arg1%\");",
"");
179 SetItemField(
"/Control/CmdDeleteObject",
"_title",
"Delete object from analysis");
180 SetItemField(
"/Control/CmdDeleteObject",
"_hidden",
"true");
182 RegisterCommand(
"/Control/CmdExecute",
"this->CmdExecute(\"%arg1%\");",
"go4sys/icons/macro_t.png");
183 SetItemField(
"/Control/CmdExecute",
"_title",
"Execute interpreter line in the analysis context. '@' means 'TGo4Analysis::Instance()->' ; A leading '$' invokes python skript.");
189 SetItemField(
"/Control/Analysis",
"_autoload",
fAutoLoadArg);
190 SetItemField(
"/Control/Analysis",
"_icon",
"go4sys/icons/control.png");
191 SetItemField(
"/Control/Analysis",
"_not_monitor",
"true");
193 RegisterObject(
"/Control",
this);
194 SetItemField(
"/Control/go4_sniffer",
"_hidden",
"true");
196 CreateItem(
"/Control/Terminal",
"Analysis terminal");
197 SetItemField(
"/Control/Terminal",
"_icon",
"go4sys/icons/analysiswin.png");
198 SetItemField(
"/Control/Terminal",
"_player",
"GO4.drawAnalysisTerminal");
200 RestrictGo4(
"/Control",
"visible=controller,admin");
204 RestrictGo4(
"/Conditions",
"allow=controller,admin");
206 RestrictGo4(
"/Parameters",
"allow=controller,admin&allow_method=CreateStatus");
211 SetItemField(
"/",
"_icon",
"go4sys/icons/go4logo2_small.png");
212 SetItemField(
"/",
"_title",
"GO4 analysis");
215 SetItemField(
"/",
"_has_restrict",
"true");
218 SetItemField(
"/",
"_has_produce_multi",
"true");
228 gROOT->GetClass(
"TGo4ParameterStatus", kTRUE, kTRUE);
229 gROOT->GetClass(
"TGo4EventElement", kTRUE, kTRUE);
230 gROOT->GetClass(
"TGo4CompositeEvent", kTRUE, kTRUE);
231 gROOT->GetClass(
"TGo4AnalysisStatus", kTRUE, kTRUE);
232 gROOT->GetClass(
"TGo4AnalysisWebStatus", kTRUE, kTRUE);
246 rec.SetField(
"_toptitle",
"Go4 http server");
248 TRootSnifferFull::ScanRoot(rec);
267 TFolder *files_fold =
dynamic_cast<TFolder *
>(
main->FindObject(
"Files"));
278 ScanCollection(rec, files_fold->GetListOfFolders(),
"Files");
283 TRootSnifferFull::ScanObjectProperties(rec, obj);
288 rec.SetField(
"_can_delete",
"true");
292 rec.SetField(
"_no_reset",
"true");
295 if (obj->InheritsFrom(TGo4Parameter::Class())) {
298 rec.SetField(
"_drawfunc",
"GO4.drawParameter");
299 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,33,0)
300 rec.SetField(
"_drawscript",
"modules:go4sys/html5/pareditor.mjs");
302 rec.SetField(
"_drawscript",
"go4sys/html/pareditor.js");
304 rec.SetField(
"_drawopt",
"editor");
305 rec.SetField(
"_icon",
"go4sys/icons/parameter.png");
309 if (obj->InheritsFrom(TGo4Condition::Class())) {
312 rec.SetField(
"_icon",
"go4sys/icons/condedit.png");
316 if (obj->InheritsFrom(TGo4EventElement::Class())) {
317 rec.SetField(
"_more",
"true");
318 rec.SetField(
"_go4event",
"true");
319 rec.SetField(
"_icon",
"go4sys/icons/eventobj.png");
323 if (obj->InheritsFrom(TGo4MsgList::Class())) {
326 rec.SetField(
"_make_request",
"GO4.MakeMsgListRequest");
327 rec.SetField(
"_after_request",
"GO4.AfterMsgListRequest");
328 rec.SetField(
"_icon",
"img_text");
336 if (path && (strcmp(path,
"Status/Analysis") == 0)) {
342 return TRootSnifferFull::FindInHierarchy(path, cl, member, chld);
370 Info(
"CmdOpenFile",
"Open ROOT file %s", fname);
377 TFolder *files_fold =
dynamic_cast<TFolder *
>(
main->FindObject(
"Files"));
379 files_fold =
main->AddFolder(
"Files",
"ROOT files");
380 files_fold->SetOwner(kTRUE);
383 auto f =
dynamic_cast<TFile *
> (files_fold->FindObject(fname));
384 if (f) { files_fold->Remove(f);
delete f; }
386 f = TFile::Open(fname);
387 if (!f)
return kFALSE;
397 Info(
"CmdCloseFiles",
"Close all opened files");
401 TFolder *files_fold =
dynamic_cast<TFolder *
>(
main->FindObject(
"Files"));
404 main->Remove(files_fold);
416 an->ClearObjects(
"Histograms");
417 an->ClearObjects(
"Conditions");
418 an->SendMessageToGUI(1, kTRUE,
"Clear Histograms and Conditions folder");
431 if (an->InitEventClasses())
437 if (an->InitEventClasses()) {
496 if (!objname || (*objname == 0)) {
497 ana->ClearObjects(
"Histograms");
498 ana->ClearObjects(
"Conditions");
503 Bool_t ok = ana->ClearObjects(objname);
508 SendStatusMessage(2, kTRUE, TString::Format(
"Could not clear object %s", objname));
523 if (!objname || (*objname == 0)) {
528 Bool_t ok = ana->DeleteObjects(objname);
533 SendStatusMessage(2, kTRUE, TString::Format(
"Could not delete object %s", objname));
542 if (!exeline || (*exeline == 0))
return kFALSE;
549 ana->ExecuteLine(exeline, &errcode);
551 return errcode != 0 ? kFALSE : kTRUE;
560 if (!title || (strlen(title) == 0))
return;
562 const char *prev = GetItemField(
"/Status/DebugOutput",
"value");
564 if (prev && (strcmp(prev,
"---") != 0)) res = prev;
565 if (res.Length() > 50000) res.Remove(0, res.Length() - 25000);
566 res.Append(
"\n"); res.Append(title);
568 SetItemField(
"/Status/DebugOutput",
"value", res);
570 const char *cur = title;
572 const char *next = strchr(cur,
'\n');
593 tm0.Set(1995,1,1,0,0,0,0,kTRUE,0);
596 fEventRate->GetXaxis()->SetTimeFormat(
"%H:%M:%S");
598 fEventRate->GetHistogram()->SetDirectory(
nullptr);
603 const char *prev = GetItemField(
"/Status/Message",
"value");
605 if (prev && (strcmp(prev,
"---") != 0)) res = prev;
606 res.Append(
"\n"); res.Append(msg);
608 SetItemField(
"/Status/Message",
"value",res);
612 fStatusMessages.AddMsg(TString::UItoa(now.Convert(kFALSE), 10) +
":" + TString::Itoa(level,10) +
":" + msg);
642 Bool_t res = ana->AddHistogram(
dynamic_cast<TH1 *
>(obj));
643 if (!res) res = ana->AddAnalysisCondition(
dynamic_cast<TGo4Condition *
>(obj));
644 if (!res) res = ana->AddDynamicEntry(
dynamic_cast<TGo4DynamicEntry *
>(obj));
647 SendStatusMessage(1, kFALSE, TString::Format(
"Added new object %s to Go4 folders.", obj->GetName()));
649 SendStatusMessage(3, kFALSE, TString::Format(
"ERROR on adding new object %s ", obj->GetName()));
657 const char *treename,
667 if (!histoname || (*histoname == 0)) histoname =
"hTreeDraw";
668 Bool_t res = ana->AddTreeHistogram(histoname, treename, varexpr, cutexpr);
670 SendStatusMessage(1,kTRUE, TString::Format(
"Added Dynamic histogram %s for tree %s.", histoname, treename));
672 SendStatusMessage(2,kTRUE, TString::Format(
"Could not add Dynamic histogram %s for tree %s.", histoname, treename));
679 TObject *obj = FindTObjectInHierarchy(itemname);
681 TH1 *h1 =
dynamic_cast<TH1 *
> (obj);
692 return IsA()->GetMethodAllAny(
"Restrict") !=
nullptr;
697 return IsA()->GetMethodAllAny(
"ProduceMulti") !=
nullptr;
706 TString call_args = TString::Format(
"\"%s\",\"%s\"", path, options);
708 TMethodCall call(IsA(),
"Restrict", call_args.Data());
715 return IsA()->GetMethodAllAny(
"SetAutoLoad") !=
nullptr;
722 TString call_args = TString::Format(
"\"%s\"", script);
724 TMethodCall call(IsA(),
"SetAutoLoad", call_args.Data());
int main(int argc, char *argv[])
void Stop() override
General stop method of slave application to be called from remote command; should be re-implemented b...
void Start() override
General start method of slave application to be called from remote command; should be re-implemented ...
void Quit() override
Quit this instance and the owned task; method to be called from command object, may be overridden in ...
This object is responsible for the organization of analysis objects.
static const char * GetTREEFOLDER()
static const char * GetHISTFOLDER()
static const char * GetUSRFOLDER()
TFolder * GetObjectFolder()
Access to top folder of all objects.
static const char * GetPICTFOLDER()
static const char * GetANALYSISFOLDER()
static const char * GetPARAFOLDER()
static const char * GetCANVFOLDER()
static const char * GetEVENTFOLDER()
static const char * GetCONDFOLDER()
void UpdateStatus(TGo4AnalysisStatus *state)
Create a copy of the analysis internal state.
static TGo4Analysis * Instance()
return analysis instance
TGo4AnalysisObjectManager * ObjectManager() const
Returns pointer on analysis object manager.
TGo4AnalysisWebStatus * CreateWebStatus()
Create a copy of the analysis internal state.
void SetSniffer(TGo4AnalysisSniffer *sniff)
Set pointer on sniffer object.
ABC for all entries that can be kept in a dynamic list.
Runtime status of a histogram object.
static const char * Message(Int_t prio, const char *text,...) GO4_PRINTF2_ARGS
Display a message.
static const char * GO4SYS()
Return GO4SYS environment variable or Go4 top directory during compile (if GO4SYS) not set.
static void SetSniffer(TNamed *sniff)
Class containing event counter and ratemeter services.
void ScanRoot(TRootSnifferScanRec &rec) override
static THttpServer * GetHttpServer()
Bool_t AddAnalysisObject(TObject *obj)
TObject * CreateItemStatus(const char *itemname)
void SetTitle(const char *title="") override
Method called by logger with every string, going to output.
static Bool_t CreateEngine(const char *name)
void StatusMessage(int level, Bool_t printout, const TString &) override
Method from analysis sniffer.
Bool_t HasRestrictMethod()
Indicate that Restrict method implemented, also commands with arguments are exists.
void RatemeterUpdate(TGo4Ratemeter *) override
Method from analysis sniffer.
Bool_t CmdClearObject(const char *objname)
Bool_t CmdDeleteObject(const char *objname)
Bool_t SetAutoLoadGo4(const char *script)
Wrapper for new method in TRootSniffer.
void ScanObjectProperties(TRootSnifferScanRec &rec, TObject *obj) override
static THttpServer * gHttpServer
Bool_t CmdOpenFile(const char *fname)
Bool_t RemoteTreeDraw(const char *histoname, const char *treename, const char *varexpr, const char *cutexpr)
TGo4Ratemeter * fRatemeter
void * FindInHierarchy(const char *path, TClass **cl=nullptr, TDataMember **member=nullptr, Int_t *chld=nullptr) override
void ProcessSnifferEvents() override
Method called in go4 analysis thread, used to executed server commands.
TGo4Sniffer(const char *name)
TGo4AnalysisWebStatus * fAnalysisStatus
Bool_t HasProduceMultiMethod()
Indicate that sniffer has MultiProcess method implemented, can be used from GUI.
TGo4MsgList fStatusMessages
Bool_t HasAutoLoadMethod()
Indicate if SetAutoLoad method exists.
Bool_t fbPythonBound
if true, python binding of go4 has already been done.
Bool_t CmdExecute(const char *exeline)
void RestrictGo4(const char *path, const char *options)
Wrapper for new method in TRootSniffer.
virtual void SendStatusMessage(Int_t level, Bool_t printout, const TString &text)
Send message to gui - need to be implemented.