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

/Go4ExampleSimple/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 "Go4Analysis/TGo4Analysis.h"
00028 #include "Go4AnalysisClient/TGo4AnalysisClient.h"
00029 #include "Go4EventServer/Go4EventServerTypes.h"
00030 #include "Go4EventServer/TGo4StepFactory.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 < 3) {
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 Bool_t writeout=kFALSE;  // write output file
00074 Text_t hostname[128];     // hostname used by GUI
00075 UInt_t iport=5000;       // port number used by GUI
00076 Int_t  iarg;              // argument index
00077 UInt_t sport=6003;       // remote event server port
00078 Text_t source[128];      // input source
00079 Text_t serv[128];        // input name
00080 Text_t asf[128];         // auto save file (batch)
00081 Text_t filetype[8];      // file type .lmd or .lml
00082 Text_t *pc,*tmpname,*outname;
00083 TGo4AnalysisClient* client;
00084 
00085 strcpy(hostname,"localhost");    
00086 //------ process arguments -------------------------
00087 
00088 // strip any path information from input:
00089 // outname is name without path and postfix
00090 // postfix .lmd is default in all cases
00091 // postfix .lml is a metafile, @ is prefixed
00092 strcpy(filetype,".lmd");
00093 tmpname=argv[2]+strlen(argv[2])-4;
00094 if((pc=strstr(tmpname,".lmd")) != 0)*pc=0;
00095 if((pc=strstr(tmpname,".lml")) != 0){*pc=0;strcpy(filetype,".lml");}
00096 tmpname=argv[2];
00097 if((pc=strstr(argv[2],"@")) != 0) tmpname++;
00098 outname=tmpname;
00099 if((tmpname=strrchr(outname,'/')) != 0) outname=tmpname+1;
00100 strncpy(asf,outname,110);     // auto save file
00101 strcat(asf,"_AS");
00102 strcpy(source,".x file.C(\"/GSI/lea/gauss\")"); // will be processed below
00103 strncpy(serv,argv[2],110); 
00104 
00105 if(strcmp(argv[1],"-gui") == 0)
00106 { // set up arguments for GUI mode
00107    runningMode = kGUI;
00108    strncpy(hostname,argv[3],110);
00109    iport = (argc>4) ? atoi(argv[4]) : 5000; // port of GUI server
00110    writeout=kFALSE;       // no output
00111  }
00112 else if(strstr(argv[1],"-server")) 
00113  {
00114 // set up analysis server mode started from GUI -client
00115    runningMode = kGUI;
00116    servermode=kTRUE;
00117    autorun=kFALSE;
00118  }
00119 else
00120  { // set up arguments for batch mode
00121    runningMode = kBatch;
00122    strcpy(source,".x ");      // for macro name
00123         if(strstr(argv[1],"-f")){strcat(source,"file.C");strcat(serv,filetype);}
00124    else if(strstr(argv[1],"-t")) strcat(source,"trans.C");
00125    else if(strstr(argv[1],"-s")) strcat(source,"stream.C");
00126    else if(strstr(argv[1],"-e")) strcat(source,"evserv.C");
00127    else if(strstr(argv[1],"-ra")) strcat(source,"random.C");
00128    else if(strstr(argv[1],"-r")) strcat(source,"revserv.C");
00129    else {
00130        cout << "invalid input source: " << argv[1] << endl;
00131        usage(); // print usage
00132        exit(0);
00133      }
00134    iarg=3;
00135    if(argc > iarg){
00136           if(strstr(argv[iarg],"-s"))servermode=kTRUE;
00137      else if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00138      else maxevents=atoi(argv[iarg]);
00139      iarg++;
00140    }
00141    if(argc > iarg){
00142           if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00143      else maxevents=atoi(argv[iarg]);
00144      iarg++;
00145    }
00146    if(argc > iarg) maxevents=atoi(argv[iarg]);
00147    if(maxevents == -1) maxevents = 99999999;
00148    cout << endl << "**** Input " << serv << " (" << argv[1] << ") ";
00149    if(strstr(argv[1],"-r")) cout << "port " << sport;
00150    cout << endl << "     process " << maxevents << " events" << endl;
00151    cout << "     auto save file: " << asf << ".root" << endl << endl;
00152    if(strstr(source,"revserv")) snprintf(source,127,".x revserv.C(\"%s\",%d)",serv,sport);
00153    else {strcat(source,"(\"");  strcat(source,serv); strcat(source,"\")");}
00154    if(servermode){
00155      autorun=kTRUE;
00156      runningMode = kGUI;
00157      cout << "     Analysis running in server mode. GUIs may connect!" << endl;
00158    }
00159  }
00160 
00161 //------ setup the analysis -------------------------
00162 
00163 // We will use only one analysis step (factory)
00164 // we use only standard components
00165   TGo4Analysis*     analysis = TGo4Analysis::Instance();
00166   TGo4StepFactory*  factory  = new TGo4StepFactory("Factory");
00167   TGo4AnalysisStep* step     = new TGo4AnalysisStep("Analysis",factory,0,0,0);
00168   analysis->AddAnalysisStep(step);
00169 
00170 // tell the factory the names of processor and output event
00171 // both will be created by the framework later
00172 // Input event is by default an MBS event
00173   factory->DefEventProcessor("XXXProc","TXXXProc");// object name, class name
00174   factory->DefOutputEvent("XXXEvent","TXXXEvent"); // object name, class name
00175 
00176 // use macros to set event input and setup
00177   gROOT->ProcessLine(source);
00178   snprintf(source,127,".x setup.C(\"%s\")",asf);
00179   gROOT->ProcessLine(source);
00180 
00181 if(servermode)
00182 {
00183    //==================== password settings for gui login (for analysis server only)
00184    analysis->SetAdministratorPassword("XXXadmin");
00185    analysis->SetControllerPassword("XXXctrl");
00186    analysis->SetObserverPassword("XXXview");
00187    // note: do not change go4 default passwords for analysis in client mode
00188    // autoconnect to gui server will not work then!!!
00189 }
00190 //------ start the analysis -------------------------
00191 
00192  if(runningMode == kBatch)
00193    {
00194      cout << "**** Main: starting analysis in batch mode ...  " << endl;
00195      analysis->SetAutoSave(kTRUE);   // optional enable auto-save
00196      if (analysis->InitEventClasses() )
00197        {
00198     analysis->RunImplicitLoop(maxevents);
00199     delete analysis;
00200     cout << "**** Main: Done!"<<endl;
00201     gApplication->Terminate();
00202        }
00203      else
00204        {
00205     cout << "**** Main: Init event classes failed, aborting!"<<endl;
00206     gApplication->Terminate();
00207        }
00208    }
00209  if(runningMode == kGUI)
00210    {
00211      if(servermode)  cout << "**** Main: starting analysis in server mode ..." << endl;
00212      else            cout << "**** Main: starting analysis in slave mode ..." << endl;
00213      // to start histogram server: kTRUE,"base","password"
00214      client = new TGo4AnalysisClient(serv, analysis, hostname, iport, kFALSE, "", "", servermode, autorun);
00215      cout << "**** Main: created AnalysisClient Instance: "<<client->GetName()<<endl;
00216    }
00217 //=================  start root application loop ==========================
00218 cout << "**** Main: Run application loop" << endl;
00219 theApp.Run();
00220 return 0;
00221 }
00222 
00223 void usage()
00224 {
00225 cout << endl;
00226 cout << "* GO4  online analysis    " << endl;
00227 cout << "* H. Essel, GSI, Darmstadt" << endl;
00228 cout << "* calling:                " << endl;
00229 cout << "* MainUserAnalysis -file|-trans|-stream|-evserv|-revserv|-random input [-server] [-port #] [events]" <<endl;
00230 cout << endl;
00231 }
00232 
00233 //----------------------------END OF GO4 SOURCE FILE ---------------------

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