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