00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <string.h>
00015 #include <stdlib.h>
00016 #include <stdio.h>
00017
00018 #include "TROOT.h"
00019 #include "TClass.h"
00020 #include "TClassTable.h"
00021 #include "TMethod.h"
00022 #include "TMethodArg.h"
00023 #include "TDataType.h"
00024 #include "TRint.h"
00025
00026 #include "TSystem.h"
00027 #include "TObjString.h"
00028 #include "Riostream.h"
00029 #include "RVersion.h"
00030 #include "TSysEvtHandler.h"
00031
00032 #include "TGo4Version.h"
00033 #include "TGo4StepFactory.h"
00034 #include "TGo4AnalysisStep.h"
00035 #include "TGo4Analysis.h"
00036 #include "TGo4AnalysisClient.h"
00037 #include "Go4EventServer.h"
00038 #include "Go4EventServerTypes.h"
00039 #include "TGo4FileStore.h"
00040
00041 #define PROCESSLOOPDELAY 20
00042
00043 #define TERMCOUNTS 10000
00044
00045
00046 void showerror(const char* msg)
00047 {
00048 std::cerr << "Error: " << msg << std::endl;
00049 std::cerr << "Call 'go4analysis -help' to see list of available arguments" << std::endl;
00050 exit(1);
00051 }
00052
00053 void printsources()
00054 {
00055 std::cout << " -file filename : use file filename (lmd or lml) as MBS event source (short: -f)" << std::endl;
00056 std::cout << " -transport server : connect to MBS transport server (short: -tr)" << std::endl;
00057 std::cout << " -stream server : connect to MBS stream server (short: -st)" << std::endl;
00058 std::cout << " -evserv server : connect to MBS event server (short: -ev)" << std::endl;
00059 std::cout << " -revserv server [port] : connect to remote event server (short: -rev)" << std::endl;
00060 std::cout << " -random : use random generator as source (short: -rnd)" << std::endl;
00061 std::cout << " -user name : create user-defined event source" << std::endl;
00062 std::cout << " -timeout tm : specify timeout parameter for event source" << std::endl;
00063 std::cout << " -skip num : skip num first events in mbs event source" << std::endl;
00064 std::cout << " -mbs-select first last step : select events interval from mbs source " << std::endl;
00065 std::cout << " first: sequence number of the first event (starts from 0)" << std::endl;
00066 std::cout << " last: sequence number of the last event" << std::endl;
00067 std::cout << " step: step over several events, 1 means all events are used" << std::endl;
00068
00069 }
00070
00071 void usage(const char* subtopic = 0)
00072 {
00073 std::cout << std::endl;
00074 std::cout << "GO4 analysis runnable " << __GO4RELEASE__ << std::endl;
00075 std::cout << "S. Linev, GSI, Darmstadt" << std::endl;
00076
00077 if ((subtopic!=0) && (strlen(subtopic)>0)) {
00078 const char* sub = subtopic;
00079 if (*sub=='-') sub++;
00080
00081 if ((strcmp(subtopic, "sources")==0) || (strcmp(subtopic, "src")==0) || (strcmp(subtopic, "src")==0)) {
00082 std::cout << "These are arguments of go4analysis which allows to specify event source" << std::endl;
00083 printsources();
00084 exit(0);
00085 } else
00086 if ((strcmp(sub, "print")==0) || (strcmp(sub, "pr")==0) ||
00087 (strcmp(sub, "type")==0) || (strcmp(sub, "ty")==0)) {
00088 std::cout << "Usage of go4analysis -print command." << std::endl;
00089 std::cout << std::endl;
00090 std::cout << " go4analysis -print|-pr|-type|-ty [PROPT] [SOURCE] [MISC]" << std::endl;
00091 std::cout << std::endl;
00092 std::cout << "PROPT: print options, right after -print command" << std::endl;
00093 std::cout << " hex : print data in hexadecimal format" << std::endl;
00094 std::cout << " dec : print data in decimal format" << std::endl;
00095 std::cout << " long : print data in long (4 bytes) form (default)" << std::endl;
00096 std::cout << " short : print data in short (2 bytes) form" << std::endl;
00097 std::cout << " sub=N : select subevent id N (default all subevents are shown)" << std::endl;
00098 std::cout << " fhead : print current lmd file header" << std::endl;
00099 std::cout << " bhead : print current buffer header" << std::endl;
00100 std::cout << "SOURCE: event source print options" << std::endl;
00101 printsources();
00102 std::cout << "MISC: other options, which may be relevant for \"print\" command" << std::endl;
00103 std::cout << " -number M : print M events, default is 1 (short: -num)" << std::endl;
00104 std::cout << " -lib name : load library, may be required for user-defined sources" << std::endl;
00105 std::cout << " -v : enable verbose mode to see some debug output (default: -v2)" << std::endl;
00106 std::cout << std::endl;
00107 std::cout << " Print event header from MBS stream server" << std::endl;
00108 std::cout << " go4analysis -stream r4-4 -print " << std::endl;
00109 std::cout << std::endl;
00110 std::cout << " Print event data in hexadecimal form from MBS event server" << std::endl;
00111 std::cout << " go4analysis -ev r2-1 -pr hex" << std::endl;
00112 std::cout << std::endl;
00113 std::cout << " Print 5 events with subevent id=1 in decimal form from MBS transport server" << std::endl;
00114 std::cout << " go4analysis -tr r2-2 -num 5 -ty dec sub=1 " << std::endl;
00115 std::cout << std::endl;
00116 exit(0);
00117 } else {
00118 std::cout << "No help for topic: \""<< subtopic << "\"" << std::endl;
00119 std::cout << "Available: print, sources" << std::endl;
00120 exit(0);
00121 }
00122 }
00123
00124 std::cout << "calling: " << std::endl;
00125 std::cout << "" << std::endl;
00126 std::cout << " go4analysis [RUN] [ANALYSIS] [STEP1] [STEP2] ... [USER]" << std::endl;
00127 std::cout << "" << std::endl;
00128 std::cout << "RUN: configuration, relevant for application run mode" << std::endl;
00129 std::cout << " -lib name : user library to load (default: libGo4UserLibrary)" << std::endl;
00130 std::cout << " -server [name] : run analysis in server mode, name - optional analysis name" << std::endl;
00131 std::cout << " -gui name guihost guiport : run analysis in gui mode, used by GUI launch analysis" << std::endl;
00132 #ifdef WITH_DABC
00133 std::cout << " -http [port] : run analysis with web-server running, " << std::endl;
00134 std::cout << " optionally port can be specified, default 8080" << std::endl;
00135 std::cout << " -dabc master_host:port : run analysis with optional connection to dabc application, "<< std::endl;
00136 std::cout << " which could receive objects from running analysis" << std::endl;
00137 std::cout << " -fastcgi port : run analysis with fastcgi server running, "<< std::endl;
00138 std::cout << " which can deliver data to normal webserver (see mod_proxy_fcgi for Apache)" << std::endl;
00139 #endif
00140 std::cout << " -run : run analysis in server mode (default only run if source specified)" << std::endl;
00141 std::cout << " -norun : exclude automatical run" << std::endl;
00142 std::cout << " -number NUMBER : process NUMBER events in batch mode" << std::endl;
00143 std::cout << " -hserver [name [passwd]] : start histogram server with optional name and password" << std::endl;
00144 std::cout << " -log [filename] : enable log output into filename (default:go4logfile.txt)" << std::endl;
00145 std::cout << " -v -v0 -v1 -v2 -v3 : change log output verbosity (0 - maximum, 1 - info, 2 - warn, 3 - errors)" << std::endl;
00146 std::cout << " -rate : display rate information during run" << std::endl;
00147 std::cout << " -print [sub=N] [hex|dec] : print events, see -help print for more info" << std::endl;
00148 std::cout << " -help [topic] : show this help or for selected topic" << std::endl;
00149 std::cout << "" << std::endl;
00150 std::cout << "ANALYSIS: common analysis configurations" << std::endl;
00151 std::cout << " -name name : specify analysis instance name" << std::endl;
00152 std::cout << " -asf [filename] : enable store autosave file and set autosave filename (default <Name>ASF.root)" << std::endl;
00153 std::cout << " -enable-asf [interval] : enable store of autosave file, optionally interval in seconds" << std::endl;
00154 std::cout << " -disable-asf : disable usage of asf" << std::endl;
00155 std::cout << " -prefs [filename] : load preferences (analysis configuration) from specified file (default Go4AnalysisPrefs.root)" << std::endl;
00156 std::cout << " -no-prefs : disable preferences loading" << std::endl;
00157 std::cout << " -maxtreesize value : define maximum tree size, value can be: 2g, 1900m, 1900000000" << std::endl;
00158 std::cout << "" << std::endl;
00159 std::cout << "STEP: individual step configurations" << std::endl;
00160 std::cout << " -step name : select step by it's name, if not found, first step will be used" << std::endl;
00161 std::cout << " -step number : select step by it's number (first step has number 0)" << std::endl;
00162 std::cout << " -enable-step : enable step processing" << std::endl;
00163 std::cout << " -disable-step : disable step processing" << std::endl;
00164 std::cout << " -file filename : use file filename (lmd or lml) as MBS event source" << std::endl;
00165 std::cout << " -transport server : connect to MBS transport server" << std::endl;
00166 std::cout << " -stream server : connect to MBS stream server" << std::endl;
00167 std::cout << " -evserv server : connect to MBS event server" << std::endl;
00168 std::cout << " -revserv server [port] : connect to remote event server" << std::endl;
00169 std::cout << " -port number : select custom port number for event source" << std::endl;
00170 std::cout << " -retry number : select number of retries when connection to source was lost" << std::endl;
00171 std::cout << " -random : use random generator as source" << std::endl;
00172 std::cout << " -user name : create user-defined event source" << std::endl;
00173 std::cout << " -source filename : read step input from the root file" << std::endl;
00174 std::cout << " -skip num : skip num first events in mbs event source" << std::endl;
00175 std::cout << " -mbs-select first last step : select events interval from mbs source" << std::endl;
00176 std::cout << " -timeout tm : specify timeout parameter for event source" << std::endl;
00177 std::cout << " -enable-source : enable step source" << std::endl;
00178 std::cout << " -disable-source : disable step source" << std::endl;
00179 std::cout << " -store filename [split buffersize compression] : write step output into the root file" << std::endl;
00180 std::cout << " -overwrite-store : overwrite file, when store output" << std::endl;
00181 std::cout << " -append-store : append to file, when store output" << std::endl;
00182 std::cout << " -backstore name : create backstore for online tree draw" << std::endl;
00183 std::cout << " -enable-store : enable step store" << std::endl;
00184 std::cout << " -disable-store : disable step store" << std::endl;
00185 std::cout << " -enable-errstop : enable stop-on-error mode" << std::endl;
00186 std::cout << " -disable-errstop : disable stop-on-error mode" << std::endl;
00187 std::cout << " -inpevt-class name : (re)define class name of input event" << std::endl;
00188 std::cout << " -outevt-class name : (re)define class name of output event" << std::endl;
00189 std::cout << std::endl;
00190 std::cout << "USER: user-defined arguments" << std::endl;
00191 std::cout << " -args [userargs] : create user analysis with constructor (int argc, char** argv) signature" << std::endl;
00192 std::cout << " all following arguments will be provided as array of strings, first argument - analysis name" << std::endl;
00193 std::cout << std::endl;
00194
00195 exit(0);
00196 }
00197
00198 class TGo4PrintProcessor : public TGo4EventProcessor {
00199 public:
00200 TGo4PrintProcessor(const char* name) : TGo4EventProcessor(name) {}
00201
00202 static Int_t fSubId;
00203 static Bool_t fHex;
00204 static Bool_t fLong;
00205 static Bool_t fData;
00206 static Bool_t fFileHead;
00207 static Bool_t fBufHead;
00208
00209 virtual Bool_t BuildEvent(TGo4EventElement* dest)
00210 {
00211 TGo4EventElement* evnt = GetInputEvent();
00212
00213 TGo4MbsEvent* mbs = dynamic_cast<TGo4MbsEvent*> (evnt);
00214 if (mbs) mbs->PrintMbsEvent(fSubId, fLong, fHex, fData, fBufHead, fFileHead);
00215 else evnt->PrintEvent();
00216
00217 return kTRUE;
00218 }
00219 };
00220
00221 Int_t TGo4PrintProcessor::fSubId = -1;
00222 Bool_t TGo4PrintProcessor::fHex = kTRUE;
00223 Bool_t TGo4PrintProcessor::fLong = kTRUE;
00224 Bool_t TGo4PrintProcessor::fData = kFALSE;
00225 Bool_t TGo4PrintProcessor::fFileHead = kFALSE;
00226 Bool_t TGo4PrintProcessor::fBufHead = kFALSE;
00227
00228 class TGo4PrintFactory : public TGo4StepFactory {
00229 public:
00230 TGo4PrintFactory(const char* name) : TGo4StepFactory(name) {}
00231 TGo4EventProcessor* CreateEventProcessor(TGo4EventProcessorParameter* par)
00232 {
00233 return new TGo4PrintProcessor("PrintProc");
00234 }
00235 };
00236
00237
00238 typedef TGo4Analysis* (UserCreateFunc)(const char* name);
00239
00240 int FindArg(int argc, char **argv, const char* argname)
00241 {
00242 if ((argname==0) || (strlen(argname)==0)) return -1;
00243 for (int n=0;n<argc;n++)
00244 if (strcmp(argv[n], argname)==0) return n;
00245 return -1;
00246 }
00247
00248 const char* GetArgValue(int argc, char **argv, const char* argname, int* pos = 0, bool incomplete = false)
00249 {
00250 int n = pos ? *pos : 0;
00251
00252 while (++n<argc)
00253 if (strcmp(argv[n], argname)==0) {
00254 if ((n+1<argc) && (argv[n+1][0]!='-')) {
00255 if (pos) *pos = n+1;
00256 return argv[n+1];
00257 } else
00258 if (incomplete) {
00259 if (pos) *pos = n+1;
00260 return "";
00261 }
00262 }
00263
00264 if (pos) *pos = 0;
00265 return 0;
00266 }
00267
00268 TList* GetClassesList(TList* prev = 0)
00269 {
00270 TClassTable::Init();
00271 char* name = 0;
00272
00273 TList* lst = new TList;
00274 lst->SetOwner(kTRUE);
00275
00276 if (prev!=0) TGo4Log::Debug("Search user classes in loaded library");
00277
00278 while ((name = TClassTable::Next()) != 0) {
00279 if (prev && prev->FindObject(name)) continue;
00280
00281 TNamed* obj = new TNamed(name, name);
00282 lst->Add(obj);
00283
00284 if (prev!=0) TGo4Log::Debug("New class %s", name);
00285 }
00286 return lst;
00287 }
00288
00289 TGo4Analysis* CreateDefaultAnalysis(TList* lst, const char* name, int user_argc, char** user_argv, bool doprint)
00290 {
00291 TIter iter(lst);
00292 TObject* obj(0);
00293
00294 TObjArray evnt_classes;
00295
00296 TClass *proc_cl(0), *an_cl(0), *evsrc_cl(0);
00297
00298 while ((obj = iter()) != 0) {
00299 TClass* cl = TClass::GetClass(obj->GetName());
00300
00301 if (cl==0) continue;
00302
00303 if (cl->InheritsFrom(TGo4EventProcessor::Class())) {
00304
00305 if ((cl!=TGo4EventProcessor::Class()) && ((proc_cl==0) || cl->InheritsFrom(proc_cl))) proc_cl = cl;
00306 } else
00307 if (cl->InheritsFrom(TGo4EventSource::Class())) {
00308 if ((cl!=TGo4EventSource::Class()) && (evsrc_cl==0)) evsrc_cl = cl;
00309 } else
00310 if (cl->InheritsFrom(TGo4EventElement::Class())) {
00311 if (cl!=TGo4EventElement::Class()) evnt_classes.Add(cl);
00312 } else
00313 if (cl->InheritsFrom(TGo4Analysis::Class())) {
00314 if ((cl!=TGo4Analysis::Class()) && (an_cl==0)) an_cl = cl;
00315 }
00316 }
00317
00318 if (doprint) {
00319 an_cl = 0;
00320 }
00321
00322 if (an_cl!=0) {
00323
00324 TGo4Log::Info("Find user analysis class %s", an_cl->GetName());
00325
00326 TMethod* meth = an_cl->GetMethodWithPrototype(an_cl->GetName(), "int,char**");
00327 if (meth!=0) {
00328 TGo4Log::Info("!!! Find constructor with prototype %s::%s(int, char**)", an_cl->GetName(), an_cl->GetName());
00329
00330 if ((user_argc>0) && (user_argv!=0))
00331 user_argv[0] = (char*) name;
00332 else {
00333 user_argc = 1;
00334 user_argv = (char**) &name;
00335 }
00336
00337 #ifdef WIN32
00338 TString cmd = TString::Format("new %s(%d, (char**)0x%x)", an_cl->GetName(), user_argc, user_argv);
00339 #else
00340 TString cmd = TString::Format("new %s(%d, (char**)%p)", an_cl->GetName(), user_argc, user_argv);
00341 #endif
00342 Int_t err = 0;
00343
00344 TGo4Log::Info("Process: %s", cmd.Data());
00345
00346 TGo4Analysis* analysis = (TGo4Analysis*) gROOT->ProcessLineFast(cmd.Data(), &err);
00347
00348 if ((analysis!=0) && (err==0)) return analysis;
00349
00350 TGo4Log::Error("Cannot create analysis class %s instance with (int, char**) prototype", an_cl->GetName());
00351 TGo4Log::Error("Implement correct analysis constructor with such signature in user library");
00352 exit(1);
00353 }
00354
00355
00356 meth = an_cl->GetMethodWithPrototype(an_cl->GetName(), "const char*");
00357 if (meth!=0) {
00358 TGo4Log::Info("!!! Find constructor with prototype %s::%s(const char*)", an_cl->GetName(), an_cl->GetName());
00359
00360 TString cmd = TString::Format("new %s(\"%s\")", an_cl->GetName(), name);
00361 Int_t err = 0;
00362
00363 TGo4Log::Info("Process: %s", cmd.Data());
00364
00365 TGo4Analysis* analysis = (TGo4Analysis*) gROOT->ProcessLineFast(cmd.Data(), &err);
00366
00367 if ((analysis!=0) && (err==0)) return analysis;
00368
00369 TGo4Log::Error("Cannot create analysis class %s instance with (const char*) prototype", an_cl->GetName());
00370 TGo4Log::Error("Implement correct analysis constructor with such signature in user library");
00371 exit(1);
00372 }
00373
00374
00375 TIter iter(an_cl->GetListOfMethods());
00376 while ((meth = (TMethod*) iter()) != 0) {
00377 if (strcmp(meth->GetName(), an_cl->GetName()) != 0) continue;
00378 if (meth->GetListOfMethodArgs()->GetSize()==0) continue;
00379 break;
00380 }
00381
00382 if (meth==0) {
00383 TGo4Log::Error("Cannot find non-default constructor for class %s", an_cl->GetName());
00384 TGo4Log::Error("Implement analysis constructor with (const char*) or (int,char**) signature");
00385 TGo4Log::Error("Or define TGo4Analysis* CreateUserAnalysis(const char*) function in user library");
00386 exit(1);
00387 }
00388
00389 TGo4Log::Info("Find constructor with %d arguments", meth->GetListOfMethodArgs()->GetSize());
00390
00391 TMethodArg *argument = 0;
00392 TIter next(meth->GetListOfMethodArgs());
00393
00394 TString cmd = TString::Format("new %s(", an_cl->GetName());
00395
00396 int counter = 0;
00397
00398 while ((argument = (TMethodArg *) next())) {
00399
00400 if (counter>0) cmd+=", ";
00401 counter++;
00402
00403 TDataType *datatype = gROOT->GetType(argument->GetTypeName());
00404
00405 TString basictype = (datatype==0) ? "int" : datatype->GetTypeName();
00406
00407 TGo4Log::Debug("Argument %s type %s basictype %s", argument->GetName(), argument->GetTitle(), basictype.Data());
00408
00409 TString argDflt = argument->GetDefault() ? argument->GetDefault() : "";
00410 if (argDflt.Length()>0) {
00411 cmd += argDflt;
00412 continue;
00413 }
00414
00415 bool isptr = strchr(argument->GetTitle(), '*') != 0;
00416
00417 if ((datatype==0) && !isptr) {
00418 TGo4Log::Error("Cannot specify any value for argument %s of class %s constructor", argument->GetName(), an_cl->GetName());
00419 TGo4Log::Error("Add CreateUserAnalysis(const char*) function in user library");
00420 exit(1);
00421 }
00422
00423 if (isptr) {
00424 if ((basictype == "char") || (basictype="Text_t")) cmd+="\"\"";
00425 else cmd+="0";
00426 } else {
00427 if ((counter==2) && (basictype=="int")) {
00428 TGo4Log::Info("Special treatment for second integer argument, suppose MBS input type");
00429 cmd += TString::Format("%d", GO4EV_MBS_FILE);
00430 } else
00431 if (basictype=="bool") {
00432 cmd += "false";
00433 } else
00434 cmd += "0";
00435 }
00436 }
00437
00438 cmd += ")";
00439
00440 Int_t err = 0;
00441 TGo4Log::Info("Process: %s", cmd.Data());
00442 TGo4Analysis* analysis = (TGo4Analysis*) gROOT->ProcessLineFast(cmd.Data(), &err);
00443 if ((analysis!=0) && (err==0)) return analysis;
00444
00445 TGo4Log::Error("Cannot create analysis class %s instance", an_cl->GetName());
00446 TGo4Log::Error("Add CreateUserAnalysis(const char*) function in user library");
00447
00448 exit(1);
00449 }
00450
00451 TClass *outev_cl(0), *inpev_cl(0);
00452
00453 const char* inp_evnt_classname = GetArgValue(user_argc, user_argv, "-inpevt-class");
00454 const char* out_evnt_classname = GetArgValue(user_argc, user_argv, "-outevt-class");
00455
00456 if (inp_evnt_classname!=0) {
00457 inpev_cl = gROOT->GetClass(inp_evnt_classname);
00458 if (inpev_cl==0) {
00459 TGo4Log::Error("Class %s not exists", inp_evnt_classname);
00460 exit(1);
00461 }
00462
00463 if (!inpev_cl->InheritsFrom(TGo4EventElement::Class())) {
00464 TGo4Log::Error("Class %s cannot be used as input event", inp_evnt_classname);
00465 exit(1);
00466 }
00467
00468 evnt_classes.Remove(inpev_cl);
00469 evnt_classes.Compress();
00470 }
00471
00472 if (out_evnt_classname!=0) {
00473 outev_cl = gROOT->GetClass(out_evnt_classname);
00474 if (outev_cl==0) {
00475 TGo4Log::Error("Class %s not exists", out_evnt_classname);
00476 exit(1);
00477 }
00478
00479 if (!outev_cl->InheritsFrom(TGo4EventElement::Class())) {
00480 TGo4Log::Error("Class %s cannot be used as output event", out_evnt_classname);
00481 exit(1);
00482 }
00483
00484 evnt_classes.Remove(outev_cl);
00485 evnt_classes.Compress();
00486 }
00487
00488
00489
00490 if ((evsrc_cl!=0) && (inpev_cl==0) && (evnt_classes.GetLast() >= 0)) {
00491 TGo4EventSource* src = (TGo4EventSource*) evsrc_cl->New();
00492
00493
00494 if ((src!=0) && !src->CheckEventClass(TGo4MbsEvent::Class())) {
00495 for (int n=0; n<=evnt_classes.GetLast(); n++) {
00496 TClass* cl = (TClass*) evnt_classes.At(n);
00497 if (!src->CheckEventClass(cl)) continue;
00498
00499
00500 if (inpev_cl!=0) { inpev_cl = 0; break; }
00501
00502 inpev_cl = cl;
00503 }
00504 }
00505
00506 delete src;
00507
00508 if (inpev_cl!=0) {
00509 evnt_classes.Remove(inpev_cl);
00510 evnt_classes.Compress();
00511 }
00512 }
00513
00514
00515 if (outev_cl==0)
00516 for (int n=0; n<=evnt_classes.GetLast(); n++) {
00517 TClass* cl = (TClass*) evnt_classes.At(n);
00518 if ((outev_cl==0) || cl->InheritsFrom(outev_cl)) outev_cl = cl;
00519 }
00520
00521 if (doprint) {
00522 TGo4Log::Info("Create default analysis with print-processor class");
00523 outev_cl = 0;
00524 } else {
00525 if (proc_cl==0) return 0;
00526 TGo4Log::Info("Create default analysis with processor class %s", proc_cl->GetName());
00527 if (outev_cl!=0)
00528 TGo4Log::Info("Use class %s as output event", outev_cl->GetName());
00529 }
00530
00531
00532 if (inpev_cl!=0)
00533 TGo4Log::Info("Use class %s as input event", inpev_cl->GetName());
00534
00535 TGo4Analysis* analysis = TGo4Analysis::Instance();
00536 analysis->SetAnalysisName(name);
00537
00538 TGo4StepFactory* factory = 0;
00539
00540 if (doprint) {
00541 factory = new TGo4PrintFactory("Factory");
00542 } else {
00543 factory = new TGo4StepFactory("Factory");
00544 factory->DefEventProcessor("Processor", proc_cl->GetName());
00545 }
00546
00547 if (inpev_cl!=0)
00548 factory->DefInputEvent("InputEvent", inpev_cl->GetName());
00549
00550 if (outev_cl!=0)
00551 factory->DefOutputEvent("OutputEvent", outev_cl->GetName());
00552 else
00553 factory->DefOutputEvent("OutputEvent", "TGo4EventElement");
00554
00555 if (evsrc_cl!=0)
00556 factory->DefUserEventSource(evsrc_cl->GetName());
00557
00558 TGo4MbsFileParameter* sourcepar = new TGo4MbsFileParameter("/GSI/lea/gauss.lmd");
00559
00560 TGo4AnalysisStep* step = new TGo4AnalysisStep("Analysis", factory, sourcepar);
00561
00562 step->SetSourceEnabled(kTRUE);
00563 step->SetStoreEnabled(kFALSE);
00564 step->SetProcessEnabled(kTRUE);
00565 step->SetErrorStopEnabled(kTRUE);
00566
00567
00568
00569 analysis->AddAnalysisStep(step);
00570
00571 return analysis;
00572 }
00573
00574
00575 int main(int argc, char **argv)
00576 {
00577 if (!TGo4Version::CheckVersion(__GO4BUILDVERSION__)) {
00578 std::cerr << "Please check your system configuration and restart analysis again" << std::endl;
00579 return -1;
00580 }
00581
00582 if (argc==1) usage();
00583
00584 int phelp = FindArg(argc, argv, "-help");
00585 if (phelp < 0) phelp = FindArg(argc, argv, "-h") > 0;
00586 if (phelp > 0) {
00587 usage(phelp < argc-1 ? argv[phelp+1] : 0);
00588 }
00589
00590 int user_argc = 0;
00591 char** user_argv = 0;
00592
00593 int userargspos = FindArg(argc, argv, "-args");
00594 if (userargspos<0) userargspos = FindArg(argc, argv, "-x");
00595 if (userargspos>0) {
00596 user_argc = argc - userargspos;
00597 user_argv = argv + userargspos;
00598
00599 argc = userargspos;
00600 }
00601
00602 bool doprint = (FindArg(argc, argv, "-print") > 0) || (FindArg(argc, argv, "-type") > 0) ||
00603 (FindArg(argc, argv, "-pr") > 0) || (FindArg(argc, argv, "-ty") > 0);
00604 if (doprint) TGo4Log::SetIgnoreLevel(2);
00605
00606 const char* logfile = GetArgValue(argc, argv, "-log", 0, true);
00607 if (logfile!=0) {
00608
00609 TGo4Log::Instance();
00610
00611 TGo4Log::LogfileEnable(kTRUE);
00612 if (strlen(logfile)==0) logfile = TGo4Log::GetDefaultLogname();
00613 TGo4Log::OpenLogfile(logfile, 0, kTRUE);
00614
00615 TString info = "go4analysis";
00616 for (int n=1;n<argc;n++) { info += " "; info += argv[n]; }
00617
00618 TGo4Log::WriteLogfile(info.Data(), true);
00619 }
00620
00621 if ((FindArg(argc, argv, "-v")>0) || (FindArg(argc, argv, "-verbose")>0)) TGo4Log::SetIgnoreLevel(-1);
00622 else if (FindArg(argc, argv, "-v0")>0) TGo4Log::SetIgnoreLevel(0);
00623 else if (FindArg(argc, argv, "-v1")>0) TGo4Log::SetIgnoreLevel(1);
00624 else if (FindArg(argc, argv, "-v2")>0) TGo4Log::SetIgnoreLevel(2);
00625 else if (FindArg(argc, argv, "-v3")>0) TGo4Log::SetIgnoreLevel(3);
00626
00627 TGo4Analysis::SetRunningMode(0);
00628 if (FindArg(argc, argv, "-gui")>0) TGo4Analysis::SetRunningMode(1); else
00629 if (FindArg(argc, argv, "-server")>0) TGo4Analysis::SetRunningMode(2);
00630
00631 const char* analysis_name = GetArgValue(argc, argv, "-server");
00632 if (analysis_name==0) analysis_name = GetArgValue(argc, argv, "-gui");
00633 if (analysis_name==0) analysis_name = GetArgValue(argc, argv, "-name");
00634 if (analysis_name==0) analysis_name = "Go4Analysis";
00635
00636 TList* lst0 = GetClassesList();
00637
00638 int argpos = 0;
00639 bool isanylib = false;
00640 const char* libname = 0;
00641 while ((libname = GetArgValue(argc, argv, "-lib", &argpos))!=0) {
00642 TGo4Log::Info("Reading library: %s", libname);
00643 if (gSystem->Load(libname)<0) return -1;
00644 isanylib = true;
00645 }
00646
00647
00648 if (!isanylib && (!doprint || GetArgValue(argc, argv, "-user"))) {
00649 libname = "libGo4UserAnalysis";
00650 TGo4Log::Info("Reading library: %s", libname);
00651 if (gSystem->Load(libname)<0) return -1;
00652 }
00653
00654 TList* lst1 = GetClassesList(lst0);
00655
00656 TGo4Analysis* analysis = 0;
00657
00658 UserCreateFunc* crfunc = (UserCreateFunc*) gSystem->DynFindSymbol("*", "CreateUserAnalysis");
00659 if (crfunc) analysis = crfunc(analysis_name);
00660 else analysis = CreateDefaultAnalysis(lst1, analysis_name, user_argc, user_argv, doprint);
00661
00662 if (analysis==0) {
00663 std::cerr << "!!! Analysis instance cannot be created" << std::endl;
00664 std::cerr << "!!! PLEASE check your analysis library " << libname << std::endl;
00665 std::cerr << "!!! One requires user subclass for TGo4Analysis class in user library" << std::endl;
00666 std::cerr << "!!! Alternatively, CreateUserAnalysis(const char*) function can be implemented" << std::endl;
00667 std::cerr << "!!! See Go4ExampleSimple, Go4Example1Step or Go4Example2Step for details" << std::endl;
00668 return -1;
00669 }
00670
00671 delete lst0; lst0 = 0;
00672 delete lst1; lst1 = 0;
00673
00674 TGo4AnalysisStep* step = analysis->GetAnalysisStep(0);
00675 if (step==0) {
00676 std::cerr << "No active step in analysis found" << std::endl;
00677 return -1;
00678 }
00679
00680
00681
00682
00683
00684 gROOT->SetBatch(kTRUE);
00685
00686 #ifdef WITH_DABC
00687 TObjArray http_args;
00688 http_args.SetOwner(kTRUE);
00689 #endif
00690
00691 Bool_t batchMode(kTRUE);
00692 Bool_t servermode(kFALSE);
00693 Bool_t hserver(kFALSE);
00694 Bool_t loadprefs(kTRUE);
00695 Bool_t showrate(kFALSE);
00696 Double_t process_interv(-1.);
00697 const char* hname = "";
00698 const char* hpasswd = "";
00699 const char* hostname = "localhost";
00700 Int_t iport(5000);
00701
00702 bool autorun(false);
00703 long maxevents(-1);
00704 Int_t canrun(0);
00705
00706 if (doprint) {
00707 maxevents = 1;
00708 analysis->SetAutoSave(kFALSE);
00709 }
00710
00711
00712
00713 int narg = 1;
00714
00715 while (narg < argc) {
00716 if (strcmp(argv[narg], "-server")==0) {
00717 narg++;
00718 batchMode = kFALSE;
00719 servermode = kTRUE;
00720
00721 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-')) narg++;
00722 } else
00723 if(strcmp(argv[narg], "-gui") == 0) {
00724 batchMode = kFALSE;
00725 if (argc <= narg + 3) showerror("Not all -gui arguments specified");
00726 narg++;
00727 narg++;
00728 hostname = argv[narg++];
00729 iport = atoi(argv[narg++]);
00730 } else
00731 #ifdef WITH_DABC
00732 if (strcmp(argv[narg], "-http")==0) {
00733 narg++;
00734 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-'))
00735 http_args.Add(new TObjString(Form("dabc:http:%s", argv[narg++])));
00736 else
00737 http_args.Add(new TObjString("dabc:http:8080"));
00738 } else
00739 if (strcmp(argv[narg], "-dabc")==0) {
00740 narg++;
00741 if (narg >= argc) showerror("Master dabc node not specified");
00742 http_args.Add(new TObjString(Form("dabc:%s", argv[narg++])));
00743 } else
00744 if (strcmp(argv[narg], "-fastcgi")==0) {
00745 narg++;
00746 if (narg >= argc) showerror("fastcgi options not specified");
00747 http_args.Add(new TObjString(Form("dabc:fastcgi:%s", argv[narg++])));
00748 } else
00749 #endif
00750 if(strcmp(argv[narg], "-lib") == 0) {
00751
00752 if (++narg >= argc) showerror("library name not specified");
00753 narg++;
00754 } else
00755 if(strcmp(argv[narg], "-name") == 0) {
00756
00757 if (++narg >= argc) showerror("analysis name not specified");
00758 narg++;
00759 } else
00760 if (strcmp(argv[narg],"-step")==0) {
00761 if (++narg < argc) {
00762 const char* step_name = argv[narg++];
00763 int step_number(-1);
00764 step = 0;
00765 if (sscanf(step_name, "%d", &step_number)==1)
00766 if (step_number>=0) step = analysis->GetAnalysisStepNum(step_number);
00767 if (step==0) step = analysis->GetAnalysisStep(step_name);
00768 if (step==0) showerror("step not found");
00769 } else
00770 showerror("step name not specified");
00771 } else
00772 if(strcmp(argv[narg],"-enable-step")==0) {
00773 narg++;
00774 step->SetProcessEnabled(kTRUE);
00775 } else
00776 if(strcmp(argv[narg],"-disable-step")==0) {
00777 narg++;
00778 step->SetProcessEnabled(kFALSE);
00779 } else
00780 if ((strcmp(argv[narg],"-file")==0) || (strcmp(argv[narg],"-f")==0)) {
00781 if (++narg < argc) {
00782 TGo4MbsFileParameter sourcepar(argv[narg++]);
00783
00784 while ((narg<argc) && (argv[narg][0]!='-'))
00785 sourcepar.AddMoreFile(argv[narg++]);
00786 step->SetEventSource(&sourcepar);
00787 step->SetSourceEnabled(kTRUE);
00788 autorun = true;
00789 } else
00790 showerror("LMD/LML file name not specified");
00791 } else
00792 if (strcmp(argv[narg],"-source")==0) {
00793 if (++narg < argc) {
00794 TGo4FileSourceParameter sourcepar(argv[narg++]);
00795 step->SetEventSource(&sourcepar);
00796 step->SetSourceEnabled(kTRUE);
00797 autorun = true;
00798 } else
00799 showerror("Input file name not specified");
00800 } else
00801 if ((strcmp(argv[narg],"-transport")==0) || (strcmp(argv[narg],"-tr")==0)) {
00802 if (++narg < argc) {
00803 TGo4MbsTransportParameter sourcepar(argv[narg++]);
00804 step->SetEventSource(&sourcepar);
00805 step->SetSourceEnabled(kTRUE);
00806 autorun = true;
00807 } else
00808 showerror("MBS Transport server name not specified");
00809 } else
00810 if ((strcmp(argv[narg],"-stream")==0) || (strcmp(argv[narg],"-st")==0)) {
00811 if (++narg < argc) {
00812 TGo4MbsStreamParameter sourcepar(argv[narg++]);
00813 step->SetEventSource(&sourcepar);
00814 step->SetSourceEnabled(kTRUE);
00815 autorun = true;
00816 } else
00817 showerror("MBS Stream server name not specified");
00818 } else
00819 if ((strcmp(argv[narg],"-evserv")==0) || (strcmp(argv[narg],"-ev")==0)) {
00820 if (++narg < argc) {
00821 TGo4MbsEventServerParameter sourcepar(argv[narg++]);
00822 step->SetEventSource(&sourcepar);
00823 step->SetSourceEnabled(kTRUE);
00824 autorun = true;
00825 } else
00826 showerror("MBS Event server name not specified");
00827 } else
00828 if ((strcmp(argv[narg],"-random")==0) || (strcmp(argv[narg],"-rnd")==0)) {
00829 narg++;
00830 TGo4MbsRandomParameter sourcepar("Random");
00831 step->SetEventSource(&sourcepar);
00832 step->SetSourceEnabled(kTRUE);
00833 autorun = true;
00834 } else
00835 if (strcmp(argv[narg],"-user")==0) {
00836 if (++narg < argc) {
00837 TGo4UserSourceParameter sourcepar(argv[narg++]);
00838 step->SetEventSource(&sourcepar);
00839 step->SetSourceEnabled(kTRUE);
00840 autorun = true;
00841 } else
00842 showerror("MBS Event server name not specified");
00843 } else
00844 if ((strcmp(argv[narg],"-revserv")==0) || (strcmp(argv[narg],"-rev")==0)) {
00845 if (++narg < argc) {
00846 const char* serv_name = argv[narg++];
00847 int serv_port = 0;
00848 if ((narg < argc) && (argv[narg][0] != '-'))
00849 serv_port = atoi(argv[narg++]);
00850 TGo4RevServParameter sourcepar(serv_name, serv_port);
00851 step->SetEventSource(&sourcepar);
00852 step->SetSourceEnabled(kTRUE);
00853 autorun = true;
00854 } else
00855 showerror("Remote event server name or port are not specified");
00856 } else
00857 if (strcmp(argv[narg],"-skip")==0) {
00858 narg++;
00859 TGo4MbsSourceParameter* param = dynamic_cast<TGo4MbsSourceParameter*> (step->GetEventSource());
00860 if (param==0) showerror("only in MBS source events can be skipped");
00861 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-')) {
00862 unsigned value=0;
00863 if (sscanf(argv[narg],"%u",&value)!=1)
00864 showerror(Form("Value error %s", argv[narg]));
00865 param->SetStartEvent(value);
00866 narg++;
00867 }
00868 } else
00869 if (strcmp(argv[narg],"-port")==0) {
00870 narg++;
00871 int port(0);
00872 if ((narg < argc) && (argv[narg][0]!='-')) {
00873 if (sscanf(argv[narg],"%d",&port)!=1)
00874 showerror(Form("Value error %s", argv[narg]));
00875 narg++;
00876 }
00877 TGo4MbsSourceParameter* param = dynamic_cast<TGo4MbsSourceParameter*> (step->GetEventSource());
00878 if (param) param->SetPort(port);
00879
00880 TGo4UserSourceParameter* user = dynamic_cast<TGo4UserSourceParameter*> (step->GetEventSource());
00881 if (user) user->SetPort(port);
00882 } else
00883 if (strcmp(argv[narg],"-retry")==0) {
00884 narg++;
00885 int nretry(0);
00886 if ((narg < argc) && (argv[narg][0]!='-')) {
00887 if (sscanf(argv[narg],"%d",&nretry)!=1)
00888 showerror(Form("Value error %s", argv[narg]));
00889 narg++;
00890 }
00891 TGo4MbsSourceParameter* param = dynamic_cast<TGo4MbsSourceParameter*> (step->GetEventSource());
00892 if (param) param->SetRetryCnt(nretry);
00893 } else
00894 if (strcmp(argv[narg],"-mbs-select")==0) {
00895 narg++;
00896 TGo4MbsSourceParameter* param = dynamic_cast<TGo4MbsSourceParameter*> (step->GetEventSource());
00897 if (param==0) showerror("only in MBS source events can be selected");
00898 unsigned cnt=0;
00899 while ((cnt<3) && (narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-')) {
00900 unsigned value(0);
00901 if ((cnt==1) && (strcmp(argv[narg],"all")==0)) value = 0; else
00902 if (sscanf(argv[narg],"%u",&value)!=1)
00903 showerror(Form("Value error %s", argv[narg]));
00904 if (cnt==0) param->SetStartEvent(value); else
00905 if (cnt==1) param->SetStopEvent(value); else
00906 if (cnt==2) param->SetEventInterval(value);
00907 narg++; cnt++;
00908 }
00909 } else
00910 if(strcmp(argv[narg],"-store")==0) {
00911 if (++narg >= argc) showerror("Store name not specified");
00912
00913 const char* sourcename = argv[narg++];
00914 int splitlevel = 1;
00915 int buffersize = 64000;
00916 int compression = 5;
00917
00918 unsigned cnt=0;
00919 while ((cnt<3) && (narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-')) {
00920 int value(0);
00921 if (sscanf(argv[narg],"%d",&value)!=1)
00922 showerror(Form("Value error %s", argv[narg]));
00923 if (cnt==0) splitlevel = value; else
00924 if (cnt==1) buffersize = value; else
00925 if (cnt==2) compression = value;
00926 narg++; cnt++;
00927 }
00928
00929 TGo4FileStoreParameter storepar(sourcename, splitlevel, buffersize, compression);
00930 step->SetEventStore(&storepar);
00931 step->SetStoreEnabled(kTRUE);
00932 } else
00933 if (strcmp(argv[narg], "-timeout")==0) {
00934 if (++narg >= argc) showerror("Timeout value not specified");
00935 if (step->GetEventSource()==0) showerror("No source parameter configured");
00936 int value(0);
00937 if (sscanf(argv[narg],"%d",&value)!=1)
00938 showerror(Form("Timeout value error %s", argv[narg]));
00939 narg++;
00940 step->GetEventSource()->SetTimeout(value);
00941 } else
00942 if (strcmp(argv[narg],"-overwrite-store")==0) {
00943 narg++;
00944 TGo4FileStoreParameter* par = dynamic_cast<TGo4FileStoreParameter*> (step->GetEventStore());
00945 if (par) par->SetOverwriteMode(kTRUE);
00946 else showerror("No file-store parameter available");
00947 } else
00948 if (strcmp(argv[narg],"-append-store")==0) {
00949 narg++;
00950 TGo4FileStoreParameter* par = dynamic_cast<TGo4FileStoreParameter*> (step->GetEventStore());
00951 if (par) par->SetOverwriteMode(kFALSE);
00952 else showerror("No file-store parameter available");
00953 } else
00954 if(strcmp(argv[narg],"-backstore")==0) {
00955 if (++narg < argc) {
00956 TGo4BackStoreParameter storepar(argv[narg++]);
00957 step->SetEventStore(&storepar);
00958 step->SetStoreEnabled(kTRUE);
00959 } else
00960 showerror("Backstore name not specified");
00961 } else
00962 if ((strcmp(argv[narg],"-events")==0) || (strcmp(argv[narg],"-number")==0) || (strcmp(argv[narg],"-num")==0)) {
00963 if (++narg < argc) {
00964 if (sscanf(argv[narg++],"%ld",&maxevents)!=1) maxevents = -1;
00965 } else
00966 showerror("number of events to process not specified");
00967 } else
00968 if (strcmp(argv[narg],"-asf")==0) {
00969 narg++;
00970 analysis->SetAutoSave(kTRUE);
00971 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-'))
00972 analysis->SetAutoSaveFile(argv[narg++]);
00973 } else
00974 if (strcmp(argv[narg],"-enable-asf")==0) {
00975 narg++;
00976 analysis->SetAutoSave(kTRUE);
00977 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-'))
00978 analysis->SetAutoSaveInterval(atoi(argv[narg++]));
00979 } else
00980 if (strcmp(argv[narg],"-disable-asf")==0) {
00981 narg++;
00982 analysis->SetAutoSave(kFALSE);
00983 } else
00984 if (strcmp(argv[narg],"-prefs")==0) {
00985 narg++;
00986 const char* fname = 0;
00987 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-'))
00988 fname = argv[narg++];
00989 analysis->LoadStatus(fname);
00990 loadprefs = kFALSE;
00991 } else
00992 if (strcmp(argv[narg],"-no-prefs")==0) {
00993 narg++;
00994 loadprefs = kFALSE;
00995 } else
00996 if(strcmp(argv[narg],"-log")==0) {
00997 narg++;
00998 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-')) narg++;
00999 } else
01000 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)) {
01001 narg++;
01002 } else
01003 if(strcmp(argv[narg],"-run")==0) {
01004 narg++;
01005 autorun = true;
01006 } else
01007 if(strcmp(argv[narg],"-norun")==0) {
01008 narg++;
01009 canrun = -1;
01010 } else
01011 if(strcmp(argv[narg],"-maxtreesize")==0) {
01012 narg++;
01013 long long maxtreesize = 1900000000;
01014 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-')) {
01015 char sbuf[1000];
01016 strncpy(sbuf, argv[narg], sizeof(sbuf));
01017 long long mult(1), val(1);
01018 int len = strlen(sbuf);
01019 if ((sbuf[len-1]=='g') || (sbuf[len-1]=='G')) { mult = 1000000000; sbuf[len-1] = 0; } else
01020 if ((sbuf[len-1]=='m') || (sbuf[len-1]=='M')) { mult = 1000000; sbuf[len-1] = 0; } else
01021 if ((sbuf[len-1]=='k') || (sbuf[len-1]=='K')) { mult = 1000; sbuf[len-1] = 0; }
01022
01023 if (sscanf(sbuf, "%lld", &val)==1) maxtreesize = val*mult;
01024 narg++;
01025 }
01026 TGo4Log::Info("Set tree file size limit to %lld bytes", maxtreesize);
01027 TGo4FileStore::SetMaxTreeSize(maxtreesize);
01028 } else
01029 if ((strcmp(argv[narg],"-print")==0) || (strcmp(argv[narg],"-type")==0) || (strcmp(argv[narg],"-ty")==0) || (strcmp(argv[narg],"-pr")==0)) {
01030 narg++;
01031 while ((narg<argc) && (argv[narg][0]!='-')) {
01032 if (strncmp(argv[narg],"sub=",4)==0) {
01033 TGo4PrintProcessor::fSubId = atoi(argv[narg] + 4);
01034 } else
01035 if (strcmp(argv[narg],"hex")==0) {
01036 TGo4PrintProcessor::fHex = kTRUE;
01037 TGo4PrintProcessor::fData = kTRUE;
01038 } else
01039 if (strcmp(argv[narg],"dec")==0) {
01040 TGo4PrintProcessor::fHex = kFALSE;
01041 TGo4PrintProcessor::fData = kTRUE;
01042 } else
01043 if (strcmp(argv[narg],"long")==0) {
01044 TGo4PrintProcessor::fLong = kTRUE;
01045 TGo4PrintProcessor::fData = kTRUE;
01046 } else
01047 if (strcmp(argv[narg],"short")==0) {
01048 TGo4PrintProcessor::fLong = kFALSE;
01049 TGo4PrintProcessor::fData = kTRUE;
01050 } else
01051 if (strcmp(argv[narg],"data")==0) {
01052 TGo4PrintProcessor::fData = kTRUE;
01053 } else
01054 if (strcmp(argv[narg],"nodata")==0) {
01055 TGo4PrintProcessor::fData = kFALSE;
01056 }
01057
01058 if (strcmp(argv[narg],"fhead")==0) {
01059 TGo4PrintProcessor::fFileHead = kTRUE;
01060 }
01061 if (strcmp(argv[narg],"bhead")==0) {
01062 TGo4PrintProcessor::fBufHead = kTRUE;
01063 }
01064 narg++;
01065 }
01066 } else
01067 if(strcmp(argv[narg],"-enable-store")==0) {
01068 narg++;
01069 step->SetStoreEnabled(kTRUE);
01070 } else
01071 if(strcmp(argv[narg],"-disable-store")==0) {
01072 narg++;
01073 step->SetStoreEnabled(kFALSE);
01074 } else
01075 if(strcmp(argv[narg],"-enable-source")==0) {
01076 narg++;
01077 step->SetSourceEnabled(kTRUE);
01078 } else
01079 if(strcmp(argv[narg],"-disable-source")==0) {
01080 narg++;
01081 step->SetSourceEnabled(kFALSE);
01082 } else
01083 if(strcmp(argv[narg],"-disable-errstop")==0) {
01084 narg++;
01085 step->SetErrorStopEnabled(kFALSE);
01086 } else
01087 if(strcmp(argv[narg],"-enable-errstop")==0) {
01088 narg++;
01089 step->SetErrorStopEnabled(kTRUE);
01090 } else
01091 if(strcmp(argv[narg],"-rate")==0) {
01092 narg++;
01093 showrate = kTRUE;
01094 } else
01095 if(strcmp(argv[narg],"-norate")==0) {
01096 narg++;
01097 showrate = kFALSE;
01098 } else
01099 if(strcmp(argv[narg],"-inpevt-class")==0) {
01100
01101
01102 narg++;
01103 if (narg < argc) narg++;
01104 } else
01105 if(strcmp(argv[narg],"-outevt-class")==0) {
01106
01107
01108 narg++;
01109 if (narg < argc) narg++;
01110 } else
01111 if(strcmp(argv[narg],"-hserver")==0) {
01112 narg++;
01113 hserver = true;
01114 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-'))
01115 hname = argv[narg++];
01116 if ((narg < argc) && (strlen(argv[narg]) > 0) && (argv[narg][0]!='-'))
01117 hpasswd = argv[narg++];
01118 } else
01119 showerror(Form("Unknown argument %d %s", narg, argv[narg]));
01120 }
01121
01122 #ifdef WITH_DABC
01123 if (http_args.GetLast()>=0) {
01124 if (gSystem->Load("libGo4Dabc")!=0)
01125 showerror("Fail to load Go4Dabc libraries");
01126
01127 TString cmd;
01128 Long_t res(0);
01129 Int_t err(0);
01130 for (Int_t n=0;n<=http_args.GetLast();n++) {
01131 cmd.Form("TGo4Dabc::CreateEngine(\"%s\");", http_args[n]->GetName());
01132 res = gROOT->ProcessLineFast(cmd.Data(), &err);
01133 if ((res<=0) || (err!=0)) showerror(Form("Fail to start %s", http_args[n]->GetName()));
01134 }
01135
01136 process_interv = 0.1;
01137 }
01138 #endif
01139
01140
01141 if(batchMode) {
01142 TGo4Log::Info("Main: starting analysis in batch mode ... ");
01143 if (analysis->InitEventClasses()) {
01144 analysis->RunImplicitLoop(maxevents, showrate, process_interv);
01145 delete analysis;
01146 TGo4Log::Info("Main: analysis batch done");
01147 } else
01148 TGo4Log::Error("Main: Init event classes failed, aborting!");
01149 } else {
01150 if (hostname==0) hostname = "localhost";
01151
01152 if(servermode) TGo4Log::Info("Main: starting analysis in server mode ...");
01153 else TGo4Log::Info("Main: starting analysis in slave mode ...");
01154
01155 if (canrun<0) autorun = false;
01156
01157 TGo4AnalysisClient* client = new TGo4AnalysisClient("UserClient", analysis, hostname, iport, hserver, hname, hpasswd, servermode, autorun, kFALSE, loadprefs, showrate);
01158
01159 TGo4Log::Info("Main: created AnalysisClient instance: %s", client->GetName());
01160 TGo4Log::Info("Main: Run application loop");
01161
01162 #ifndef WIN32
01163 #if ROOT_VERSION_CODE <= ROOT_VERSION(5,25,2)
01164
01165 gSystem->AddFileHandler(new TFileHandler(0, TFileHandler::kRead));
01166 #endif
01167 #endif
01168
01169 int termcounter=0;
01170
01171 while (TGo4Analysis::Exists()) {
01172
01173 if (gSystem==0) {
01174
01175
01176
01177
01178
01179 abort();
01180
01181 }
01182
01183 gSystem->ProcessEvents();
01184 gSystem->Sleep(PROCESSLOOPDELAY);
01185 if(client->IsBeingQuit()) {
01186 if(termcounter == 0) {
01187 termcounter = TERMCOUNTS;
01188 TGo4Log::Info("Found Quit state: starting termination counter with %d s", PROCESSLOOPDELAY * TERMCOUNTS / 1000);
01189 } else
01190 if (termcounter>0) {
01191 termcounter--;
01192 if (termcounter == 0) {
01193 TGo4Log::Info("Reached end of termination counter after %d s, terminating.", PROCESSLOOPDELAY * TERMCOUNTS / 1000);
01194 break;
01195 }
01196 if ((termcounter % (10000 / PROCESSLOOPDELAY)) == 0)
01197 TGo4Log::Info("Counting termination counter down, remains %d s", PROCESSLOOPDELAY * termcounter / 1000);
01198 }
01199 }
01200 }
01201
01202 }
01203
01204 TGo4Log::Info("Main: THE END");
01205 TGo4Log::CloseLogfile();
01206
01207 return 0;
01208 }