GSI Object Oriented Online Offline (Go4)  GO4-5.3.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MainGo4EventServerExample.cxx
Go to the documentation of this file.
1 // $Id: MainGo4EventServerExample.cxx 1905 2016-04-27 07:54:31Z adamczew $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum für Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
29 #include <stdlib.h>
30 
31 #include "Riostream.h"
32 #include "TApplication.h"
33 #include "TH1.h"
34 #include "TBrowser.h"
35 #include "TCanvas.h"
36 #include "TBenchmark.h"
37 
38 #include "TGo4Log.h"
39 #include "Go4EventServer.h"
40 #include "TGo4SimpleEvent.h"
41 #include "TGo4SimpleSubEvent.h"
43 
44 void usage()
45 {
46  std::cout << "usage: MainGo4EventServerExample eventnumber"<<std::endl;
47 }
48 
49 int main(int argc, char **argv)
50 {
51  if(argc<2) { usage(); return 0; }
52 
53  TApplication theApp("App", &argc, argv);
54 
55  // the following statements control go4 debug output:
56  TGo4Log::Instance(); // init logger object
57  TGo4Log::SetIgnoreLevel(0); // set this to 1 to suppress detailed debug output
58  // set this to 2 to get warnings and errors only
59  // set this to 3 to get errors only
60  TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages to file
61 
62  TBenchmark mybench;
63  const char* num=argv[1];
64  Int_t maxevents=atoi(num);
65  Int_t value=0;
66 
67  TCanvas* can = new TCanvas("MyCanvas","MainGo4EventServer");
68  can->Divide(1,2);
69  TH1D* histo1 = new TH1D ("histogram 1", "mbsevent data",400,0,4000);
70  TH1D* histo2 = new TH1D ("histogram 2", "simpleevent data",400,0,4000);
71 
72  TGo4MbsSubEvent* sub=0;
73  TGo4SimpleSubEvent* simpsub=0;
74 
75  // create the event structure objects:
76  // raw mbs event
77  Short_t idfield[2]= {0,3}; // this array defines the procids for the subevents
78  // note: if other procids are found during read,
79  // subevents of theses procids will be added dynamically
80  TGo4MbsEvent* event = new TGo4MbsEvent(2, idfield, 1);
81  // create initial mbs event with 2 subevents
82  // having the procids giving in the idfield (0 and 3)
83  // initial size for each subevent data field is 1 longword
84  // initial size is reallocated dynamically
85  TGo4SimpleEvent* simpevent = new TGo4SimpleEvent(2);
86  // user event with 2 subevents
88  // the "unpack processor" converting mbs events to user events
89  TGo4EventSource* input=0;
90 // TGo4EventSource* simpinput=0;
91  TGo4EventStore* output=0;
92  TGo4EventStore* simpoutput=0;
93 
94  // Create instance of TGo4EventSource which specifies
95  // the input. Please change subclass of TGo4EventSource
96  // to change input type.
98  TString testfilename=TString::Format("%s/data/test.lmd",getenv("GO4SYS")); // this file is part of go4 distribution
99  input= new TGo4MbsFile(testfilename.Data());
100 // input= new TGo4MbsFile("dat0.lmd");
101  // for listmode file with given path and name
102  // file will be opened in constructor and closed in destructor
104  // input= new TGo4MbsTransport("r2f-2");
105  // connect to mbs transport channel, with given hostname
106  // constructor connects to transport, dtor disconnects
108 // input= new TGo4MbsStream("r2f-2");
109  // connect to mbs stream channel, with given hostname
110  // constructor connects to stream, dtor disconnects
112 // input= new TGo4MbsEventServer("r2f-2");
113  // connect to mbs event server channel, with given hostname
114  // constructor connects to event server, dtor disconnects
116 // input= new TGo4RevServ("r2f-2");
117  // connect to mbs remote event server, with given hostname
118  // constructor connects to revserv , dtor disconnects
119 
120  // optional: output of the mbs raw event classes into ROOT file
121  output = new TGo4FileStore("MbsEvents",99,5);
122 
123  // optional: input of the mbs raw events from ROOT file
124  //simpinput= new TGo4FileSource("MbsEvents");
125 
126  // output of user events into ROOT file
127  simpoutput = new TGo4FileStore("SimpleEvents",99,5);
128 
130  event->PrintEvent();
131  simpevent->PrintEvent();
132 
134  event->SetEventSource(input); // tell raw event to be filled from mbs source
135 // event->SetEventSource(simpinput); // tell raw event to be read from root file
136 
137  proc->SetInputEvent(event); // tell "unpack processor" to take mbs event as input
138  simpevent->SetEventSource(proc); // tell user event to be filled by unpack processor
139 
140 
141  std::cout << "starting event loop:"<< std::endl;
142  mybench.Start("Go4EventServer");
143  for(Int_t t=0; t<maxevents; ++t)
144  {
146  event->Clear();
147  Int_t errmess=event->Fill(); // fills raw event from mbs source
148  if(errmess==GETEVT__NOMORE)
149  {
150  std::cout << "no more events from MbsSource."<< std::endl;
151  break;
152  //gApplication->Terminate();
153  }
154  else if(errmess!=0)
155  {
156  std::cout << "ERROR on event fill."<< std::endl;
157  break;
158  }
160  sub=event->GetSubEvent(3); // subevent by procid
161  if (sub)
162  {
163  value= sub->Data(1); // access data array at 1
164  if(value)
165  {
166  histo1->Fill(value);
167  //std::cout << "found value:" << value << std::endl;
168  }
169  }
170 
171 
172 
173 
174  if(output)
175  output->Store(event); // write mbs raw event to ROOT file
176 
178  simpevent->Clear();
179  simpevent->Fill(); // this will invoke unpack processor methods
181  simpsub=simpevent->GetSubEvent(3);
182  if (simpsub)
183  {
184  value= simpsub->fiD1; // userevents have data as members,
185  // may also be seen in ROOT TreeBrowser
186  if(value)
187 
188  {
189  histo2->Fill(value);
190  //std::cout << "found value:" << value << std::endl;
191  }
192 
193  }
194 
195  if(simpoutput)
196  simpoutput->Store(simpevent); // write user event to ROOT file
197 
198 
199  if(t%2000==0 && t!=0)
200  {
201  event->PrintEvent();
202  can->cd(1);
203  histo1->Draw();
204  can->cd(2);
205  histo2->Draw();
206  can->Modified();
207  can->Update();
208  std::cout << " 2000 events processed "<< std::endl;
209  }
210 
211  } // for(.....)
212  std::cout << "\t finished filling and saving events."<<std::endl;
213  mybench.Show("Go4EventServer");
214  delete output;
215  delete event;
216  delete input;
217  delete simpoutput;
218  delete simpevent;
219  delete proc;
220  //gApplication->Terminate();
221  theApp.Run();
222  return 0;
223 }
static TGo4Log * Instance()
Definition: TGo4Log.cxx:87
virtual Int_t Store(TGo4EventElement *event)=0
static void SetIgnoreLevel(Int_t level)
Definition: TGo4Log.cxx:322
#define GETEVT__NOMORE
Definition: f_evt.h:141
virtual Int_t Fill()
virtual void Clear(Option_t *t="")
TGo4SimpleSubEvent * GetSubEvent(Short_t procid)
void SetInputEvent(TGo4EventElement *raw)
int main(int argc, char **argv)
void SetEventSource(TGo4EventSource *src)
Int_t Data(Int_t i) const
static void LogfileEnable(Bool_t on=kTRUE)
Definition: TGo4Log.cxx:369