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