client_test.C
Go to the documentation of this file.
1 //
2 // Test GENIE event server client
3 //
4 // C.Andreopoulos
5 //
6 
7 gROOT->Reset();
8 
9 int port = 9090;
10 
11 TSocket * sock = 0;
12 
13 bool handshake (void);
14 void configure (string particle_list);
15 void request_xsec (string opt);
16 void request_event (string opt);
17 void shutdown (void);
18 
19 //..........................................................................
21 {
22  // handhake with genie event server
23  //
24  bool is_alive = handshake();
25  assert(is_alive);
26 
27  // configure genie event server
28  //
29  configure("load-splines neutrino-list=14,-14,12,-12 target-list=1000260560");
30 
31  // request total cross section data (sum for all enabled channels) for
32  // some initial state
33  //
34  request_xsec("14 1000260560");
35 
36  // request the generation of some events
37  //
38  request_event("14011011 1 14 1.849474 0.740705 53.184013 14 1000260560 0.012129 -0.941614 16.443062");
39  request_event("14011011 2 14 2.187474 0.362736 22.218212 14 1000260560 0.120932 0.239200 3.212121");
40  request_event("14011011 3 14 1.094340 0.127128 18.210291 14 1000260560 0.239001 -0.129101 8.029121");
41 
42  // shutdown the genie event server
43  //
44  shutdown();
45 }
46 //..........................................................................
47 bool handshake(void)
48 {
49  sock = new TSocket("localhost", port);
50  if(!sock) return false;
51 
52  cout << "Pinging the GENIE event server" << endl;
53 
54  sock->Send("RUB GENIE LAMP");
55  cout << "Sent: RUB GENIE LAMP" << endl;
56 
57  char mesg[2048];
58  sock->Recv(mesg,2048);
59  cout << "Received: " << mesg << endl;
60 
61  bool is_alive = (strcmp(mesg,"YOU HAVE 3 WISHES!") == 0);
62  return is_alive;
63 }
64 //..........................................................................
65 void configure(string particle_list)
66 {
67 // Sytnax:
68 // mesg sent:
69 // CONFIG: load-splines neutrino-list=comma_separated_list_of_pdg_codes target_list=comma_separated_list_of_pdg_codes
70 //
71  cout << "Configuring the GENIE event server" << endl;
72 
73  string cmd = "CONFIG: " + particle_list;
74 
75  sock->Send(cmd.c_str());
76  cout << "Sent: " << cmd << endl;
77 
78  char mesg[2048];
79  sock->Recv(mesg,2048);
80  cout << "Received: " << mesg << endl;
81 
82  bool is_configured = (strcmp(mesg,"CONFIG COMPLETED") == 0);
83  assert(is_configured);
84 }
85 //..........................................................................
86 void request_xsec(string opt)
87 {
88 // Syntax:
89 // mesg sent:
90 // XSEC: ipdgnu ipdgtgt
91 // mesg recv (E in GeV, Sig in 1E-38 cm^2):
92 // XSECSPL: npoints
93 // knot(0) E(0) Sig(0)
94 // knot(1) E(1) Sig(1)
95 // knot(2) E(2) Sig(2)
96 // ....
97 //
98 
99  string cmd = "XSEC: " + opt;
100 
101  sock->Send(cmd.c_str());
102  cout << "Sent: " << cmd << endl;
103 
104  while(1) {
105  char mesg[2048];
106  sock->Recv(mesg,2048);
107  cout << "Received: " << mesg << endl;
108 
109  bool exit_loop = (strcmp(mesg,"FAILED")==0) ||
110  (strcmp(mesg,"XSEC SENT")==0);
111 
112  if(exit_loop) break;
113  }
114 }
115 //..........................................................................
116 void request_event(string opt)
117 {
118 // Syntax:
119 // mesg sent:
120 // EVTVTX: irun ievt ipdgnunosoc vtx_x vtx_y vtx_z ipdgnu ipdgtgt px_nu py_nu pz_nu
121 // mesg recv:
122 // EVTREC: irun ievt ipdgnunosoc vtx_x vtx_y vtx_z
123 // ipdgnu ipdgtgt px_nu py_nu pz_nu
124 // int_type iaction nucleon struck-quark xbj_int ybj_int w2_int q2_int
125 // total-xsection diff-xsection ihadmod
126 // STDHEP: nlines
127 // indx ist ipdg jmo1 jmo2 jda1 jda2 px py pz E mass vx vy vz time
128 // ...
129 // indx ist ipdg jmo1 jmo2 jda1 jda2 px py pz E mass vx vy vz time
130 //
131  string cmd = "EVTVTX: " + opt;
132 
133  sock->Send(cmd.c_str());
134  cout << "Sent: " << cmd << endl;
135 
136  while(1) {
137  char mesg[2048];
138  sock->Recv(mesg,2048);
139  cout << "Received: " << mesg << endl;
140 
141  bool exit_loop = (strcmp(mesg,"FAILED")==0) ||
142  (strcmp(mesg,"EVENT GENERATED")==0);
143 
144  if(exit_loop) break;
145  }
146 }
147 //..........................................................................
148 void shutdown(void)
149 {
150  sock->Send("SHUTDOWN");
151  cout << "Sent: SHUTDOWN" << endl;
152 
153  char mesg[2048];
154  sock->Recv(mesg,2048);
155  cout << "Received: " << mesg << endl;
156 
157  sock->Close();
158 }
159 //..........................................................................
160 
TSocket * sock
Definition: client_test.C:11
void shutdown(void)
Definition: client_test.C:148
string cmd
Definition: run_hadd.py:52
void request_event(string opt)
Definition: client_test.C:116
OStream cout
Definition: OStream.cxx:6
bool handshake(void)
Definition: client_test.C:47
void client_test()
Definition: client_test.C:20
void request_xsec(string opt)
Definition: client_test.C:86
assert(nhit_max >=nhit_nbins)
int port
Definition: client_test.C:9
void configure(string particle_list)
Definition: client_test.C:65