Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

MainUserAnalysis.cxx

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

Generated on Fri Nov 28 12:59:09 2008 for Go4-v3.04-1 by  doxygen 1.4.2