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 "TXXXAnalysis.h"
00028 #include "Go4AnalysisClient/TGo4AnalysisClient.h"
00029
00030 void usage();
00031
00032 TROOT go4application("GO4","Go4 user analysis");
00033
00034 #define kGUI 2
00035 #define kBatch 1
00036
00037
00038 int main(int argc, char **argv)
00039 {
00040 if(argc < 2) {
00041 usage();
00042 exit(0);
00043 }
00044
00045
00046 TApplication theApp("Go4App", 0, 0);
00047
00048
00049
00050
00051
00052
00053
00054
00056
00057
00059
00060
00061
00062
00063
00064
00065
00066
00067 Bool_t servermode=kFALSE;
00068 Bool_t autorun=kFALSE;
00069 Int_t runningMode;
00070 Int_t maxevents = -1;
00071 Int_t intype=GO4EV_MBS_FILE;
00072 Bool_t writeout1=kFALSE;
00073 Bool_t writeout2=kFALSE;
00074 Text_t hostname[128];
00075 UInt_t iport=5000;
00076 UInt_t sport=6003;
00077 Int_t iarg;
00078 Text_t serv[128];
00079 Text_t out[128];
00080 Text_t anl[128];
00081 Text_t asf[128];
00082 Text_t filetype[8];
00083 Text_t *pc,*tmpname,*outname;
00084 TXXXAnalysis* analysis;
00085
00086
00087 strcpy(serv,"Go4AnalysisServer");
00088 strcpy(out,"gauss_XXXEvent");
00089 strcpy(anl,"gauss_XXXAnl");
00090 strcpy(hostname,"localhost");
00091
00092
00093
00094
00095
00096
00097 strcpy(filetype,".lmd");
00098 tmpname=argv[2]+strlen(argv[2])-4;
00099 if((pc=strstr(tmpname,".lmd")) != 0)*pc=0;
00100 if((pc=strstr(tmpname,".lml")) != 0){*pc=0;strcpy(filetype,".lml");}
00101 tmpname=argv[2];
00102 if((pc=strstr(argv[2],"@")) != 0) tmpname++;
00103 outname=tmpname;
00104 if((tmpname=strrchr(outname,'/')) != 0) outname=tmpname+1;
00105 strncpy(asf,outname,120);
00106 strcat(asf,"_AS");
00107 strncpy(out,outname,110);
00108 strcat(out,"_XXXEvent");
00109 strncpy(anl,outname,110);
00110 strcat(anl,"_XXXAnl");
00111 strncpy(serv,argv[2],110);
00112
00113 if(strstr(argv[1],"-gui"))
00114 {
00115 if(argc < 4) {
00116 usage();
00117 exit(0);
00118 }
00119
00120 runningMode = kGUI;
00121 strncpy(hostname,argv[3],110);
00122 iport = (argc>4) ? atoi(argv[4]) : 5000;
00123 }
00124 else if(strstr(argv[1],"-server"))
00125 {
00126
00127 runningMode = kGUI;
00128 servermode=kTRUE;
00129 autorun=kFALSE;
00130 }
00131 else
00132
00133 {
00134 if(argc < 3) {
00135 usage();
00136 exit(0);
00137 }
00138
00139 runningMode = kBatch;
00140 if(strstr(argv[1],"-f")){intype=GO4EV_MBS_FILE;strcat(serv,filetype);}
00141 else if(strstr(argv[1],"-t")) intype=GO4EV_MBS_TRANSPORT;
00142 else if(strstr(argv[1],"-s")) intype=GO4EV_MBS_STREAM;
00143 else if(strstr(argv[1],"-e")) intype=GO4EV_MBS_EVENTSERVER;
00144 else if(strstr(argv[1],"-ra")) intype=GO4EV_MBS_RANDOM;
00145 else if(strstr(argv[1],"-r")) intype=GO4EV_MBS_REVSERV;
00146 else {
00147 cout << "invalid input type: " << argv[1] << endl;
00148 usage();
00149 exit(0);
00150 }
00151 iarg=3;
00152 if(argc > iarg){
00153 if(strstr(argv[iarg],"-s"))servermode=kTRUE;
00154 else if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00155 else if(strstr(argv[iarg],"-o"))writeout2=kTRUE;
00156 else maxevents=atoi(argv[iarg]);
00157 iarg++;
00158 }
00159 if(argc > iarg){
00160 if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00161 else if(strstr(argv[iarg],"-o"))writeout2=kTRUE;
00162 else maxevents=atoi(argv[iarg]);
00163 iarg++;
00164 }
00165 if(argc > iarg){
00166 if(strstr(argv[iarg],"-o"))writeout2=kTRUE;
00167 else maxevents=atoi(argv[iarg]);
00168 iarg++;
00169 }
00170 if(argc > iarg) maxevents=atoi(argv[iarg]);
00171
00172 if(maxevents == -1) maxevents = 99999999;
00173 cout << endl << "**** Input " << serv << " (" << argv[1] << ") ";
00174 if(strstr(argv[1],"-r")) cout << "port " << sport;
00175 cout << endl << " output step1: " << out << ".root";
00176 if(writeout1) cout << " enabled"; else cout << " disabled";
00177 cout << endl << " output step2: " << anl << ".root";
00178 if(writeout2) cout << " enabled"; else cout << " disabled";
00179 cout << endl << " process " << maxevents << " events" << endl;
00180 cout << " auto save file: " << asf << ".root" << endl << endl;
00181 if(servermode){
00182 autorun=kTRUE;
00183 runningMode = kGUI;
00184 cout << " Analysis running in server mode. GUIs may connect!" << endl;
00185 }
00186 }
00187
00188
00189
00190
00191 TGo4Log::Instance();
00192 TGo4Log::SetIgnoreLevel(1);
00193
00194
00195 TGo4Log::OpenLogfile("XXXLogfile.txt","--Logfile for go4 XXX--",kFALSE);
00196 TGo4Log::LogfileEnable(kFALSE);
00197
00198 analysis = new TXXXAnalysis(serv,intype,sport,out,anl,writeout1,writeout2);
00199 if(servermode)
00200 {
00201
00202 analysis->SetAdministratorPassword("XXXadmin");
00203 analysis->SetControllerPassword("XXXctrl");
00204 analysis->SetObserverPassword("XXXview");
00205
00206
00207 }
00208
00209 analysis->SetAutoSaveFile(asf);
00210 analysis->SetAutoSaveInterval(0);
00211 analysis->SetAutoSave(kFALSE);
00212
00213
00214
00215
00216 if(runningMode == kBatch)
00217 {
00218 cout << "**** Main: starting analysis in batch mode ... " << endl;
00219 analysis->SetAutoSave(kTRUE);
00220 if (analysis->InitEventClasses() )
00221 {
00222 analysis->RunImplicitLoop(maxevents);
00223 delete analysis;
00224 cout << "**** Main: Done!"<<endl;
00225 gApplication->Terminate();
00226 }
00227 else
00228 {
00229 cout << "**** Main: Init event classes failed, aborting!"<<endl;
00230 gApplication->Terminate();
00231 }
00232 }
00233 if(runningMode == kGUI)
00234 {
00235 if(servermode) cout << "**** Main: starting analysis in server mode ..." << endl;
00236 else cout << "**** Main: starting analysis in slave mode ..." << endl;
00237
00238 TGo4AnalysisClient* client = new TGo4AnalysisClient(serv, analysis, hostname, iport, kFALSE, "", "", servermode, autorun);
00239
00240
00241 cout << "**** Main created AnalysisClient Instance: "<<client->GetName()<<endl;
00242 }
00243
00244 cout << "Run the application loop" << endl;
00245 theApp.Run();
00246 return 0;
00247 }
00248
00249 void usage()
00250 {
00251 cout << endl;
00252 cout << "* GO4 online analysis " << endl;
00253 cout << "* H. Essel, GSI, Darmstadt" << endl;
00254 cout << "* calling for batch: " << endl;
00255 cout << "* MainUserAnalysis -file|-trans|-stream|-evserv|-revserv|-random input [-server] [-port #] [-output] [events]" <<endl;
00256 cout << "* calling as server: " << endl;
00257 cout << "* MainUserAnalysis -server name [-run]" <<endl;
00258 cout << endl;
00259 }
00260
00261