21#include "TClassTable.h"
24#include "TMethodArg.h"
27#include "TObjString.h"
28#include "TInterpreter.h"
47#define PROCESSLOOPDELAY 20
49#define TERMCOUNTS 10000
54 std::cerr <<
"Error: " << msg << std::endl;
55 std::cerr <<
"Call 'go4analysis -help' to see list of available arguments" << std::endl;
61 std::cout <<
" -file filename : use file filename (lmd or lml) as MBS event source (short: -f)" << std::endl;
62 std::cout <<
" -transport server : connect to MBS transport server (short: -tr)" << std::endl;
63 std::cout <<
" -stream server : connect to MBS stream server (short: -st)" << std::endl;
64 std::cout <<
" -evserv server : connect to MBS event server (short: -ev)" << std::endl;
65 std::cout <<
" -revserv server [port] : connect to remote event server (short: -rev)" << std::endl;
66 std::cout <<
" -random : use random generator as source (short: -rnd)" << std::endl;
68 std::cout <<
" -hdf5 name : use HDF5 formatted file (h5) as event source" << std::endl;
70 std::cout <<
" -user name : create user-defined event source" << std::endl;
71 std::cout <<
" -timeout tm : specify timeout parameter for event source" << std::endl;
72 std::cout <<
" -skip num : skip num first events in mbs event source" << std::endl;
73 std::cout <<
" -mbs-select first last step : select events interval from mbs source " << std::endl;
74 std::cout <<
" first: sequence number of the first event (starts from 0)" << std::endl;
75 std::cout <<
" last: sequence number of the last event" << std::endl;
76 std::cout <<
" step: step over several events, 1 means all events are used" << std::endl;
80void usage(
const char *subtopic =
nullptr)
82 std::cout << std::endl;
83 std::cout <<
"GO4 analysis runnable " <<
__GO4RELEASE__ << std::endl;
84 std::cout <<
"S. Linev, GSI, Darmstadt" << std::endl;
86 if (subtopic && (strlen(subtopic) > 0)) {
87 const char *sub = subtopic;
88 if (*sub ==
'-') sub++;
90 if ((strcmp(subtopic,
"sources") == 0) || (strcmp(subtopic,
"src") == 0) || (strcmp(subtopic,
"src") == 0)) {
91 std::cout <<
"These are arguments of go4analysis which allows to specify event source" << std::endl;
95 if ((strcmp(sub,
"print") == 0) || (strcmp(sub,
"pr") == 0) ||
96 (strcmp(sub,
"type") == 0) || (strcmp(sub,
"ty") == 0)) {
97 std::cout <<
"Usage of go4analysis -print command." << std::endl;
98 std::cout << std::endl;
99 std::cout <<
" go4analysis -print|-pr|-type|-ty [PROPT] [SOURCE] [MISC]" << std::endl;
100 std::cout << std::endl;
101 std::cout <<
"PROPT: print options, right after -print command" << std::endl;
102 std::cout <<
" hex : print data in hexadecimal format" << std::endl;
103 std::cout <<
" dec : print data in decimal format" << std::endl;
104 std::cout <<
" long : print data in long (4 bytes) form (default)" << std::endl;
105 std::cout <<
" short : print data in short (2 bytes) form" << std::endl;
106 std::cout <<
" sub=N : select subevent id N (default all subevents are shown)" << std::endl;
107 std::cout <<
" fhead : print current lmd file header" << std::endl;
108 std::cout <<
" bhead : print current buffer header" << std::endl;
109 std::cout <<
"SOURCE: event source print options" << std::endl;
111 std::cout <<
"MISC: other options, which may be relevant for \"print\" command" << std::endl;
112 std::cout <<
" -number M : print M events, default is 1 (short: -num)" << std::endl;
113 std::cout <<
" -lib name : load library, may be required for user-defined sources" << std::endl;
114 std::cout <<
" -v : enable verbose mode to see some debug output (default: -v2)" << std::endl;
115 std::cout << std::endl;
116 std::cout <<
" Print event header from MBS stream server" << std::endl;
117 std::cout <<
" go4analysis -stream r4-4 -print " << std::endl;
118 std::cout << std::endl;
119 std::cout <<
" Print event data in hexadecimal form from MBS event server" << std::endl;
120 std::cout <<
" go4analysis -ev r2-1 -pr hex" << std::endl;
121 std::cout << std::endl;
122 std::cout <<
" Print 5 events with subevent id=1 in decimal form from MBS transport server" << std::endl;
123 std::cout <<
" go4analysis -tr r2-2 -num 5 -ty dec sub=1 " << std::endl;
124 std::cout << std::endl;
127 std::cout <<
"No help for topic: \""<< subtopic <<
"\"" << std::endl;
128 std::cout <<
"Available: print, sources" << std::endl;
133 std::cout <<
"calling: " << std::endl;
134 std::cout <<
"" << std::endl;
135 std::cout <<
" go4analysis [RUN] [ANALYSIS] [STEP1] [STEP2] ... [USER]" << std::endl;
136 std::cout <<
"" << std::endl;
137 std::cout <<
"RUN: configuration, relevant for application run mode" << std::endl;
138 std::cout <<
" -lib name : user library to load (default: libGo4UserLibrary)" << std::endl;
139 std::cout <<
" -server [name] : run analysis in server mode, name - optional analysis name" << std::endl;
140 std::cout <<
" -gui name guihost guiport : run analysis in gui mode, used by GUI launch analysis" << std::endl;
142 std::cout <<
" -http [port] : run analysis with web-server running, " << std::endl;
143 std::cout <<
" optionally port can be specified, default 8080" << std::endl;
144 std::cout <<
" -auth [filename] : use authentication file to restrict access to http server " << std::endl;
145 std::cout <<
" file should contain 'controller' and 'admin' accounts for 'go4' domain" << std::endl;
146 std::cout <<
" Could be generated with htdigets utility, by default '$GO4SYS/etc/.htdigest' filename is used" << std::endl;
147 std::cout <<
" -fastcgi port : run analysis with fastcgi server running, "<< std::endl;
148 std::cout <<
" which can deliver data to normal webserver (see mod_proxy_fcgi for Apache)" << std::endl;
149 std::cout <<
" -jsroot location : use JSROOT from other location like https://root.cern.ch/js/latest/" << std::endl;
151 std::cout <<
" -dabc master_host:port : run analysis with optional connection to dabc application, "<< std::endl;
152 std::cout <<
" which could receive objects from running analysis" << std::endl;
155 std::cout <<
" -run : run analysis in server mode (default only run if source specified)" << std::endl;
156 std::cout <<
" -norun : exclude automatical run" << std::endl;
157 std::cout <<
" -number NUMBER : process NUMBER events in batch mode" << std::endl;
158 std::cout <<
" -hserver [name [passwd]] : start histogram server with optional name and password" << std::endl;
159 std::cout <<
" -log [filename] : enable log output into filename (default:go4logfile.txt)" << std::endl;
160 std::cout <<
" -v -v0 -v1 -v2 -v3 : change log output verbosity (0 - maximum, 1 - info, 2 - warn, 3 - errors)" << std::endl;
161 std::cout <<
" -gdebug [lvl] : set ROOT gDebug value, default 1" << std::endl;
162 std::cout <<
" -rate : display rate information during run" << std::endl;
163 std::cout <<
" -print [sub=N] [hex|dec] : print events, see -help print for more info" << std::endl;
164 std::cout <<
" -help [topic] : show this help or for selected topic" << std::endl;
165 std::cout <<
" -version : print only go4 version" << std::endl;
166 std::cout <<
" -graphics : enable graphics in the analysis" << std::endl;
167 std::cout <<
"" << std::endl;
168 std::cout <<
"ANALYSIS: common analysis configurations" << std::endl;
169 std::cout <<
" -name name : specify analysis instance name" << std::endl;
170 std::cout <<
" -asf [filename] : enable store autosave file and set autosave filename (default <Name>ASF.root)" << std::endl;
171 std::cout <<
" -enable-asf [interval] : enable store of autosave file, optionally interval in seconds" << std::endl;
172 std::cout <<
" -disable-asf : disable usage of asf" << std::endl;
173 std::cout <<
" -prefs [filename] : load preferences (analysis configuration) from specified file (default Go4AnalysisPrefs.root)" << std::endl;
174 std::cout <<
" -no-prefs : disable preferences loading" << std::endl;
175 std::cout <<
" -maxtreesize value : define maximum tree size, value can be: 2g, 1900m, 1900000000" << std::endl;
176 std::cout <<
"" << std::endl;
177 std::cout <<
"STEP: individual step configurations" << std::endl;
178 std::cout <<
" -step name : select step by it's name, if not found, first step will be used" << std::endl;
179 std::cout <<
" -step number : select step by it's number (first step has number 0)" << std::endl;
180 std::cout <<
" -enable-step : enable step processing" << std::endl;
181 std::cout <<
" -disable-step : disable step processing" << std::endl;
182 std::cout <<
" -file filename : use file filename (lmd or lml) as MBS event source" << std::endl;
183 std::cout <<
" -transport server : connect to MBS transport server" << std::endl;
184 std::cout <<
" -stream server : connect to MBS stream server" << std::endl;
185 std::cout <<
" -evserv server : connect to MBS event server" << std::endl;
186 std::cout <<
" -revserv server [port] : connect to remote event server" << std::endl;
187 std::cout <<
" -port number : select custom port number for event source" << std::endl;
188 std::cout <<
" -retry number : select number of retries when connection to source was lost" << std::endl;
189 std::cout <<
" -random : use random generator as source" << std::endl;
190 std::cout <<
" -user name : create user-defined event source" << std::endl;
191 std::cout <<
" -source filename : read step input from the root file" << std::endl;
193 std::cout <<
" -hdf5 filename : read step input from hdf5 file (.h5)" << std::endl;
195 std::cout <<
" -skip num : skip num first events in mbs event source" << std::endl;
196 std::cout <<
" -mbs-select first last step : select events interval from mbs source" << std::endl;
197 std::cout <<
" -timeout tm : specify timeout parameter for event source" << std::endl;
198 std::cout <<
" -enable-source : enable step source" << std::endl;
199 std::cout <<
" -disable-source : disable step source" << std::endl;
200 std::cout <<
" -store filename [split buffersize compression] : write step output into the root file" << std::endl;
201 std::cout <<
" -overwrite-store : overwrite file, when store output" << std::endl;
202 std::cout <<
" -append-store : append to file, when store output" << std::endl;
203 std::cout <<
" -backstore name : create backstore for online tree draw" << std::endl;
205 std::cout <<
" -hdf5store filename : write step output into hdf5 file (.h5)" << std::endl;
207 std::cout <<
" -userstore name : create user-defined store for output data" << std::endl;
208 std::cout <<
" -enable-store : enable step store" << std::endl;
209 std::cout <<
" -disable-store : disable step store" << std::endl;
210 std::cout <<
" -enable-errstop : enable stop-on-error mode" << std::endl;
211 std::cout <<
" -disable-errstop : disable stop-on-error mode" << std::endl;
212 std::cout <<
" -inpevt-class name : (re)define class name of input event" << std::endl;
213 std::cout <<
" -outevt-class name : (re)define class name of output event" << std::endl;
214 std::cout << std::endl;
215 std::cout <<
"USER: user-defined arguments" << std::endl;
216 std::cout <<
" -args [userargs] : create user analysis with constructor (int argc, char **argv) signature" << std::endl;
217 std::cout <<
" all following arguments will be provided as array of strings, first argument - analysis name" << std::endl;
218 std::cout << std::endl;
263int FindArg(
int argc,
char **argv,
const char *argname)
265 if (!argname || (strlen(argname) == 0))
267 for (
int n = 0; n < argc; n++)
268 if (strcmp(argv[n], argname) == 0)
273const char *
GetArgValue(
int argc,
char **argv,
const char *argname,
int* pos =
nullptr,
bool incomplete =
false)
275 int n = pos ? *pos : 0;
278 if (strcmp(argv[n], argname) == 0) {
279 if ((n+1<argc) && (argv[n+1][0]!=
'-')) {
296 char *name =
nullptr;
298 TList *lst =
new TList;
299 lst->SetOwner(kTRUE);
301 if (prev)
TGo4Log::Debug(
"Search user classes in loaded library");
303 while ((name = TClassTable::Next()) !=
nullptr) {
304 if (prev && prev->FindObject(name))
continue;
306 auto obj =
new TNamed(name, name);
318 TObjArray evnt_classes;
320 TClass *proc_cl =
nullptr, *an_cl =
nullptr, *evsrc_cl =
nullptr, *evstore_cl =
nullptr;
322 while (
auto obj = iter()) {
323 TClass *cl = TClass::GetClass(obj->GetName());
326 if (!cl || !cl->IsStartingWithTObject())
continue;
328 if (cl->InheritsFrom(TGo4EventProcessor::Class())) {
330 if ((cl != TGo4EventProcessor::Class()) && (!proc_cl || cl->InheritsFrom(proc_cl)))
332 }
else if (cl->InheritsFrom(TGo4EventSource::Class())) {
333 if ((cl != TGo4EventSource::Class()) && !evsrc_cl)
335 }
else if (cl->InheritsFrom(TGo4EventStore::Class())) {
336 if ((cl != TGo4EventStore::Class()) && !evstore_cl)
338 }
else if (cl->InheritsFrom(TGo4EventElement::Class())) {
339 if (cl != TGo4EventElement::Class())
340 evnt_classes.Add(cl);
341 }
else if (cl->InheritsFrom(TGo4Analysis::Class())) {
342 if ((cl != TGo4Analysis::Class()) && !an_cl)
353 TGo4Log::Info(
"Find user analysis class %s", an_cl->GetName());
355 TMethod* meth = an_cl->GetMethodWithPrototype(an_cl->GetName(),
"int,char**");
357 TGo4Log::Info(
"!!! Find constructor with prototype %s::%s(int, char **)", an_cl->GetName(), an_cl->GetName());
359 if ((user_argc > 0) && user_argv) {
360 user_argv[0] = (
char*) name;
363 user_argv = (
char **) &name;
367 TString cmd = TString::Format(
"new %s(%d, (char **)0x%x)", an_cl->GetName(), user_argc, user_argv);
369 TString cmd = TString::Format(
"new %s(%d, (char **)%p)", an_cl->GetName(), user_argc, user_argv);
377 if (analysis && (err == 0))
return analysis;
379 TGo4Log::Error(
"Cannot create analysis class %s instance with (int, char **) prototype", an_cl->GetName());
380 TGo4Log::Error(
"Implement correct analysis constructor with such signature in user library");
385 meth = an_cl->GetMethodWithPrototype(an_cl->GetName(),
"const char*");
387 TGo4Log::Info(
"!!! Find constructor with prototype %s::%s(const char *)", an_cl->GetName(), an_cl->GetName());
389 TString cmd = TString::Format(
"new %s(\"%s\")", an_cl->GetName(), name);
396 if (analysis && (err == 0))
return analysis;
398 TGo4Log::Error(
"Cannot create analysis class %s instance with (const char *) prototype", an_cl->GetName());
399 TGo4Log::Error(
"Implement correct analysis constructor with such signature in user library");
404 TIter iter(an_cl->GetListOfMethods());
405 while ((meth = (TMethod*) iter()) !=
nullptr) {
406 if (strcmp(meth->GetName(), an_cl->GetName()) != 0)
continue;
407 if (meth->GetListOfMethodArgs()->GetSize() == 0)
continue;
412 TGo4Log::Error(
"Cannot find non-default constructor for class %s", an_cl->GetName());
413 TGo4Log::Error(
"Implement analysis constructor with (const char *) or (int, char **) signature");
414 TGo4Log::Error(
"Or define TGo4Analysis *CreateUserAnalysis(const char *) function in user library");
418 TGo4Log::Info(
"Find constructor with %d arguments", meth->GetListOfMethodArgs()->GetSize());
420 TIter next(meth->GetListOfMethodArgs());
422 TString cmd = TString::Format(
"new %s(", an_cl->GetName());
426 while (
auto argument = (TMethodArg *) next()) {
428 if (counter > 0) cmd+=
", ";
431 TDataType *datatype = gROOT->GetType(argument->GetTypeName());
433 TString basictype = !datatype ?
"int" : datatype->GetTypeName();
435 TGo4Log::Debug(
"Argument %s type %s basictype %s", argument->GetName(), argument->GetTitle(), basictype.Data());
437 TString argDflt = argument->GetDefault() ? argument->GetDefault() :
"";
438 if (argDflt.Length()>0) {
443 bool isptr = strchr(argument->GetTitle(),
'*') !=
nullptr;
445 if (!datatype && !isptr) {
446 TGo4Log::Error(
"Cannot specify any value for argument %s of class %s constructor", argument->GetName(), an_cl->GetName());
447 TGo4Log::Error(
"Add CreateUserAnalysis(const char *) function in user library");
452 if ((basictype ==
"char") || (basictype ==
"Text_t")) cmd +=
"\"\"";
455 if ((counter==2) && (basictype==
"int")) {
456 TGo4Log::Info(
"Special treatment for second integer argument, suppose MBS input type");
459 if (basictype==
"bool") {
471 if (analysis && (err == 0))
return analysis;
473 TGo4Log::Error(
"Cannot create analysis class %s instance", an_cl->GetName());
474 TGo4Log::Error(
"Add CreateUserAnalysis(const char *) function in user library");
479 TClass *outev_cl =
nullptr, *inpev_cl =
nullptr;
481 const char *inp_evnt_classname =
GetArgValue(user_argc, user_argv,
"-inpevt-class");
482 const char *out_evnt_classname =
GetArgValue(user_argc, user_argv,
"-outevt-class");
484 if (inp_evnt_classname) {
485 inpev_cl = gROOT->GetClass(inp_evnt_classname);
491 if (!inpev_cl->InheritsFrom(TGo4EventElement::Class())) {
492 TGo4Log::Error(
"Class %s cannot be used as input event", inp_evnt_classname);
496 evnt_classes.Remove(inpev_cl);
497 evnt_classes.Compress();
500 if (out_evnt_classname) {
501 outev_cl = gROOT->GetClass(out_evnt_classname);
507 if (!outev_cl->InheritsFrom(TGo4EventElement::Class())) {
508 TGo4Log::Error(
"Class %s cannot be used as output event", out_evnt_classname);
512 evnt_classes.Remove(outev_cl);
513 evnt_classes.Compress();
518 if (evsrc_cl && !inpev_cl && (evnt_classes.GetLast() >= 0)) {
523 for (
int n = 0; n <= evnt_classes.GetLast(); n++) {
524 TClass *cl = (TClass *) evnt_classes.At(n);
528 if (inpev_cl) { inpev_cl =
nullptr;
break; }
537 evnt_classes.Remove(inpev_cl);
538 evnt_classes.Compress();
544 for (
int n = 0; n <= evnt_classes.GetLast(); n++) {
545 TClass *cl = (TClass *)evnt_classes.At(n);
546 if (!outev_cl || cl->InheritsFrom(outev_cl)) outev_cl = cl;
550 TGo4Log::Info(
"Create default analysis with print-processor class");
553 if (!proc_cl)
return nullptr;
554 TGo4Log::Info(
"Create default analysis with processor class %s", proc_cl->GetName());
556 TGo4Log::Info(
"Use class %s as output event", outev_cl->GetName());
561 TGo4Log::Info(
"Use class %s as input event", inpev_cl->GetName());
593 step->SetSourceEnabled(kTRUE);
594 step->SetStoreEnabled(evstore_cl !=
nullptr);
595 step->SetProcessEnabled(kTRUE);
596 step->SetErrorStopEnabled(kTRUE);
609 std::cerr <<
"Please check your system configuration and restart analysis again" << std::endl;
618 if ((
FindArg(argc, argv,
"-version") > 0) || (
FindArg(argc, argv,
"--version") > 0)) {
623 int phelp =
FindArg(argc, argv,
"-help");
624 if (phelp < 0) phelp =
FindArg(argc, argv,
"-h") > 0;
626 usage(phelp < argc-1 ? argv[phelp+1] : 0);
631 char **user_argv =
nullptr;
633 int userargspos =
FindArg(argc, argv,
"-args");
634 if (userargspos<0) userargspos =
FindArg(argc, argv,
"-x");
636 user_argc = argc - userargspos;
637 user_argv = argv + userargspos;
642 bool doprint = (
FindArg(argc, argv,
"-print") > 0) || (
FindArg(argc, argv,
"-type") > 0) ||
643 (
FindArg(argc, argv,
"-pr") > 0) || (
FindArg(argc, argv,
"-ty") > 0);
646 const char *logfile =
GetArgValue(argc, argv,
"-log", 0,
true);
654 TString info =
"go4analysis";
655 for (
int n = 1; n < argc; n++) { info +=
" "; info += argv[n]; }
660 if ((
FindArg(argc, argv,
"-v") > 0) || (
FindArg(argc, argv,
"-verbose") > 0))
662 else if (
FindArg(argc, argv,
"-v0") > 0)
664 else if (
FindArg(argc, argv,
"-v1") > 0)
666 else if (
FindArg(argc, argv,
"-v2") > 0)
668 else if (
FindArg(argc, argv,
"-v3") > 0)
672 if (
FindArg(argc, argv,
"-gui") > 0)
674 else if (
FindArg(argc, argv,
"-server") > 0)
680 gInterpreter->SetProcessLineLock(kFALSE);
686 if (go4inc.Length() > 0)
687 gInterpreter->AddIncludePath(go4inc.Data());
689 const char *extra_incl = gSystem->Getenv(
"GO4EXTRAINCLUDE");
690 if (extra_incl && *extra_incl)
691 gInterpreter->AddIncludePath(extra_incl);
693 const char *analysis_name =
GetArgValue(argc, argv,
"-server");
694 if (!analysis_name) analysis_name =
GetArgValue(argc, argv,
"-gui");
695 if (!analysis_name) analysis_name =
GetArgValue(argc, argv,
"-name");
696 if (!analysis_name) analysis_name =
"Go4Analysis";
701 bool isanylib =
false;
702 const char *libname =
nullptr;
703 while ((libname =
GetArgValue(argc, argv,
"-lib", &argpos)) !=
nullptr) {
705 if (gSystem->Load(libname)<0)
return -1;
710 if (!isanylib && (!doprint ||
GetArgValue(argc, argv,
"-user"))) {
711 libname =
"libGo4UserAnalysis";
713 if (gSystem->Load(libname)<0)
return -1;
721 if (crfunc) analysis = crfunc(analysis_name);
725 std::cerr <<
"!!! Analysis instance cannot be created" << std::endl;
726 std::cerr <<
"!!! PLEASE check your analysis library " << libname << std::endl;
727 std::cerr <<
"!!! One requires user subclass for TGo4Analysis class in user library" << std::endl;
728 std::cerr <<
"!!! Alternatively, CreateUserAnalysis(const char *) function can be implemented" << std::endl;
729 std::cerr <<
"!!! See Go4ExampleSimple, Go4Example1Step or Go4Example2Step for details" << std::endl;
733 delete lst0; lst0 =
nullptr;
734 delete lst1; lst1 =
nullptr;
738 std::cerr <<
"No active step in analysis found" << std::endl;
746 gROOT->SetBatch(kTRUE);
749 http_args.SetOwner(kTRUE);
751 const char *auth_domain =
"go4";
754 Bool_t batchMode = kTRUE;
755 Bool_t servermode = kFALSE;
756 Bool_t httpmode = kFALSE;
757 Bool_t hserver = kFALSE;
758 Bool_t loadprefs = kTRUE;
759 Bool_t showrate = kFALSE;
760 Double_t process_interv = -1.;
761 const char *hname =
"";
762 const char *hpasswd =
"";
763 const char *hostname =
"localhost";
766 bool autorun =
false;
779 while (narg < argc) {
780 if (strcmp(argv[narg],
"-server") == 0) {
785 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-')) narg++;
787 if(strcmp(argv[narg],
"-gui") == 0) {
789 if (argc <= narg + 3)
showerror(
"Not all -gui arguments specified");
792 hostname = argv[narg++];
793 iport = atoi(argv[narg++]);
796 if (strcmp(argv[narg],
"-http") == 0) {
799 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
800 http_args.Add(
new TObjString(TString::Format(
"http:%s?top=Go4", argv[narg++])));
802 http_args.Add(
new TObjString(
"http:8080?top=Go4"));
804 if (strcmp(argv[narg],
"-fastcgi") == 0) {
807 if (narg >= argc)
showerror(
"fastcgi options not specified");
808 http_args.Add(
new TObjString(TString::Format(
"fastcgi:%s?top=Go4", argv[narg++])));
810 if (strcmp(argv[narg],
"-jsroot") == 0) {
812 if (narg >= argc)
showerror(
"jsroot location not specified");
813 http_args.Add(
new TObjString(TString::Format(
"jsroot:%s", argv[narg++])));
815 if (strcmp(argv[narg],
"-auth") == 0) {
817 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
818 auth_file = argv[narg++];
822 if (strcmp(argv[narg],
"-domain") == 0) {
824 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
825 auth_domain = argv[narg++];
830 if (strcmp(argv[narg],
"-dabc") == 0) {
832 if (narg >= argc)
showerror(
"Master dabc node not specified");
833 const char *hostname = gSystem->HostName();
834 if (!hostname || (*hostname == 0)) hostname =
"localhost";
835 http_args.Add(
new TObjString(TString::Format(
"dabc:%s?top=Go4/%s_pid%d", argv[narg++],hostname,gSystem->GetPid())));
839 if(strcmp(argv[narg],
"-lib") == 0) {
841 if (++narg >= argc)
showerror(
"library name not specified");
844 if(strcmp(argv[narg],
"-name") == 0) {
846 if (++narg >= argc)
showerror(
"analysis name not specified");
849 if (strcmp(argv[narg],
"-step") == 0) {
851 const char *step_name = argv[narg++];
852 int step_number = -1;
854 if (sscanf(step_name,
"%d", &step_number) == 1)
861 if(strcmp(argv[narg],
"-enable-step") == 0) {
865 if(strcmp(argv[narg],
"-disable-step") == 0) {
869 if ((strcmp(argv[narg],
"-file") == 0) || (strcmp(argv[narg],
"-f") == 0)) {
873 while ((narg<argc) && (argv[narg][0]!=
'-'))
879 showerror(
"LMD/LML file name not specified");
881 if (strcmp(argv[narg],
"-source") == 0) {
888 showerror(
"Input file name not specified");
890 if ((strcmp(argv[narg],
"-transport") == 0) || (strcmp(argv[narg],
"-tr") == 0)) {
897 showerror(
"MBS Transport server name not specified");
899 if ((strcmp(argv[narg],
"-stream") == 0) || (strcmp(argv[narg],
"-st") == 0)) {
906 showerror(
"MBS Stream server name not specified");
908 if ((strcmp(argv[narg],
"-evserv") == 0) || (strcmp(argv[narg],
"-ev") == 0)) {
915 showerror(
"MBS Event server name not specified");
917 if ((strcmp(argv[narg],
"-random") == 0) || (strcmp(argv[narg],
"-rnd") == 0)) {
924 if (strcmp(argv[narg],
"-user") == 0) {
931 showerror(
"User source name not specified");
935 if (strcmp(argv[narg],
"-hdf5") == 0) {
942 showerror(
"HDF5 file name not specified");
947 if ((strcmp(argv[narg],
"-revserv") == 0) || (strcmp(argv[narg],
"-rev") == 0)) {
949 const char *serv_name = argv[narg++];
951 if ((narg < argc) && (argv[narg][0] !=
'-'))
952 serv_port = atoi(argv[narg++]);
958 showerror(
"Remote event server name or port are not specified");
960 if (strcmp(argv[narg],
"-skip") == 0) {
963 if (!param)
showerror(
"only in MBS source events can be skipped");
964 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-')) {
966 if (sscanf(argv[narg],
"%u",&value)!=1)
967 showerror(TString::Format(
"Value error %s", argv[narg]));
972 if (strcmp(argv[narg],
"-port") == 0) {
975 if ((narg < argc) && (argv[narg][0] !=
'-')) {
976 if (sscanf(argv[narg],
"%d",&port)!=1)
977 showerror(TString::Format(
"Value error %s", argv[narg]));
981 if (param) param->
SetPort(port);
986 if (strcmp(argv[narg],
"-retry") == 0) {
989 if ((narg < argc) && (argv[narg][0]!=
'-')) {
990 if (sscanf(argv[narg],
"%d",&nretry)!=1)
991 showerror(TString::Format(
"Value error %s", argv[narg]));
997 if (strcmp(argv[narg],
"-mbs-select") == 0) {
1000 if (!param)
showerror(
"only in MBS source events can be selected");
1002 while ((cnt < 3) && (narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0] !=
'-')) {
1004 if ((cnt==1) && (strcmp(argv[narg],
"all") == 0)) value = 0;
else
1005 if (sscanf(argv[narg],
"%u",&value)!=1)
1006 showerror(TString::Format(
"Value error %s", argv[narg]));
1013 if(strcmp(argv[narg],
"-store") == 0) {
1014 if (++narg >= argc)
showerror(
"Store name not specified");
1016 const char *sourcename = argv[narg++];
1018 int buffersize = 64000;
1019 int compression = 5;
1022 while ((cnt < 3) && (narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0] !=
'-')) {
1024 if (sscanf(argv[narg],
"%d",&value)!=1)
1025 showerror(TString::Format(
"Value error %s", argv[narg]));
1026 if (cnt == 0) splitlevel = value;
else
1027 if (cnt==1) buffersize = value;
else
1028 if (cnt==2) compression = value;
1036 if (strcmp(argv[narg],
"-timeout") == 0) {
1037 if (++narg >= argc)
showerror(
"Timeout value not specified");
1040 if (sscanf(argv[narg],
"%d",&value)!=1)
1041 showerror(TString::Format(
"Timeout value error %s", argv[narg]));
1045 if (strcmp(argv[narg],
"-overwrite-store") == 0) {
1049 else showerror(
"No file-store parameter available");
1051 if (strcmp(argv[narg],
"-append-store") == 0) {
1055 else showerror(
"No file-store parameter available");
1057 if(strcmp(argv[narg],
"-backstore") == 0) {
1058 if (++narg < argc) {
1063 showerror(
"Backstore name not specified");
1065 if(strcmp(argv[narg],
"-userstore") == 0) {
1066 if (++narg < argc) {
1071 showerror(
"User store name not specified");
1074 if(strcmp(argv[narg],
"-hdf5store") == 0) {
1075 if (++narg < argc) {
1080 showerror(
"HDF5 store name not specified");
1083 if ((strcmp(argv[narg],
"-events") == 0) || (strcmp(argv[narg],
"-number") == 0) || (strcmp(argv[narg],
"-num") == 0)) {
1084 if (++narg < argc) {
1085 if (sscanf(argv[narg++],
"%ld",&maxevents)!=1) maxevents = -1;
1087 showerror(
"number of events to process not specified");
1089 if (strcmp(argv[narg],
"-asf") == 0) {
1092 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
1095 if (strcmp(argv[narg],
"-enable-asf") == 0) {
1098 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
1101 if (strcmp(argv[narg],
"-disable-asf") == 0) {
1105 if (strcmp(argv[narg],
"-prefs") == 0) {
1107 const char *fname =
nullptr;
1108 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
1109 fname = argv[narg++];
1113 if (strcmp(argv[narg],
"-no-prefs") == 0) {
1117 if(strcmp(argv[narg],
"-log") == 0) {
1119 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-')) narg++;
1121 if(strcmp(argv[narg],
"-gdebug") == 0) {
1123 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
1124 gDebug = TString(argv[narg++]).Atoi();
1128 if((strcmp(argv[narg],
"-v") == 0) || (strcmp(argv[narg],
"-v0") == 0) || (strcmp(argv[narg],
"-v1") == 0) || (strcmp(argv[narg],
"-v2") == 0) || (strcmp(argv[narg],
"-v3") == 0)) {
1131 if((strcmp(argv[narg],
"-graphics") == 0) || (strcmp(argv[narg],
"-gr") == 0)) {
1133 gROOT->SetBatch(kFALSE);
1134 process_interv = 0.1;
1135 new TApplication(
"Go4App", &app_argc, argv);
1136 TStyle::BuildStyles();
1139 if(strcmp(argv[narg],
"-run") == 0) {
1143 if(strcmp(argv[narg],
"-norun") == 0) {
1147 if(strcmp(argv[narg],
"-maxtreesize") == 0) {
1149 long long maxtreesize = 1900000000;
1150 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-')) {
1152 strncpy(sbuf, argv[narg],
sizeof(sbuf)-1);
1153 long long mult = 1, val = 1;
1154 int len = strlen(sbuf);
1155 if ((sbuf[len-1]==
'g') || (sbuf[len-1]==
'G')) { mult = 1000000000; sbuf[len-1] = 0; }
else
1156 if ((sbuf[len-1]==
'm') || (sbuf[len-1]==
'M')) { mult = 1000000; sbuf[len-1] = 0; }
else
1157 if ((sbuf[len-1]==
'k') || (sbuf[len-1]==
'K')) { mult = 1000; sbuf[len-1] = 0; }
1158 if (sscanf(sbuf,
"%lld", &val)==1) maxtreesize = val*mult;
1161 TGo4Log::Info(
"Set tree file size limit to %lld bytes", maxtreesize);
1164 if ((strcmp(argv[narg],
"-print") == 0) || (strcmp(argv[narg],
"-type") == 0) || (strcmp(argv[narg],
"-ty") == 0) || (strcmp(argv[narg],
"-pr") == 0)) {
1166 while ((narg<argc) && (argv[narg][0]!=
'-')) {
1167 if (strncmp(argv[narg],
"sub=",4) == 0) {
1170 if (strcmp(argv[narg],
"hex") == 0) {
1174 if (strcmp(argv[narg],
"dec") == 0) {
1178 if (strcmp(argv[narg],
"long") == 0) {
1182 if (strcmp(argv[narg],
"short") == 0) {
1186 if (strcmp(argv[narg],
"data") == 0) {
1189 if (strcmp(argv[narg],
"nodata") == 0) {
1192 if (strcmp(argv[narg],
"fhead") == 0) {
1195 if (strcmp(argv[narg],
"bhead") == 0) {
1201 if(strcmp(argv[narg],
"-enable-store") == 0) {
1205 if(strcmp(argv[narg],
"-disable-store") == 0) {
1209 if(strcmp(argv[narg],
"-enable-source") == 0) {
1213 if(strcmp(argv[narg],
"-disable-source") == 0) {
1217 if(strcmp(argv[narg],
"-disable-errstop") == 0) {
1221 if(strcmp(argv[narg],
"-enable-errstop") == 0) {
1225 if(strcmp(argv[narg],
"-rate") == 0) {
1229 if(strcmp(argv[narg],
"-norate") == 0) {
1233 if(strcmp(argv[narg],
"-inpevt-class") == 0) {
1237 if (narg < argc) narg++;
1239 if(strcmp(argv[narg],
"-outevt-class") == 0) {
1243 if (narg < argc) narg++;
1245 if(strcmp(argv[narg],
"-hserver") == 0) {
1248 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
1249 hname = argv[narg++];
1250 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!=
'-'))
1251 hpasswd = argv[narg++];
1253 showerror(TString::Format(
"Unknown argument %d %s", narg, argv[narg]));
1257 if (http_args.GetLast() >= 0) {
1258 if (gSystem->Load(
"libGo4Http") != 0)
1259 showerror(
"Fail to load libGo4Http.so library");
1266 for (Int_t n = 0; n <= http_args.GetLast(); n++) {
1267 TString engine = http_args[n]->GetName();
1268 if ((engine.Index(
"http:") == 0) && (auth_file.Length() > 0))
1269 engine.Append(TString::Format(
"&auth_file=%s&auth_domain=%s", auth_file.Data(), auth_domain));
1271 cmd.Form(
"TGo4Sniffer::CreateEngine(\"%s\");", engine.Data());
1273 auto res = gROOT->ProcessLineFast(cmd.Data(), &err);
1274 if ((res <= 0) || (err != 0)) {
1275 printf(
"Fail to start %s", engine.Data());
1280 process_interv = 0.1;
1286 TGo4Log::Info(
"Main: starting analysis in batch mode ... ");
1288 Bool_t enter_loop = kTRUE;
1289 if ((canrun >= 0) || autorun) {
1293 enter_loop = kFALSE;
1300 analysis->
RunImplicitLoop(maxevents, showrate, process_interv, httpmode);
1305 if (!hostname) hostname =
"localhost";
1307 if(servermode)
TGo4Log::Info(
"Main: starting analysis in server mode ...");
1308 else TGo4Log::Info(
"Main: starting analysis in slave mode ...");
1310 if (canrun < 0) autorun =
false;
1312 auto client =
new TGo4AnalysisClient(
"UserClient", analysis, hostname, iport, hserver, hname, hpasswd, servermode, autorun, kFALSE, loadprefs, showrate);
1314 TGo4Log::Info(
"Main: created AnalysisClient instance: %s", client->GetName());
1317 int termcounter = 0;
1331 gSystem->ProcessEvents();
1333 if(client->IsBeingQuit()) {
1334 if(termcounter == 0) {
1338 if (termcounter>0) {
1340 if (termcounter == 0) {
int FindArg(int argc, char **argv, const char *argname)
int main(int argc, char **argv)
void usage(const char *subtopic=nullptr)
TGo4Analysis * CreateDefaultAnalysis(TList *lst, const char *name, int user_argc, char **user_argv, bool doprint)
TList * GetClassesList(TList *prev=nullptr)
void showerror(const TString &msg)
const char * GetArgValue(int argc, char **argv, const char *argname, int *pos=nullptr, bool incomplete=false)
TGo4Analysis * UserCreateFunc(const char *name)
#define __GO4BUILDVERSION__
Contains a single step of the analysis.
void SetErrorStopEnabled(Bool_t on)
Enables or disables the stop-on-error mode.
void SetProcessEnabled(Bool_t on=kTRUE)
Enables or disables the event processing.
void SetStoreEnabled(Bool_t on=kTRUE)
Enables or disables the event store.
TGo4EventStoreParameter * GetEventStore() const
Return current event store parameter.
void SetEventSource(TGo4EventSourceParameter *kind)
Sets the event source parameter which is used on initialization of this step.
TGo4EventSourceParameter * GetEventSource() const
Return current event source parameter.
void SetSourceEnabled(Bool_t on=kTRUE)
Enables or disables the event source.
void SetEventStore(TGo4EventStoreParameter *kind)
Sets the event store parameter which is used on initialization of this step.
The mother of all go4 analysis.
TGo4AnalysisStep * GetAnalysisStepNum(Int_t number)
Access to certain analysis step by number.
static TGo4Analysis * Instance()
return analysis instance
virtual Bool_t InitEventClasses()
Initialization of the event class plugins which are delivered from the user defined event factory.
void StartAnalysis()
(Re)Start analysis event loop, works in both batch and gui-controlled mode
void SetAnalysisName(const char *name)
Set analysis name.
void SetAutoSave(Bool_t on=kTRUE)
Enable/disable functionality of AutoSave method.
TGo4AnalysisStep * GetAnalysisStep(const char *name)
Access to certain analysis step by name.
static void SetRunningMode(int mode)
Set analysis running mode.
void SetAutoSaveFile(const char *filename=nullptr, Bool_t overwrite=kFALSE, Int_t compression=5)
Set file for autosave action.
static Bool_t Exists()
check if analysis instance exists
const char * GetDefaultTestFileName() const
Returns default lmd test file name (in GO4SYS installation directory)
Bool_t AddAnalysisStep(TGo4AnalysisStep *next)
Method for user analysis constructor to setup the list of analysis steps.
Bool_t LoadStatus(const char *filename=nullptr)
Load Analysis Status from file and set analysis to these settings.
Int_t RunImplicitLoop(Int_t times, Bool_t showrate=kFALSE, Double_t process_event_interval=-1., Bool_t iswebserver=kFALSE)
Processes the UserEventFunc in an implicit loop for "times" times.
void SetAutoSaveInterval(Int_t interval=0)
Set time interval (in s) for autosave action.
virtual void PrintEvent()
Method prints content of the event.
Basic type for all classes containing information to parametrize the event processor.
Abstract event processor.
TGo4EventProcessor(const char *name)
TGo4EventElement * GetInputEvent()
Access to external raw event which is set as association member.
friend class TGo4EventElement
void SetTimeout(Int_t out)
virtual Bool_t CheckEventClass(TClass *cl)
Check that event class is supported by event source.
void SetOverwriteMode(Bool_t over=kTRUE)
static void SetMaxTreeSize(Long64_t sz)
static TGo4Log * Instance()
static TString subGO4SYS(const char *subdir)
Return subdirectory in the GO4SYS.
static void Info(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 1.
static void WriteLogfile(const char *text, Bool_t withtime=kTRUE)
Write text to current logfile if this is open.
static void SetIgnoreLevel(Int_t level)
Define threshold for output.
static void LogfileEnable(Bool_t on=kTRUE)
switch writing to logfile on or off
static void Debug(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 0.
static const char * GO4INCPATH()
Return include path for this Go4 installation.
static void EnableRedirection()
static void Error(const char *text,...) GO4_PRINTF_ARGS
User shortcut for message with prio 3.
static void OpenLogfile(const char *name=nullptr, const char *headercomment=nullptr, Bool_t appendmode=kFALSE)
Open file of name for logmessage output.
static void CloseLogfile()
Close logfile if existing.
static const char * GetDefaultLogname()
Return default name of log file.
MBS event server parameter.
Wrapper for the standard gsi event structure as delivered from mbs.
void PrintMbsEvent(Int_t subid=-1, Bool_t longw=kTRUE, Bool_t hexw=kTRUE, Bool_t dataw=kTRUE, Bool_t bufhead=kFALSE, Bool_t filhead=kFALSE)
Print MBS event.
void AddMoreFile(const char *more)
Add more file names in to the parameter.
void SetStartEvent(UInt_t firstindex)
Define the Start index for the NextEvent.
void SetPort(Int_t port)
Set optional port number, 0 or negative value means that default port number will be used.
void SetStopEvent(UInt_t lastindex)
Define the index of Stop event.
void SetRetryCnt(Int_t cnt)
Set number of allowed reconnection retries.
void SetEventInterval(UInt_t skipinterval)
Defines event interval.
static void SetPollingMode(Bool_t on=kTRUE)
TGo4EventProcessor * CreateEventProcessor(TGo4EventProcessorParameter *par)
TGo4PrintFactory(const char *name)
Bool_t BuildEvent(TGo4EventElement *dest) override
Fill the destination event dest.
TGo4PrintProcessor(const char *name)
Ready to use step factory.
void DefUserEventSource(const char *Sclass)
Configure class name for event source.
TGo4StepFactory()
Default constructor.
void DefEventProcessor(const char *Pname, const char *Pclass)
Configure name and class name for event processor.
void DefUserEventStore(const char *Sclass)
Configure class name for event store.
void DefInputEvent(const char *Iname, const char *Iclass)
Configure name and class name for input event.
void DefOutputEvent(const char *Oname, const char *Oclass)
Configure name and class name for output event.
static Bool_t CheckVersion(Int_t version)
Returns true if Version number matches the argument of the Method.