Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4Example2Step/MainUserAnalysis.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
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(); // print announcement
00031 
00032 TROOT go4application("GO4","Go4 user analysis");
00033 
00034 #define kGUI   2
00035 #define kBatch 1
00036 
00037 //==================  analysis main program ============================
00038 int main(int argc, char **argv)
00039 {
00040 if(argc < 2) {
00041   usage(); // no argument: print usage
00042   exit(0);
00043 }
00044 
00045 //=================  init root application loop ==========================
00046 TApplication theApp("Go4App", 0, 0);
00047 
00048 //================= Begin analysis setup ==================================
00049 // argv[0] program
00050 // argv[1] "-gui" when started by GUI.
00051 //         In this case the following args are (delivered by GUI):
00052 // argv[2] analysis name as specified in GUI
00053 // argv[3] hostname of GUI
00054 // argv[4] connector port of GUI
00056 // argv[1] "-server" when started as analysis server by GUI client
00057 // argv[2] optional name
00059 //         if not -gui or -server the args are for batch (designed by user):
00060 // argv[1] -file|-trans|-stream|-evserv|-revserv|-random
00061 // argv[2] input name (file or server)
00062 // argv[3] optional -server // use batch arguments, but run immediately as server 
00063 // argv[4] optional -port portnumber
00064 // argv[5] optional -output
00065 // argv[6] optional number of events
00066 
00067 Bool_t servermode=kFALSE; // run analysis slave as servertask
00068 Bool_t autorun=kFALSE;    // immedeately run analysis on start
00069 Int_t  runningMode;       // kGUI or kBatch
00070 Int_t  maxevents = -1;    // number of events (batch mode)
00071 Int_t  intype=GO4EV_MBS_FILE; // type of source
00072 Bool_t writeout1=kFALSE;  // write output file
00073 Bool_t writeout2=kFALSE;  // write output file
00074 Text_t hostname[128];     // hostname used by GUI
00075 UInt_t iport=5000;        // port number used by GUI
00076 UInt_t sport=6003;        // remote event server port
00077 Int_t  iarg;              // argument index
00078 Text_t serv[128];         // input name
00079 Text_t out[128];          // output root events
00080 Text_t anl[128];          // output root events
00081 Text_t asf[128];          // auto save file (batch)
00082 Text_t filetype[8];       // file type .lmd or .lml
00083 Text_t *pc,*tmpname,*outname;
00084 TXXXAnalysis* analysis;
00085 
00086 // some defaults:
00087 strcpy(serv,"Go4AnalysisServer"); // name (servermode only) 
00088 strcpy(out,"gauss_XXXEvent");
00089 strcpy(anl,"gauss_XXXAnl");
00090 strcpy(hostname,"localhost");    
00091 
00092 // Now parse arguments
00093    // strip any path information from input:
00094    // outname is name without path and postfix
00095    // postfix .lmd is default in all cases
00096    // postfix .lml is a metafile, @ is prefixed
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);     // auto save file
00106    strcat(asf,"_AS");
00107    strncpy(out,outname,110);     // output root file
00108    strcat(out,"_XXXEvent"); // append name of output event object
00109    strncpy(anl,outname,110);     // output root file
00110    strcat(anl,"_XXXAnl");   // append name of output event object
00111    strncpy(serv,argv[2],110);     // input (file with full path)
00112    
00113 if(strstr(argv[1],"-gui"))
00114 {
00115   if(argc < 4) {
00116    usage(); // too few argument for gui
00117    exit(0);
00118    }   
00119 // set up arguments for GUI mode
00120    runningMode = kGUI;
00121    strncpy(hostname,argv[3],110);
00122    iport = (argc>4) ? atoi(argv[4]) : 5000; // port of GUI server
00123  }
00124 else if(strstr(argv[1],"-server")) 
00125  {
00126 // set up analysis server mode started from GUI -client
00127    runningMode = kGUI;
00128    servermode=kTRUE;
00129    autorun=kFALSE;
00130  }
00131 else
00132 // set up arguments for batch mode
00133  {
00134    if(argc < 3) {
00135    usage(); // too few argument for gui
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(); // print 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 // Now setup the  analysis itself
00188 // arguments could be adjusted for other needs
00189 
00190 //=================== log message settings =============================
00191 TGo4Log::Instance();        // init logger object
00192 TGo4Log::SetIgnoreLevel(1); // set this to 1 to suppress detailed debug output
00193                             // set this to 2 to get warnings and errors only
00194                             // set this to 3 to get errors only
00195 TGo4Log::OpenLogfile("XXXLogfile.txt","--Logfile for go4 XXX--",kFALSE);
00196 TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages
00197 
00198 analysis = new TXXXAnalysis(serv,intype,sport,out,anl,writeout1,writeout2);
00199 if(servermode)
00200 {
00201    //==================== password settings for gui login (for analysis server only)
00202    analysis->SetAdministratorPassword("XXXadmin");
00203    analysis->SetControllerPassword("XXXctrl");
00204    analysis->SetObserverPassword("XXXview");
00205    // note: do not change go4 default passwords for analysis in client mode
00206    // autoconnect to gui server will not work then!!!
00207 }
00208 
00209 analysis->SetAutoSaveFile(asf);   // optional
00210 analysis->SetAutoSaveInterval(0); // after n seconds , 0 = at termination of event loop
00211 analysis->SetAutoSave(kFALSE);    // optional
00212 
00213 // analysis->Print();
00214 // ===================== End analysis setup ================================
00215 
00216  if(runningMode == kBatch)
00217    {
00218      cout << "**** Main: starting analysis in batch mode ...  " << endl;
00219      analysis->SetAutoSave(kTRUE);   // optional enable auto-save
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      // to start histogram server: kTRUE,"base","password"
00238      TGo4AnalysisClient* client = new TGo4AnalysisClient(serv, analysis, hostname, iport, kFALSE, "", "", servermode, autorun);
00239      // other ctor needs at least 5 argcs, disabled..                                        
00240      //TGo4AnalysisClient* client = new TGo4AnalysisClient(argc,argv,analysis,kFALSE,"","",servermode, autorun);
00241      cout << "**** Main created AnalysisClient Instance: "<<client->GetName()<<endl;
00242    }
00243 //=================  start root application loop ==========================
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:55:54 2005 for Go4-v2.10-5 by doxygen1.2.15