00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "Riostream.h"
00017 #include <string.h>
00018 #include <stdlib.h>
00019
00020 #include "TROOT.h"
00021 #include "TRint.h"
00022 #include "TApplication.h"
00023 #include "snprintf.h"
00024
00025 #include "TGo4StepFactory.h"
00026 #include "TGo4AnalysisStep.h"
00027 #include "TGo4Analysis.h"
00028 #include "TGo4AnalysisClient.h"
00029 #include "Go4EventServerTypes.h"
00030
00031 void usage();
00032
00033 TROOT go4application("GO4","Go4 user analysis");
00034
00035 #define kGUI 2
00036 #define kBatch 1
00037
00038
00039 int main(int argc, char **argv)
00040 {
00041 if(argc < 3) {
00042 usage();
00043 exit(0);
00044 }
00045
00046
00047 TApplication theApp("Go4App", 0, 0);
00048
00049
00050
00051
00052
00053
00054
00055
00057
00058
00060
00061
00062
00063
00064
00065
00066
00067
00068 Bool_t servermode=kFALSE;
00069 Bool_t autorun=kFALSE;
00070 Int_t runningMode;
00071 Int_t maxevents = -1;
00072 Bool_t writeout=kFALSE;
00073 Text_t hostname[128];
00074 UInt_t iport=5000;
00075 Int_t iarg;
00076 UInt_t sport=6003;
00077 Text_t source[128];
00078 Text_t serv[128];
00079 Text_t asf[128];
00080 Text_t filetype[8];
00081 Text_t *pc,*tmpname,*outname;
00082 TGo4AnalysisClient* client;
00083
00084 strcpy(hostname,"localhost");
00085
00086
00087
00088
00089
00090
00091 strcpy(filetype,".lmd");
00092 tmpname=argv[2]+strlen(argv[2])-4;
00093 if((pc=strstr(tmpname,".lmd")) != 0)*pc=0;
00094 if((pc=strstr(tmpname,".lml")) != 0){*pc=0;strcpy(filetype,".lml");}
00095 tmpname=argv[2];
00096 if((pc=strstr(argv[2],"@")) != 0) tmpname++;
00097 outname=tmpname;
00098 if((tmpname=strrchr(outname,'/')) != 0) outname=tmpname+1;
00099 strncpy(asf,outname,110);
00100 strcat(asf,"_AS");
00101 strcpy(source,".x file.C(\"/GSI/lea/gauss\")");
00102 strncpy(serv,argv[2],110);
00103
00104 if(strcmp(argv[1],"-gui") == 0)
00105 {
00106 runningMode = kGUI;
00107 strncpy(hostname,argv[3],110);
00108 iport = (argc>4) ? atoi(argv[4]) : 5000;
00109 writeout=kFALSE;
00110 }
00111 else if(strstr(argv[1],"-server"))
00112 {
00113
00114 runningMode = kGUI;
00115 servermode=kTRUE;
00116 autorun=kFALSE;
00117 }
00118 else
00119 {
00120 runningMode = kBatch;
00121 strcpy(source,".x ");
00122 if(strstr(argv[1],"-f")){strcat(source,"file.C");strcat(serv,filetype);}
00123 else if(strstr(argv[1],"-t")) strcat(source,"trans.C");
00124 else if(strstr(argv[1],"-s")) strcat(source,"stream.C");
00125 else if(strstr(argv[1],"-e")) strcat(source,"evserv.C");
00126 else if(strstr(argv[1],"-ra")) strcat(source,"random.C");
00127 else if(strstr(argv[1],"-r")) strcat(source,"revserv.C");
00128 else {
00129 cout << "invalid input source: " << argv[1] << endl;
00130 usage();
00131 exit(0);
00132 }
00133 iarg=3;
00134 if(argc > iarg){
00135 if(strstr(argv[iarg],"-s"))servermode=kTRUE;
00136 else if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00137 else maxevents=atoi(argv[iarg]);
00138 iarg++;
00139 }
00140 if(argc > iarg){
00141 if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00142 else maxevents=atoi(argv[iarg]);
00143 iarg++;
00144 }
00145 if(argc > iarg) maxevents=atoi(argv[iarg]);
00146 if(maxevents == -1) maxevents = 99999999;
00147 cout << endl << "**** Input " << serv << " (" << argv[1] << ") ";
00148 if(strstr(argv[1],"-r")) cout << "port " << sport;
00149 cout << endl << " process " << maxevents << " events" << endl;
00150 cout << " auto save file: " << asf << ".root" << endl << endl;
00151 if(strstr(source,"revserv")) snprintf(source,127,".x revserv.C(\"%s\",%d)",serv,sport);
00152 else {strcat(source,"(\""); strcat(source,serv); strcat(source,"\")");}
00153 if(servermode){
00154 autorun=kTRUE;
00155 runningMode = kGUI;
00156 cout << " Analysis running in server mode. GUIs may connect!" << endl;
00157 }
00158 }
00159
00160
00161
00162
00163
00164 TGo4Analysis* analysis = TGo4Analysis::Instance();
00165 TGo4StepFactory* factory = new TGo4StepFactory("Factory");
00166 TGo4AnalysisStep* step = new TGo4AnalysisStep("Analysis",factory,0,0,0);
00167 analysis->AddAnalysisStep(step);
00168
00169
00170
00171
00172 factory->DefEventProcessor("XXXProc","TXXXProc");
00173 factory->DefOutputEvent("XXXEvent","TGo4EventElement");
00174
00175
00176 gROOT->ProcessLine(source);
00177 snprintf(source,127,".x setup.C(\"%s\")",asf);
00178 gROOT->ProcessLine(source);
00179
00180 if(servermode)
00181 {
00182
00183 analysis->SetAdministratorPassword("XXXadmin");
00184 analysis->SetControllerPassword("XXXctrl");
00185 analysis->SetObserverPassword("XXXview");
00186
00187
00188 }
00189
00190
00191 if(runningMode == kBatch)
00192 {
00193 cout << "**** Main: starting analysis in batch mode ... " << endl;
00194 analysis->SetAutoSave(kTRUE);
00195 if (analysis->InitEventClasses() )
00196 {
00197 analysis->RunImplicitLoop(maxevents);
00198 delete analysis;
00199 cout << "**** Main: Done!"<<endl;
00200 gApplication->Terminate();
00201 }
00202 else
00203 {
00204 cout << "**** Main: Init event classes failed, aborting!"<<endl;
00205 gApplication->Terminate();
00206 }
00207 }
00208 if(runningMode == kGUI)
00209 {
00210 if(servermode) cout << "**** Main: starting analysis in server mode ..." << endl;
00211 else cout << "**** Main: starting analysis in slave mode ..." << endl;
00212
00213 client = new TGo4AnalysisClient(serv, analysis, hostname, iport, kFALSE, "", "", servermode, autorun);
00214 cout << "**** Main: created AnalysisClient Instance: "<<client->GetName()<<endl;
00215 }
00216
00217 cout << "**** Main: Run application loop" << endl;
00218 theApp.Run();
00219 return 0;
00220 }
00221
00222 void usage()
00223 {
00224 cout << endl;
00225 cout << "* GO4 online analysis " << endl;
00226 cout << "* H. Essel, GSI, Darmstadt" << endl;
00227 cout << "* calling: " << endl;
00228 cout << "* MainUserAnalysis -file|-trans|-stream|-evserv|-revserv|-random input [-server] [-port #] [events]" <<endl;
00229 cout << endl;
00230 }
00231
00232