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

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