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