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 "TApplication.h"
00022 
00023 #include "Go4EventServerTypes.h"
00024 #include "TXXXAnalysis.h"
00025 #include "TGo4AnalysisClient.h"
00026 
00027 void usage(); // print announcement
00028 
00029 TROOT go4application("GO4","Go4 user analysis");
00030 
00031 #define kGUI   2
00032 #define kBatch 1
00033 
00034 //==================  analysis main program ============================
00035 int main(int argc, char **argv)
00036 {
00037 if(argc < 3) {
00038   usage(); // no argument: print usage
00039   exit(0);
00040 }
00041 
00042 //=================  init root application loop ==========================
00043 TApplication theApp("Go4App", 0, 0);
00044 
00045 //================= Begin analysis setup ==================================
00046 // argv[0] program
00047 // argv[1] "-gui" when started by GUI.
00048 //         In this case the following args are (delivered by GUI):
00049 // argv[2] analysis name as specified in GUI
00050 // argv[3] hostname of GUI
00051 // argv[4] connector port of GUI
00052 //         if not GUI (batch mode) the args are (designed by user):
00053 // argv[1] -file|-trans|-stream|-evserv|-revserv
00054 // argv[2] input name (file or server)
00055 // argv[3] optional -p portnumber
00056 // argv[4] optional -output or number of events
00057 // argv[5] optional number of events
00058 
00059 Int_t  runningMode;      // kGUI or kBatch
00060 Int_t  maxevents = -1;   // number of events (batch mode)
00061 Int_t  intype=GO4EV_NULL;// type of source
00062 Bool_t writeout=kFALSE;  // write output file
00063 UInt_t iport;            // port number used by GUI
00064 UInt_t sport=6003;       // remote event server port
00065 Int_t  iarg;             // argument index
00066 Text_t serv[128];        // input name
00067 Text_t out[128];         // output root events
00068 Text_t asf[128];         // auto save file (batch)
00069 Text_t filetype[8];      // file type .lmd or .lml
00070 Text_t *pc,*tmpname,*outname;
00071 
00072 // strip any path information from input:
00073 // outname is name without path
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);     // output root file
00083  strcat(out,"_XXXEvent"); // append name of output event object
00084  strncpy(asf,outname,110);     // auto save file
00085  strcat(asf,"_AS");
00086 
00087 if(strcmp(argv[1],"-gui") == 0)
00088 {
00089 // set up arguments for GUI mode
00090    runningMode = kGUI;
00091    iport = (argc>4) ? atoi(argv[4]) : 5000; // port of GUI server
00092    intype=GO4EV_MBS_FILE;
00093    writeout=kFALSE;        // no output
00094    strcpy(serv,"/GSI/lea/gauss"); // default input file
00095    strcpy(out,"gauss_XXXEvent");
00096  }
00097  else
00098 // set up arguments for batch mode
00099  {
00100    runningMode = kBatch;
00101    strncpy(serv,argv[2],110);     // input (file with full path)
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(); // print 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 // Now setup the  analysis itself
00134 // arguments could be adjusted for other needs
00135 
00136 TXXXAnalysis* analysis = new TXXXAnalysis(serv,intype,sport,out,writeout);
00137 analysis->SetAutoSaveFile(asf);   // optional
00138 analysis->SetAutoSaveInterval(0); // after n seconds , 0 = at termination of event loop
00139 analysis->SetAutoSave(kFALSE);    // optional
00140 
00141 // ===================== End analysis setup ================================
00142 
00143  if(runningMode == kBatch)
00144    {
00145      cout << "**** Main: starting analysis in batch mode ...  " << endl;
00146      analysis->SetAutoSave(kTRUE);   // optional enable auto-save
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      // to start histogram server: kTRUE,"base","password"
00164      TGo4AnalysisClient* client = new TGo4AnalysisClient(argc,argv,analysis,kFALSE,"","");
00165      cout << "**** Main created AnalysisClient Instance: "<<client->GetName()<<endl;
00166    }
00167 //=================  start root application loop ==========================
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 //----------------------------END OF GO4 SOURCE FILE ---------------------

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