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 
00024 #include "TGo4Log.h"
00025 #include "TMeshAnalysis.h"
00026 #include "TGo4AnalysisClient.h"
00027 #include "Go4EventServer.h"
00028 
00029 void usage(); // print announcement
00030 
00031 TROOT go4application("GO4","Go4 user analysis");
00032 
00033 #define kGUI   2
00034 #define kBatch 1
00035 
00036 //==================  analysis main program ============================
00037 int main(int argc, char **argv)
00038 {
00039 if(argc < 3) {
00040   usage(); // no argument: print usage
00041   exit(0);
00042 }
00043 
00044 //=================  init root application loop ==========================
00045 TApplication theApp("Go4App", 0, 0);
00046 
00047 //================= Begin analysis setup ==================================
00048 // argv[0] program
00049 // argv[1] "-gui" when started by GUI.
00050 //         In this case the following args are (delivered by GUI):
00051 // argv[2] analysis name as specified in GUI
00052 // argv[3] hostname of GUI
00053 // argv[4] connector port of GUI
00054 //         if not GUI (batch mode) the args are (designed by user):
00055 // argv[1] -file|-trans|-stream|-evserv|-revserv
00056 // argv[2] input name (file or server)
00057 // argv[3] optional -p portnumber
00058 // argv[4] optional -output or number of events
00059 // argv[5] optional number of events
00060 
00061 Int_t  runningMode;      // kGUI or kBatch
00062 Int_t  maxevents = -1;   // number of events (batch mode)
00063 Int_t  intype=GO4EV_NULL;// type of source
00064 Bool_t writeout1=kFALSE;  // write output file
00065 Bool_t writeout2=kFALSE;  // write output file
00066 UInt_t iport;            // port number used by GUI
00067 UInt_t sport=6003;       // remote event server port
00068 Int_t  iarg;             // argument index
00069 Text_t serv[128];        // input name
00070 Text_t out[128];         // output root events
00071 Text_t anl[128];         // output root events
00072 Text_t asf[128];         // auto save file (batch)
00073 Text_t filetype[8];      // file type .lmd or .lml
00074 Text_t *pc,*tmpname,*outname;
00075 TMeshAnalysis* analysis;
00076 
00077 // strip any path information from input:
00078 // outname is name without path and postfix
00079 // postfix .lmd is default in all cases
00080 // postfix .lml is a metafile, @ is prefixed
00081  strcpy(filetype,".lmd");
00082  tmpname=argv[2]+strlen(argv[2])-4;
00083  if((pc=strstr(tmpname,".lmd")) != 0)*pc=0;
00084  if((pc=strstr(tmpname,".lml")) != 0){*pc=0;strcpy(filetype,".lml");}
00085  tmpname=argv[2];
00086  if((pc=strstr(argv[2],"@")) != 0) tmpname++;
00087  outname=tmpname;
00088  if((tmpname=strrchr(outname,'/')) != 0) outname=tmpname+1;
00089  strncpy(asf,outname,110);     // auto save file
00090  strcat(asf,"_AS");
00091 
00092 if(strcmp(argv[1],"-gui") == 0)
00093 {
00094 // set up arguments for GUI mode
00095    runningMode = kGUI;
00096    iport = (argc>4) ? atoi(argv[4]) : 5000; // port of GUI server
00097    intype=GO4EV_MBS_FILE;
00098    writeout1=kFALSE;        // no output
00099    writeout2=kFALSE;        // no output
00100    strcpy(serv,"/GSI/lea/gauss"); // default input file
00101    strcpy(out,"gauss_MeshRawEvent");
00102    strcpy(anl,"gauss_MeshAnl");
00103  }
00104  else
00105 // set up arguments for batch mode
00106  {
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    runningMode = kBatch;
00112    strncpy(serv,argv[2],110);     // input (file with full path)
00113         if(strstr(argv[1],"-f")){intype=GO4EV_MBS_FILE;strcat(serv,filetype);}
00114    else if(strstr(argv[1],"-t")) intype=GO4EV_MBS_TRANSPORT;
00115    else if(strstr(argv[1],"-s")) intype=GO4EV_MBS_STREAM;
00116    else if(strstr(argv[1],"-e")) intype=GO4EV_MBS_EVENTSERVER;
00117    else if(strstr(argv[1],"-r")) intype=GO4EV_MBS_REVSERV;
00118    else {
00119        cout << "invalid input type: " << argv[1] << endl;
00120        usage(); // print usage
00121        exit(0);
00122      }
00123    iarg=3;
00124    if(argc > iarg){
00125      if(strstr(argv[iarg],"-o"))writeout2=kTRUE;
00126      else if(strstr(argv[iarg],"-p")){iarg++; sport=atoi(argv[iarg]);}
00127      else maxevents=atoi(argv[iarg]);
00128      iarg++;
00129    }
00130    if(argc > iarg){
00131      if(strstr(argv[iarg],"-o"))writeout2=kTRUE;
00132      else maxevents=atoi(argv[iarg]);
00133      iarg++;
00134    }
00135    if(argc > iarg)maxevents=atoi(argv[iarg]);
00136    if(maxevents == -1) maxevents = 99999999;
00137    cout << endl << "**** Input " << serv << " (" << argv[1] << ") ";
00138    if(strstr(argv[1],"-r")) cout << "port " << sport;
00139    cout << endl << "     output step1: " << out << ".root";
00140    if(writeout1) cout << " enabled"; else cout << " disabled";
00141    cout << endl << "     output step2: " << anl << ".root";
00142    if(writeout2) cout << " enabled"; else cout << " disabled";
00143    cout << endl << "     process " << maxevents << " events" << endl;
00144    cout << "     auto save file: " << asf << ".root" << endl << endl;
00145  }
00146 // Now setup the  analysis itself
00147 // arguments could be adjusted for other needs
00148 
00149 //=================== log message settings =============================
00150 TGo4Log::Instance();        // init logger object
00151 TGo4Log::SetIgnoreLevel(1); // set this to 1 to suppress detailed debug output
00152                             // set this to 2 to get warnings and errors only
00153                             // set this to 3 to get errors only
00154 TGo4Log::OpenLogfile("XXXLogfile.txt","--Logfile for go4 XXX--",kFALSE);
00155 TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages
00156 
00157 analysis = new TMeshAnalysis(serv,intype,sport,out,anl,writeout1,writeout2);
00158 
00159 analysis->SetAutoSaveFile(asf);   // optional
00160 analysis->SetAutoSaveInterval(0); // after n seconds , 0 = at termination of event loop
00161 analysis->SetAutoSave(kFALSE);    // optional
00162 
00163 // ===================== End analysis setup ================================
00164 
00165  if(runningMode == kBatch)
00166    {
00167      cout << "**** Main: starting analysis in batch mode ...  " << endl;
00168      analysis->SetAutoSave(kTRUE);   // optional enable auto-save
00169      if (analysis->InitEventClasses() )
00170        {
00171           analysis->RunImplicitLoop(maxevents);
00172           delete analysis;
00173           cout << "**** Main: Done!"<<endl;
00174           gApplication->Terminate();
00175        }
00176      else
00177        {
00178           cout << "**** Main: Init event classes failed, aborting!"<<endl;
00179           gApplication->Terminate();
00180        }
00181    }
00182  if(runningMode == kGUI)
00183    {
00184      cout << "**** Main: starting analysis in client mode ..." << endl;
00185      // to start histogram server: kTRUE,"base","password"
00186      TGo4AnalysisClient* client = new TGo4AnalysisClient(argc,argv,analysis,kFALSE,"","");
00187      cout << "**** Main created AnalysisClient Instance: "<<client->GetName()<<endl;
00188    }
00189 //=================  start root application loop ==========================
00190 cout << "Run the application loop" << endl;
00191 theApp.Run();
00192 return 0;
00193 }
00194 
00195 void usage()
00196 {
00197 cout << endl;
00198 cout << "* GO4  online analysis    " << endl;
00199 cout << "* H. Essel, GSI, Darmstadt" << endl;
00200 cout << "* calling:                " << endl;
00201 cout << "* MainUserAnalysis -file|-trans|-stream|-evserv|-revserv input [-port #] [-output] [events]" <<endl;
00202 cout << endl;
00203 }
00204 
00205 //----------------------------END OF GO4 SOURCE FILE ---------------------

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