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 < 3) {
00041 usage();
00042 exit(0);
00043 }
00044
00045
00046 TApplication theApp("Go4App", 0, 0);
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 Int_t runningMode;
00063 Int_t maxevents = -1;
00064 Int_t intype=GO4EV_NULL;
00065 Bool_t writeout=kFALSE;
00066 UInt_t iport;
00067 UInt_t sport=6003;
00068 Int_t iarg;
00069 Text_t serv[128];
00070 Text_t out[128];
00071 Text_t asf[128];
00072 Text_t filetype[8];
00073 Text_t *pc,*tmpname,*outname;
00074
00075
00076
00077 strcpy(filetype,".lmd");
00078 tmpname=argv[2]+strlen(argv[2])-4;
00079 if((pc=strstr(tmpname,".lmd")) != 0)*pc=0;
00080 if((pc=strstr(tmpname,".lml")) != 0){*pc=0;strcpy(filetype,".lml");}
00081 tmpname=argv[2];
00082 if((pc=strstr(argv[2],"@")) != 0) tmpname++;
00083 outname=tmpname;
00084 if((tmpname=strrchr(outname,'/')) != 0) outname=tmpname+1;
00085 strncpy(out,outname,110);
00086 strcat(out,"_XXXEvent");
00087 strncpy(asf,outname,110);
00088 strcat(asf,"_AS");
00089
00090 if(strcmp(argv[1],"-gui") == 0)
00091 {
00092
00093 runningMode = kGUI;
00094 iport = (argc>4) ? atoi(argv[4]) : 5000;
00095 intype=GO4EV_MBS_FILE;
00096 writeout=kFALSE;
00097 strcpy(serv,"/GSI/lea/gauss");
00098 strcpy(out,"gauss_XXXEvent");
00099 }
00100 else
00101
00102 {
00103 runningMode = kBatch;
00104 strncpy(serv,argv[2],110);
00105 if(strstr(argv[1],"-f")){intype=GO4EV_MBS_FILE;strcat(serv,filetype);}
00106 else if(strstr(argv[1],"-t")) intype=GO4EV_MBS_TRANSPORT;
00107 else if(strstr(argv[1],"-s")) intype=GO4EV_MBS_STREAM;
00108 else if(strstr(argv[1],"-e")) intype=GO4EV_MBS_EVENTSERVER;
00109 else if(strstr(argv[1],"-r")) intype=GO4EV_MBS_REVSERV;
00110 else {
00111 cout << "invalid input type: " << argv[1] << endl;
00112 usage();
00113 exit(0);
00114 }
00115 iarg=3;
00116 if(argc > iarg){
00117 if(strstr(argv[iarg],"-o"))writeout=kTRUE;
00118 else if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00119 else maxevents=atoi(argv[iarg]);
00120 iarg++;
00121 }
00122 if(argc > iarg){
00123 if(strstr(argv[iarg],"-o"))writeout=kTRUE;
00124 else maxevents=atoi(argv[iarg]);
00125 iarg++;
00126 }
00127 if(argc > iarg)maxevents=atoi(argv[iarg]);
00128 if(maxevents == -1) maxevents = 99999999;
00129 cout << endl << "**** Input " << serv << " (" << argv[1] << ") ";
00130 if(strstr(argv[1],"-r")) cout << "port " << sport;
00131 cout << endl << " output " << out << ".root";
00132 if(writeout) cout << " enabled"; else cout << " disabled";
00133 cout << endl << " process " << maxevents << " events" << endl;
00134 cout << " auto save file: " << asf << ".root" << endl << endl;
00135 }
00136
00137
00138
00139 TXXXAnalysis* analysis = new TXXXAnalysis(serv,intype,sport,out,writeout);
00140 analysis->SetAutoSaveFile(asf);
00141 analysis->SetAutoSaveInterval(0);
00142 analysis->SetAutoSave(kFALSE);
00143
00144
00145
00146 if(runningMode == kBatch)
00147 {
00148 cout << "**** Main: starting analysis in batch mode ... " << endl;
00149 analysis->SetAutoSave(kTRUE);
00150 if (analysis->InitEventClasses() )
00151 {
00152 analysis->RunImplicitLoop(maxevents);
00153 delete analysis;
00154 cout << "**** Main: Done!"<<endl;
00155 gApplication->Terminate();
00156 }
00157 else
00158 {
00159 cout << "**** Main: Init event classes failed, aborting!"<<endl;
00160 gApplication->Terminate();
00161 }
00162 }
00163 if(runningMode == kGUI)
00164 {
00165 cout << "**** Main: starting analysis in client mode ..." << endl;
00166
00167 TGo4AnalysisClient* client = new TGo4AnalysisClient(argc,argv,analysis,kFALSE,"","");
00168 cout << "**** Main created AnalysisClient Instance: "<<client->GetName()<<endl;
00169 }
00170
00171 cout << "Run the application loop" << endl;
00172 theApp.Run();
00173 return 0;
00174 }
00175
00176 void usage()
00177 {
00178 cout << endl;
00179 cout << "* GO4 online analysis " << endl;
00180 cout << "* H. Essel, GSI, Darmstadt" << endl;
00181 cout << "* calling: " << endl;
00182 cout << "* MainUserAnalysis -file|-trans|-stream|-evserv|-revserv input [-port #] [-output] [events]" <<endl;
00183 cout << endl;
00184 }
00185
00186