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

MainGo4EventServerExample.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 //----------------------------------------------------------------
00031 #include "Riostream.h"
00032 #include <stdlib.h>
00033 
00034 #include "TApplication.h"
00035 
00036 #include "TH1.h"
00037 #include "TBrowser.h"
00038 #include "TCanvas.h"
00039 #include "TBenchmark.h"
00040 
00041 #include "TGo4Log.h"
00042 
00043 #include "Go4EventServer.h"
00044 
00045 #include "TGo4SimpleEvent.h"
00046 #include "TGo4SimpleSubEvent.h"
00047 #include "TGo4SimpleEventProcessor.h"
00048 
00049 void usage();
00050 
00051 int main(int argc, char **argv)
00052 {
00053      if(argc<2) { usage(); return 0; }
00054 
00055      TApplication theApp("App", &argc, argv);
00056 
00057      // the following statements control go4 debug output:
00058      TGo4Log::Instance(); // init logger object
00059      TGo4Log::SetIgnoreLevel(0); // set this to 1 to suppress detailed debug output
00060                            // set this to 2 to get warnings and errors only
00061                            // set this to 3 to get errors only
00062      TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages to file
00063 
00064      TBenchmark mybench;
00065      Text_t* num=argv[1];
00066      Int_t maxevents=atoi(num);
00067      Int_t value=0;
00068 
00069      TCanvas* can = new TCanvas("MyCanvas","MainGo4EventServer");
00070      can->Divide(1,2);
00071      TH1D* histo1 = new TH1D ("histogram 1", "mbsevent data",400,0,4000);
00072      TH1D* histo2 = new TH1D ("histogram 2", "simpleevent data",400,0,4000);
00073 
00074      TGo4MbsSubEvent* sub=0;
00075      TGo4SimpleSubEvent* simpsub=0;
00076 
00077      // create the event structure objects:
00078      // raw mbs event
00079      Short_t idfield[2]= {0,3}; // this array defines the procids for the subevents
00080                                 // note: if other procids are found during read,
00081                                 // subevents of theses procids will be added dynamically
00082      TGo4MbsEvent* event = new TGo4MbsEvent(2, idfield, 1);
00083                                 // create initial mbs event with 2 subevents
00084                                 // having the procids giving in the idfield (0 and 3)
00085                                 // initial size for each subevent data field is 1 longword
00086                                 // initial size is reallocated dynamically
00087      TGo4SimpleEvent* simpevent = new TGo4SimpleEvent(2);
00088                                 // user event with 2 subevents
00089      TGo4SimpleEventProcessor* proc = new TGo4SimpleEventProcessor();
00090                                 // the "unpack processor" converting mbs events to user events
00091      TGo4EventSource* input=0;
00092 //         TGo4EventSource* simpinput=0;
00093      TGo4EventStore* output=0;
00094      TGo4EventStore* simpoutput=0;
00095 
00096      // Create instance of TGo4EventSource which specifies
00097      // the input. Please change subclass of TGo4EventSource
00098      // to change input type.
00100      input= new TGo4MbsFile("/GSI/lea/examples/gauss.lmd");
00101 //         input= new TGo4MbsFile("dat0.lmd");
00102         // for listmode file with given path and name
00103         // file will be opened in constructor and closed in destructor
00105      //         input= new TGo4MbsTransport("r2f-2");
00106         // connect to mbs transport channel, with given hostname
00107         // constructor connects to transport, dtor disconnects
00109 //         input= new TGo4MbsStream("r2f-2");
00110         // connect to mbs stream channel, with given hostname
00111         // constructor connects to stream, dtor disconnects
00113 //         input= new TGo4MbsEventServer("r2f-2");
00114         // connect to mbs event server channel, with given hostname
00115         // constructor connects to event server, dtor disconnects
00117 //         input= new TGo4RevServ("r2f-2");
00118         // connect to mbs remote event server, with given hostname
00119         // constructor connects to revserv , dtor disconnects
00120 
00121      // optional: output of the mbs raw event classes into ROOT file
00122      output = new TGo4FileStore("MbsEvents",99,5);
00123 
00124      // optional: input of the mbs raw events from ROOT file
00125      //simpinput= new TGo4FileSource("MbsEvents");
00126 
00127      // output of user events into ROOT file
00128      simpoutput = new TGo4FileStore("SimpleEvents",99,5);
00129 
00131      event->PrintEvent();
00132      simpevent->PrintEvent();
00133 
00135      event->SetEventSource(input); // tell raw event to be filled from mbs source
00136 //        event->SetEventSource(simpinput); // tell raw event to be read from root file
00137 
00138      proc->SetInputEvent(event); // tell "unpack processor" to take mbs event as input
00139      simpevent->SetEventSource(proc); // tell user event to be filled by unpack processor
00140 
00141 
00142      cout << "starting event loop:"<< endl;
00143      mybench.Start("Go4EventServer");
00144      for(Int_t t=0; t<maxevents; ++t)
00145         {
00147            event->Clear();
00148            Int_t errmess=event->Fill(); // fills raw event from mbs source
00149            if(errmess==GETEVT__NOMORE)
00150               {
00151                  cout << "no more events from MbsSource."<< endl;
00152                  break;
00153                  //gApplication->Terminate();
00154               }
00155            else if(errmess!=0)
00156               {
00157                  cout << "ERROR on event fill."<< endl;
00158                  break;
00159               }
00161            sub=event->GetSubEvent(3); // subevent by procid
00162            if (sub)
00163               {
00164                  value= sub->Data(1); // access data array at 1
00165                  if(value)
00166                     {
00167                        histo1->Fill(value);
00168                        //cout << "found value:" << value << endl;
00169                     }
00170               }
00171 
00172 
00173 
00174 
00175            if(output)
00176              output->Store(event);   // write mbs raw event to ROOT file
00177 
00179            simpevent->Clear();
00180            simpevent->Fill(); // this will invoke unpack processor methods
00182            simpsub=simpevent->GetSubEvent(3);
00183            if (simpsub)
00184               {
00185                  value= simpsub->fiD1;  // userevents have data as members,
00186                                         // may also be seen in ROOT TreeBrowser
00187                  if(value)
00188 
00189                     {
00190                        histo2->Fill(value);
00191                        //cout << "found value:" << value << endl;
00192                     }
00193 
00194               }
00195 
00196            if(simpoutput)
00197              simpoutput->Store(simpevent); // write user event to ROOT file
00198 
00199 
00200            if(t%2000==0 && t!=0)
00201               {
00202                  event->PrintEvent();
00203                  can->cd(1);
00204                  histo1->Draw();
00205                  can->cd(2);
00206                  histo2->Draw();
00207                  can->Modified();
00208                  can->Update();
00209                  cout << " 2000 events processed "<< endl;
00210               }
00211 
00212         } // for(.....)
00213      cout << "\t finished filling and saving events."<<endl;
00214      mybench.Show("Go4EventServer");
00215      delete output;
00216      delete event;
00217      delete input;
00218      delete simpoutput;
00219      delete simpevent;
00220      delete proc;
00221      //gApplication->Terminate();
00222      theApp.Run();
00223      return 0;
00224 }
00225 
00226 void usage()
00227 {
00228    cout << "usage: MainGo4EventServerExample eventnumber"<<endl;
00229 }
00230 
00231 
00232 
00233 
00234 
00235 //----------------------------END OF GO4 SOURCE FILE ---------------------

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