GSI Object Oriented Online Offline (Go4) GO4-6.4.0
Loading...
Searching...
No Matches
MainGo4EventServerExample.cxx
Go to the documentation of this file.
1// $Id$
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
22
23#include <iostream>
24
25#include "TApplication.h"
26#include "TH1.h"
27#include "TCanvas.h"
28#include "TBenchmark.h"
29
30#include "TGo4Log.h"
31#include "Go4EventServer.h"
32#include "TGo4SimpleEvent.h"
33#include "TGo4SimpleSubEvent.h"
35
36int main(int argc, char **argv)
37{
38 if(argc<2) {
39 std::cout << "usage: MainGo4EventServerExample eventnumber"<<std::endl;
40 return 0;
41 }
42
43 TApplication theApp("App", &argc, argv);
44
45 // the following statements control go4 debug output:
46 TGo4Log::Instance(); // init logger object
47 TGo4Log::SetIgnoreLevel(0); // set this to 1 to suppress detailed debug output
48 // set this to 2 to get warnings and errors only
49 // set this to 3 to get errors only
50 TGo4Log::LogfileEnable(kFALSE); // will enable or disable logging all messages to file
51
52 TBenchmark mybench;
53 const char *num = argv[1];
54 Int_t maxevents = atoi(num);
55 Int_t value = 0;
56
57 TCanvas *can = new TCanvas("MyCanvas","MainGo4EventServer");
58 can->Divide(1,2);
59 TH1D* histo1 = new TH1D ("histogram 1", "mbsevent data",400,0,4000);
60 TH1D* histo2 = new TH1D ("histogram 2", "simpleevent data",400,0,4000);
61
62 TGo4MbsSubEvent *sub = nullptr;
63 TGo4SimpleSubEvent* simpsub = nullptr;
64
65 // create the event structure objects:
66 // raw mbs event
67 Short_t idfield[2] = {0,3}; // this array defines the procids for the subevents
68 // note: if other procids are found during read,
69 // subevents of theses procids will be added dynamically
70 TGo4MbsEvent *event = new TGo4MbsEvent(2, idfield, 1);
71 // create initial mbs event with 2 subevents
72 // having the procids giving in the idfield (0 and 3)
73 // initial size for each subevent data field is 1 longword
74 // initial size is reallocated dynamically
75 TGo4SimpleEvent* simpevent = new TGo4SimpleEvent(2);
76 // user event with 2 subevents
78 // the "unpack processor" converting mbs events to user events
79 TGo4EventSource *input = nullptr;
80 // TGo4EventSource *simpinput = nullptr;
81 TGo4EventStore *output = nullptr;
82 TGo4EventStore *simpoutput = nullptr;
83
84 // Create instance of TGo4EventSource which specifies
85 // the input. Please change subclass of TGo4EventSource
86 // to change input type.
88 TString testfilename = TString::Format("%s/data/test.lmd",getenv("GO4SYS")); // this file is part of go4 distribution
89 input = new TGo4MbsFile(testfilename.Data());
90// input= new TGo4MbsFile("dat0.lmd");
91 // for listmode file with given path and name
92 // file will be opened in constructor and closed in destructor
94 // input= new TGo4MbsTransport("r2f-2");
95 // connect to mbs transport channel, with given hostname
96 // constructor connects to transport, dtor disconnects
98// input= new TGo4MbsStream("r2f-2");
99 // connect to mbs stream channel, with given hostname
100 // constructor connects to stream, dtor disconnects
102// input= new TGo4MbsEventServer("r2f-2");
103 // connect to mbs event server channel, with given hostname
104 // constructor connects to event server, dtor disconnects
106// input= new TGo4RevServ("r2f-2");
107 // connect to mbs remote event server, with given hostname
108 // constructor connects to revserv, dtor disconnects
109
110 // optional: output of the mbs raw event classes into ROOT file
111 output = new TGo4FileStore("MbsEvents",99,5);
112
113 // optional: input of the mbs raw events from ROOT file
114 //simpinput= new TGo4FileSource("MbsEvents");
115
116 // output of user events into ROOT file
117 simpoutput = new TGo4FileStore("SimpleEvents",99,5);
118
120 event->PrintEvent();
121 simpevent->PrintEvent();
122
124 event->SetEventSource(input); // tell raw event to be filled from mbs source
125// event->SetEventSource(simpinput); // tell raw event to be read from root file
126
127 proc->SetInputEvent(event); // tell "unpack processor" to take mbs event as input
128 simpevent->SetEventSource(proc); // tell user event to be filled by unpack processor
129
130
131 std::cout << "starting event loop:"<< std::endl;
132 mybench.Start("Go4EventServer");
133 for(Int_t t = 0; t < maxevents; ++t)
134 {
136 event->Clear();
137 Int_t errmess = event->Fill(); // fills raw event from mbs source
138 if(errmess==GETEVT__NOMORE)
139 {
140 std::cout << "no more events from MbsSource."<< std::endl;
141 break;
142 //gApplication->Terminate();
143 }
144 else if(errmess != 0)
145 {
146 std::cout << "ERROR on event fill."<< std::endl;
147 break;
148 }
150 sub=event->GetSubEvent(3); // subevent by procid
151 if (sub) {
152 value = sub->Data(1); // access data array at 1
153 if (value) {
154 histo1->Fill(value);
155 }
156 }
157
158 if(output)
159 output->Store(event); // write mbs raw event to ROOT file
160
162 simpevent->Clear();
163 simpevent->Fill(); // this will invoke unpack processor methods
165 simpsub=simpevent->GetSubEvent(3);
166 if (simpsub)
167 {
168 value= simpsub->fiD1; // userevents have data as members,
169 // may also be seen in ROOT TreeBrowser
170 if(value) {
171 histo2->Fill(value);
172 }
173 }
174
175 if(simpoutput)
176 simpoutput->Store(simpevent); // write user event to ROOT file
177
178
179 if(t%2000 == 0 && t != 0) {
180 event->PrintEvent();
181 can->cd(1);
182 histo1->Draw();
183 can->cd(2);
184 histo2->Draw();
185 can->Modified();
186 can->Update();
187 std::cout << " 2000 events processed "<< std::endl;
188 }
189
190 } // for(.....)
191 std::cout << "\t finished filling and saving events."<<std::endl;
192 mybench.Show("Go4EventServer");
193 delete output;
194 delete event;
195 delete input;
196 delete simpoutput;
197 delete simpevent;
198 delete proc;
199 //gApplication->Terminate();
200 theApp.Run();
201 return 0;
202}
int main(int argc, char **argv)
MainGo4EventServerExample.
void SetEventSource(TGo4EventSource *src)
Setter for the event source that is currently used by the Fill method.
void SetInputEvent(TGo4EventElement *raw)
Sets reference to external raw event which is used by the concrete processor to unpack the interestin...
The abstract interface class for the raw event store.
virtual Int_t Store(TGo4EventElement *event)=0
Stores eventelement event into the storage implementation.
Event store which fills entries to an own root TTree in a TFile.
static TGo4Log * Instance()
Definition TGo4Log.cxx:85
static void SetIgnoreLevel(Int_t level)
Define threshold for output.
Definition TGo4Log.cxx:332
static void LogfileEnable(Bool_t on=kTRUE)
switch writing to logfile on or off
Definition TGo4Log.cxx:363
Wrapper for the standard gsi event structure as delivered from mbs.
Implements the gsi mbs lmd file source.
Definition TGo4MbsFile.h:30
Subevent class for gsi mbs data.
Int_t Data(Int_t i) const
Returns the value at position i in the fiData field.
Simple Event structure containing a fixed size TClonesArray of subevents.
Int_t Fill() override
Method called by the event owner (analysis step) to fill the event element from the set event source.
void PrintEvent() override
Method prints content of the event.
TGo4SimpleSubEvent * GetSubEvent(Short_t procid)
Access to subevent in list by procid.
void Clear(Option_t *opt="") override
Method called by the event owner (analysis step) to clear the event element.
Int_t fiD1
Data longword.
#define GETEVT__NOMORE
Definition f_evt.h:134