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