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

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

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